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 20210 : IMPLEMENT_FORWARD_XINTERFACE2(OTableColumnDescriptor,OColumn,TXChild)
61 :
62 642 : void OTableColumnDescriptor::impl_registerProperties()
63 : {
64 642 : sal_Int32 nDefaultAttr = m_bActAsDescriptor ? 0 : PropertyAttribute::READONLY;
65 :
66 642 : registerProperty( PROPERTY_TYPENAME, PROPERTY_ID_TYPENAME, nDefaultAttr, &m_aTypeName, cppu::UnoType<decltype(m_aTypeName)>::get() );
67 642 : registerProperty( PROPERTY_DESCRIPTION, PROPERTY_ID_DESCRIPTION, nDefaultAttr, &m_aDescription, cppu::UnoType<decltype(m_aDescription)>::get() );
68 642 : registerProperty( PROPERTY_DEFAULTVALUE, PROPERTY_ID_DEFAULTVALUE, nDefaultAttr, &m_aDefaultValue, cppu::UnoType<decltype(m_aDefaultValue)>::get() );
69 :
70 642 : if ( m_bActAsDescriptor )
71 639 : registerProperty( PROPERTY_AUTOINCREMENTCREATION, PROPERTY_ID_AUTOINCREMENTCREATION, nDefaultAttr, &m_aAutoIncrementValue, cppu::UnoType<decltype(m_aAutoIncrementValue)>::get() );
72 :
73 642 : registerProperty( PROPERTY_TYPE, PROPERTY_ID_TYPE, nDefaultAttr, &m_nType, cppu::UnoType<decltype(m_nType)>::get() );
74 642 : registerProperty( PROPERTY_PRECISION, PROPERTY_ID_PRECISION, nDefaultAttr, &m_nPrecision, cppu::UnoType<decltype(m_nPrecision)>::get() );
75 642 : registerProperty( PROPERTY_SCALE, PROPERTY_ID_SCALE, nDefaultAttr, &m_nScale, cppu::UnoType<decltype(m_nScale)>::get() );
76 642 : registerProperty( PROPERTY_ISNULLABLE, PROPERTY_ID_ISNULLABLE, nDefaultAttr, &m_nIsNullable, cppu::UnoType<decltype(m_nIsNullable)>::get() );
77 642 : registerProperty( PROPERTY_ISAUTOINCREMENT, PROPERTY_ID_ISAUTOINCREMENT, nDefaultAttr, &m_bAutoIncrement, cppu::UnoType<decltype(m_bAutoIncrement)>::get() );
78 642 : registerProperty( PROPERTY_ISROWVERSION, PROPERTY_ID_ISROWVERSION, nDefaultAttr, &m_bRowVersion, cppu::UnoType<decltype(m_bRowVersion)>::get() );
79 642 : registerProperty( PROPERTY_ISCURRENCY, PROPERTY_ID_ISCURRENCY, nDefaultAttr, &m_bCurrency, cppu::UnoType<decltype(m_bCurrency)>::get() );
80 :
81 642 : OColumnSettings::registerProperties( *this );
82 642 : }
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 9 : ::cppu::IPropertyArrayHelper* OTableColumnDescriptor::createArrayHelper( ) const
102 : {
103 9 : Sequence< Property > aProps;
104 9 : describeProperties( aProps );
105 9 : return new ::cppu::OPropertyArrayHelper( aProps );
106 : }
107 :
108 : // cppu::OPropertySetHelper
109 59903 : ::cppu::IPropertyArrayHelper& OTableColumnDescriptor::getInfoHelper()
110 : {
111 59903 : return *static_cast< ::comphelper::OPropertyArrayUsageHelper< OTableColumnDescriptor >* >(this)->getArrayHelper();
112 : }
113 :
114 937 : void OTableColumnDescriptor::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception, std::exception)
115 : {
116 937 : OColumn::setFastPropertyValue_NoBroadcast( nHandle, rValue );
117 937 : ::dbaccess::notifyDataSourceModified( m_xParent, true );
118 937 : }
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 429 : void SAL_CALL OTableColumnDescriptor::setParent( const Reference< XInterface >& _xParent ) throw (NoSupportException, RuntimeException, std::exception)
127 : {
128 429 : ::osl::MutexGuard aGuard(m_aMutex);
129 429 : m_xParent = _xParent;
130 429 : }
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 3 : OQueryColumn::OQueryColumn( const Reference< XPropertySet >& _rxParserColumn, const Reference< XConnection >& _rxConnection, const OUString &i_sLabel )
164 : :OTableColumnDescriptor( false /* do not act as descriptor */ )
165 3 : ,m_sLabel(i_sLabel)
166 : {
167 3 : const sal_Int32 nPropAttr = PropertyAttribute::READONLY;
168 3 : registerProperty( PROPERTY_CATALOGNAME, PROPERTY_ID_CATALOGNAME, nPropAttr, &m_sCatalogName, cppu::UnoType<decltype(m_sCatalogName)>::get() );
169 3 : registerProperty( PROPERTY_SCHEMANAME, PROPERTY_ID_SCHEMANAME, nPropAttr, &m_sSchemaName, cppu::UnoType<decltype(m_sSchemaName)>::get() );
170 3 : registerProperty( PROPERTY_TABLENAME, PROPERTY_ID_TABLENAME, nPropAttr, &m_sTableName, cppu::UnoType<decltype(m_sTableName)>::get() );
171 3 : registerProperty( PROPERTY_REALNAME, PROPERTY_ID_REALNAME, nPropAttr, &m_sRealName, cppu::UnoType<decltype(m_sRealName)>::get() );
172 3 : registerProperty( PROPERTY_LABEL, PROPERTY_ID_LABEL, nPropAttr, &m_sLabel, cppu::UnoType<decltype(m_sLabel)>::get() );
173 :
174 :
175 3 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_TYPENAME ) >>= m_aTypeName );
176 3 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_ISNULLABLE ) >>= m_nIsNullable );
177 3 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_PRECISION ) >>= m_nPrecision );
178 3 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_SCALE ) >>= m_nScale );
179 3 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_TYPE ) >>= m_nType );
180 3 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_ISAUTOINCREMENT ) >>= m_bAutoIncrement );
181 3 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_ISCURRENCY ) >>= m_bCurrency );
182 3 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_NAME ) >>= m_sName );
183 :
184 3 : m_bRowVersion = false;
185 :
186 3 : Reference< XPropertySetInfo > xPSI( _rxParserColumn->getPropertySetInfo(), UNO_SET_THROW );
187 3 : if ( xPSI->hasPropertyByName( PROPERTY_DEFAULTVALUE ) )
188 3 : OSL_VERIFY( _rxParserColumn->getPropertyValue( PROPERTY_DEFAULTVALUE ) >>= m_aDefaultValue );
189 :
190 : // copy some optional properties from the parser column
191 12 : 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 6 : };
203 15 : for ( size_t i=0; i < sizeof( aProps ) / sizeof( aProps[0] ); ++i )
204 : {
205 12 : if ( xPSI->hasPropertyByName( aProps[i].sName ) )
206 12 : setFastPropertyValue_NoBroadcast( aProps[i].nHandle, _rxParserColumn->getPropertyValue( aProps[i].sName ) );
207 : }
208 :
209 : // determine the table column we're based on
210 3 : osl_atomic_increment( &m_refCount );
211 : {
212 3 : m_xOriginalTableColumn = impl_determineOriginalTableColumn( _rxConnection );
213 : }
214 6 : osl_atomic_decrement( &m_refCount );
215 3 : }
216 :
217 6 : OQueryColumn::~OQueryColumn()
218 : {
219 6 : }
220 :
221 3 : Reference< XPropertySet > OQueryColumn::impl_determineOriginalTableColumn( const Reference< XConnection >& _rxConnection )
222 : {
223 : OSL_PRECOND( _rxConnection.is(), "OQueryColumn::impl_determineOriginalTableColumn: illegal connection!" );
224 3 : if ( !_rxConnection.is() )
225 0 : return NULL;
226 :
227 3 : Reference< XPropertySet > xOriginalTableColumn;
228 : try
229 : {
230 : // determine the composed table name, plus the column name, as indicated by the
231 : // respective properties
232 6 : OUString sCatalog, sSchema, sTable;
233 3 : OSL_VERIFY( getPropertyValue( PROPERTY_CATALOGNAME ) >>= sCatalog );
234 3 : OSL_VERIFY( getPropertyValue( PROPERTY_SCHEMANAME ) >>= sSchema );
235 3 : OSL_VERIFY( getPropertyValue( PROPERTY_TABLENAME ) >>= sTable );
236 3 : if ( sCatalog.isEmpty() && sSchema.isEmpty() && sTable.isEmpty() )
237 0 : return NULL;
238 :
239 : OUString sComposedTableName = ::dbtools::composeTableName(
240 6 : _rxConnection->getMetaData(), sCatalog, sSchema, sTable, false, ::dbtools::eComplete );
241 :
242 : // retrieve the table in question
243 6 : Reference< XTablesSupplier > xSuppTables( _rxConnection, UNO_QUERY_THROW );
244 6 : Reference< XNameAccess > xTables( xSuppTables->getTables(), UNO_QUERY_THROW );
245 3 : if ( !xTables->hasByName( sComposedTableName ) )
246 0 : return NULL;
247 :
248 6 : Reference< XColumnsSupplier > xSuppCols( xTables->getByName( sComposedTableName ), UNO_QUERY_THROW );
249 6 : Reference< XNameAccess > xColumns( xSuppCols->getColumns(), UNO_QUERY_THROW );
250 :
251 6 : OUString sColumn;
252 3 : OSL_VERIFY( getPropertyValue( PROPERTY_REALNAME ) >>= sColumn );
253 3 : if ( !xColumns->hasByName( sColumn ) )
254 0 : return NULL;
255 :
256 6 : xOriginalTableColumn.set( xColumns->getByName( sColumn ), UNO_QUERY );
257 : }
258 0 : catch( const Exception& )
259 : {
260 : DBG_UNHANDLED_EXCEPTION();
261 : }
262 3 : 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 63 : ::cppu::IPropertyArrayHelper& SAL_CALL OQueryColumn::getInfoHelper()
273 : {
274 63 : return *OQueryColumn_PBase::getArrayHelper();
275 : }
276 :
277 1 : ::cppu::IPropertyArrayHelper* OQueryColumn::createArrayHelper() const
278 : {
279 1 : return OTableColumnDescriptor::createArrayHelper();
280 : }
281 :
282 18 : void SAL_CALL OQueryColumn::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
283 : {
284 18 : OTableColumnDescriptor::getFastPropertyValue( _rValue, _nHandle );
285 :
286 : // special treatment for column settings:
287 18 : if ( !OColumnSettings::isColumnSettingProperty( _nHandle ) )
288 18 : 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 838 : OColumnWrapper::OColumnWrapper( const Reference< XPropertySet > & rCol, const bool _bNameIsReadOnly )
317 : :OColumn( _bNameIsReadOnly )
318 : ,m_xAggregate(rCol)
319 838 : ,m_nColTypeID(-1)
320 : {
321 : // which type of aggregate property do we have?
322 : // we distinguish the properties by the containment of optional properties
323 838 : m_nColTypeID = 0;
324 838 : if ( m_xAggregate.is() )
325 : {
326 838 : Reference <XPropertySetInfo > xInfo(m_xAggregate->getPropertySetInfo());
327 838 : m_nColTypeID |= xInfo->hasPropertyByName(PROPERTY_DESCRIPTION) ? HAS_DESCRIPTION : 0;
328 838 : m_nColTypeID |= xInfo->hasPropertyByName(PROPERTY_DEFAULTVALUE) ? HAS_DEFAULTVALUE : 0;
329 838 : m_nColTypeID |= xInfo->hasPropertyByName(PROPERTY_ISROWVERSION) ? HAS_ROWVERSION : 0;
330 838 : m_nColTypeID |= xInfo->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION) ? HAS_AUTOINCREMENT_CREATION : 0;
331 838 : m_nColTypeID |= xInfo->hasPropertyByName(PROPERTY_CATALOGNAME) ? HAS_CATALOGNAME : 0;
332 838 : m_nColTypeID |= xInfo->hasPropertyByName(PROPERTY_SCHEMANAME) ? HAS_SCHEMANAME : 0;
333 838 : m_nColTypeID |= xInfo->hasPropertyByName(PROPERTY_TABLENAME) ? HAS_TABLENAME : 0;
334 :
335 838 : m_xAggregate->getPropertyValue(PROPERTY_NAME) >>= m_sName;
336 : }
337 838 : }
338 :
339 838 : OColumnWrapper::~OColumnWrapper()
340 : {
341 838 : }
342 :
343 28474 : OUString OColumnWrapper::impl_getPropertyNameFromHandle( const sal_Int32 _nHandle ) const
344 : {
345 28474 : OUString sPropName;
346 28474 : sal_Int16 nAttributes( 0 );
347 28474 : const_cast< OColumnWrapper* >( this )->getInfoHelper().fillPropertyMembersByHandle( &sPropName, &nAttributes, _nHandle );
348 : OSL_ENSURE( !sPropName.isEmpty(), "OColumnWrapper::impl_getPropertyNameFromHandle: property not found!" );
349 28474 : return sPropName;
350 : }
351 :
352 25395 : 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 25395 : if ( OColumn::isRegisteredProperty( nHandle ) )
358 : {
359 3229 : OColumn::getFastPropertyValue( rValue, nHandle );
360 : }
361 : else
362 : {
363 22166 : rValue = m_xAggregate->getPropertyValue( impl_getPropertyNameFromHandle( nHandle ) );
364 : }
365 25395 : }
366 :
367 2016 : sal_Bool OColumnWrapper::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle,
368 : const Any& rValue ) throw (IllegalArgumentException)
369 : {
370 2016 : bool bModified( false );
371 2016 : if ( OColumn::isRegisteredProperty( nHandle ) )
372 : {
373 2016 : 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 = true;
382 : }
383 : }
384 2016 : return bModified;
385 : }
386 :
387 172 : void OColumnWrapper::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception, std::exception)
388 : {
389 172 : if ( OColumn::isRegisteredProperty( nHandle ) )
390 : {
391 172 : OColumn::setFastPropertyValue_NoBroadcast( nHandle, rValue );
392 : }
393 : else
394 : {
395 0 : m_xAggregate->setPropertyValue( impl_getPropertyNameFromHandle( nHandle ), rValue );
396 : }
397 172 : }
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 838 : OTableColumnDescriptorWrapper::OTableColumnDescriptorWrapper( const Reference< XPropertySet >& _rCol, const bool _bPureWrap, const bool _bIsDescriptor )
409 838 : :OColumnWrapper( _rCol, !_bIsDescriptor )
410 : ,m_bPureWrap( _bPureWrap )
411 838 : ,m_bIsDescriptor( _bIsDescriptor )
412 : {
413 : // let the ColumnSettings register its properties
414 838 : OColumnSettings::registerProperties( *this );
415 838 : }
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 247 : ::cppu::IPropertyArrayHelper* OTableColumnDescriptorWrapper::createArrayHelper( sal_Int32 nId ) const
436 : {
437 247 : const sal_Int32 nHaveAlways = 7;
438 :
439 : // Which optional properties are contained?
440 247 : const sal_Int32 nHaveOptionally (::std::bitset<7>(nId).count());
441 :
442 247 : BEGIN_PROPERTY_SEQUENCE( nHaveAlways + nHaveOptionally )
443 :
444 247 : DECL_PROP0_BOOL( ISAUTOINCREMENT );
445 247 : DECL_PROP0_BOOL( ISCURRENCY );
446 247 : DECL_PROP0( ISNULLABLE, sal_Int32 );
447 247 : DECL_PROP0( PRECISION, sal_Int32 );
448 247 : DECL_PROP0( SCALE, sal_Int32 );
449 247 : DECL_PROP0( TYPE, sal_Int32 );
450 247 : DECL_PROP0( TYPENAME, OUString );
451 :
452 247 : if ( nId & HAS_AUTOINCREMENT_CREATION )
453 : {
454 221 : DECL_PROP1( AUTOINCREMENTCREATION, OUString, MAYBEVOID );
455 : }
456 247 : if ( nId & HAS_DEFAULTVALUE )
457 : {
458 247 : DECL_PROP0( DEFAULTVALUE, OUString );
459 : }
460 247 : if ( nId & HAS_DESCRIPTION )
461 : {
462 247 : DECL_PROP0( DESCRIPTION, OUString );
463 : }
464 247 : if ( nId & HAS_ROWVERSION )
465 : {
466 247 : DECL_PROP0_BOOL( ISROWVERSION );
467 : }
468 247 : if ( nId & HAS_CATALOGNAME )
469 : {
470 26 : DECL_PROP0( CATALOGNAME, OUString );
471 : }
472 247 : if ( nId & HAS_SCHEMANAME )
473 : {
474 26 : DECL_PROP0( SCHEMANAME, OUString );
475 : }
476 247 : if ( nId & HAS_TABLENAME )
477 : {
478 26 : DECL_PROP0( TABLENAME, OUString );
479 : }
480 :
481 : END_PROPERTY_SEQUENCE()
482 :
483 247 : if ( !m_bIsDescriptor )
484 : {
485 6032 : for ( Property* prop = aDescriptor.getArray();
486 3016 : prop != aDescriptor.getArray() + aDescriptor.getLength();
487 : ++prop
488 : )
489 : {
490 2769 : 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 494 : Sequence< Property > aBaseProperties;
496 247 : describeProperties( aBaseProperties );
497 :
498 494 : Sequence< Property > aAllProperties( ::comphelper::concatSequences( aDescriptor, aBaseProperties ) );
499 494 : 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 27411 : void OTableColumnDescriptorWrapper::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
509 : {
510 27411 : if ( m_bPureWrap )
511 : {
512 2016 : rValue = m_xAggregate->getPropertyValue( impl_getPropertyNameFromHandle( nHandle ) );
513 : }
514 : else
515 : {
516 25395 : OColumnWrapper::getFastPropertyValue( rValue, nHandle );
517 : }
518 27411 : }
519 :
520 6022 : sal_Bool OTableColumnDescriptorWrapper::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue ) throw (IllegalArgumentException)
521 : {
522 6022 : bool bModified(false);
523 6022 : 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 4006 : rOldValue = m_xAggregate->getPropertyValue( impl_getPropertyNameFromHandle( nHandle ) );
531 4006 : if ( rOldValue != rValue )
532 : {
533 286 : rConvertedValue = rValue;
534 286 : bModified = true;
535 : }
536 : }
537 : else
538 : {
539 2016 : bModified = OColumnWrapper::convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, rValue );
540 : }
541 6022 : return bModified;
542 : }
543 :
544 458 : void OTableColumnDescriptorWrapper::setFastPropertyValue_NoBroadcast(
545 : sal_Int32 nHandle,
546 : const Any& rValue
547 : )
548 : throw (Exception, std::exception)
549 : {
550 458 : if ( m_bPureWrap )
551 : {
552 286 : m_xAggregate->setPropertyValue( impl_getPropertyNameFromHandle( nHandle ), rValue );
553 : }
554 : else
555 : {
556 172 : OColumnWrapper::setFastPropertyValue_NoBroadcast( nHandle, rValue );
557 : }
558 458 : }
559 :
560 : // OTableColumnWrapper
561 838 : OTableColumnWrapper::OTableColumnWrapper( const Reference< XPropertySet >& rCol, const Reference< XPropertySet >& _xColDefintion,
562 : const bool _bPureWrap )
563 838 : :OTableColumnDescriptorWrapper( rCol, _bPureWrap, false )
564 : {
565 838 : osl_atomic_increment( &m_refCount );
566 838 : if ( _xColDefintion.is() )
567 : {
568 : try
569 : {
570 591 : ::comphelper::copyProperties( _xColDefintion, this );
571 : }
572 0 : catch( const Exception& )
573 : {
574 : DBG_UNHANDLED_EXCEPTION();
575 : }
576 : }
577 838 : osl_atomic_decrement( &m_refCount );
578 838 : }
579 :
580 1676 : OTableColumnWrapper::~OTableColumnWrapper()
581 : {
582 1676 : }
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 101352 : ::cppu::IPropertyArrayHelper& OTableColumnWrapper::getInfoHelper()
600 : {
601 101352 : return *static_cast< OIdPropertyArrayUsageHelper< OTableColumnWrapper >* >(this)->getArrayHelper(m_nColTypeID);
602 : }
603 :
604 : // comphelper::OPropertyArrayUsageHelper
605 247 : ::cppu::IPropertyArrayHelper* OTableColumnWrapper::createArrayHelper( sal_Int32 nId ) const
606 : {
607 247 : return OTableColumnDescriptorWrapper::createArrayHelper( nId );
608 : }
609 :
610 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|