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