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