LibreOffice Module connectivity (master) 1
ZDriverWrapper.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "ZDriverWrapper.hxx"
21#include "ZConnectionPool.hxx"
22#include <osl/diagnose.h>
23
24
25namespace connectivity
26{
27
28
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::sdbc;
31 using namespace ::com::sun::star::beans;
32
33 ODriverWrapper::ODriverWrapper( Reference< XAggregation >& _rxAggregateDriver, OConnectionPool* _pPool )
34 :m_pConnectionPool(_pPool)
35 {
36 OSL_ENSURE(_rxAggregateDriver.is(), "ODriverWrapper::ODriverWrapper: invalid aggregate!");
37 OSL_ENSURE(m_pConnectionPool.is(), "ODriverWrapper::ODriverWrapper: invalid connection pool!");
38
39 osl_atomic_increment( &m_refCount );
40 if (_rxAggregateDriver.is())
41 {
42 // transfer the (one and only) real ref to the aggregate to our member
43 m_xDriverAggregate = _rxAggregateDriver;
44 _rxAggregateDriver = nullptr;
45
46 // a second "real" reference
47 m_xDriver.set(m_xDriverAggregate, UNO_QUERY);
48 OSL_ENSURE(m_xDriver.is(), "ODriverWrapper::ODriverWrapper: invalid aggregate (no XDriver)!");
49
50 // set ourself as delegator
51 m_xDriverAggregate->setDelegator( getXWeak() );
52 }
53 osl_atomic_decrement( &m_refCount );
54 }
55
56
58 {
59 if (m_xDriverAggregate.is())
60 m_xDriverAggregate->setDelegator(nullptr);
61 }
62
63
64 Any SAL_CALL ODriverWrapper::queryInterface( const Type& _rType )
65 {
66 Any aReturn = ODriverWrapper_BASE::queryInterface(_rType);
67 return aReturn.hasValue() ? aReturn : (m_xDriverAggregate.is() ? m_xDriverAggregate->queryAggregation(_rType) : aReturn);
68 }
69
70
71 Reference< XConnection > SAL_CALL ODriverWrapper::connect( const OUString& url, const Sequence< PropertyValue >& info )
72 {
73 Reference< XConnection > xConnection;
74 if (m_pConnectionPool.is())
75 // route this through the pool
76 xConnection = m_pConnectionPool->getConnectionWithInfo( url, info );
77 else if (m_xDriver.is())
78 xConnection = m_xDriver->connect( url, info );
79
80 return xConnection;
81 }
82
83
84 sal_Bool SAL_CALL ODriverWrapper::acceptsURL( const OUString& url )
85 {
86 return m_xDriver.is() && m_xDriver->acceptsURL(url);
87 }
88
89
90 Sequence< DriverPropertyInfo > SAL_CALL ODriverWrapper::getPropertyInfo( const OUString& url, const Sequence< PropertyValue >& info )
91 {
92 Sequence< DriverPropertyInfo > aInfo;
93 if (m_xDriver.is())
94 aInfo = m_xDriver->getPropertyInfo(url, info);
95 return aInfo;
96 }
97
98
99 sal_Int32 SAL_CALL ODriverWrapper::getMajorVersion( )
100 {
101 return m_xDriver.is() ? m_xDriver->getMajorVersion() : 0;
102 }
103
104
106 {
107 return m_xDriver.is() ? m_xDriver->getMinorVersion() : 0;
108 }
109
110
111} // namespace connectivity
112
113
114/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::sdbc::XDriver > m_xDriver
virtual ~ODriverWrapper() override
dtor
virtual sal_Int32 SAL_CALL getMinorVersion() override
css::uno::Reference< css::uno::XAggregation > m_xDriverAggregate
virtual sal_Int32 SAL_CALL getMajorVersion() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
ODriverWrapper(css::uno::Reference< css::uno::XAggregation > &_rxAggregateDriver, OConnectionPool *_pPool)
creates a new wrapper for a driver
virtual sal_Bool SAL_CALL acceptsURL(const OUString &url) override
virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info) override
rtl::Reference< OConnectionPool > m_pConnectionPool
virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info) override
ULONG m_refCount
Type
unsigned char sal_Bool