update dev300-m58
[ooovba.git] / connectivity / source / cpool / ZPooledConnection.cxx
blob64293811d5f2b5984a717f7eef44aaf790b919f2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ZPooledConnection.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "ZPooledConnection.hxx"
34 #include "ZConnectionWrapper.hxx"
35 #ifndef _CONNECTIVITY_CONNECTIONWRAPPER_HXX_
36 #include "connectivity/ConnectionWrapper.hxx"
37 #endif
38 #include <com/sun/star/sdbc/XCloseable.hpp>
39 #include <comphelper/types.hxx>
40 #include <comphelper/uno3.hxx>
41 #include <cppuhelper/component.hxx>
42 #include <cppuhelper/compbase1.hxx>
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::lang;
46 using namespace ::com::sun::star::sdbc;
47 using namespace ::com::sun::star::container;
48 using namespace ::com::sun::star::reflection;
49 using namespace connectivity;
50 using namespace ::osl;
52 OPooledConnection::OPooledConnection(const Reference< XConnection >& _xConnection,
53 const Reference< ::com::sun::star::reflection::XProxyFactory >& _rxProxyFactory)
54 : OPooledConnection_Base(m_aMutex)
55 ,m_xRealConnection(_xConnection)
56 ,m_xProxyFactory(_rxProxyFactory)
60 // -----------------------------------------------------------------------------
61 // OComponentHelper
62 void SAL_CALL OPooledConnection::disposing(void)
64 MutexGuard aGuard(m_aMutex);
65 if (m_xComponent.is())
66 m_xComponent->removeEventListener(this);
67 m_xComponent.clear();
68 ::comphelper::disposeComponent(m_xRealConnection);
70 // -----------------------------------------------------------------------------
71 // XEventListener
72 void SAL_CALL OPooledConnection::disposing( const EventObject& /*Source*/ ) throw (RuntimeException)
74 m_xComponent.clear();
76 // -----------------------------------------------------------------------------
77 //XPooledConnection
78 Reference< XConnection > OPooledConnection::getConnection() throw(SQLException, RuntimeException)
80 if(!m_xComponent.is() && m_xRealConnection.is())
82 Reference< XAggregation > xConProxy = m_xProxyFactory->createProxy(m_xRealConnection.get());
83 m_xComponent = new OConnectionWeakWrapper(xConProxy);
84 // register as event listener for the new connection
85 if (m_xComponent.is())
86 m_xComponent->addEventListener(this);
88 return Reference< XConnection >(m_xComponent,UNO_QUERY);
90 // -----------------------------------------------------------------------------