1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _CONNECTIVITY_DRIVERMANAGER_HXX_
29 #define _CONNECTIVITY_DRIVERMANAGER_HXX_
30 
31 #include <com/sun/star/sdbc/XDriverManager.hpp>
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <com/sun/star/container/XEnumerationAccess.hpp>
34 #include <com/sun/star/uno/XNamingService.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/sdbc/XDriverAccess.hpp>
37 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
38 
39 #include <cppuhelper/implbase5.hxx>
40 #include <comphelper/stl_types.hxx>
41 #include <comphelper/logging.hxx>
42 #include <comphelper/componentcontext.hxx>
43 #include <osl/mutex.hxx>
44 #include "connectivity/DriversConfig.hxx"
45 
46 namespace drivermanager
47 {
48 
49 	//======================================================================
50 	//= various
51 	//======================================================================
52 	typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >						SdbcDriver;
53 	DECLARE_STL_USTRINGACCESS_MAP( SdbcDriver, DriverCollection );
54 
55 	typedef ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory >		DriverFactory;
56 	struct DriverAccess
57 	{
58 		::rtl::OUString		sImplementationName;		/// the implementation name of the driver
59 		DriverFactory		xComponentFactory;			/// the factory to create the driver component (if not already done so)
60 		SdbcDriver			xDriver;					/// the driver itself
61 	};
62 
63     //==========================================================================
64     //= OSDBCDriverManager - the one-instance service for managing SDBC drivers
65     //==========================================================================
66     typedef	::cppu::WeakImplHelper5	<	::com::sun::star::sdbc::XDriverManager
67 								    ,	::com::sun::star::sdbc::XDriverAccess
68 								    ,	::com::sun::star::container::XEnumerationAccess
69 								    ,	::com::sun::star::lang::XServiceInfo
70 								    ,	::com::sun::star::uno::XNamingService
71 								    >	OSDBCDriverManager_Base;
72 
73     class OSDBCDriverManager : public OSDBCDriverManager_Base
74     {
75 	    friend class ODriverEnumeration;
76 
77 	    ::osl::Mutex			        m_aMutex;
78         ::comphelper::ComponentContext  m_aContext;
79         ::comphelper::EventLogger       m_aEventLogger;
80 
81 	    DECLARE_STL_VECTOR(DriverAccess, DriverAccessArray);
82 	    DriverAccessArray		        m_aDriversBS;
83 
84 	    // for drivers registered at runtime (not bootstrapped) we don't require an XServiceInfo interface,
85 	    // so we have to remember their impl-name in another way
86 	    DECLARE_STL_USTRINGACCESS_MAP(SdbcDriver, DriverCollection);
87 	    DriverCollection				m_aDriversRT;
88 
89         ::connectivity::DriversConfig   m_aDriverConfig;
90 	    sal_Int32				        m_nLoginTimeout;
91 
92     private:
93 	    OSDBCDriverManager(
94 		    const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
95         ~OSDBCDriverManager();
96 
97     public:
98 
99     // XDriverManager
100         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);
101         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);
102         virtual void SAL_CALL setLoginTimeout( sal_Int32 seconds ) throw(::com::sun::star::uno::RuntimeException);
103         virtual sal_Int32 SAL_CALL getLoginTimeout(  ) throw(::com::sun::star::uno::RuntimeException);
104 
105     // XDriverAccess
106         virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > SAL_CALL getDriverByURL( const ::rtl::OUString& url ) throw(::com::sun::star::uno::RuntimeException);
107 
108     // XEnumerationAccess
109         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration(  ) throw(::com::sun::star::uno::RuntimeException);
110 
111     // XElementAccess
112         virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw(::com::sun::star::uno::RuntimeException);
113         virtual sal_Bool SAL_CALL hasElements(  ) throw(::com::sun::star::uno::RuntimeException);
114 
115     // XServiceInfo
116         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
117         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
118         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
119 
120     // XServiceInfo - static methods
121         static ::rtl::OUString SAL_CALL getImplementationName_static(  ) throw(::com::sun::star::uno::RuntimeException);
122         static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static(  ) throw(::com::sun::star::uno::RuntimeException);
123         static ::rtl::OUString SAL_CALL getSingletonName_static(  ) throw(::com::sun::star::uno::RuntimeException);
124         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 );
125 
126     // XNamingService
127         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);
128         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);
129         virtual void SAL_CALL revokeObject( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
130 
131     protected:
132 	    ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > implGetDriverForURL(const ::rtl::OUString& _rURL);
133 
134 	    /** retrieve the driver order preferences from the configuration and
135 		    sort m_aDriversBS accordingly.
136 	    */
137 	    void initializeDriverPrecedence();
138 
139 	    void bootstrapDrivers();
140     };
141 
142 }	// namespace drivermanager
143 
144 #endif // _CONNECTIVITY_DRIVERMANAGER_HXX_
145 
146 
147