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