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 "ZPooledConnection.hxx"
27 #include "ZConnectionWrapper.hxx"
28 #ifndef _CONNECTIVITY_CONNECTIONWRAPPER_HXX_
29 #include "connectivity/ConnectionWrapper.hxx"
30 #endif
31 #include <com/sun/star/sdbc/XCloseable.hpp>
32 #include <comphelper/types.hxx>
33 #include <comphelper/uno3.hxx>
34 #include <cppuhelper/component.hxx>
35 #include <cppuhelper/compbase1.hxx>
36 
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::sdbc;
40 using namespace ::com::sun::star::container;
41 using namespace ::com::sun::star::reflection;
42 using namespace connectivity;
43 using namespace ::osl;
44 
OPooledConnection(const Reference<XConnection> & _xConnection,const Reference<::com::sun::star::reflection::XProxyFactory> & _rxProxyFactory)45 OPooledConnection::OPooledConnection(const Reference< XConnection >& _xConnection,
46 									const Reference< ::com::sun::star::reflection::XProxyFactory >& _rxProxyFactory)
47 	: OPooledConnection_Base(m_aMutex)
48 	,m_xRealConnection(_xConnection)
49 	,m_xProxyFactory(_rxProxyFactory)
50 {
51 
52 }
53 // -----------------------------------------------------------------------------
54 // OComponentHelper
disposing(void)55 void SAL_CALL OPooledConnection::disposing(void)
56 {
57 	MutexGuard aGuard(m_aMutex);
58 	if (m_xComponent.is())
59 		m_xComponent->removeEventListener(this);
60 m_xComponent.clear();
61 	::comphelper::disposeComponent(m_xRealConnection);
62 }
63 // -----------------------------------------------------------------------------
64 // XEventListener
disposing(const EventObject &)65 void SAL_CALL OPooledConnection::disposing( const EventObject& /*Source*/ ) throw (RuntimeException)
66 {
67 m_xComponent.clear();
68 }
69 // -----------------------------------------------------------------------------
70 //XPooledConnection
getConnection()71 Reference< XConnection > OPooledConnection::getConnection()  throw(SQLException, RuntimeException)
72 {
73 	if(!m_xComponent.is() && m_xRealConnection.is())
74 	{
75 		Reference< XAggregation > xConProxy = m_xProxyFactory->createProxy(m_xRealConnection.get());
76 		m_xComponent = new OConnectionWeakWrapper(xConProxy);
77 		// register as event listener for the new connection
78 		if (m_xComponent.is())
79 			m_xComponent->addEventListener(this);
80 	}
81 	return Reference< XConnection >(m_xComponent,UNO_QUERY);
82 }
83 // -----------------------------------------------------------------------------
84 
85