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