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_HSQLDB_CONNECTION_HXX 25 #define CONNECTIVITY_HSQLDB_CONNECTION_HXX 26 27 #include "connectivity/ConnectionWrapper.hxx" 28 /** === begin UNO includes === **/ 29 #include <com/sun/star/util/XFlushable.hpp> 30 #include <com/sun/star/sdbc/XDriver.hpp> 31 #ifndef __com_sun_star_sdb_application_XTableUIProvider_hpp__ 32 #include <com/sun/star/sdb/application/XTableUIProvider.hpp> 33 #endif 34 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 35 /** === end UNO includes === **/ 36 #include <cppuhelper/compbase2.hxx> 37 #include <comphelper/uno3.hxx> 38 #include <cppuhelper/interfacecontainer.hxx> 39 #include <memory> 40 41 namespace connectivity 42 { 43 namespace hsqldb 44 { 45 class SAL_NO_VTABLE IMethodGuardAccess 46 { 47 public: 48 virtual ::osl::Mutex& getMutex() const = 0; 49 virtual void checkDisposed() const = 0; 50 }; 51 52 //========================================================================== 53 //= OHsqlConnection - wraps all methods to the real connection from the driver 54 //= but when disposed it doesn't dispose the real connection 55 //========================================================================== 56 typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::util::XFlushable 57 , ::com::sun::star::sdb::application::XTableUIProvider 58 > OHsqlConnection_BASE; 59 60 class OHsqlConnection :public ::comphelper::OBaseMutex 61 ,public OHsqlConnection_BASE 62 ,public OConnectionWrapper 63 ,public IMethodGuardAccess 64 { 65 private: 66 ::cppu::OInterfaceContainerHelper m_aFlushListeners; 67 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > m_xDriver; 68 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xORB; 69 bool m_bIni; 70 bool m_bReadOnly; 71 72 protected: 73 virtual void SAL_CALL disposing(void); 74 virtual ~OHsqlConnection(); 75 76 public: 77 OHsqlConnection( 78 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > _rxDriver, 79 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection, 80 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _xORB 81 ); 82 83 // XServiceInfo 84 DECLARE_SERVICE_INFO(); 85 DECLARE_XTYPEPROVIDER() 86 DECLARE_XINTERFACE( ) 87 88 // IMethodGuardAccess 89 virtual ::osl::Mutex& getMutex() const; 90 virtual void checkDisposed() const; 91 92 // XFlushable 93 virtual void SAL_CALL flush( ) throw (::com::sun::star::uno::RuntimeException); 94 virtual void SAL_CALL addFlushListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushListener >& l ) throw (::com::sun::star::uno::RuntimeException); 95 virtual void SAL_CALL removeFlushListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushListener >& l ) throw (::com::sun::star::uno::RuntimeException); 96 97 // XTableUIProvider 98 virtual ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > SAL_CALL getTableIcon( const ::rtl::OUString& TableName, ::sal_Int32 ColorMode ) throw (::com::sun::star::uno::RuntimeException); 99 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getTableEditor( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& DocumentUI, const ::rtl::OUString& TableName ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 100 101 private: 102 #if 0 103 // TODO: resource 104 /** creates the dialog used for editing a linked table 105 106 @param _rTableName 107 the name of the table to create the editor for. 108 109 @param _rxDocumentUI 110 the UI of the database document, for which the editor is to be created. 111 Must not be <NULL/>. 112 113 @return 114 the table editor dialog instance. 115 116 @throws ::com::sun::star::lang::WrappedTargetException 117 if creating the dialog instance fails 118 119 @throws ::com::sun::star::uno::RuntimeException 120 if a serious error occures 121 122 @precond 123 Our mutex is locked. 124 */ 125 ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XExecutableDialog > 126 impl_createLinkedTableEditor_throw( 127 const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& _rxDocumentUI, 128 const ::rtl::OUString& _rTableName 129 ); 130 #endif 131 132 /** retrieves our table container 133 @return 134 our table container. Guaranteed to not be <NULL/>. 135 @throws ::com::sun::star::lang::WrappedTargetException 136 if a non-RuntimeException is caught during obtaining the container. 137 @throws ::com::sun::star::uno::RuntimeException 138 if a serious error occurs 139 @precond 140 We're not disposed. 141 */ 142 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > 143 impl_getTableContainer_throw(); 144 145 /** checks whether the given table name denotes an existing table 146 @param _rTableName 147 the fully name of the table to check for existence 148 @throws ::com::sun::star::lang::IllegalArgumentException 149 if the name does not denote an existing table 150 @precond 151 We're not disposed. 152 */ 153 void impl_checkExistingTable_throw( const ::rtl::OUString& _rTableName ); 154 155 /** checks whether the given table name refers to a HSQL TEXT TABLE 156 */ 157 bool impl_isTextTable_nothrow( const ::rtl::OUString& _rTableName ); 158 159 /** retrieves the icon for HSQL TEXT TABLEs 160 */ 161 ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > 162 impl_getTextTableIcon_nothrow( ::sal_Int32 _ColorMode ); 163 }; 164 165 //========================================================================== 166 //= OHsqlConnection 167 //========================================================================== 168 class MethodGuard : public ::osl::MutexGuard 169 { 170 private: 171 typedef ::osl::MutexGuard BaseGuard; 172 173 public: 174 MethodGuard( const IMethodGuardAccess& _rComponent ) 175 :BaseGuard( _rComponent.getMutex() ) 176 { 177 _rComponent.checkDisposed(); 178 } 179 }; 180 } 181 } 182 #endif // CONNECTIVITY_HSQLDB_CONNECTION_HXX 183