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_SCONNECTION_HXX 25 #define CONNECTIVITY_SCONNECTION_HXX 26 27 #include <com/sun/star/sdbc/SQLWarning.hpp> 28 #include <com/sun/star/beans/PropertyValue.hpp> 29 #include "OSubComponent.hxx" 30 #include "OTypeInfo.hxx" 31 #include <com/sun/star/lang/DisposedException.hpp> 32 #include <com/sun/star/lang/XServiceInfo.hpp> 33 #include <com/sun/star/lang/XUnoTunnel.hpp> 34 #include <com/sun/star/sdbc/XWarningsSupplier.hpp> 35 #include <com/sun/star/sdbc/XConnection.hpp> 36 #include <cppuhelper/compbase3.hxx> 37 #include <cppuhelper/weakref.hxx> 38 39 #include <map> 40 41 namespace connectivity 42 { 43 namespace skeleton 44 { 45 46 typedef ::cppu::WeakComponentImplHelper3< ::com::sun::star::sdbc::XConnection, 47 ::com::sun::star::sdbc::XWarningsSupplier, 48 ::com::sun::star::lang::XServiceInfo 49 > OMetaConnection_BASE; 50 51 class OStatement_Base; 52 class SkeletonDriver; 53 class ODatabaseMetaData; 54 55 typedef OMetaConnection_BASE OConnection_BASE; // implements basics and text encoding 56 typedef ::std::vector< ::connectivity::OTypeInfo> TTypeInfoVector; 57 typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray; 58 59 class OConnection : public OBase_Mutex, 60 public OConnection_BASE, 61 public connectivity::skeleton::OSubComponent<OConnection, OConnection_BASE> 62 { 63 friend class connectivity::skeleton::OSubComponent<OConnection, OConnection_BASE>; 64 65 protected: 66 67 rtl_TextEncoding m_nTextEncoding; // the encoding which is used for all text conversions 68 //==================================================================== 69 // Data attributes 70 //==================================================================== 71 TTypeInfoVector m_aTypeInfo; // vector containing an entry 72 // for each row returned by 73 // DatabaseMetaData.getTypeInfo. 74 ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData > m_xMetaData; 75 76 OWeakRefArray m_aStatements; // vector containing a list 77 // of all the Statement objects 78 // for this Connection 79 80 ::com::sun::star::sdbc::SQLWarning m_aLastWarning; // Last SQLWarning generated by 81 // an operation 82 ::rtl::OUString m_aURL; // URL of connection 83 ::rtl::OUString m_sUser; // the user name 84 SkeletonDriver* m_pDriver; // Pointer to the owning 85 // driver object 86 87 sal_Bool m_bClosed; 88 sal_Bool m_bUseCatalog; // should we use the catalog on filebased databases 89 sal_Bool m_bUseOldDateFormat; 90 91 92 void buildTypeInfo() throw( ::com::sun::star::sdbc::SQLException); 93 94 public: 95 virtual void construct( const ::rtl::OUString& url,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info) throw(::com::sun::star::sdbc::SQLException); 96 97 OConnection(SkeletonDriver* _pDriver); 98 virtual ~OConnection(); 99 100 void closeAllStatements () throw( ::com::sun::star::sdbc::SQLException); 101 102 // OComponentHelper 103 virtual void SAL_CALL disposing(void); 104 // XInterface 105 virtual void SAL_CALL release() throw(); 106 107 // XServiceInfo 108 DECLARE_SERVICE_INFO(); 109 // XConnection 110 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement > SAL_CALL createStatement( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 111 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 112 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareCall( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 113 virtual ::rtl::OUString SAL_CALL nativeSQL( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 114 virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 115 virtual sal_Bool SAL_CALL getAutoCommit( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 116 virtual void SAL_CALL commit( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 117 virtual void SAL_CALL rollback( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 118 virtual sal_Bool SAL_CALL isClosed( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 119 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 120 virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 121 virtual sal_Bool SAL_CALL isReadOnly( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 122 virtual void SAL_CALL setCatalog( const ::rtl::OUString& catalog ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 123 virtual ::rtl::OUString SAL_CALL getCatalog( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 124 virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 125 virtual sal_Int32 SAL_CALL getTransactionIsolation( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 126 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTypeMap( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 127 virtual void SAL_CALL setTypeMap( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 128 // XCloseable 129 virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 130 // XWarningsSupplier 131 virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 132 virtual void SAL_CALL clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 133 // 134 135 // should we use the catalog on filebased databases isCatalogUsed() const136 inline sal_Bool isCatalogUsed() const { return m_bUseCatalog; } getUserName() const137 inline ::rtl::OUString getUserName() const { return m_sUser; } getDriver() const138 inline SkeletonDriver* getDriver() const { return m_pDriver;} getTextEncoding() const139 inline rtl_TextEncoding getTextEncoding() const { return m_nTextEncoding; } 140 }; 141 } 142 } 143 #endif // CONNECTIVITY_SCONNECTION_HXX 144 145