1*caf5cd79SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*caf5cd79SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*caf5cd79SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*caf5cd79SAndrew Rist  * distributed with this work for additional information
6*caf5cd79SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*caf5cd79SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*caf5cd79SAndrew Rist  * "License"); you may not use this file except in compliance
9*caf5cd79SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*caf5cd79SAndrew Rist  *
11*caf5cd79SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*caf5cd79SAndrew Rist  *
13*caf5cd79SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*caf5cd79SAndrew Rist  * software distributed under the License is distributed on an
15*caf5cd79SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*caf5cd79SAndrew Rist  * KIND, either express or implied.  See the License for the
17*caf5cd79SAndrew Rist  * specific language governing permissions and limitations
18*caf5cd79SAndrew Rist  * under the License.
19*caf5cd79SAndrew Rist  *
20*caf5cd79SAndrew Rist  *************************************************************/
21*caf5cd79SAndrew Rist 
22*caf5cd79SAndrew Rist 
23cdf0e10cSrcweir #ifndef CONNECTIVITY_POOLCOLLECTION_HXX
24cdf0e10cSrcweir #define CONNECTIVITY_POOLCOLLECTION_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <cppuhelper/implbase5.hxx>
27cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyChangeListener.hpp>
28cdf0e10cSrcweir #include <com/sun/star/sdbc/XDriverManager.hpp>
29cdf0e10cSrcweir #include <com/sun/star/sdbc/XDriver.hpp>
30cdf0e10cSrcweir #include <com/sun/star/sdbc/XDriverAccess.hpp>
31cdf0e10cSrcweir #include <com/sun/star/sdbc/XPooledConnection.hpp>
32cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
33cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
35cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp>
36cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
37cdf0e10cSrcweir #include <com/sun/star/frame/XTerminateListener.hpp>
38cdf0e10cSrcweir #include <com/sun/star/reflection/XProxyFactory.hpp>
39cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
40cdf0e10cSrcweir #include <osl/mutex.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir namespace connectivity
43cdf0e10cSrcweir {
44cdf0e10cSrcweir 	class OConnectionPool;
45cdf0e10cSrcweir 	//==========================================================================
46cdf0e10cSrcweir 	//= OPoolCollection - the one-instance service for PooledConnections
47cdf0e10cSrcweir 	//= manages the active connections and the connections in the pool
48cdf0e10cSrcweir 	//==========================================================================
49cdf0e10cSrcweir 	typedef	::cppu::WeakImplHelper5<	::com::sun::star::sdbc::XDriverManager,
50cdf0e10cSrcweir 										::com::sun::star::sdbc::XDriverAccess,
51cdf0e10cSrcweir 										::com::sun::star::lang::XServiceInfo,
52cdf0e10cSrcweir 										::com::sun::star::frame::XTerminateListener,
53cdf0e10cSrcweir 										::com::sun::star::beans::XPropertyChangeListener
54cdf0e10cSrcweir 										>	OPoolCollection_Base;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	/// OPoolCollection: controll the whole connection pooling for oo
57cdf0e10cSrcweir 	class OPoolCollection : public OPoolCollection_Base
58cdf0e10cSrcweir 	{
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 		//==========================================================================
61cdf0e10cSrcweir 		typedef ::comphelper::OInterfaceCompare< ::com::sun::star::sdbc::XDriver >	ODriverCompare;
62cdf0e10cSrcweir 		DECLARE_STL_USTRINGACCESS_MAP(OConnectionPool*,	OConnectionPools);
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 		DECLARE_STL_MAP(
65cdf0e10cSrcweir 				::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >,
66cdf0e10cSrcweir 				::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDriver >,
67cdf0e10cSrcweir 				ODriverCompare,
68cdf0e10cSrcweir 				MapDriver2DriverRef );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 		MapDriver2DriverRef																	m_aDriverProxies;
71cdf0e10cSrcweir 		::osl::Mutex																		m_aMutex;
72cdf0e10cSrcweir 		OConnectionPools																	m_aPools;		   // the driver pools
73cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >	m_xServiceFactory;
74cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriverManager >			m_xManager;
75cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriverAccess >			m_xDriverAccess;
76cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::reflection::XProxyFactory >		m_xProxyFactory;
77cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >				m_xConfigNode;		// config node for generel connection pooling
78cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::frame::XDesktop>				m_xDesktop;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	private:
81cdf0e10cSrcweir 		OPoolCollection();							// never implemented
82cdf0e10cSrcweir 		OPoolCollection(const OPoolCollection&);	// never implemented
83cdf0e10cSrcweir 		int operator= (const OPoolCollection&);			// never implemented
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 		OPoolCollection(
86cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&	_rxFactory);
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 		// some configuration helper methods
89cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createWithServiceFactory(const ::rtl::OUString& _rPath) const;
90cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getConfigPoolRoot();
91cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createWithProvider(	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxConfProvider,
92cdf0e10cSrcweir 																									const ::rtl::OUString& _rPath) const;
93cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > openNode(	const ::rtl::OUString& _rPath,
94cdf0e10cSrcweir 																						const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xTreeNode) const throw();
95cdf0e10cSrcweir 		sal_Bool isPoolingEnabled();
96cdf0e10cSrcweir 		sal_Bool isDriverPoolingEnabled(const ::rtl::OUString& _sDriverImplName,
97cdf0e10cSrcweir 										::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxDriverNode);
98cdf0e10cSrcweir 		sal_Bool isPoolingEnabledByUrl(	const ::rtl::OUString& _sUrl,
99cdf0e10cSrcweir 										::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >& _rxDriver,
100cdf0e10cSrcweir 										::rtl::OUString& _rsImplName,
101cdf0e10cSrcweir 										::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxDriverNode);
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 		OConnectionPool* getConnectionPool(	const ::rtl::OUString& _sImplName,
104cdf0e10cSrcweir 											const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >& _xDriver,
105cdf0e10cSrcweir 											const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxDriverNode);
106cdf0e10cSrcweir 		void clearConnectionPools(sal_Bool _bDispose);
107cdf0e10cSrcweir 		void clearDesktop();
108cdf0e10cSrcweir 	protected:
109cdf0e10cSrcweir 		virtual ~OPoolCollection();
110cdf0e10cSrcweir 	public:
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 		static ::com::sun::star::uno::Any getNodeValue(	const ::rtl::OUString& _rPath,
113cdf0e10cSrcweir 														const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _xTreeNode)throw();
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	// XDriverManager
116cdf0e10cSrcweir 		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);
117cdf0e10cSrcweir 		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);
118cdf0e10cSrcweir 		virtual void SAL_CALL setLoginTimeout( sal_Int32 seconds ) throw(::com::sun::star::uno::RuntimeException);
119cdf0e10cSrcweir 		virtual sal_Int32 SAL_CALL getLoginTimeout(  ) throw(::com::sun::star::uno::RuntimeException);
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	//XDriverAccess
122cdf0e10cSrcweir 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > SAL_CALL getDriverByURL( const ::rtl::OUString& url ) throw (::com::sun::star::uno::RuntimeException);
123cdf0e10cSrcweir 	// XServiceInfo
124cdf0e10cSrcweir 		virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
125cdf0e10cSrcweir 		virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
126cdf0e10cSrcweir 		virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 	// XServiceInfo - static methods
129cdf0e10cSrcweir 		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 >&);
130cdf0e10cSrcweir 		static ::rtl::OUString SAL_CALL getImplementationName_Static(  ) throw(::com::sun::star::uno::RuntimeException);
131cdf0e10cSrcweir 		static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_Static(  ) throw(::com::sun::star::uno::RuntimeException);
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 		// XEventListener
134cdf0e10cSrcweir 		virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
135cdf0e10cSrcweir 		// XPropertyChangeListener
136cdf0e10cSrcweir 		virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException);
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 		// XTerminateListener
139cdf0e10cSrcweir 		virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException);
140cdf0e10cSrcweir 		virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::uno::RuntimeException);
141cdf0e10cSrcweir 	};
142cdf0e10cSrcweir }
143cdf0e10cSrcweir #endif // CONNECTIVITY_POOLCOLLECTION_HXX
144cdf0e10cSrcweir 
145