Update ooo320-m1
[ooovba.git] / dbaccess / source / core / api / column.cxx
blob577d267d66a86ae7a9f6f561267a7124399dec58
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: column.cxx,v $
10 * $Revision: 1.55 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef _DBA_COREAPI_COLUMN_HXX_
35 #include "column.hxx"
36 #endif
37 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
38 #include "dbastrings.hrc"
39 #endif
40 #ifndef _DBA_CORE_RESOURCE_HXX_
41 #include "core_resource.hxx"
42 #endif
43 #ifndef _DBA_CORE_RESOURCE_HRC_
44 #include "core_resource.hrc"
45 #endif
46 #ifndef _DBASHARED_APITOOLS_HXX_
47 #include "apitools.hxx"
48 #endif
49 #ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_
50 #include <com/sun/star/sdbc/ColumnValue.hpp>
51 #endif
52 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
53 #include <cppuhelper/typeprovider.hxx>
54 #endif
55 #ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_
56 #include <com/sun/star/sdbc/DataType.hpp>
57 #endif
58 #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
59 #include <com/sun/star/lang/DisposedException.hpp>
60 #endif
61 #ifndef _COMPHELPER_SEQUENCE_HXX_
62 #include <comphelper/sequence.hxx>
63 #endif
64 #ifndef _COMPHELPER_PROPERTY_HXX_
65 #include <comphelper/property.hxx>
66 #endif
67 #ifndef _COMPHELPER_ENUMHELPER_HXX_
68 #include <comphelper/enumhelper.hxx>
69 #endif
70 #ifndef _COMPHELPER_TYPES_HXX_
71 #include <comphelper/types.hxx>
72 #endif
73 #ifndef _COMPHELPER_EXTRACT_HXX_
74 #include <comphelper/extract.hxx>
75 #endif
76 #ifndef _OSL_DIAGNOSE_H_
77 #include <osl/diagnose.h>
78 #endif
79 #ifndef _COMPHELPER_SEQSTREAM_HXX
80 #include <comphelper/seqstream.hxx>
81 #endif
82 #ifndef _COMPHELPER_BASIC_IO_HXX_
83 #include <comphelper/basicio.hxx>
84 #endif
85 #ifndef _TOOLS_DEBUG_HXX
86 #include <tools/debug.hxx>
87 #endif
88 #ifndef CONNECTIVITY_TABLEHELPER_HXX
89 #include <connectivity/TTableHelper.hxx>
90 #endif
91 #ifndef _DBACORE_DEFINITIONCOLUMN_HXX_
92 #include "definitioncolumn.hxx"
93 #endif
94 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
95 #include <connectivity/dbtools.hxx>
96 #endif
97 #ifndef _DBHELPER_DBEXCEPTION_HXX_
98 #include <connectivity/dbexception.hxx>
99 #endif
100 #ifndef DBA_CONTAINERMEDIATOR_HXX
101 #include "ContainerMediator.hxx"
102 #endif
103 #ifndef DBACORE_SDBCORETOOLS_HXX
104 #include "sdbcoretools.hxx"
105 #endif
107 #include <algorithm>
109 using namespace dbaccess;
110 using namespace connectivity;
111 using namespace connectivity;
112 using namespace ::com::sun::star::sdbc;
113 using namespace ::com::sun::star::sdbcx;
114 using namespace ::com::sun::star::beans;
115 using namespace ::com::sun::star::uno;
116 using namespace ::com::sun::star::lang;
117 using namespace ::com::sun::star::awt;
118 using namespace ::com::sun::star::io;
119 using namespace ::com::sun::star::container;
120 using namespace ::com::sun::star::util;
121 using namespace ::osl;
122 using namespace ::comphelper;
123 using namespace ::cppu;
125 DBG_NAME(OColumn)
127 //============================================================
128 //= OColumn
129 //============================================================
130 //--------------------------------------------------------------------------
131 OColumn::OColumn()
132 :OColumnBase(m_aMutex)
133 , OPropertySetHelper(OColumnBase::rBHelper)
135 DBG_CTOR(OColumn, NULL);
138 //--------------------------------------------------------------------------
139 OColumn::~OColumn()
141 DBG_DTOR(OColumn, NULL);
144 // com::sun::star::lang::XTypeProvider
145 //--------------------------------------------------------------------------
146 Sequence< Type > OColumn::getTypes() throw (RuntimeException)
148 OTypeCollection aTypes(::getCppuType( (const Reference< XPropertySet > *)0 ),
149 ::getCppuType( (const Reference< XMultiPropertySet > *)0 ),
150 OColumnBase::getTypes());
151 return aTypes.getTypes();
154 // com::sun::star::uno::XInterface
155 //--------------------------------------------------------------------------
156 Any OColumn::queryInterface( const Type & rType ) throw (RuntimeException)
158 Any aIface = OColumnBase::queryInterface( rType );
159 if (!aIface.hasValue())
160 aIface = ::cppu::queryInterface(
161 rType,
162 static_cast< XPropertySet * >( this ),
163 static_cast< XMultiPropertySet * >( this ));
165 return aIface;
168 //--------------------------------------------------------------------------
169 void OColumn::acquire() throw()
171 OColumnBase::acquire();
174 //--------------------------------------------------------------------------
175 void OColumn::release() throw()
177 OColumnBase::release();
180 // ::com::sun::star::lang::XServiceInfo
181 //------------------------------------------------------------------------------
182 rtl::OUString OColumn::getImplementationName( ) throw(RuntimeException)
184 return rtl::OUString::createFromAscii("com.sun.star.sdb.OColumn");
187 //------------------------------------------------------------------------------
188 sal_Bool OColumn::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
190 return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
193 //------------------------------------------------------------------------------
194 Sequence< ::rtl::OUString > OColumn::getSupportedServiceNames( ) throw (RuntimeException)
196 Sequence< ::rtl::OUString > aSNS( 1 );
197 aSNS[0] = SERVICE_SDBCX_COLUMN;
198 return aSNS;
201 // OComponentHelper
202 //------------------------------------------------------------------------------
203 void OColumn::disposing()
205 OPropertySetHelper::disposing();
208 // com::sun::star::beans::XPropertySet
209 //------------------------------------------------------------------------------
210 Reference< XPropertySetInfo > OColumn::getPropertySetInfo() throw (RuntimeException)
212 return createPropertySetInfo( getInfoHelper() ) ;
215 //------------------------------------------------------------------------------
216 void OColumn::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
218 switch (nHandle)
220 case PROPERTY_ID_NAME:
221 rValue <<= m_sName;
222 break;
226 //------------------------------------------------------------------------------
227 sal_Bool OColumn::convertFastPropertyValue(
228 Any & rConvertedValue,
229 Any & rOldValue,
230 sal_Int32 nHandle,
231 const Any& rValue )
232 throw (IllegalArgumentException)
234 sal_Bool bModified = sal_False;
235 switch (nHandle)
237 case PROPERTY_ID_NAME:
238 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_sName);
239 break;
241 return bModified;
244 //------------------------------------------------------------------------------
245 void OColumn::setFastPropertyValue_NoBroadcast(
246 sal_Int32 nHandle,
247 const Any& rValue
249 throw (Exception)
251 switch (nHandle)
253 case PROPERTY_ID_NAME:
254 OSL_ENSURE(rValue.getValueType().equals(::getCppuType(static_cast< ::rtl::OUString* >(NULL))),
255 "OColumn::setFastPropertyValue_NoBroadcast(NAME) : invalid value !");
256 rValue >>= m_sName;
257 break;
261 //--------------------------------------------------------------------------
262 Sequence< sal_Int8 > OColumn::getUnoTunnelImplementationId()
264 static ::cppu::OImplementationId * pId = 0;
265 if (! pId)
267 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
268 if (! pId)
270 static ::cppu::OImplementationId aId;
271 pId = &aId;
274 return pId->getImplementationId();
277 // com::sun::star::lang::XUnoTunnel
278 //------------------------------------------------------------------
279 sal_Int64 OColumn::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
281 if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
282 return reinterpret_cast<sal_Int64>(this);
284 return 0;
286 // -----------------------------------------------------------------------------
287 ::rtl::OUString SAL_CALL OColumn::getName( ) throw(::com::sun::star::uno::RuntimeException)
289 return m_sName;
291 // -----------------------------------------------------------------------------
292 void SAL_CALL OColumn::setName( const ::rtl::OUString& _rName ) throw(::com::sun::star::uno::RuntimeException)
294 m_sName = _rName;
296 // -----------------------------------------------------------------------------
297 void OColumn::fireValueChange(const ::connectivity::ORowSetValue& /*_rOldValue*/)
299 DBG_ERROR( "OColumn::fireValueChange: not implemented!" );
301 // -----------------------------------------------------------------------------
302 //============================================================
303 //= OColumnSettings
304 //============================================================
305 DBG_NAME( OColumnSettings )
306 //------------------------------------------------------------------------------
307 OColumnSettings::OColumnSettings()
308 :m_bHidden(sal_False)
310 DBG_CTOR( OColumnSettings, NULL );
313 //------------------------------------------------------------------------------
314 OColumnSettings::~OColumnSettings()
316 DBG_DTOR( OColumnSettings, NULL );
319 // com::sun::star::lang::XUnoTunnel
320 //------------------------------------------------------------------
321 sal_Int64 OColumnSettings::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
323 if ( ( rId.getLength() == 16 )
324 && ( 0 == rtl_compareMemory( getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
326 return reinterpret_cast< sal_Int64 >( this );
328 return 0;
331 //--------------------------------------------------------------------------
332 Sequence< sal_Int8 > OColumnSettings::getUnoTunnelImplementationId()
334 static ::cppu::OImplementationId * pId = 0;
335 if (! pId)
337 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
338 if (! pId)
340 static ::cppu::OImplementationId aId;
341 pId = &aId;
344 return pId->getImplementationId();
347 //------------------------------------------------------------------------------
348 void OColumnSettings::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
350 switch (nHandle)
352 case PROPERTY_ID_ALIGN:
353 rValue = m_aAlignment;
354 break;
355 case PROPERTY_ID_NUMBERFORMAT:
356 rValue = m_aFormatKey;
357 break;
358 case PROPERTY_ID_RELATIVEPOSITION:
359 rValue = m_aRelativePosition;
360 break;
361 case PROPERTY_ID_WIDTH:
362 rValue = m_aWidth;
363 break;
364 case PROPERTY_ID_HIDDEN:
365 rValue.setValue(&m_bHidden, getBooleanCppuType());
366 break;
367 case PROPERTY_ID_CONTROLMODEL:
368 rValue <<= m_xControlModel;
369 break;
370 case PROPERTY_ID_HELPTEXT:
371 rValue = m_aHelpText;
372 break;
373 case PROPERTY_ID_CONTROLDEFAULT:
374 rValue = m_aControlDefault;
375 break;
379 //------------------------------------------------------------------------------
380 sal_Bool OColumnSettings::convertFastPropertyValue(
381 Any & rConvertedValue,
382 Any & rOldValue,
383 sal_Int32 nHandle,
384 const Any& rValue )
385 throw (IllegalArgumentException)
387 sal_Bool bModified = sal_False;
388 switch (nHandle)
390 case PROPERTY_ID_ALIGN:
391 bModified = !uno_type_equalData(
392 const_cast< void* >( m_aAlignment.getValue() ), m_aAlignment.getValueType().getTypeLibType(),
393 const_cast< void* >( rValue.getValue() ), rValue.getValueType().getTypeLibType(),
394 reinterpret_cast< uno_QueryInterfaceFunc >( cpp_queryInterface ),
395 reinterpret_cast< uno_ReleaseFunc >( cpp_release )
397 if ( bModified )
399 rConvertedValue = rValue;
400 rOldValue = m_aAlignment;
402 break;
403 case PROPERTY_ID_WIDTH:
404 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aWidth,
405 ::getCppuType(static_cast< sal_Int32* >(NULL)));
406 break;
407 case PROPERTY_ID_HIDDEN:
408 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bHidden);
409 break;
410 case PROPERTY_ID_RELATIVEPOSITION:
411 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aRelativePosition,
412 ::getCppuType(static_cast< sal_Int32* >(NULL)));
413 break;
414 case PROPERTY_ID_NUMBERFORMAT:
415 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aFormatKey,
416 ::getCppuType(static_cast< sal_Int32* >(NULL)));
417 break;
418 case PROPERTY_ID_CONTROLMODEL:
420 Reference< XPropertySet > xTest;
421 if (!::cppu::extractInterface(xTest, rValue))
422 throw IllegalArgumentException();
423 if (xTest.get() != m_xControlModel.get())
425 bModified = sal_True;
426 rOldValue <<= m_xControlModel;
427 rConvertedValue <<= rValue;
430 break;
431 case PROPERTY_ID_HELPTEXT:
432 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aHelpText,
433 ::getCppuType(static_cast< ::rtl::OUString* >(NULL)));
434 break;
435 case PROPERTY_ID_CONTROLDEFAULT:
436 bModified = rValue != m_aControlDefault;
437 if ( bModified )
439 rConvertedValue = rValue;
440 rOldValue = m_aControlDefault;
442 break;
444 return bModified;
447 //------------------------------------------------------------------------------
448 void OColumnSettings::setFastPropertyValue_NoBroadcast(
449 sal_Int32 nHandle,
450 const Any& rValue
452 throw (Exception)
454 switch (nHandle)
456 case PROPERTY_ID_ALIGN:
458 if ( rValue.hasValue() )
460 sal_Int32 nAlign = 0;
461 sal_Bool bSuccess =
462 // copy the data from the to-be-set value
463 uno_type_assignData(
464 static_cast< void* >( &nAlign ), ::getCppuType(static_cast< sal_Int32* >(NULL)).getTypeLibType(),
465 const_cast< void* >( rValue.getValue() ), rValue.getValueType().getTypeLibType(),
466 reinterpret_cast< uno_QueryInterfaceFunc >( cpp_queryInterface ),
467 reinterpret_cast< uno_AcquireFunc >( cpp_acquire ),
468 reinterpret_cast< uno_ReleaseFunc >( cpp_release ) );
470 OSL_ENSURE( bSuccess,
471 "OPropertyStateContainer::setFastPropertyValue_NoBroadcast : ooops .... the value could not be assigned!");
472 if ( bSuccess )
473 m_aAlignment <<= nAlign;
475 else
476 m_aAlignment = rValue;
479 break;
480 case PROPERTY_ID_WIDTH:
481 OSL_ENSURE(!rValue.hasValue() || rValue.getValueType().equals(::getCppuType(static_cast< sal_Int32* >(NULL))),
482 "OColumnSettings::setFastPropertyValue_NoBroadcast(WIDTH) : invalid value !");
483 m_aWidth = rValue;
484 break;
485 case PROPERTY_ID_NUMBERFORMAT:
486 OSL_ENSURE(!rValue.hasValue() || rValue.getValueType().equals(::getCppuType(static_cast< sal_Int32* >(NULL))),
487 "OColumnSettings::setFastPropertyValue_NoBroadcast(NUMBERFORMAT) : invalid value !");
488 m_aFormatKey = rValue;
489 break;
490 case PROPERTY_ID_RELATIVEPOSITION:
491 OSL_ENSURE(!rValue.hasValue() || rValue.getValueType().equals(::getCppuType(static_cast< sal_Int32* >(NULL))),
492 "OColumnSettings::setFastPropertyValue_NoBroadcast(ID_RELATIVEPOSITION) : invalid value !");
493 m_aRelativePosition = rValue;
494 break;
495 case PROPERTY_ID_HIDDEN:
496 OSL_ENSURE(rValue.getValueType().equals(::getBooleanCppuType()),
497 "OColumnSettings::setFastPropertyValue_NoBroadcast(HIDDEN) : invalid value !");
498 m_bHidden = ::comphelper::getBOOL(rValue);
499 break;
500 case PROPERTY_ID_HELPTEXT:
501 OSL_ENSURE(!rValue.hasValue() || rValue.getValueType().equals(::getCppuType(static_cast< ::rtl::OUString* >(NULL))),
502 "OColumnSettings::setFastPropertyValue_NoBroadcast(ID_RELATIVEPOSITION) : invalid value !");
503 m_aHelpText = rValue;
504 break;
505 case PROPERTY_ID_CONTROLDEFAULT:
506 m_aControlDefault = rValue;
507 break;
512 //------------------------------------------------------------------------------
513 sal_Bool OColumnSettings::isDefaulted() const
515 return !m_aAlignment.hasValue()
516 && !m_aWidth.hasValue()
517 && !m_aFormatKey.hasValue()
518 && !m_aRelativePosition.hasValue()
519 && !m_aHelpText.hasValue()
520 && !m_aControlDefault.hasValue()
521 && !m_bHidden;
525 //============================================================
526 //= OColumns
527 //============================================================
528 DBG_NAME(OColumns);
530 //--------------------------------------------------------------------------
531 OColumns::OColumns(::cppu::OWeakObject& _rParent,
532 ::osl::Mutex& _rMutex,
533 sal_Bool _bCaseSensitive,const ::std::vector< ::rtl::OUString> &_rVector,
534 IColumnFactory* _pColFactory,
535 ::connectivity::sdbcx::IRefreshableColumns* _pRefresh,
536 sal_Bool _bAddColumn,
537 sal_Bool _bDropColumn,
538 sal_Bool _bUseHardRef)
539 : OColumns_BASE(_rParent,_bCaseSensitive,_rMutex,_rVector,_bUseHardRef)
540 ,m_pMediator(NULL)
541 ,m_xDrvColumns(NULL)
542 ,m_pColFactoryImpl(_pColFactory)
543 ,m_pRefreshColumns(_pRefresh)
544 ,m_bInitialized(sal_False)
545 ,m_bAddColumn(_bAddColumn)
546 ,m_bDropColumn(_bDropColumn)
548 DBG_CTOR(OColumns, NULL);
550 // -------------------------------------------------------------------------
551 OColumns::OColumns(::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex,
552 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxDrvColumns,
553 sal_Bool _bCaseSensitive,const ::std::vector< ::rtl::OUString> &_rVector,
554 IColumnFactory* _pColFactory,
555 ::connectivity::sdbcx::IRefreshableColumns* _pRefresh,
556 sal_Bool _bAddColumn,
557 sal_Bool _bDropColumn,
558 sal_Bool _bUseHardRef)
559 : OColumns_BASE(_rParent,_bCaseSensitive,_rMutex,_rVector,_bUseHardRef)
560 ,m_pMediator(NULL)
561 ,m_xDrvColumns(_rxDrvColumns)
562 ,m_pColFactoryImpl(_pColFactory)
563 ,m_pRefreshColumns(_pRefresh)
564 ,m_bInitialized(sal_False)
565 ,m_bAddColumn(_bAddColumn)
566 ,m_bDropColumn(_bDropColumn)
568 DBG_CTOR(OColumns, NULL);
570 //--------------------------------------------------------------------------
571 OColumns::~OColumns()
573 DBG_DTOR(OColumns, NULL);
576 // XServiceInfo
577 //------------------------------------------------------------------------------
578 rtl::OUString OColumns::getImplementationName( ) throw(RuntimeException)
580 return rtl::OUString::createFromAscii("com.sun.star.sdb.OColumns");
583 //------------------------------------------------------------------------------
584 sal_Bool OColumns::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
586 return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
589 //------------------------------------------------------------------------------
590 Sequence< ::rtl::OUString > OColumns::getSupportedServiceNames( ) throw (RuntimeException)
592 Sequence< ::rtl::OUString > aSNS( 1 );
593 aSNS[0] = SERVICE_SDBCX_CONTAINER;
594 return aSNS;
597 //------------------------------------------------------------------
598 void OColumns::append( const ::rtl::OUString& _rName, OColumn* _pColumn )
600 MutexGuard aGuard(m_rMutex);
602 OSL_ENSURE( _pColumn, "OColumns::append: invalid column!" );
603 OSL_ENSURE( !m_pElements->exists( _rName ),"OColumns::append: Column already exists");
605 _pColumn->m_sName = _rName;
607 // now really insert the column
608 insertElement( _rName, _pColumn );
611 //------------------------------------------------------------------
612 void OColumns::clearColumns()
614 MutexGuard aGuard(m_rMutex);
615 disposing();
618 // -----------------------------------------------------------------------------
619 void SAL_CALL OColumns::disposing(void)
621 MutexGuard aGuard(m_rMutex);
622 m_xDrvColumns = NULL;
623 m_pMediator = NULL;
624 m_pColFactoryImpl = NULL;
625 OColumns_BASE::disposing();
628 // -------------------------------------------------------------------------
629 void OColumns::impl_refresh() throw(::com::sun::star::uno::RuntimeException)
631 if (m_pRefreshColumns)
632 m_pRefreshColumns->refreshColumns();
635 // -------------------------------------------------------------------------
636 connectivity::sdbcx::ObjectType OColumns::createObject(const ::rtl::OUString& _rName)
638 OSL_ENSURE(m_pColFactoryImpl, "OColumns::createObject: no column factory!");
640 connectivity::sdbcx::ObjectType xRet;
641 if ( m_pColFactoryImpl )
643 xRet = m_pColFactoryImpl->createColumn(_rName);
644 Reference<XChild> xChild(xRet,UNO_QUERY);
645 if ( xChild.is() )
646 xChild->setParent(static_cast<XChild*>(static_cast<TXChild*>(this)));
649 Reference<XPropertySet> xDest(xRet,UNO_QUERY);
650 if ( m_pMediator && xDest.is() )
651 m_pMediator->notifyElementCreated(_rName,xDest);
653 return xRet;
655 // -------------------------------------------------------------------------
656 Reference< XPropertySet > OColumns::createDescriptor()
658 if ( m_pColFactoryImpl )
660 Reference<XPropertySet> xRet = m_pColFactoryImpl->createColumnDescriptor();
661 Reference<XChild> xChild(xRet,UNO_QUERY);
662 if ( xChild.is() )
663 xChild->setParent(static_cast<XChild*>(static_cast<TXChild*>(this)));
664 return xRet;
666 else
667 return Reference< XPropertySet >();
669 // -------------------------------------------------------------------------
670 Any SAL_CALL OColumns::queryInterface( const Type & rType ) throw(RuntimeException)
672 Any aRet;
673 if(m_xDrvColumns.is())
675 aRet = m_xDrvColumns->queryInterface(rType);
676 if ( aRet.hasValue() )
677 aRet = OColumns_BASE::queryInterface( rType);
678 if ( !aRet.hasValue() )
679 aRet = TXChild::queryInterface( rType);
680 return aRet;
682 else if(!m_pTable || (m_pTable && !m_pTable->isNew()))
684 if(!m_bAddColumn && rType == getCppuType( (Reference<XAppend>*)0))
685 return Any();
686 if(!m_bDropColumn && rType == getCppuType( (Reference<XDrop>*)0))
687 return Any();
690 aRet = OColumns_BASE::queryInterface( rType);
691 if ( !aRet.hasValue() )
692 aRet = TXChild::queryInterface( rType);
693 return aRet;
695 // -------------------------------------------------------------------------
696 Sequence< Type > SAL_CALL OColumns::getTypes( ) throw(RuntimeException)
698 sal_Bool bAppendFound = sal_False,bDropFound = sal_False;
700 sal_Int32 nSize = 0;
701 Type aAppendType = getCppuType( (Reference<XAppend>*)0);
702 Type aDropType = getCppuType( (Reference<XDrop>*)0);
703 if(m_xDrvColumns.is())
705 Reference<XTypeProvider> xTypes(m_xDrvColumns,UNO_QUERY);
706 Sequence< Type > aTypes(xTypes->getTypes());
708 Sequence< Type > aSecTypes(OColumns_BASE::getTypes());
711 const Type* pBegin = aTypes.getConstArray();
712 const Type* pEnd = pBegin + aTypes.getLength();
713 for (;pBegin != pEnd ; ++pBegin)
715 if(aAppendType == *pBegin)
716 bAppendFound = sal_True;
717 else if(aDropType == *pBegin)
718 bDropFound = sal_True;
720 nSize = (bDropFound ? (bAppendFound ? 0 : 1) : (bAppendFound ? 1 : 2));
722 else
724 nSize = ((m_pTable && m_pTable->isNew()) ? 0 :
725 ((m_bDropColumn ?
726 (m_bAddColumn ? 0 : 1) : (m_bAddColumn ? 1 : 2))));
727 bDropFound = (m_pTable && m_pTable->isNew()) || m_bDropColumn;
728 bAppendFound = (m_pTable && m_pTable->isNew()) || m_bAddColumn;
730 Sequence< Type > aTypes(::comphelper::concatSequences(OColumns_BASE::getTypes(),TXChild::getTypes()));
731 Sequence< Type > aRet(aTypes.getLength() - nSize);
733 const Type* pBegin = aTypes.getConstArray();
734 const Type* pEnd = pBegin + aTypes.getLength();
735 for(sal_Int32 i=0;pBegin != pEnd ;++pBegin)
737 if(*pBegin != aAppendType && *pBegin != aDropType)
738 aRet.getArray()[i++] = *pBegin;
739 else if(bDropFound && *pBegin == aDropType)
740 aRet.getArray()[i++] = *pBegin;
741 else if(bAppendFound && *pBegin == aAppendType)
742 aRet.getArray()[i++] = *pBegin;
744 return aRet;
746 // -------------------------------------------------------------------------
747 // XAppend
748 sdbcx::ObjectType OColumns::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& descriptor )
750 sdbcx::ObjectType xReturn;
752 Reference< XAppend > xAppend( m_xDrvColumns, UNO_QUERY );
753 if ( xAppend.is() )
755 xAppend->appendByDescriptor(descriptor);
756 xReturn = createObject( _rForName );
758 else if ( m_pTable && !m_pTable->isNew() )
760 if ( m_bAddColumn )
761 xReturn = OColumns_BASE::appendObject( _rForName, descriptor );
762 else
763 ::dbtools::throwGenericSQLException( DBA_RES( RID_STR_NO_COLUMN_ADD ), static_cast<XChild*>(static_cast<TXChild*>(this)) );
765 else
766 xReturn = cloneDescriptor( descriptor );
768 if ( m_pColFactoryImpl )
769 m_pColFactoryImpl->columnAppended( descriptor );
771 ::dbaccess::notifyDataSourceModified(m_xParent,sal_True);
773 return xReturn;
775 // -------------------------------------------------------------------------
776 // XDrop
777 void OColumns::dropObject(sal_Int32 _nPos,const ::rtl::OUString _sElementName)
779 Reference< XDrop > xDrop( m_xDrvColumns, UNO_QUERY );
780 if ( xDrop.is() )
782 xDrop->dropByName( _sElementName );
784 else if ( m_pTable && !m_pTable->isNew() )
786 if ( m_bDropColumn )
787 OColumns_BASE::dropObject(_nPos,_sElementName);
788 else
789 ::dbtools::throwGenericSQLException( DBA_RES( RID_STR_NO_COLUMN_DROP ), static_cast<XChild*>(static_cast<TXChild*>(this)) );
792 if ( m_pColFactoryImpl )
793 m_pColFactoryImpl->columnDropped(_sElementName);
795 ::dbaccess::notifyDataSourceModified(m_xParent,sal_True);
797 // -----------------------------------------------------------------------------
799 Reference< XInterface > SAL_CALL OColumns::getParent( ) throw (RuntimeException)
801 ::osl::MutexGuard aGuard(m_rMutex);
802 return m_xParent;
804 // -----------------------------------------------------------------------------
805 void SAL_CALL OColumns::setParent( const Reference< XInterface >& _xParent ) throw (NoSupportException, RuntimeException)
807 ::osl::MutexGuard aGuard(m_rMutex);
808 m_xParent = _xParent;
810 // -----------------------------------------------------------------------------