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 
24cdf0e10cSrcweir #ifndef _CONNECTIVITY_DRIVERMANAGER_HXX_
25cdf0e10cSrcweir #define _CONNECTIVITY_DRIVERMANAGER_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/sdbc/XDriverManager.hpp>
28cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp>
30cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
32cdf0e10cSrcweir #include <com/sun/star/sdbc/XDriverAccess.hpp>
33cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <cppuhelper/implbase5.hxx>
36cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
37cdf0e10cSrcweir #include <comphelper/logging.hxx>
38cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
39cdf0e10cSrcweir #include <osl/mutex.hxx>
40cdf0e10cSrcweir #include "connectivity/DriversConfig.hxx"
41cdf0e10cSrcweir 
42cdf0e10cSrcweir namespace drivermanager
43cdf0e10cSrcweir {
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 	//======================================================================
46cdf0e10cSrcweir 	//= various
47cdf0e10cSrcweir 	//======================================================================
48cdf0e10cSrcweir 	typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >						SdbcDriver;
49cdf0e10cSrcweir 	DECLARE_STL_USTRINGACCESS_MAP( SdbcDriver, DriverCollection );
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 	typedef ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory >		DriverFactory;
52cdf0e10cSrcweir 	struct DriverAccess
53cdf0e10cSrcweir 	{
54cdf0e10cSrcweir 		::rtl::OUString		sImplementationName;		/// the implementation name of the driver
55cdf0e10cSrcweir 		DriverFactory		xComponentFactory;			/// the factory to create the driver component (if not already done so)
56cdf0e10cSrcweir 		SdbcDriver			xDriver;					/// the driver itself
57cdf0e10cSrcweir 	};
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     //==========================================================================
60cdf0e10cSrcweir     //= OSDBCDriverManager - the one-instance service for managing SDBC drivers
61cdf0e10cSrcweir     //==========================================================================
62cdf0e10cSrcweir     typedef	::cppu::WeakImplHelper5	<	::com::sun::star::sdbc::XDriverManager
63cdf0e10cSrcweir 								    ,	::com::sun::star::sdbc::XDriverAccess
64cdf0e10cSrcweir 								    ,	::com::sun::star::container::XEnumerationAccess
65cdf0e10cSrcweir 								    ,	::com::sun::star::lang::XServiceInfo
66cdf0e10cSrcweir 								    ,	::com::sun::star::uno::XNamingService
67cdf0e10cSrcweir 								    >	OSDBCDriverManager_Base;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     class OSDBCDriverManager : public OSDBCDriverManager_Base
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir 	    friend class ODriverEnumeration;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	    ::osl::Mutex			        m_aMutex;
74cdf0e10cSrcweir         ::comphelper::ComponentContext  m_aContext;
75cdf0e10cSrcweir         ::comphelper::EventLogger       m_aEventLogger;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	    DECLARE_STL_VECTOR(DriverAccess, DriverAccessArray);
78cdf0e10cSrcweir 	    DriverAccessArray		        m_aDriversBS;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	    // for drivers registered at runtime (not bootstrapped) we don't require an XServiceInfo interface,
81cdf0e10cSrcweir 	    // so we have to remember their impl-name in another way
82cdf0e10cSrcweir 	    DECLARE_STL_USTRINGACCESS_MAP(SdbcDriver, DriverCollection);
83cdf0e10cSrcweir 	    DriverCollection				m_aDriversRT;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         ::connectivity::DriversConfig   m_aDriverConfig;
86cdf0e10cSrcweir 	    sal_Int32				        m_nLoginTimeout;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     private:
89cdf0e10cSrcweir 	    OSDBCDriverManager(
90cdf0e10cSrcweir 		    const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
91cdf0e10cSrcweir         ~OSDBCDriverManager();
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     public:
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     // XDriverManager
96cdf0e10cSrcweir         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);
97cdf0e10cSrcweir         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);
98cdf0e10cSrcweir         virtual void SAL_CALL setLoginTimeout( sal_Int32 seconds ) throw(::com::sun::star::uno::RuntimeException);
99cdf0e10cSrcweir         virtual sal_Int32 SAL_CALL getLoginTimeout(  ) throw(::com::sun::star::uno::RuntimeException);
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     // XDriverAccess
102cdf0e10cSrcweir         virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > SAL_CALL getDriverByURL( const ::rtl::OUString& url ) throw(::com::sun::star::uno::RuntimeException);
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     // XEnumerationAccess
105cdf0e10cSrcweir         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration(  ) throw(::com::sun::star::uno::RuntimeException);
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     // XElementAccess
108cdf0e10cSrcweir         virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw(::com::sun::star::uno::RuntimeException);
109cdf0e10cSrcweir         virtual sal_Bool SAL_CALL hasElements(  ) throw(::com::sun::star::uno::RuntimeException);
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     // XServiceInfo
112cdf0e10cSrcweir         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
113cdf0e10cSrcweir         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
114cdf0e10cSrcweir         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     // XServiceInfo - static methods
117cdf0e10cSrcweir         static ::rtl::OUString SAL_CALL getImplementationName_static(  ) throw(::com::sun::star::uno::RuntimeException);
118cdf0e10cSrcweir         static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static(  ) throw(::com::sun::star::uno::RuntimeException);
119cdf0e10cSrcweir         static ::rtl::OUString SAL_CALL getSingletonName_static(  ) throw(::com::sun::star::uno::RuntimeException);
120cdf0e10cSrcweir         static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL Create( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxContext );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     // XNamingService
123cdf0e10cSrcweir         virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getRegisteredObject( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
124cdf0e10cSrcweir         virtual void SAL_CALL registerObject( const ::rtl::OUString& Name, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Object ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
125cdf0e10cSrcweir         virtual void SAL_CALL revokeObject( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     protected:
128cdf0e10cSrcweir 	    ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > implGetDriverForURL(const ::rtl::OUString& _rURL);
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	    /** retrieve the driver order preferences from the configuration and
131cdf0e10cSrcweir 		    sort m_aDriversBS accordingly.
132cdf0e10cSrcweir 	    */
133cdf0e10cSrcweir 	    void initializeDriverPrecedence();
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	    void bootstrapDrivers();
136cdf0e10cSrcweir     };
137cdf0e10cSrcweir 
138cdf0e10cSrcweir }	// namespace drivermanager
139cdf0e10cSrcweir 
140cdf0e10cSrcweir #endif // _CONNECTIVITY_DRIVERMANAGER_HXX_
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 
143