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