1caf5cd79SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3caf5cd79SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4caf5cd79SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5caf5cd79SAndrew Rist  * distributed with this work for additional information
6caf5cd79SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7caf5cd79SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8caf5cd79SAndrew Rist  * "License"); you may not use this file except in compliance
9caf5cd79SAndrew Rist  * with the License.  You may obtain a copy of the License at
10caf5cd79SAndrew Rist  *
11caf5cd79SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12caf5cd79SAndrew Rist  *
13caf5cd79SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14caf5cd79SAndrew Rist  * software distributed under the License is distributed on an
15caf5cd79SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16caf5cd79SAndrew Rist  * KIND, either express or implied.  See the License for the
17caf5cd79SAndrew Rist  * specific language governing permissions and limitations
18caf5cd79SAndrew Rist  * under the License.
19caf5cd79SAndrew Rist  *
20caf5cd79SAndrew Rist  *************************************************************/
21caf5cd79SAndrew Rist 
22caf5cd79SAndrew 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>
33*8f985ee8SAriel Constenla-Haile //#include <com/sun/star/lang/XSingleServiceFactory.hpp>
34*8f985ee8SAriel Constenla-Haile #include <com/sun/star/lang/XSingleComponentFactory.hpp>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <cppuhelper/implbase5.hxx>
37cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
38cdf0e10cSrcweir #include <comphelper/logging.hxx>
39cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
40cdf0e10cSrcweir #include <osl/mutex.hxx>
41cdf0e10cSrcweir #include "connectivity/DriversConfig.hxx"
42cdf0e10cSrcweir 
43cdf0e10cSrcweir namespace drivermanager
44cdf0e10cSrcweir {
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 	//======================================================================
47cdf0e10cSrcweir 	//= various
48cdf0e10cSrcweir 	//======================================================================
49cdf0e10cSrcweir 	typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >						SdbcDriver;
50cdf0e10cSrcweir 	DECLARE_STL_USTRINGACCESS_MAP( SdbcDriver, DriverCollection );
51cdf0e10cSrcweir 
52*8f985ee8SAriel Constenla-Haile 	typedef ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory >		DriverFactory;
53cdf0e10cSrcweir 	struct DriverAccess
54cdf0e10cSrcweir 	{
55cdf0e10cSrcweir 		::rtl::OUString		sImplementationName;		/// the implementation name of the driver
56cdf0e10cSrcweir 		DriverFactory		xComponentFactory;			/// the factory to create the driver component (if not already done so)
57cdf0e10cSrcweir 		SdbcDriver			xDriver;					/// the driver itself
58cdf0e10cSrcweir 	};
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     //==========================================================================
61cdf0e10cSrcweir     //= OSDBCDriverManager - the one-instance service for managing SDBC drivers
62cdf0e10cSrcweir     //==========================================================================
63cdf0e10cSrcweir     typedef	::cppu::WeakImplHelper5	<	::com::sun::star::sdbc::XDriverManager
64cdf0e10cSrcweir 								    ,	::com::sun::star::sdbc::XDriverAccess
65cdf0e10cSrcweir 								    ,	::com::sun::star::container::XEnumerationAccess
66cdf0e10cSrcweir 								    ,	::com::sun::star::lang::XServiceInfo
67cdf0e10cSrcweir 								    ,	::com::sun::star::uno::XNamingService
68cdf0e10cSrcweir 								    >	OSDBCDriverManager_Base;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     class OSDBCDriverManager : public OSDBCDriverManager_Base
71cdf0e10cSrcweir     {
72cdf0e10cSrcweir 	    friend class ODriverEnumeration;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	    ::osl::Mutex			        m_aMutex;
75cdf0e10cSrcweir         ::comphelper::ComponentContext  m_aContext;
76cdf0e10cSrcweir         ::comphelper::EventLogger       m_aEventLogger;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	    DECLARE_STL_VECTOR(DriverAccess, DriverAccessArray);
79cdf0e10cSrcweir 	    DriverAccessArray		        m_aDriversBS;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	    // for drivers registered at runtime (not bootstrapped) we don't require an XServiceInfo interface,
82cdf0e10cSrcweir 	    // so we have to remember their impl-name in another way
83cdf0e10cSrcweir 	    DECLARE_STL_USTRINGACCESS_MAP(SdbcDriver, DriverCollection);
84cdf0e10cSrcweir 	    DriverCollection				m_aDriversRT;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir         ::connectivity::DriversConfig   m_aDriverConfig;
87cdf0e10cSrcweir 	    sal_Int32				        m_nLoginTimeout;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     private:
90cdf0e10cSrcweir 	    OSDBCDriverManager(
91cdf0e10cSrcweir 		    const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
92cdf0e10cSrcweir         ~OSDBCDriverManager();
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     public:
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     // XDriverManager
97cdf0e10cSrcweir         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);
98cdf0e10cSrcweir         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);
99cdf0e10cSrcweir         virtual void SAL_CALL setLoginTimeout( sal_Int32 seconds ) throw(::com::sun::star::uno::RuntimeException);
100cdf0e10cSrcweir         virtual sal_Int32 SAL_CALL getLoginTimeout(  ) throw(::com::sun::star::uno::RuntimeException);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     // XDriverAccess
103cdf0e10cSrcweir         virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > SAL_CALL getDriverByURL( const ::rtl::OUString& url ) throw(::com::sun::star::uno::RuntimeException);
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     // XEnumerationAccess
106cdf0e10cSrcweir         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration(  ) throw(::com::sun::star::uno::RuntimeException);
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     // XElementAccess
109cdf0e10cSrcweir         virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw(::com::sun::star::uno::RuntimeException);
110cdf0e10cSrcweir         virtual sal_Bool SAL_CALL hasElements(  ) throw(::com::sun::star::uno::RuntimeException);
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     // XServiceInfo
113cdf0e10cSrcweir         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
114cdf0e10cSrcweir         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
115cdf0e10cSrcweir         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     // XServiceInfo - static methods
118cdf0e10cSrcweir         static ::rtl::OUString SAL_CALL getImplementationName_static(  ) throw(::com::sun::star::uno::RuntimeException);
119cdf0e10cSrcweir         static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static(  ) throw(::com::sun::star::uno::RuntimeException);
120cdf0e10cSrcweir         static ::rtl::OUString SAL_CALL getSingletonName_static(  ) throw(::com::sun::star::uno::RuntimeException);
121cdf0e10cSrcweir         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 );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     // XNamingService
124cdf0e10cSrcweir         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);
125cdf0e10cSrcweir         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);
126cdf0e10cSrcweir         virtual void SAL_CALL revokeObject( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     protected:
129cdf0e10cSrcweir 	    ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > implGetDriverForURL(const ::rtl::OUString& _rURL);
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	    /** retrieve the driver order preferences from the configuration and
132cdf0e10cSrcweir 		    sort m_aDriversBS accordingly.
133cdf0e10cSrcweir 	    */
134cdf0e10cSrcweir 	    void initializeDriverPrecedence();
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	    void bootstrapDrivers();
137cdf0e10cSrcweir     };
138cdf0e10cSrcweir 
139cdf0e10cSrcweir }	// namespace drivermanager
140cdf0e10cSrcweir 
141cdf0e10cSrcweir #endif // _CONNECTIVITY_DRIVERMANAGER_HXX_
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 
144