1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 #include "ZDriverWrapper.hxx"
27 #include "ZConnectionPool.hxx"
28 #include <osl/diagnose.h>
29 
30 //........................................................................
31 namespace connectivity
32 {
33 //........................................................................
34 
35 	using namespace ::com::sun::star::uno;
36 	using namespace ::com::sun::star::sdbc;
37 	using namespace ::com::sun::star::beans;
38 
39 	//====================================================================
40 	//= ODriverWrapper
41 	//====================================================================
42 	//--------------------------------------------------------------------
ODriverWrapper(Reference<XAggregation> & _rxAggregateDriver,OConnectionPool * _pPool)43 	ODriverWrapper::ODriverWrapper( Reference< XAggregation >& _rxAggregateDriver, OConnectionPool* _pPool )
44 		:m_pConnectionPool(_pPool)
45 	{
46 		OSL_ENSURE(_rxAggregateDriver.is(), "ODriverWrapper::ODriverWrapper: invalid aggregate!");
47 		OSL_ENSURE(m_pConnectionPool, "ODriverWrapper::ODriverWrapper: invalid connection pool!");
48 
49 		if (m_pConnectionPool)
50 			m_pConnectionPool->acquire();
51 
52 		osl_incrementInterlockedCount( &m_refCount );
53 		if (_rxAggregateDriver.is())
54 		{
55 			// transfer the (one and only) real ref to the aggregate to our member
56 			m_xDriverAggregate = _rxAggregateDriver;
57 			_rxAggregateDriver = NULL;
58 
59 			// a second "real" reference
60 			m_xDriver = Reference< XDriver >(m_xDriverAggregate, UNO_QUERY);
61 			OSL_ENSURE(m_xDriver.is(), "ODriverWrapper::ODriverWrapper: invalid aggregate (no XDriver)!");
62 
63 			// set ourself as delegator
64 			m_xDriverAggregate->setDelegator( static_cast< XWeak* >( this ) );
65 		}
66 		osl_decrementInterlockedCount( &m_refCount );
67 	}
68 
69 	//--------------------------------------------------------------------
~ODriverWrapper()70 	ODriverWrapper::~ODriverWrapper()
71 	{
72 		if (m_xDriverAggregate.is())
73 			m_xDriverAggregate->setDelegator(NULL);
74 
75 		if (m_pConnectionPool)
76 			m_pConnectionPool->release();
77 		m_pConnectionPool = NULL;
78 	}
79 
80 	//--------------------------------------------------------------------
queryInterface(const Type & _rType)81 	Any SAL_CALL ODriverWrapper::queryInterface( const Type& _rType ) throw (RuntimeException)
82 	{
83 		Any aReturn = ODriverWrapper_BASE::queryInterface(_rType);
84 		return aReturn.hasValue() ? aReturn : (m_xDriverAggregate.is() ? m_xDriverAggregate->queryAggregation(_rType) : aReturn);
85 	}
86 
87 	//--------------------------------------------------------------------
connect(const::rtl::OUString & url,const Sequence<PropertyValue> & info)88 	Reference< XConnection > SAL_CALL ODriverWrapper::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw (SQLException, RuntimeException)
89 	{
90 		Reference< XConnection > xConnection;
91 		if (m_pConnectionPool)
92 			// route this through the pool
93 			xConnection = m_pConnectionPool->getConnectionWithInfo( url, info );
94 		else if (m_xDriver.is())
95 			xConnection = m_xDriver->connect( url, info );
96 
97 		return xConnection;
98 	}
99 
100 	//--------------------------------------------------------------------
acceptsURL(const::rtl::OUString & url)101 	sal_Bool SAL_CALL ODriverWrapper::acceptsURL( const ::rtl::OUString& url ) throw (SQLException, RuntimeException)
102 	{
103 		return m_xDriver.is() && m_xDriver->acceptsURL(url);
104 	}
105 
106 	//--------------------------------------------------------------------
getPropertyInfo(const::rtl::OUString & url,const Sequence<PropertyValue> & info)107 	Sequence< DriverPropertyInfo > SAL_CALL ODriverWrapper::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw (SQLException, RuntimeException)
108 	{
109 		Sequence< DriverPropertyInfo > aInfo;
110 		if (m_xDriver.is())
111 			aInfo = m_xDriver->getPropertyInfo(url, info);
112 		return aInfo;
113 	}
114 
115 	//--------------------------------------------------------------------
getMajorVersion()116 	sal_Int32 SAL_CALL ODriverWrapper::getMajorVersion(  ) throw (RuntimeException)
117 	{
118 		return m_xDriver.is() ? m_xDriver->getMajorVersion() : 0;
119 	}
120 
121 	//--------------------------------------------------------------------
getMinorVersion()122 	sal_Int32 SAL_CALL ODriverWrapper::getMinorVersion(  ) throw (RuntimeException)
123 	{
124 		return m_xDriver.is() ? m_xDriver->getMinorVersion() : 0;
125 	}
126 
127 //........................................................................
128 }	// namespace connectivity
129 //........................................................................
130 
131 
132