diff options
author | Frank Schönheit <fs@openoffice.org> | 2001-05-25 09:59:48 +0000 |
---|---|---|
committer | Frank Schönheit <fs@openoffice.org> | 2001-05-25 09:59:48 +0000 |
commit | b13fb65f71db4bfe60aabc26a217b39e9bcb6326 (patch) | |
tree | 0581b9e2348289dbf780940abca81121ee7d4678 /connectivity/source | |
parent | 2eea835a28c63057a2e08fe4339bdaca843ddf3a (diff) |
#86996# getDriverByURL: return a proxy for the real driver, so we can reroute the XDriver::connect through the pool
Diffstat (limited to 'connectivity/source')
-rw-r--r-- | connectivity/source/cpool/ZConnectionPool.cxx | 58 | ||||
-rw-r--r-- | connectivity/source/cpool/ZConnectionPool.hxx | 25 |
2 files changed, 77 insertions, 6 deletions
diff --git a/connectivity/source/cpool/ZConnectionPool.cxx b/connectivity/source/cpool/ZConnectionPool.cxx index 243d72ab8122..e1fc7e09ce9d 100644 --- a/connectivity/source/cpool/ZConnectionPool.cxx +++ b/connectivity/source/cpool/ZConnectionPool.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ZConnectionPool.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: oj $ $Date: 2001-05-17 09:13:25 $ + * last change: $Author: fs $ $Date: 2001-05-25 10:59:48 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -82,12 +82,16 @@ #ifndef CONNECTIVITY_POOLEDCONNECTION_HXX #include "ZPooledConnection.hxx" #endif +#ifndef _CONNECTIVITY_CPOOL_ZDRIVERWRAPPER_HXX_ +#include "ZDriverWrapper.hxx" +#endif using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::container; +using namespace ::com::sun::star::reflection; using namespace ::osl; using namespace connectivity; @@ -109,8 +113,18 @@ OConnectionPool::OConnectionPool(const Reference< XMultiServiceFactory >& _rxF { // bootstrap all objects supporting the .sdb.Driver service m_xManager = Reference< XDriverManager >(m_xServiceFactory->createInstance(::rtl::OUString::createFromAscii("com.sun.star.sdbc.DriverManager") ), UNO_QUERY); + m_xDriverAccess = Reference< XDriverAccess >(m_xManager, UNO_QUERY); + + OSL_ENSURE(m_xDriverAccess.is(), "OConnectionPool::OConnectionPool: have no (or an invalid) driver manager!"); + m_xTimer = new OPoolTimer(this,::vos::TTimeValue(10,0)); m_xTimer->start(); + + m_xProxyFactory = Reference< XProxyFactory >( + m_xServiceFactory->createInstance( + ::rtl::OUString::createFromAscii("com.sun.star.reflection.ProxyFactory")), + UNO_QUERY); + OSL_ENSURE(m_xProxyFactory.is(), "OConnectionPool::OConnectionPool: could not create a proxy factory!"); } // ----------------------------------------------------------------------------- OConnectionPool::~OConnectionPool() @@ -234,7 +248,45 @@ Sequence< ::rtl::OUString > SAL_CALL OConnectionPool::getSupportedServiceNames_S //-------------------------------------------------------------------------- Reference< XDriver > SAL_CALL OConnectionPool::getDriverByURL( const ::rtl::OUString& _rURL ) throw(RuntimeException) { - return Reference< XDriverAccess>(m_xManager,UNO_QUERY)->getDriverByURL(_rURL); + Reference< XDriver > xDriver; + if (m_xDriverAccess.is()) + { + xDriver = m_xDriverAccess->getDriverByURL(_rURL); + + Reference< XDriver > xExistentProxy; + // look if we already have a proxy for this driver + for ( ConstMapDriver2DriverRefIterator aLookup = m_aDriverProxies.begin(); + aLookup != m_aDriverProxies.end(); + ++aLookup + ) + { + // hold the proxy alive as long as we're in this loop round + xExistentProxy = aLookup->second; + + if (xExistentProxy.is() && (aLookup->first.get() == xDriver.get())) + // already created a proxy for this + break; + } + if (xExistentProxy.is()) + { + xDriver = xExistentProxy; + } + else + { // create a new proxy for the driver + // this allows us to control the connections created by it + if (m_xProxyFactory.is()) + { + Reference< XAggregation > xDriverProxy = m_xProxyFactory->createProxy(xDriver.get()); + OSL_ENSURE(xDriverProxy.is(), "OConnectionPool::getDriverByURL: invalid proxy returned by the proxy factory!"); + + xDriver = new ODriverWrapper(xDriverProxy, this); + } + else + OSL_ENSURE(sal_False, "OConnectionPool::getDriverByURL: could not instantiate a proxy factory!"); + } + } + + return xDriver; } //-------------------------------------------------------------------------- diff --git a/connectivity/source/cpool/ZConnectionPool.hxx b/connectivity/source/cpool/ZConnectionPool.hxx index 2d5e4745e980..80094c969a29 100644 --- a/connectivity/source/cpool/ZConnectionPool.hxx +++ b/connectivity/source/cpool/ZConnectionPool.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ZConnectionPool.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: oj $ $Date: 2001-04-26 09:12:37 $ + * last change: $Author: fs $ $Date: 2001-05-25 10:59:48 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -88,6 +88,12 @@ #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_ #include <com/sun/star/beans/PropertyValue.hpp> #endif +#ifndef _COM_SUN_STAR_REFLECTION_XPROXYFACTORY_HPP_ +#include <com/sun/star/reflection/XProxyFactory.hpp> +#endif +#ifndef _CPPUHELPER_WEAKREF_HXX_ +#include <cppuhelper/weakref.hxx> +#endif #ifndef _CPPUHELPER_IMPLBASE4_HXX_ #include <cppuhelper/implbase4.hxx> #endif @@ -123,6 +129,9 @@ namespace connectivity }; //========================================================================== + typedef ::comphelper::OInterfaceCompare< ::com::sun::star::sdbc::XDriver > ODriverCompare; + + //========================================================================== //= OConnectionPool - the one-instance service for PooledConnections //= manages the active connections and the connections in the pool //========================================================================== @@ -135,7 +144,7 @@ namespace connectivity // typedef for the interanl structure typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPooledConnection> > TPooledConnections; - DECLARE_STL_USTRINGACCESS_MAP(::com::sun::star::uno::Any,PropertyMap); + DECLARE_STL_USTRINGACCESS_MAP(::com::sun::star::uno::Any,PropertyMap); // contains the currently pooled connections typedef struct { @@ -166,6 +175,16 @@ namespace connectivity ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceFactory; ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriverManager > m_xManager; + ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriverAccess > m_xDriverAccess; + ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XProxyFactory > m_xProxyFactory; + + DECLARE_STL_MAP( + ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >, + ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDriver >, + ODriverCompare, + MapDriver2DriverRef ); + + MapDriver2DriverRef m_aDriverProxies; private: OConnectionPool( |