xref: /trunk/main/dbaccess/source/core/inc/definitioncolumn.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 #ifndef _DBACORE_DEFINITIONCOLUMN_HXX_
28 #define _DBACORE_DEFINITIONCOLUMN_HXX_
29 
30 #include "apitools.hxx"
31 #include "column.hxx"
32 #include "columnsettings.hxx"
33 
34 #include <com/sun/star/sdbc/DataType.hpp>
35 #include <com/sun/star/sdbc/ColumnValue.hpp>
36 #include <com/sun/star/container/XChild.hpp>
37 
38 #include <comphelper/IdPropArrayHelper.hxx>
39 #include <comphelper/uno3.hxx>
40 #include <cppuhelper/implbase1.hxx>
41 
42 
43 namespace dbaccess
44 {
45 
46     typedef ::cppu::ImplHelper1< ::com::sun::star::container::XChild > TXChild;
47     // =========================================================================
48     //= OTableColumnDescriptor
49     // =========================================================================
50     /**
51      *  provides the properties for description. A descriptor could be used to create a new table column.
52      */
53     class OTableColumnDescriptor : public OColumn
54                                   ,public OColumnSettings
55                                   ,public ::comphelper::OPropertyArrayUsageHelper < OTableColumnDescriptor >
56                                   ,public TXChild
57     {
58         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >   m_xParent;
59         const bool                                                              m_bActAsDescriptor;
60 
61     protected:
62     //  <properties>
63         rtl::OUString           m_aTypeName;
64         rtl::OUString           m_aDescription;
65         rtl::OUString           m_aDefaultValue;
66         rtl::OUString           m_aAutoIncrementValue;
67         sal_Int32               m_nType;
68         sal_Int32               m_nPrecision;
69         sal_Int32               m_nScale;
70         sal_Int32               m_nIsNullable;
71         sal_Bool                m_bAutoIncrement;
72         sal_Bool                m_bRowVersion;
73         sal_Bool                m_bCurrency;
74     //  </properties>
75 
76     public:
77         OTableColumnDescriptor( const bool _bActAsDescriptor )
78             :OColumn( !_bActAsDescriptor )
79             ,m_bActAsDescriptor( _bActAsDescriptor )
80             ,m_nType( ::com::sun::star::sdbc::DataType::SQLNULL )
81             ,m_nPrecision( 0 )
82             ,m_nScale( 0 )
83             ,m_nIsNullable( ::com::sun::star::sdbc::ColumnValue::NULLABLE_UNKNOWN )
84             ,m_bAutoIncrement( sal_False )
85             ,m_bRowVersion( sal_False )
86             ,m_bCurrency( sal_False )
87         {
88             impl_registerProperties();
89         }
90 
91         DECLARE_XINTERFACE( )
92 
93         // com::sun::star::lang::XTypeProvider
94         virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException);
95 
96         // ::com::sun::star::lang::XServiceInfo
97         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
98         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
99 
100         // ::com::sun::star::container::XChild
101         virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent(  ) throw (::com::sun::star::uno::RuntimeException);
102         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);
103 
104         // ::comphelper::OPropertyArrayUsageHelper
105         virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const;
106 
107         // ::cppu::OPropertySetHelper
108         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
109         virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception);
110 
111     private:
112         void    impl_registerProperties();
113     };
114 
115     // =========================================================================
116     // = OTableColumn
117     // =========================================================================
118     class OTableColumn;
119     typedef ::comphelper::OPropertyArrayUsageHelper < OTableColumn >    OTableColumn_PBase;
120     /** describes a column of a table
121      */
122     class OTableColumn  :public OTableColumnDescriptor
123                         ,public OTableColumn_PBase
124     {
125     protected:
126         virtual ~OTableColumn();
127 
128     public:
129         OTableColumn(const ::rtl::OUString& _rName);
130 
131         // XTypeProvider
132         virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException);
133 
134         // XServiceInfo
135         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
136 
137         // OPropertyArrayUsageHelper
138         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
139         virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const;
140     };
141 
142     // =========================================================================
143     // = OQueryColumn
144     // =========================================================================
145     class OQueryColumn;
146     typedef ::comphelper::OPropertyArrayUsageHelper< OQueryColumn > OQueryColumn_PBase;
147     /** a column of a Query, with additional information obtained from parsing the query statement
148     */
149     class OQueryColumn  :public OTableColumnDescriptor
150                         ,public OQueryColumn_PBase
151     {
152         // <properties>
153         ::rtl::OUString m_sCatalogName;
154         ::rtl::OUString m_sSchemaName;
155         ::rtl::OUString m_sTableName;
156         ::rtl::OUString m_sRealName;
157         ::rtl::OUString m_sLabel;
158         // </properties>
159 
160         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >   m_xOriginalTableColumn;
161 
162     protected:
163         ~OQueryColumn();
164 
165     public:
166         OQueryColumn(
167             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxParserColumn,
168             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,
169             const ::rtl::OUString i_sLabel
170         );
171 
172         // XTypeProvider
173         virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException);
174 
175         // XServiceInfo
176         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
177 
178         // *Property*
179         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
180         virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const;
181         virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const;
182 
183     private:
184         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
185                 impl_determineOriginalTableColumn(
186                     const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection
187                 );
188 
189         using ::cppu::OPropertySetHelper::getFastPropertyValue;
190     };
191 
192     // =========================================================================
193     // = OColumnWrapper
194     // =========================================================================
195     /**
196      *  describes all properties for a columns of a table. Only the view parts are provided
197      *  directly, all the other parts are derived from a driver implementation
198      */
199     class OColumnWrapper    :public OColumn
200     {
201     protected:
202         // definition which is provided by a driver!
203         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
204                                 m_xAggregate;
205 
206         sal_Int32               m_nColTypeID;
207 
208     protected:
209         OColumnWrapper( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rCol, const bool _bNameIsReadOnly );
210         virtual ~OColumnWrapper();
211 
212     public:
213         virtual void SAL_CALL getFastPropertyValue(
214                                 ::com::sun::star::uno::Any& rValue,
215                                 sal_Int32 nHandle
216                                  ) const;
217         virtual sal_Bool SAL_CALL convertFastPropertyValue(
218                                 ::com::sun::star::uno::Any & rConvertedValue,
219                                 ::com::sun::star::uno::Any & rOldValue,
220                                 sal_Int32 nHandle,
221                                 const ::com::sun::star::uno::Any& rValue )
222                                     throw (::com::sun::star::lang::IllegalArgumentException);
223         virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
224                                     sal_Int32 nHandle,
225                                     const ::com::sun::star::uno::Any& rValue
226                                                      )
227                                                      throw (::com::sun::star::uno::Exception);
228 
229         virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
230 
231     protected:
232         ::rtl::OUString impl_getPropertyNameFromHandle( const sal_Int32 _nHandle ) const;
233 
234     protected:
235         using OColumn::getFastPropertyValue;
236     };
237 
238     // =========================================================================
239     // = OTableColumnDescriptorWrapper
240     // =========================================================================
241     /**
242      *  provides the properties for description. A descriptor could be used to create a new table column.
243      */
244     class OTableColumnDescriptorWrapper :public OColumnWrapper
245                                         ,public OColumnSettings
246                                         ,public ::comphelper::OIdPropertyArrayUsageHelper < OTableColumnDescriptorWrapper >
247     {
248         const bool  m_bPureWrap;
249         const bool  m_bIsDescriptor;
250 
251     public:
252         OTableColumnDescriptorWrapper(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rCol,
253             const bool _bPureWrap, const bool _bIsDescriptor );
254 
255     // com::sun::star::lang::XTypeProvider
256         virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException);
257 
258     // ::com::sun::star::lang::XServiceInfo
259         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
260         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
261 
262     // OIdPropertyArrayUsageHelper
263         virtual ::cppu::IPropertyArrayHelper* createArrayHelper(sal_Int32 nId) const;
264 
265     // cppu::OPropertySetHelper
266         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
267         virtual void SAL_CALL getFastPropertyValue(
268                                     ::com::sun::star::uno::Any& rValue,
269                                     sal_Int32 nHandle
270                                          ) const;
271         virtual sal_Bool SAL_CALL convertFastPropertyValue(
272                                 ::com::sun::star::uno::Any & rConvertedValue,
273                                 ::com::sun::star::uno::Any & rOldValue,
274                                 sal_Int32 nHandle,
275                                 const ::com::sun::star::uno::Any& rValue )
276                                     throw (::com::sun::star::lang::IllegalArgumentException);
277         virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
278                                     sal_Int32 nHandle,
279                                     const ::com::sun::star::uno::Any& rValue
280                                                      )
281                                                      throw (::com::sun::star::uno::Exception);
282 
283     protected:
284         using OColumnWrapper::getFastPropertyValue;
285     };
286 
287     // =========================================================================
288     // = OTableColumnWrapper
289     // =========================================================================
290     /**
291      *  describes all properties for a columns of a table. Only the view parts are provided
292      *  directly, all the other parts are derived from a driver implementation
293      */
294     class OTableColumnWrapper   :public OTableColumnDescriptorWrapper
295                                 ,public ::comphelper::OIdPropertyArrayUsageHelper < OTableColumnWrapper >
296     {
297     protected:
298         ~OTableColumnWrapper();
299 
300     public:
301         OTableColumnWrapper( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rCol,
302                              const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rColDefintion,
303                              const bool _bPureWrap );
304 
305     // ::com::sun::star::lang::XTypeProvider
306         virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException);
307 
308     // ::com::sun::star::lang::XServiceInfo
309         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
310         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
311 
312     // OIdPropertyArrayUsageHelper
313         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
314         virtual ::cppu::IPropertyArrayHelper* createArrayHelper(sal_Int32 nId) const;
315     };
316 }
317 #endif // _DBACORE_DEFINITIONCOLUMN_HXX_
318 
319