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