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 _DBA_COREAPI_COLUMN_HXX_ 25 #define _DBA_COREAPI_COLUMN_HXX_ 26 27 #include "columnsettings.hxx" 28 29 #include <com/sun/star/container/XChild.hpp> 30 #include <com/sun/star/container/XEnumerationAccess.hpp> 31 #include <com/sun/star/container/XIndexAccess.hpp> 32 #include <com/sun/star/container/XNameAccess.hpp> 33 #include <com/sun/star/container/XNamed.hpp> 34 #include <com/sun/star/io/IOException.hpp> 35 #include <com/sun/star/io/XObjectInputStream.hpp> 36 #include <com/sun/star/io/XObjectOutputStream.hpp> 37 #include <com/sun/star/lang/WrappedTargetException.hpp> 38 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 39 #include <com/sun/star/lang/XServiceInfo.hpp> 40 #include <com/sun/star/lang/XUnoTunnel.hpp> 41 #include <com/sun/star/sdbc/XResultSet.hpp> 42 #include <com/sun/star/sdbcx/XAppend.hpp> 43 #include <com/sun/star/sdbcx/XDrop.hpp> 44 #include <com/sun/star/util/XNumberFormatsSupplier.hpp> 45 46 #include <comphelper/broadcasthelper.hxx> 47 #include <comphelper/proparrhlp.hxx> 48 #include <comphelper/propertycontainer.hxx> 49 #include <comphelper/stl_types.hxx> 50 #include <connectivity/CommonTools.hxx> 51 #include <connectivity/FValue.hxx> 52 #include <connectivity/TColumnsHelper.hxx> 53 #include <connectivity/sdbcx/IRefreshable.hxx> 54 #include <cppuhelper/compbase2.hxx> 55 #include <cppuhelper/compbase4.hxx> 56 #include <cppuhelper/implbase1.hxx> 57 #include <cppuhelper/propshlp.hxx> 58 #include <osl/diagnose.h> 59 60 #include <hash_map> 61 62 namespace dbaccess 63 { 64 65 //************************************************************ 66 // OColumn 67 //************************************************************ 68 typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::lang::XServiceInfo, 69 ::com::sun::star::container::XNamed 70 > OColumnBase; 71 72 //------------------------------------------------------------ 73 class OColumn :public comphelper::OBaseMutex 74 ,public OColumnBase 75 ,public ::comphelper::OPropertyContainer 76 ,public IPropertyContainer // convenience for the derived class which also derive from OColumnSettings 77 { 78 friend class OColumns; 79 80 protected: 81 // <properties> 82 ::rtl::OUString m_sName; 83 // </properties> 84 85 protected: 86 OColumn( const bool _bNameIsReadOnly ); 87 88 public: 89 virtual ~OColumn(); 90 91 // com::sun::star::lang::XTypeProvider 92 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException); 93 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException) = 0; 94 95 // com::sun::star::uno::XInterface 96 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException); 97 virtual void SAL_CALL acquire() throw(); 98 virtual void SAL_CALL release() throw(); 99 100 // com::sun::star::beans::XPropertySet 101 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); 102 103 // cppu::OComponentHelper 104 virtual void SAL_CALL disposing(void); 105 106 // ::com::sun::star::lang::XServiceInfo 107 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); 108 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); 109 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); 110 111 // XNamed 112 virtual ::rtl::OUString SAL_CALL getName( ) throw(::com::sun::star::uno::RuntimeException); 113 virtual void SAL_CALL setName( const ::rtl::OUString& _rName ) throw(::com::sun::star::uno::RuntimeException); 114 115 virtual void fireValueChange( const ::connectivity::ORowSetValue& _rOldValue ); 116 117 protected: 118 // IPropertyContainer 119 virtual void registerProperty( const ::rtl::OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void* _pPointerToMember, const ::com::sun::star::uno::Type& _rMemberType ); 120 virtual void registerMayBeVoidProperty( const ::rtl::OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, ::com::sun::star::uno::Any* _pPointerToMember, const ::com::sun::star::uno::Type& _rExpectedType ); 121 virtual void registerPropertyNoMember( const ::rtl::OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, const ::com::sun::star::uno::Type& _rType, const void* _pInitialValue ); 122 }; 123 124 //============================================================ 125 //= IColumnFactory - used by OColumns for creating new columns 126 //============================================================ 127 class SAL_NO_VTABLE IColumnFactory 128 { 129 public: 130 /** creates a OColumn object which should represent the column with a given name 131 */ 132 virtual OColumn* 133 createColumn( const ::rtl::OUString& _rName ) const = 0; 134 135 /** creates a column descriptor object. 136 137 A column descriptor object is used to append new columns to the collection. If such an append 138 actually happened, columnAppended is called afterwards. 139 */ 140 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > createColumnDescriptor() = 0; 141 142 /** notifies that a column, created from a column descriptor, has been appended 143 */ 144 virtual void columnAppended( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxSourceDescriptor ) = 0; 145 146 /** notifies that a column with a given name has been dropped 147 */ 148 virtual void columnDropped( const ::rtl::OUString& _sName ) = 0; 149 }; 150 151 //============================================================ 152 //= OColumns 153 //= general columns map, could be used for readonly access 154 //= no appending and dropping is supported 155 //============================================================ 156 typedef ::std::hash_map<rtl::OUString, OColumn*, ::comphelper::UStringMixHash, ::comphelper::UStringMixEqual> OColumnMap; 157 typedef ::std::vector<OColumn*> OColumnArray; 158 159 class OContainerMediator; 160 typedef ::cppu::ImplHelper1< ::com::sun::star::container::XChild > TXChild; 161 typedef connectivity::OColumnsHelper OColumns_BASE; 162 //------------------------------------------------------------ 163 class OColumns : public OColumns_BASE 164 ,public TXChild 165 { 166 OContainerMediator* m_pMediator; 167 168 protected: 169 // comes from the driver can be null 170 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xDrvColumns; 171 ::com::sun::star::uno::WeakReference< ::com::sun::star::uno::XInterface > m_xParent; 172 IColumnFactory* m_pColFactoryImpl; 173 ::connectivity::sdbcx::IRefreshableColumns* m_pRefreshColumns; 174 175 sal_Bool m_bInitialized : 1; 176 sal_Bool m_bAddColumn : 1; 177 sal_Bool m_bDropColumn : 1; 178 179 virtual void impl_refresh() throw(::com::sun::star::uno::RuntimeException); 180 virtual connectivity::sdbcx::ObjectType createObject(const ::rtl::OUString& _rName); 181 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > createDescriptor(); 182 virtual connectivity::sdbcx::ObjectType appendObject( const ::rtl::OUString& _rForName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor ); 183 virtual void dropObject(sal_Int32 _nPos,const ::rtl::OUString _sElementName); 184 185 public: createBaseObject(const::rtl::OUString & _rName)186 connectivity::sdbcx::ObjectType createBaseObject(const ::rtl::OUString& _rName) 187 { 188 return OColumns_BASE::createObject(_rName); 189 } 190 /** flag which determines whether the container is filled or not 191 */ isInitialized() const192 inline sal_Bool isInitialized() const { return m_bInitialized; } setInitialized()193 inline void setInitialized() {m_bInitialized = sal_True;} setMediator(OContainerMediator * _pMediator)194 inline void setMediator(OContainerMediator* _pMediator) { m_pMediator = _pMediator; } 195 196 public: 197 /** constructs an empty container without configuration location. 198 @param rParent the parent object. This instance will be used for refcounting, so the parent 199 cannot die before the container does. 200 @param _rMutex the mutex of the parent. 201 @param _bCaseSensitive the initial case sensitivity flag 202 @see setCaseSensitive 203 */ 204 OColumns( 205 ::cppu::OWeakObject& _rParent, 206 ::osl::Mutex& _rMutex, 207 sal_Bool _bCaseSensitive, 208 const ::std::vector< ::rtl::OUString>& _rVector, 209 IColumnFactory* _pColFactory, 210 ::connectivity::sdbcx::IRefreshableColumns* _pRefresh, 211 sal_Bool _bAddColumn = sal_False, 212 sal_Bool _bDropColumn = sal_False, 213 sal_Bool _bUseHardRef = sal_True); 214 215 OColumns( 216 ::cppu::OWeakObject& _rParent, 217 ::osl::Mutex& _rMutex, 218 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxDrvColumns, 219 sal_Bool _bCaseSensitive, 220 const ::std::vector< ::rtl::OUString> &_rVector, 221 IColumnFactory* _pColFactory, 222 ::connectivity::sdbcx::IRefreshableColumns* _pRefresh, 223 sal_Bool _bAddColumn = sal_False, 224 sal_Bool _bDropColumn = sal_False, 225 sal_Bool _bUseHardRef = sal_True); 226 virtual ~OColumns(); 227 228 //XInterface 229 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); acquire()230 virtual void SAL_CALL acquire() throw() { OColumns_BASE::acquire(); } release()231 virtual void SAL_CALL release() throw() { OColumns_BASE::release(); } 232 //XTypeProvider 233 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException); 234 235 // ::com::sun::star::lang::XServiceInfo 236 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); 237 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); 238 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); 239 240 // ::com::sun::star::container::XChild 241 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent( ) throw (::com::sun::star::uno::RuntimeException); 242 virtual void SAL_CALL setParent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Parent ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException); 243 244 void append(const ::rtl::OUString& rName, OColumn*); 245 void clearColumns(); 246 // only the name is identical to ::cppu::OComponentHelper 247 virtual void SAL_CALL disposing(void); 248 249 private: 250 using OColumns_BASE::setParent; 251 }; 252 } 253 #endif // _DBA_COREAPI_COLUMN_HXX_ 254 255