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