Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <bitset>
21 :
22 : #include "apitools.hxx"
23 : #include "dbastrings.hrc"
24 : #include "definitioncolumn.hxx"
25 : #include "sdbcoretools.hxx"
26 :
27 : #include <com/sun/star/beans/PropertyAttribute.hpp>
28 : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
29 :
30 : #include <comphelper/property.hxx>
31 : #include <comphelper/types.hxx>
32 : #include <connectivity/dbtools.hxx>
33 : #include <cppuhelper/typeprovider.hxx>
34 : #include <tools/debug.hxx>
35 : #include <tools/diagnose_ex.h>
36 :
37 : using namespace ::com::sun::star::sdbc;
38 : using namespace ::com::sun::star::sdbcx;
39 : using namespace ::com::sun::star::beans;
40 : using namespace ::com::sun::star::uno;
41 : using namespace ::com::sun::star::lang;
42 : using namespace ::com::sun::star::container;
43 : using namespace ::cppu;
44 : using namespace ::comphelper;
45 : using namespace ::osl;
46 : using namespace dbaccess;
47 :
48 : namespace
49 : {
50 : const sal_Int32 HAS_DESCRIPTION = 0x00000001;
51 : const sal_Int32 HAS_DEFAULTVALUE = 0x00000002;
52 : const sal_Int32 HAS_ROWVERSION = 0x00000004;
53 : const sal_Int32 HAS_AUTOINCREMENT_CREATION = 0x00000008;
54 : const sal_Int32 HAS_CATALOGNAME = 0x00000010;
55 : const sal_Int32 HAS_SCHEMANAME = 0x00000020;
56 : const sal_Int32 HAS_TABLENAME = 0x00000040;
57 : }
58 :
59 : //============================================================
60 : //= OTableColumnDescriptor
61 : //============================================================
62 0 : IMPLEMENT_FORWARD_XINTERFACE2(OTableColumnDescriptor,OColumn,TXChild)
63 :
64 0 : void OTableColumnDescriptor::impl_registerProperties()
65 : {
66 0 : sal_Int32 nDefaultAttr = m_bActAsDescriptor ? 0 : PropertyAttribute::READONLY;
67 :
68 0 : registerProperty( PROPERTY_TYPENAME, PROPERTY_ID_TYPENAME, nDefaultAttr, &m_aTypeName, ::getCppuType( &m_aTypeName ) );
69 0 : registerProperty( PROPERTY_DESCRIPTION, PROPERTY_ID_DESCRIPTION, nDefaultAttr, &m_aDescription, ::getCppuType( &m_aDescription ) );
70 0 : registerProperty( PROPERTY_DEFAULTVALUE, PROPERTY_ID_DEFAULTVALUE, nDefaultAttr, &m_aDefaultValue, ::getCppuType( &m_aDefaultValue ) );
71 :
72 0 : if ( m_bActAsDescriptor )
73 0 : registerProperty( PROPERTY_AUTOINCREMENTCREATION, PROPERTY_ID_AUTOINCREMENTCREATION, nDefaultAttr, &m_aAutoIncrementValue, ::getCppuType( &m_aAutoIncrementValue ) );
74 :
75 0 : registerProperty( PROPERTY_TYPE, PROPERTY_ID_TYPE, nDefaultAttr, &m_nType, ::getCppuType( &m_nType ) );
76 0 : registerProperty( PROPERTY_PRECISION, PROPERTY_ID_PRECISION, nDefaultAttr, &m_nPrecision, ::getCppuType( &m_nPrecision ) );
77 0 : registerProperty( PROPERTY_SCALE, PROPERTY_ID_SCALE, nDefaultAttr, &m_nScale, ::getCppuType( &m_nScale ) );
78 0 : registerProperty( PROPERTY_ISNULLABLE, PROPERTY_ID_ISNULLABLE, nDefaultAttr, &m_nIsNullable, ::getCppuType( &m_nIsNullable ) );
79 0 : registerProperty( PROPERTY_ISAUTOINCREMENT, PROPERTY_ID_ISAUTOINCREMENT, nDefaultAttr, &m_bAutoIncrement, ::getCppuType( &m_bAutoIncrement ) );
80 0 : registerProperty( PROPERTY_ISROWVERSION, PROPERTY_ID_ISROWVERSION, nDefaultAttr, &m_bRowVersion, ::getCppuType( &m_bRowVersion ) );
81 0 : registerProperty( PROPERTY_ISCURRENCY, PROPERTY_ID_ISCURRENCY, nDefaultAttr, &m_bCurrency, ::getCppuType( &m_bCurrency ) );
82 :
83 0 : OColumnSettings::registerProperties( *this );
84 0 : }
85 :
86 0 : IMPLEMENT_GET_IMPLEMENTATION_ID( OTableColumnDescriptor )
87 :
88 : // ::com::sun::star::lang::XServiceInfo
89 0 : rtl::OUString OTableColumnDescriptor::getImplementationName( ) throw (RuntimeException)
90 : {
91 0 : return rtl::OUString("com.sun.star.sdb.OTableColumnDescriptor");
92 : }
93 :
94 0 : Sequence< ::rtl::OUString > OTableColumnDescriptor::getSupportedServiceNames( ) throw (RuntimeException)
95 : {
96 0 : Sequence< ::rtl::OUString > aSNS( 2 );
97 0 : aSNS[0] = m_bActAsDescriptor ? SERVICE_SDBCX_COLUMNDESCRIPTOR : SERVICE_SDBCX_COLUMN;
98 0 : aSNS[1] = SERVICE_SDB_COLUMNSETTINGS;
99 0 : return aSNS;
100 : }
101 :
102 : // comphelper::OPropertyArrayUsageHelper
103 0 : ::cppu::IPropertyArrayHelper* OTableColumnDescriptor::createArrayHelper( ) const
104 : {
105 0 : Sequence< Property > aProps;
106 0 : describeProperties( aProps );
107 0 : return new ::cppu::OPropertyArrayHelper( aProps );
108 : }
109 :
110 : // cppu::OPropertySetHelper
111 0 : ::cppu::IPropertyArrayHelper& OTableColumnDescriptor::getInfoHelper()
112 : {
113 0 : return *static_cast< ::comphelper::OPropertyArrayUsageHelper< OTableColumnDescriptor >* >(this)->getArrayHelper();
114 : }
115 :
116 0 : void OTableColumnDescriptor::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception)
117 : {
118 0 : OColumn::setFastPropertyValue_NoBroadcast( nHandle, rValue );
119 0 : ::dbaccess::notifyDataSourceModified( m_xParent, sal_True );
120 0 : }
121 :
122 0 : Reference< XInterface > SAL_CALL OTableColumnDescriptor::getParent( ) throw (RuntimeException)
123 : {
124 0 : ::osl::MutexGuard aGuard(m_aMutex);
125 0 : return m_xParent;
126 : }
127 :
128 0 : void SAL_CALL OTableColumnDescriptor::setParent( const Reference< XInterface >& _xParent ) throw (NoSupportException, RuntimeException)
129 : {
130 0 : ::osl::MutexGuard aGuard(m_aMutex);
131 0 : m_xParent = _xParent;
132 0 : }
133 : //============================================================
134 : //= OTableColumn
135 : //============================================================
136 : DBG_NAME(OTableColumn);
137 :
138 0 : OTableColumn::OTableColumn( const ::rtl::OUString& _rName )
139 0 : :OTableColumnDescriptor( false /* do not act as descriptor */ )
140 : {
141 : DBG_CTOR(OTableColumn,NULL);
142 0 : m_sName = _rName;
143 0 : }
144 :
145 0 : OTableColumn::~OTableColumn()
146 : {
147 : DBG_DTOR(OTableColumn,NULL);
148 0 : }
149 :
150 0 : IMPLEMENT_GET_IMPLEMENTATION_ID( OTableColumn )
151 :
152 0 : rtl::OUString OTableColumn::getImplementationName( ) throw (RuntimeException)
153 : {
154 0 : return rtl::OUString("com.sun.star.sdb.OTableColumn");
155 : }
156 :
157 0 : ::cppu::IPropertyArrayHelper& SAL_CALL OTableColumn::getInfoHelper()
158 : {
159 0 : return *OTableColumn_PBase::getArrayHelper();
160 : }
161 :
162 0 : ::cppu::IPropertyArrayHelper* OTableColumn::createArrayHelper( ) const
163 : {
164 0 : return OTableColumnDescriptor::createArrayHelper();
165 : }
166 :
167 : // =========================================================================
168 : //= OQueryColumn
169 : // =========================================================================
170 : DBG_NAME( OQueryColumn );
171 :
172 0 : OQueryColumn::OQueryColumn( const Reference< XPropertySet >& _rxParserColumn, const Reference< XConnection >& _rxConnection, const ::rtl::OUString &i_sLabel )
173 : :OTableColumnDescriptor( false /* do not act as descriptor */ )
174 0 : ,m_sLabel(i_sLabel)
175 : {
176 0 : const sal_Int32 nPropAttr = PropertyAttribute::READONLY;
177 0 : registerProperty( PROPERTY_CATALOGNAME, PROPERTY_ID_CATALOGNAME, nPropAttr, &m_sCatalogName, ::getCppuType( &m_sCatalogName ) );
178 0 : registerProperty( PROPERTY_SCHEMANAME, PROPERTY_ID_SCHEMANAME, nPropAttr, &m_sSchemaName, ::getCppuType( &m_sSchemaName ) );
179 0 : registerProperty( PROPERTY_TABLENAME, PROPERTY_ID_TABLENAME, nPropAttr, &m_sTableName, ::getCppuType( &m_sTableName ) );
180 0 : registerProperty( PROPERTY_REALNAME, PROPERTY_ID_REALNAME, nPropAttr, &m_sRealName, ::getCppuType( &m_sRealName ) );
181 0 : registerProperty( PROPERTY_LABEL, PROPERTY_ID_LABEL, nPropAttr, &m_sLabel, ::getCppuType( &m_sLabel ) );
182 :
183 : DBG_CTOR( OQueryColumn, NULL );
184 :
185 0 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_TYPENAME ) >>= m_aTypeName );
186 0 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_ISNULLABLE ) >>= m_nIsNullable );
187 0 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_PRECISION ) >>= m_nPrecision );
188 0 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_SCALE ) >>= m_nScale );
189 0 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_TYPE ) >>= m_nType );
190 0 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_ISAUTOINCREMENT ) >>= m_bAutoIncrement );
191 0 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_ISCURRENCY ) >>= m_bCurrency );
192 0 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_NAME ) >>= m_sName );
193 :
194 0 : m_bRowVersion = sal_False;
195 :
196 0 : Reference< XPropertySetInfo > xPSI( _rxParserColumn->getPropertySetInfo(), UNO_SET_THROW );
197 0 : if ( xPSI->hasPropertyByName( PROPERTY_DEFAULTVALUE ) )
198 0 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_DEFAULTVALUE ) >>= m_aDefaultValue );
199 :
200 : // copy some optional properties from the parser column
201 0 : struct PropertyDescriptor
202 : {
203 : ::rtl::OUString sName;
204 : sal_Int32 nHandle;
205 : };
206 : PropertyDescriptor aProps[] =
207 : {
208 : { PROPERTY_CATALOGNAME, PROPERTY_ID_CATALOGNAME },
209 : { PROPERTY_SCHEMANAME, PROPERTY_ID_SCHEMANAME },
210 : { PROPERTY_TABLENAME, PROPERTY_ID_TABLENAME },
211 : { PROPERTY_REALNAME, PROPERTY_ID_REALNAME }
212 0 : };
213 0 : for ( size_t i=0; i < sizeof( aProps ) / sizeof( aProps[0] ); ++i )
214 : {
215 0 : if ( xPSI->hasPropertyByName( aProps[i].sName ) )
216 0 : setFastPropertyValue_NoBroadcast( aProps[i].nHandle, _rxParserColumn->getPropertyValue( aProps[i].sName ) );
217 : }
218 :
219 : // determine the table column we're based on
220 0 : osl_atomic_increment( &m_refCount );
221 : {
222 0 : m_xOriginalTableColumn = impl_determineOriginalTableColumn( _rxConnection );
223 : }
224 0 : osl_atomic_decrement( &m_refCount );
225 0 : }
226 :
227 0 : OQueryColumn::~OQueryColumn()
228 : {
229 : DBG_DTOR( OQueryColumn, NULL );
230 0 : }
231 :
232 0 : Reference< XPropertySet > OQueryColumn::impl_determineOriginalTableColumn( const Reference< XConnection >& _rxConnection )
233 : {
234 : OSL_PRECOND( _rxConnection.is(), "OQueryColumn::impl_determineOriginalTableColumn: illegal connection!" );
235 0 : if ( !_rxConnection.is() )
236 0 : return NULL;
237 :
238 0 : Reference< XPropertySet > xOriginalTableColumn;
239 : try
240 : {
241 : // determine the composed table name, plus the column name, as indicated by the
242 : // respective properties
243 0 : ::rtl::OUString sCatalog, sSchema, sTable;
244 0 : OSL_VERIFY( getPropertyValue( PROPERTY_CATALOGNAME ) >>= sCatalog );
245 0 : OSL_VERIFY( getPropertyValue( PROPERTY_SCHEMANAME ) >>= sSchema );
246 0 : OSL_VERIFY( getPropertyValue( PROPERTY_TABLENAME ) >>= sTable );
247 0 : if ( sCatalog.isEmpty() && sSchema.isEmpty() && sTable.isEmpty() )
248 0 : return NULL;
249 :
250 : ::rtl::OUString sComposedTableName = ::dbtools::composeTableName(
251 0 : _rxConnection->getMetaData(), sCatalog, sSchema, sTable, sal_False, ::dbtools::eComplete );
252 :
253 : // retrieve the table in question
254 0 : Reference< XTablesSupplier > xSuppTables( _rxConnection, UNO_QUERY_THROW );
255 0 : Reference< XNameAccess > xTables( xSuppTables->getTables(), UNO_QUERY_THROW );
256 0 : if ( !xTables->hasByName( sComposedTableName ) )
257 0 : return NULL;
258 :
259 0 : Reference< XColumnsSupplier > xSuppCols( xTables->getByName( sComposedTableName ), UNO_QUERY_THROW );
260 0 : Reference< XNameAccess > xColumns( xSuppCols->getColumns(), UNO_QUERY_THROW );
261 :
262 0 : ::rtl::OUString sColumn;
263 0 : OSL_VERIFY( getPropertyValue( PROPERTY_REALNAME ) >>= sColumn );
264 0 : if ( !xColumns->hasByName( sColumn ) )
265 0 : return NULL;
266 :
267 0 : xOriginalTableColumn.set( xColumns->getByName( sColumn ), UNO_QUERY );
268 : }
269 0 : catch( const Exception& )
270 : {
271 : DBG_UNHANDLED_EXCEPTION();
272 : }
273 0 : return xOriginalTableColumn;
274 : }
275 :
276 0 : IMPLEMENT_GET_IMPLEMENTATION_ID( OQueryColumn )
277 :
278 0 : ::rtl::OUString SAL_CALL OQueryColumn::getImplementationName( ) throw(RuntimeException)
279 : {
280 0 : return ::rtl::OUString( "org.openoffice.comp.dbaccess.OQueryColumn" );
281 : }
282 :
283 0 : ::cppu::IPropertyArrayHelper& SAL_CALL OQueryColumn::getInfoHelper()
284 : {
285 0 : return *OQueryColumn_PBase::getArrayHelper();
286 : }
287 :
288 0 : ::cppu::IPropertyArrayHelper* OQueryColumn::createArrayHelper() const
289 : {
290 0 : return OTableColumnDescriptor::createArrayHelper();
291 : }
292 :
293 0 : void SAL_CALL OQueryColumn::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
294 : {
295 0 : OTableColumnDescriptor::getFastPropertyValue( _rValue, _nHandle );
296 :
297 : // special treatment for column settings:
298 0 : if ( !OColumnSettings::isColumnSettingProperty( _nHandle ) )
299 0 : return;
300 :
301 : // If the setting has its default value, then try to obtain the value from the table column which
302 : // this query column is based on
303 0 : if ( !OColumnSettings::isDefaulted( _nHandle, _rValue ) )
304 0 : return;
305 :
306 0 : if ( !m_xOriginalTableColumn.is() )
307 0 : return;
308 :
309 : try
310 : {
311 : // determine original property name
312 0 : ::rtl::OUString sPropName;
313 0 : sal_Int16 nAttributes( 0 );
314 0 : const_cast< OQueryColumn* >( this )->getInfoHelper().fillPropertyMembersByHandle( &sPropName, &nAttributes, _nHandle );
315 : OSL_ENSURE( !sPropName.isEmpty(), "OColumnWrapper::impl_getPropertyNameFromHandle: property not found!" );
316 :
317 0 : _rValue = m_xOriginalTableColumn->getPropertyValue( sPropName );
318 : }
319 0 : catch( const Exception& )
320 : {
321 : DBG_UNHANDLED_EXCEPTION();
322 : }
323 : }
324 :
325 : //==========================================================================
326 : //= OColumnWrapper
327 : //==========================================================================
328 : DBG_NAME(OColumnWrapper);
329 :
330 0 : OColumnWrapper::OColumnWrapper( const Reference< XPropertySet > & rCol, const bool _bNameIsReadOnly )
331 : :OColumn( _bNameIsReadOnly )
332 : ,m_xAggregate(rCol)
333 0 : ,m_nColTypeID(-1)
334 : {
335 : DBG_CTOR(OColumnWrapper,NULL);
336 : // which type of aggregate property do we have?
337 : // we distingish the properties by the containment of optional properties
338 0 : m_nColTypeID = 0;
339 0 : if ( m_xAggregate.is() )
340 : {
341 0 : Reference <XPropertySetInfo > xInfo(m_xAggregate->getPropertySetInfo());
342 0 : m_nColTypeID |= xInfo->hasPropertyByName(PROPERTY_DESCRIPTION) ? HAS_DESCRIPTION : 0;
343 0 : m_nColTypeID |= xInfo->hasPropertyByName(PROPERTY_DEFAULTVALUE) ? HAS_DEFAULTVALUE : 0;
344 0 : m_nColTypeID |= xInfo->hasPropertyByName(PROPERTY_ISROWVERSION) ? HAS_ROWVERSION : 0;
345 0 : m_nColTypeID |= xInfo->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION) ? HAS_AUTOINCREMENT_CREATION : 0;
346 0 : m_nColTypeID |= xInfo->hasPropertyByName(PROPERTY_CATALOGNAME) ? HAS_CATALOGNAME : 0;
347 0 : m_nColTypeID |= xInfo->hasPropertyByName(PROPERTY_SCHEMANAME) ? HAS_SCHEMANAME : 0;
348 0 : m_nColTypeID |= xInfo->hasPropertyByName(PROPERTY_TABLENAME) ? HAS_TABLENAME : 0;
349 :
350 0 : m_xAggregate->getPropertyValue(PROPERTY_NAME) >>= m_sName;
351 : }
352 0 : }
353 :
354 0 : OColumnWrapper::~OColumnWrapper()
355 : {
356 : DBG_DTOR(OColumnWrapper,NULL);
357 0 : }
358 :
359 0 : ::rtl::OUString OColumnWrapper::impl_getPropertyNameFromHandle( const sal_Int32 _nHandle ) const
360 : {
361 0 : ::rtl::OUString sPropName;
362 0 : sal_Int16 nAttributes( 0 );
363 0 : const_cast< OColumnWrapper* >( this )->getInfoHelper().fillPropertyMembersByHandle( &sPropName, &nAttributes, _nHandle );
364 : OSL_ENSURE( !sPropName.isEmpty(), "OColumnWrapper::impl_getPropertyNameFromHandle: property not found!" );
365 0 : return sPropName;
366 : }
367 :
368 0 : void OColumnWrapper::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
369 : {
370 : // derived classes are free to either use the OPropertyContainer(Helper) mechanisms for properties,
371 : // or to declare additional properties which are to be forwarded to the wrapped object. So we need
372 : // to distinguish those cases.
373 0 : if ( OColumn::isRegisteredProperty( nHandle ) )
374 : {
375 0 : OColumn::getFastPropertyValue( rValue, nHandle );
376 : }
377 : else
378 : {
379 0 : rValue = m_xAggregate->getPropertyValue( impl_getPropertyNameFromHandle( nHandle ) );
380 : }
381 0 : }
382 :
383 0 : sal_Bool OColumnWrapper::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle,
384 : const Any& rValue ) throw (IllegalArgumentException)
385 : {
386 0 : sal_Bool bModified( sal_False );
387 0 : if ( OColumn::isRegisteredProperty( nHandle ) )
388 : {
389 0 : bModified = OColumn::convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, rValue );
390 : }
391 : else
392 : {
393 0 : getFastPropertyValue( rOldValue, nHandle );
394 0 : if ( rOldValue != rValue )
395 : {
396 0 : rConvertedValue = rValue;
397 0 : bModified = sal_True;
398 : }
399 : }
400 0 : return bModified;
401 : }
402 :
403 0 : void OColumnWrapper::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception)
404 : {
405 0 : if ( OColumn::isRegisteredProperty( nHandle ) )
406 : {
407 0 : OColumn::setFastPropertyValue_NoBroadcast( nHandle, rValue );
408 : }
409 : else
410 : {
411 0 : m_xAggregate->setPropertyValue( impl_getPropertyNameFromHandle( nHandle ), rValue );
412 : }
413 0 : }
414 :
415 0 : sal_Int64 SAL_CALL OColumnWrapper::getSomething( const Sequence< sal_Int8 >& aIdentifier ) throw(RuntimeException)
416 : {
417 0 : Reference< XUnoTunnel > xTunnel( m_xAggregate, UNO_QUERY);
418 0 : if ( xTunnel.is() )
419 0 : return xTunnel->getSomething( aIdentifier );
420 0 : return 0;
421 : }
422 :
423 : //============================================================
424 : //= OTableColumnDescriptorWrapper
425 : //============================================================
426 0 : OTableColumnDescriptorWrapper::OTableColumnDescriptorWrapper( const Reference< XPropertySet >& _rCol, const bool _bPureWrap, const bool _bIsDescriptor )
427 0 : :OColumnWrapper( _rCol, !_bIsDescriptor )
428 : ,m_bPureWrap( _bPureWrap )
429 0 : ,m_bIsDescriptor( _bIsDescriptor )
430 : {
431 : // let the ColumnSettings register its properties
432 0 : OColumnSettings::registerProperties( *this );
433 0 : }
434 :
435 : // com::sun::star::lang::XTypeProvider
436 0 : IMPLEMENT_GET_IMPLEMENTATION_ID( OTableColumnDescriptorWrapper )
437 :
438 : // ::com::sun::star::lang::XServiceInfo
439 0 : rtl::OUString OTableColumnDescriptorWrapper::getImplementationName( ) throw (RuntimeException)
440 : {
441 0 : return rtl::OUString("com.sun.star.sdb.OTableColumnDescriptorWrapper");
442 : }
443 :
444 0 : Sequence< ::rtl::OUString > OTableColumnDescriptorWrapper::getSupportedServiceNames( ) throw (RuntimeException)
445 : {
446 0 : Sequence< ::rtl::OUString > aSNS( 2 );
447 0 : aSNS[0] = SERVICE_SDBCX_COLUMNDESCRIPTOR;
448 0 : aSNS[1] = SERVICE_SDB_COLUMNSETTINGS;
449 0 : return aSNS;
450 : }
451 :
452 : // comphelper::OPropertyArrayUsageHelper
453 0 : ::cppu::IPropertyArrayHelper* OTableColumnDescriptorWrapper::createArrayHelper( sal_Int32 nId ) const
454 : {
455 0 : const sal_Int32 nHaveAlways = 7;
456 :
457 : // Which optional properties are contained?
458 0 : const sal_Int32 nHaveOptionally (::std::bitset<7>(nId).count());
459 :
460 0 : BEGIN_PROPERTY_SEQUENCE( nHaveAlways + nHaveOptionally )
461 :
462 0 : DECL_PROP0_BOOL( ISAUTOINCREMENT );
463 0 : DECL_PROP0_BOOL( ISCURRENCY );
464 0 : DECL_PROP0( ISNULLABLE, sal_Int32 );
465 0 : DECL_PROP0( PRECISION, sal_Int32 );
466 0 : DECL_PROP0( SCALE, sal_Int32 );
467 0 : DECL_PROP0( TYPE, sal_Int32 );
468 0 : DECL_PROP0( TYPENAME, ::rtl::OUString );
469 :
470 0 : if ( nId & HAS_AUTOINCREMENT_CREATION )
471 : {
472 0 : DECL_PROP1( AUTOINCREMENTCREATION, ::rtl::OUString, MAYBEVOID );
473 : }
474 0 : if ( nId & HAS_DEFAULTVALUE )
475 : {
476 0 : DECL_PROP0( DEFAULTVALUE, ::rtl::OUString );
477 : }
478 0 : if ( nId & HAS_DESCRIPTION )
479 : {
480 0 : DECL_PROP0( DESCRIPTION, ::rtl::OUString );
481 : }
482 0 : if ( nId & HAS_ROWVERSION )
483 : {
484 0 : DECL_PROP0_BOOL( ISROWVERSION );
485 : }
486 0 : if ( nId & HAS_CATALOGNAME )
487 : {
488 0 : DECL_PROP0( CATALOGNAME, ::rtl::OUString );
489 : }
490 0 : if ( nId & HAS_SCHEMANAME )
491 : {
492 0 : DECL_PROP0( SCHEMANAME, ::rtl::OUString );
493 : }
494 0 : if ( nId & HAS_TABLENAME )
495 : {
496 0 : DECL_PROP0( TABLENAME, ::rtl::OUString );
497 : }
498 :
499 : END_PROPERTY_SEQUENCE()
500 :
501 0 : if ( !m_bIsDescriptor )
502 : {
503 0 : for ( Property* prop = aDescriptor.getArray();
504 0 : prop != aDescriptor.getArray() + aDescriptor.getLength();
505 : ++prop
506 : )
507 : {
508 0 : prop->Attributes |= PropertyAttribute::READONLY;
509 : }
510 : }
511 :
512 : // finally also describe the properties which are maintained by our base class, in particular the OPropertyContainerHelper
513 0 : Sequence< Property > aBaseProperties;
514 0 : describeProperties( aBaseProperties );
515 :
516 0 : Sequence< Property > aAllProperties( ::comphelper::concatSequences( aDescriptor, aBaseProperties ) );
517 0 : return new ::cppu::OPropertyArrayHelper( aAllProperties, sal_False );
518 : }
519 :
520 : // cppu::OPropertySetHelper
521 0 : ::cppu::IPropertyArrayHelper& OTableColumnDescriptorWrapper::getInfoHelper()
522 : {
523 0 : return *static_cast< OIdPropertyArrayUsageHelper< OTableColumnDescriptorWrapper >* >(this)->getArrayHelper(m_nColTypeID);
524 : }
525 :
526 0 : void OTableColumnDescriptorWrapper::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
527 : {
528 0 : if ( m_bPureWrap )
529 : {
530 0 : rValue = m_xAggregate->getPropertyValue( impl_getPropertyNameFromHandle( nHandle ) );
531 : }
532 : else
533 : {
534 0 : OColumnWrapper::getFastPropertyValue( rValue, nHandle );
535 : }
536 0 : }
537 :
538 0 : sal_Bool OTableColumnDescriptorWrapper::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue ) throw (IllegalArgumentException)
539 : {
540 0 : sal_Bool bModified(sal_False);
541 0 : if ( m_bPureWrap )
542 : {
543 : // do not delegate to OColumnWrapper: It would, for the properties which were registered with registerProperty,
544 : // ask the OPropertyContainer base class, which is not what we want here.
545 : // TODO: the whole "m_bPureWrap"-thingie is strange. We should have a dedicated class doing this wrapping,
546 : // not a class which normally serves other purposes, and only sometimes does a "pure wrap". It makes the
547 : // code unnecessarily hard to maintain, and error prone.
548 0 : rOldValue = m_xAggregate->getPropertyValue( impl_getPropertyNameFromHandle( nHandle ) );
549 0 : if ( rOldValue != rValue )
550 : {
551 0 : rConvertedValue = rValue;
552 0 : bModified = sal_True;
553 : }
554 : }
555 : else
556 : {
557 0 : bModified = OColumnWrapper::convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, rValue );
558 : }
559 0 : return bModified;
560 : }
561 :
562 0 : void OTableColumnDescriptorWrapper::setFastPropertyValue_NoBroadcast(
563 : sal_Int32 nHandle,
564 : const Any& rValue
565 : )
566 : throw (Exception)
567 : {
568 0 : if ( m_bPureWrap )
569 : {
570 0 : m_xAggregate->setPropertyValue( impl_getPropertyNameFromHandle( nHandle ), rValue );
571 : }
572 : else
573 : {
574 0 : OColumnWrapper::setFastPropertyValue_NoBroadcast( nHandle, rValue );
575 : }
576 0 : }
577 :
578 : //============================================================
579 : //= OTableColumnWrapper
580 : //============================================================
581 0 : OTableColumnWrapper::OTableColumnWrapper( const Reference< XPropertySet >& rCol, const Reference< XPropertySet >& _xColDefintion,
582 : const bool _bPureWrap )
583 0 : :OTableColumnDescriptorWrapper( rCol, _bPureWrap, false )
584 : {
585 0 : osl_atomic_increment( &m_refCount );
586 0 : if ( _xColDefintion.is() )
587 : {
588 : try
589 : {
590 0 : ::comphelper::copyProperties( _xColDefintion, this );
591 : }
592 0 : catch( const Exception& )
593 : {
594 : DBG_UNHANDLED_EXCEPTION();
595 : }
596 : }
597 0 : osl_atomic_decrement( &m_refCount );
598 0 : }
599 :
600 0 : OTableColumnWrapper::~OTableColumnWrapper()
601 : {
602 0 : }
603 :
604 0 : IMPLEMENT_GET_IMPLEMENTATION_ID( OTableColumnWrapper )
605 :
606 0 : rtl::OUString OTableColumnWrapper::getImplementationName( ) throw (RuntimeException)
607 : {
608 0 : return rtl::OUString("com.sun.star.sdb.OTableColumnWrapper" );
609 : }
610 :
611 0 : Sequence< ::rtl::OUString > OTableColumnWrapper::getSupportedServiceNames( ) throw (RuntimeException)
612 : {
613 0 : Sequence< ::rtl::OUString > aSNS( 2 );
614 0 : aSNS[0] = SERVICE_SDBCX_COLUMN;
615 0 : aSNS[1] = SERVICE_SDB_COLUMNSETTINGS;
616 0 : return aSNS;
617 : }
618 :
619 0 : ::cppu::IPropertyArrayHelper& OTableColumnWrapper::getInfoHelper()
620 : {
621 0 : return *static_cast< OIdPropertyArrayUsageHelper< OTableColumnWrapper >* >(this)->getArrayHelper(m_nColTypeID);
622 : }
623 :
624 : // comphelper::OPropertyArrayUsageHelper
625 0 : ::cppu::IPropertyArrayHelper* OTableColumnWrapper::createArrayHelper( sal_Int32 nId ) const
626 : {
627 0 : return OTableColumnDescriptorWrapper::createArrayHelper( nId );
628 : }
629 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|