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 #ifndef CONNECTIVITY_POOLCOLLECTION_HXX 24 #define CONNECTIVITY_POOLCOLLECTION_HXX 25 26 #include <cppuhelper/implbase5.hxx> 27 #include <com/sun/star/beans/XPropertyChangeListener.hpp> 28 #include <com/sun/star/sdbc/XDriverManager.hpp> 29 #include <com/sun/star/sdbc/XDriver.hpp> 30 #include <com/sun/star/sdbc/XDriverAccess.hpp> 31 #include <com/sun/star/sdbc/XPooledConnection.hpp> 32 #include <com/sun/star/sdbc/XConnection.hpp> 33 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 34 #include <com/sun/star/lang/XServiceInfo.hpp> 35 #include <com/sun/star/lang/XEventListener.hpp> 36 #include <com/sun/star/frame/XDesktop.hpp> 37 #include <com/sun/star/frame/XTerminateListener.hpp> 38 #include <com/sun/star/reflection/XProxyFactory.hpp> 39 #include <comphelper/stl_types.hxx> 40 #include <osl/mutex.hxx> 41 42 namespace connectivity 43 { 44 class OConnectionPool; 45 //========================================================================== 46 //= OPoolCollection - the one-instance service for PooledConnections 47 //= manages the active connections and the connections in the pool 48 //========================================================================== 49 typedef ::cppu::WeakImplHelper5< ::com::sun::star::sdbc::XDriverManager, 50 ::com::sun::star::sdbc::XDriverAccess, 51 ::com::sun::star::lang::XServiceInfo, 52 ::com::sun::star::frame::XTerminateListener, 53 ::com::sun::star::beans::XPropertyChangeListener 54 > OPoolCollection_Base; 55 56 /// OPoolCollection: controll the whole connection pooling for oo 57 class OPoolCollection : public OPoolCollection_Base 58 { 59 60 //========================================================================== 61 typedef ::comphelper::OInterfaceCompare< ::com::sun::star::sdbc::XDriver > ODriverCompare; 62 DECLARE_STL_USTRINGACCESS_MAP(OConnectionPool*, OConnectionPools); 63 64 DECLARE_STL_MAP( 65 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >, 66 ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDriver >, 67 ODriverCompare, 68 MapDriver2DriverRef ); 69 70 MapDriver2DriverRef m_aDriverProxies; 71 ::osl::Mutex m_aMutex; 72 OConnectionPools m_aPools; // the driver pools 73 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceFactory; 74 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriverManager > m_xManager; 75 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriverAccess > m_xDriverAccess; 76 ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XProxyFactory > m_xProxyFactory; 77 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xConfigNode; // config node for generel connection pooling 78 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDesktop> m_xDesktop; 79 80 private: 81 OPoolCollection(); // never implemented 82 OPoolCollection(const OPoolCollection&); // never implemented 83 int operator= (const OPoolCollection&); // never implemented 84 85 OPoolCollection( 86 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory); 87 88 // some configuration helper methods 89 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createWithServiceFactory(const ::rtl::OUString& _rPath) const; 90 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getConfigPoolRoot(); 91 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createWithProvider( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxConfProvider, 92 const ::rtl::OUString& _rPath) const; 93 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > openNode( const ::rtl::OUString& _rPath, 94 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xTreeNode) const throw(); 95 sal_Bool isPoolingEnabled(); 96 sal_Bool isDriverPoolingEnabled(const ::rtl::OUString& _sDriverImplName, 97 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxDriverNode); 98 sal_Bool isPoolingEnabledByUrl( const ::rtl::OUString& _sUrl, 99 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >& _rxDriver, 100 ::rtl::OUString& _rsImplName, 101 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxDriverNode); 102 103 OConnectionPool* getConnectionPool( const ::rtl::OUString& _sImplName, 104 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >& _xDriver, 105 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxDriverNode); 106 void clearConnectionPools(sal_Bool _bDispose); 107 void clearDesktop(); 108 protected: 109 virtual ~OPoolCollection(); 110 public: 111 112 static ::com::sun::star::uno::Any getNodeValue( const ::rtl::OUString& _rPath, 113 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _xTreeNode)throw(); 114 115 // XDriverManager 116 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection( const ::rtl::OUString& url ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 117 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnectionWithInfo( const ::rtl::OUString& url, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 118 virtual void SAL_CALL setLoginTimeout( sal_Int32 seconds ) throw(::com::sun::star::uno::RuntimeException); 119 virtual sal_Int32 SAL_CALL getLoginTimeout( ) throw(::com::sun::star::uno::RuntimeException); 120 121 //XDriverAccess 122 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > SAL_CALL getDriverByURL( const ::rtl::OUString& url ) throw (::com::sun::star::uno::RuntimeException); 123 // XServiceInfo 124 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); 125 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); 126 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); 127 128 // XServiceInfo - static methods 129 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL CreateInstance(const::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); 130 static ::rtl::OUString SAL_CALL getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException); 131 static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException); 132 133 // XEventListener 134 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); 135 // XPropertyChangeListener 136 virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException); 137 138 // XTerminateListener 139 virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException); 140 virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::uno::RuntimeException); 141 }; 142 } 143 #endif // CONNECTIVITY_POOLCOLLECTION_HXX 144 145