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 #ifndef CONNECTIVITY_MYSQL_DRIVER_HXX 24 #define CONNECTIVITY_MYSQL_DRIVER_HXX 25 26 #include <com/sun/star/sdbc/XDriver.hpp> 27 #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> 28 #include <com/sun/star/lang/XServiceInfo.hpp> 29 #include <cppuhelper/compbase3.hxx> 30 #include <comphelper/uno3.hxx> 31 #include <comphelper/stl_types.hxx> 32 #include <comphelper/broadcasthelper.hxx> 33 #include "connectivity/CommonTools.hxx" 34 35 //........................................................................ 36 namespace connectivity 37 { 38 //........................................................................ 39 40 class OMetaConnection; 41 42 namespace mysql 43 { 44 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL ODriverDelegator_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception ); 45 46 typedef ::cppu::WeakComponentImplHelper3< ::com::sun::star::sdbc::XDriver 47 , ::com::sun::star::sdbcx::XDataDefinitionSupplier 48 , ::com::sun::star::lang::XServiceInfo 49 > ODriverDelegator_BASE; 50 51 typedef ::std::pair< ::com::sun::star::uno::WeakReferenceHelper,OMetaConnection*> TWeakConnectionPair; 52 typedef ::std::pair< ::com::sun::star::uno::WeakReferenceHelper,TWeakConnectionPair> TWeakPair; 53 typedef ::std::vector< TWeakPair > TWeakPairVector; 54 DECLARE_STL_USTRINGACCESS_MAP(::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >,TJDBCDrivers); 55 typedef enum 56 { 57 D_ODBC, 58 D_JDBC, 59 D_NATIVE 60 } T_DRIVERTYPE; 61 62 63 /** delegates all calls to the orignal driver and extend the existing one with the SDBCX layer. 64 65 */ 66 class ODriverDelegator : public ::comphelper::OBaseMutex 67 ,public ODriverDelegator_BASE 68 { 69 TJDBCDrivers m_aJdbcDrivers; // all jdbc drivers 70 TWeakPairVector m_aConnections; // vector containing a list 71 // of all the Connection objects 72 // for this Driver 73 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > m_xODBCDriver; 74 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > m_xNativeDriver; 75 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; 76 ::rtl::OUString m_sOldDriverClass; 77 T_DRIVERTYPE m_eDriverType; 78 79 /** load the driver we want to delegate. 80 The <member>m_xODBCDriver</member> or <member>m_xDBCDriver</member> may be <NULL/> if the driver could not be loaded. 81 @param url 82 The URL. 83 @param info 84 The property info contains which driver we have to delegate. 85 @return 86 The driver which was currently selected. 87 */ 88 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > loadDriver( const ::rtl::OUString& url, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ); 89 90 public: 91 /** creates a new delegator for a mysql driver 92 */ 93 ODriverDelegator(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory); 94 95 // XServiceInfo 96 DECLARE_SERVICE_INFO(); 97 static ::rtl::OUString getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException); 98 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw (::com::sun::star::uno::RuntimeException); 99 100 // XDriver 101 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL connect( 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 sal_Bool SAL_CALL acceptsURL( const ::rtl::OUString& url ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 103 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( 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); 104 virtual sal_Int32 SAL_CALL getMajorVersion( ) throw (::com::sun::star::uno::RuntimeException); 105 virtual sal_Int32 SAL_CALL getMinorVersion( ) throw (::com::sun::star::uno::RuntimeException); 106 107 // XDataDefinitionSupplier 108 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByConnection( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& connection ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 109 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByURL( 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); 110 protected: 111 /// dtor 112 virtual ~ODriverDelegator(); 113 // OComponentHelper 114 virtual void SAL_CALL disposing(void); 115 }; 116 } 117 118 //........................................................................ 119 } // namespace connectivity 120 //........................................................................ 121 #endif // CONNECTIVITY_MYSQL_DRIVER_HXX 122 123