1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TableDeco.cxx,v $
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_CORE_TABLEDECORATOR_HXX_
35 #include "TableDeco.hxx"
37 #ifndef _DBACORE_DEFINITIONCOLUMN_HXX_
38 #include <definitioncolumn.hxx>
40 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
41 #include "dbastrings.hrc"
43 #ifndef _DBA_CORE_RESOURCE_HXX_
44 #include "core_resource.hxx"
46 #ifndef _DBA_CORE_RESOURCE_HRC_
47 #include "core_resource.hrc"
49 #ifndef _TOOLS_DEBUG_HXX
50 #include <tools/debug.hxx>
53 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
54 #include <cppuhelper/typeprovider.hxx>
56 #ifndef _COMPHELPER_ENUMHELPER_HXX_
57 #include <comphelper/enumhelper.hxx>
59 #ifndef _COMPHELPER_CONTAINER_HXX_
60 #include <comphelper/container.hxx>
62 #ifndef _COMPHELPER_SEQUENCE_HXX_
63 #include <comphelper/sequence.hxx>
65 #ifndef _COMPHELPER_PROPERTY_HXX_
66 #include <comphelper/property.hxx>
68 #ifndef _COMPHELPER_TYPES_HXX_
69 #include <comphelper/types.hxx>
71 #ifndef _COM_SUN_STAR_UTIL_XREFRESHLISTENER_HPP_
72 #include <com/sun/star/util/XRefreshListener.hpp>
74 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
75 #include <com/sun/star/sdbc/XConnection.hpp>
77 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
78 #include <com/sun/star/sdbc/XRow.hpp>
80 #ifndef _COM_SUN_STAR_SDBCX_PRIVILEGE_HPP_
81 #include <com/sun/star/sdbcx/Privilege.hpp>
83 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
84 #include <com/sun/star/beans/PropertyAttribute.hpp>
86 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
87 #include <connectivity/dbtools.hxx>
89 #ifndef _DBHELPER_DBEXCEPTION_HXX_
90 #include <connectivity/dbexception.hxx>
92 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
93 #include <connectivity/dbtools.hxx>
95 #ifndef _COMPHELPER_EXTRACT_HXX_
96 #include <comphelper/extract.hxx>
98 #ifndef DBA_CONTAINERMEDIATOR_HXX
99 #include "ContainerMediator.hxx"
101 #include <rtl/logfile.hxx>
103 using namespace dbaccess
;
104 using namespace ::com::sun::star::uno
;
105 using namespace ::com::sun::star::util
;
106 using namespace ::com::sun::star::lang
;
107 using namespace ::com::sun::star::beans
;
108 using namespace ::com::sun::star::sdbc
;
109 using namespace ::com::sun::star::sdbcx
;
110 using namespace ::com::sun::star::container
;
111 using namespace ::osl
;
112 using namespace ::comphelper
;
113 using namespace ::dbtools
;
114 using namespace ::cppu
;
116 //==========================================================================
117 //= ODBTableDecorator
118 //==========================================================================
119 DBG_NAME(ODBTableDecorator
)
120 // -----------------------------------------------------------------------------
121 ODBTableDecorator::ODBTableDecorator( const Reference
< XConnection
>& _rxConnection
, const Reference
< XColumnsSupplier
>& _rxNewTable
,
122 const Reference
< XNumberFormatsSupplier
>& _rxNumberFormats
, const Reference
< XNameAccess
>& _xColumnDefinitions
) throw(SQLException
)
123 :OTableDescriptor_BASE(m_aMutex
)
124 ,ODataSettings(OTableDescriptor_BASE::rBHelper
)
125 ,m_xTable(_rxNewTable
)
126 ,m_xColumnDefinitions(_xColumnDefinitions
)
127 ,m_xConnection( _rxConnection
)
128 ,m_xMetaData( _rxConnection
.is() ? _rxConnection
->getMetaData() : Reference
< XDatabaseMetaData
>() )
129 ,m_xNumberFormats( _rxNumberFormats
)
133 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::ODBTableDecorator" );
134 DBG_CTOR(ODBTableDecorator
, NULL
);
135 ODataSettings::registerPropertiesFor(this);
137 // -------------------------------------------------------------------------
138 ODBTableDecorator::~ODBTableDecorator()
140 DBG_DTOR(ODBTableDecorator
, NULL
);
145 //--------------------------------------------------------------------------
146 Sequence
< sal_Int8
> ODBTableDecorator::getImplementationId() throw (RuntimeException
)
148 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getImplementationId" );
149 static OImplementationId
* pId
= 0;
152 MutexGuard
aGuard( Mutex::getGlobalMutex() );
155 static OImplementationId aId
;
159 return pId
->getImplementationId();
163 //------------------------------------------------------------------------------
164 void SAL_CALL
ODBTableDecorator::disposing()
166 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::disposing" );
167 OPropertySetHelper::disposing();
168 OTableDescriptor_BASE::disposing();
170 MutexGuard
aGuard(m_aMutex
);
174 m_xColumnDefinitions
= NULL
;
175 m_xNumberFormats
= NULL
;
177 m_pColumns
->disposing();
178 m_xColumnMediator
= NULL
;
180 // -----------------------------------------------------------------------------
181 sal_Bool SAL_CALL
ODBTableDecorator::convertFastPropertyValue(
182 Any
& rConvertedValue
,
186 throw (::com::sun::star::lang::IllegalArgumentException
)
188 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::convertFastPropertyValue" );
189 sal_Bool bRet
= sal_True
;
192 case PROPERTY_ID_PRIVILEGES
:
193 case PROPERTY_ID_FILTER
:
194 case PROPERTY_ID_ORDER
:
195 case PROPERTY_ID_APPLYFILTER
:
196 case PROPERTY_ID_FONT
:
197 case PROPERTY_ID_ROW_HEIGHT
:
198 case PROPERTY_ID_TEXTCOLOR
:
199 case PROPERTY_ID_TEXTLINECOLOR
:
200 case PROPERTY_ID_TEXTEMPHASIS
:
201 case PROPERTY_ID_TEXTRELIEF
:
202 case PROPERTY_ID_FONTCHARWIDTH
:
203 case PROPERTY_ID_FONTCHARSET
:
204 case PROPERTY_ID_FONTFAMILY
:
205 case PROPERTY_ID_FONTHEIGHT
:
206 case PROPERTY_ID_FONTKERNING
:
207 case PROPERTY_ID_FONTNAME
:
208 case PROPERTY_ID_FONTORIENTATION
:
209 case PROPERTY_ID_FONTPITCH
:
210 case PROPERTY_ID_FONTSLANT
:
211 case PROPERTY_ID_FONTSTRIKEOUT
:
212 case PROPERTY_ID_FONTSTYLENAME
:
213 case PROPERTY_ID_FONTUNDERLINE
:
214 case PROPERTY_ID_FONTWEIGHT
:
215 case PROPERTY_ID_FONTWIDTH
:
216 case PROPERTY_ID_FONTWORDLINEMODE
:
217 case PROPERTY_ID_FONTTYPE
:
218 bRet
= ODataSettings::convertFastPropertyValue(rConvertedValue
, rOldValue
,nHandle
,rValue
);
224 getFastPropertyValue(aValue
,nHandle
);
225 bRet
= ::comphelper::tryPropertyValue(rConvertedValue
,rOldValue
,rValue
,aValue
,::getCppuType(reinterpret_cast< ::rtl::OUString
*>(NULL
)));
227 break; // we assume that it works
231 // -----------------------------------------------------------------------------
232 void ODBTableDecorator::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle
, const Any
& _rValue
) throw (Exception
)
234 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::setFastPropertyValue_NoBroadcast" );
237 case PROPERTY_ID_PRIVILEGES
:
238 OSL_ENSURE(0,"Property is readonly!");
239 case PROPERTY_ID_FILTER
:
240 case PROPERTY_ID_ORDER
:
241 case PROPERTY_ID_APPLYFILTER
:
242 case PROPERTY_ID_FONT
:
243 case PROPERTY_ID_ROW_HEIGHT
:
244 case PROPERTY_ID_TEXTCOLOR
:
245 case PROPERTY_ID_TEXTLINECOLOR
:
246 case PROPERTY_ID_TEXTEMPHASIS
:
247 case PROPERTY_ID_TEXTRELIEF
:
248 case PROPERTY_ID_FONTCHARWIDTH
:
249 case PROPERTY_ID_FONTCHARSET
:
250 case PROPERTY_ID_FONTFAMILY
:
251 case PROPERTY_ID_FONTHEIGHT
:
252 case PROPERTY_ID_FONTKERNING
:
253 case PROPERTY_ID_FONTNAME
:
254 case PROPERTY_ID_FONTORIENTATION
:
255 case PROPERTY_ID_FONTPITCH
:
256 case PROPERTY_ID_FONTSLANT
:
257 case PROPERTY_ID_FONTSTRIKEOUT
:
258 case PROPERTY_ID_FONTSTYLENAME
:
259 case PROPERTY_ID_FONTUNDERLINE
:
260 case PROPERTY_ID_FONTWEIGHT
:
261 case PROPERTY_ID_FONTWIDTH
:
262 case PROPERTY_ID_FONTWORDLINEMODE
:
263 case PROPERTY_ID_FONTTYPE
:
265 ODataSettings::setFastPropertyValue_NoBroadcast(_nHandle
, _rValue
);
267 case PROPERTY_ID_CATALOGNAME
:
269 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
270 xProp
->setPropertyValue(PROPERTY_CATALOGNAME
,_rValue
);
273 case PROPERTY_ID_SCHEMANAME
:
275 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
276 xProp
->setPropertyValue(PROPERTY_SCHEMANAME
,_rValue
);
279 case PROPERTY_ID_NAME
:
281 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
282 xProp
->setPropertyValue(PROPERTY_NAME
,_rValue
);
285 case PROPERTY_ID_DESCRIPTION
:
287 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
288 xProp
->setPropertyValue(PROPERTY_DESCRIPTION
,_rValue
);
291 case PROPERTY_ID_TYPE
:
293 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
294 xProp
->setPropertyValue(PROPERTY_TYPE
,_rValue
);
299 //------------------------------------------------------------------------------
300 void ODBTableDecorator::getFastPropertyValue(Any
& _rValue
, sal_Int32 _nHandle
) const
302 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getFastPropertyValue" );
305 case PROPERTY_ID_PRIVILEGES
:
307 if ( -1 == m_nPrivileges
)
309 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
310 Reference
<XPropertySetInfo
> xInfo
= xProp
->getPropertySetInfo();
311 if ( xInfo
->hasPropertyByName(PROPERTY_PRIVILEGES
) )
313 _rValue
<<= m_nPrivileges
;
319 case PROPERTY_ID_FILTER
:
320 case PROPERTY_ID_ORDER
:
321 case PROPERTY_ID_APPLYFILTER
:
322 case PROPERTY_ID_FONT
:
323 case PROPERTY_ID_ROW_HEIGHT
:
324 case PROPERTY_ID_TEXTCOLOR
:
325 case PROPERTY_ID_TEXTLINECOLOR
:
326 case PROPERTY_ID_TEXTEMPHASIS
:
327 case PROPERTY_ID_TEXTRELIEF
:
328 case PROPERTY_ID_FONTCHARWIDTH
:
329 case PROPERTY_ID_FONTCHARSET
:
330 case PROPERTY_ID_FONTFAMILY
:
331 case PROPERTY_ID_FONTHEIGHT
:
332 case PROPERTY_ID_FONTKERNING
:
333 case PROPERTY_ID_FONTNAME
:
334 case PROPERTY_ID_FONTORIENTATION
:
335 case PROPERTY_ID_FONTPITCH
:
336 case PROPERTY_ID_FONTSLANT
:
337 case PROPERTY_ID_FONTSTRIKEOUT
:
338 case PROPERTY_ID_FONTSTYLENAME
:
339 case PROPERTY_ID_FONTUNDERLINE
:
340 case PROPERTY_ID_FONTWEIGHT
:
341 case PROPERTY_ID_FONTWIDTH
:
342 case PROPERTY_ID_FONTWORDLINEMODE
:
343 case PROPERTY_ID_FONTTYPE
:
344 ODataSettings::getFastPropertyValue(_rValue
, _nHandle
);
346 case PROPERTY_ID_CATALOGNAME
:
348 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
349 _rValue
= xProp
->getPropertyValue(PROPERTY_CATALOGNAME
);
352 case PROPERTY_ID_SCHEMANAME
:
354 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
355 _rValue
= xProp
->getPropertyValue(PROPERTY_SCHEMANAME
);
358 case PROPERTY_ID_NAME
:
360 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
361 _rValue
= xProp
->getPropertyValue(PROPERTY_NAME
);
364 case PROPERTY_ID_DESCRIPTION
:
366 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
367 _rValue
= xProp
->getPropertyValue(PROPERTY_DESCRIPTION
);
370 case PROPERTY_ID_TYPE
:
372 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
373 _rValue
= xProp
->getPropertyValue(PROPERTY_TYPE
);
377 OSL_ENSURE(0,"Invalid Handle for table");
380 // -------------------------------------------------------------------------
381 void ODBTableDecorator::construct()
383 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::construct" );
384 sal_Bool bNotFound
= sal_True
;
385 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
388 Reference
<XPropertySetInfo
> xInfo
= xProp
->getPropertySetInfo();
389 bNotFound
= !xInfo
->hasPropertyByName(PROPERTY_PRIVILEGES
);
392 registerProperty(PROPERTY_PRIVILEGES
, PROPERTY_ID_PRIVILEGES
, PropertyAttribute::BOUND
| PropertyAttribute::READONLY
,
393 &m_nPrivileges
, ::getCppuType(static_cast<sal_Int32
*>(NULL
)));
395 // -----------------------------------------------------------------------------
396 ::cppu::IPropertyArrayHelper
* ODBTableDecorator::createArrayHelper(sal_Int32
/*_nId*/) const
398 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::createArrayHelper" );
399 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
400 Reference
<XPropertySetInfo
> xInfo
= xProp
->getPropertySetInfo();
402 Sequence
< Property
> aTableProps
= xInfo
->getProperties();
403 Property
* pIter
= aTableProps
.getArray();
404 Property
* pEnd
= pIter
+ aTableProps
.getLength();
405 for (;pIter
!= pEnd
; ++pIter
)
407 if (0 == pIter
->Name
.compareToAscii(PROPERTY_CATALOGNAME
))
408 pIter
->Handle
= PROPERTY_ID_CATALOGNAME
;
409 else if (0 ==pIter
->Name
.compareToAscii(PROPERTY_SCHEMANAME
))
410 pIter
->Handle
= PROPERTY_ID_SCHEMANAME
;
411 else if (0 ==pIter
->Name
.compareToAscii(PROPERTY_NAME
))
412 pIter
->Handle
= PROPERTY_ID_NAME
;
413 else if (0 ==pIter
->Name
.compareToAscii(PROPERTY_DESCRIPTION
))
414 pIter
->Handle
= PROPERTY_ID_DESCRIPTION
;
415 else if (0 ==pIter
->Name
.compareToAscii(PROPERTY_TYPE
))
416 pIter
->Handle
= PROPERTY_ID_TYPE
;
417 else if (0 ==pIter
->Name
.compareToAscii(PROPERTY_PRIVILEGES
))
418 pIter
->Handle
= PROPERTY_ID_PRIVILEGES
;
421 describeProperties(aTableProps
);
423 return new ::cppu::OPropertyArrayHelper(aTableProps
);
425 // -----------------------------------------------------------------------------
426 ::cppu::IPropertyArrayHelper
& SAL_CALL
ODBTableDecorator::getInfoHelper()
428 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getInfoHelper" );
429 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
431 Reference
<XPropertySetInfo
> xInfo
= xProp
->getPropertySetInfo();
432 bool bIsDescriptor
= (xInfo
->getPropertyByName(PROPERTY_NAME
).Attributes
& PropertyAttribute::READONLY
) == 0;
434 return *ODBTableDecorator_PROP::getArrayHelper( bIsDescriptor
? 0 : 1 );
436 // TODO: this is a HACK, and prone to errors
437 // The OIdPropertyArrayUsageHelper is intended for classes where there exists a known, limited
438 // number of different property set infos (distinguished by the ID), all implemented by this very
440 // However, in this case here we have an unknown, potentially unlimited number of different
441 // property set infos: Depending on the table for which we act as decorator, different property
444 // -------------------------------------------------------------------------
446 IMPLEMENT_SERVICE_INFO1(ODBTableDecorator
, "com.sun.star.sdb.dbaccess.ODBTableDecorator", SERVICE_SDBCX_TABLE
)
447 // -------------------------------------------------------------------------
448 Any SAL_CALL
ODBTableDecorator::queryInterface( const Type
& rType
) throw(RuntimeException
)
450 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::queryInterface" );
454 aRet
= m_xTable
->queryInterface(rType
);
456 { // now we know that our table supports this type so we return ourself
457 aRet
= OTableDescriptor_BASE::queryInterface(rType
);
459 aRet
= ODataSettings::queryInterface(rType
);
465 // -------------------------------------------------------------------------
466 Sequence
< Type
> SAL_CALL
ODBTableDecorator::getTypes( ) throw(RuntimeException
)
468 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getTypes" );
469 Reference
<XTypeProvider
> xTypes(m_xTable
,UNO_QUERY
);
470 OSL_ENSURE(xTypes
.is(),"Table must be a TypePropvider!");
471 return xTypes
->getTypes();
474 // -----------------------------------------------------------------------------
476 //------------------------------------------------------------------------------
477 void SAL_CALL
ODBTableDecorator::rename( const ::rtl::OUString
& _rNewName
) throw(SQLException
, ElementExistException
, RuntimeException
)
479 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::rename" );
480 ::osl::MutexGuard
aGuard(m_aMutex
);
481 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
482 Reference
<XRename
> xRename(m_xTable
,UNO_QUERY
);
485 // ::rtl::OUString sOldName;
486 // Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
487 // xProp->getPropertyValue(PROPERTY_NAME) >>= sOldName;
488 xRename
->rename(_rNewName
);
490 else // not supported
491 throw SQLException(DBACORE_RESSTRING(RID_STR_NO_TABLE_RENAME
),*this,SQLSTATE_GENERAL
,1000,Any() );
495 //------------------------------------------------------------------------------
496 void SAL_CALL
ODBTableDecorator::alterColumnByName( const ::rtl::OUString
& _rName
, const Reference
< XPropertySet
>& _rxDescriptor
) throw(SQLException
, NoSuchElementException
, RuntimeException
)
498 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::alterColumnByName" );
499 ::osl::MutexGuard
aGuard(m_aMutex
);
500 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
501 Reference
<XAlterTable
> xAlter(m_xTable
,UNO_QUERY
);
504 xAlter
->alterColumnByName(_rName
,_rxDescriptor
);
507 throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_ALTER_BY_NAME
),*this,SQLSTATE_GENERAL
,1000,Any() );
509 m_pColumns
->refresh();
512 //------------------------------------------------------------------------------
513 void SAL_CALL
ODBTableDecorator::alterColumnByIndex( sal_Int32 _nIndex
, const Reference
< XPropertySet
>& _rxDescriptor
) throw(SQLException
, IndexOutOfBoundsException
, RuntimeException
)
515 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::alterColumnByIndex" );
516 ::osl::MutexGuard
aGuard(m_aMutex
);
517 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
518 Reference
<XAlterTable
> xAlter(m_xTable
,UNO_QUERY
);
521 xAlter
->alterColumnByIndex(_nIndex
,_rxDescriptor
);
523 m_pColumns
->refresh();
525 else // not supported
526 throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_ALTER_BY_INDEX
),*this,SQLSTATE_GENERAL
,1000,Any() );
528 // -----------------------------------------------------------------------------
529 Reference
< XNameAccess
> ODBTableDecorator::getIndexes() throw (RuntimeException
)
531 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getIndexes" );
532 ::osl::MutexGuard
aGuard(m_aMutex
);
533 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
534 return Reference
< XIndexesSupplier
>(m_xTable
,UNO_QUERY
)->getIndexes();
536 // -------------------------------------------------------------------------
537 Reference
< XIndexAccess
> ODBTableDecorator::getKeys() throw (RuntimeException
)
539 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getKeys" );
540 ::osl::MutexGuard
aGuard(m_aMutex
);
541 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
542 return Reference
< XKeysSupplier
>(m_xTable
,UNO_QUERY
)->getKeys();
544 // -------------------------------------------------------------------------
545 Reference
< XNameAccess
> ODBTableDecorator::getColumns() throw (RuntimeException
)
547 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getColumns" );
548 ::osl::MutexGuard
aGuard(m_aMutex
);
549 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
556 // -----------------------------------------------------------------------------
557 ::rtl::OUString SAL_CALL
ODBTableDecorator::getName() throw(RuntimeException
)
559 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getName" );
560 ::osl::MutexGuard
aGuard(m_aMutex
);
561 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
562 Reference
<XNamed
> xName(m_xTable
,UNO_QUERY
);
563 OSL_ENSURE(xName
.is(),"Table should support the XNamed interface");
564 return xName
->getName();
566 // -----------------------------------------------------------------------------
567 sal_Int64 SAL_CALL
ODBTableDecorator::getSomething( const Sequence
< sal_Int8
>& rId
) throw(RuntimeException
)
569 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getSomething" );
570 if (rId
.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId
.getConstArray(), 16 ) )
571 return reinterpret_cast<sal_Int64
>(this);
574 Reference
<XUnoTunnel
> xTunnel(m_xTable
,UNO_QUERY
);
576 nRet
= xTunnel
->getSomething(rId
);
579 // -----------------------------------------------------------------------------
580 Sequence
< sal_Int8
> ODBTableDecorator::getUnoTunnelImplementationId()
582 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getUnoTunnelImplementationId" );
583 static ::cppu::OImplementationId
* pId
= 0;
586 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
589 static ::cppu::OImplementationId aId
;
593 return pId
->getImplementationId();
595 // -----------------------------------------------------------------------------
596 void ODBTableDecorator::fillPrivileges() const
598 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::fillPrivileges" );
599 // somebody is asking for the privileges an we do not know them, yet
603 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
606 if ( xProp
->getPropertySetInfo()->hasPropertyByName(PROPERTY_PRIVILEGES
) )
608 xProp
->getPropertyValue(PROPERTY_PRIVILEGES
) >>= m_nPrivileges
;
610 if ( m_nPrivileges
== 0 ) // second chance
612 ::rtl::OUString sCatalog
,sSchema
,sName
;
613 xProp
->getPropertyValue(PROPERTY_CATALOGNAME
) >>= sCatalog
;
614 xProp
->getPropertyValue(PROPERTY_SCHEMANAME
) >>= sSchema
;
615 xProp
->getPropertyValue(PROPERTY_NAME
) >>= sName
;
616 m_nPrivileges
= ::dbtools::getTablePrivileges(getMetaData(),sCatalog
,sSchema
, sName
);
620 catch(const SQLException
& e
)
623 DBG_ERROR("ODBTableDecorator::ODBTableDecorator : could not collect the privileges !");
626 // -----------------------------------------------------------------------------
627 Reference
< XPropertySet
> SAL_CALL
ODBTableDecorator::createDataDescriptor( ) throw (RuntimeException
)
629 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::createDataDescriptor" );
630 ::osl::MutexGuard
aGuard(m_aMutex
);
631 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
633 Reference
< XDataDescriptorFactory
> xFactory( m_xTable
, UNO_QUERY
);
634 DBG_ASSERT( xFactory
.is(), "ODBTableDecorator::createDataDescriptor: invalid table!" );
635 Reference
< XColumnsSupplier
> xColsSupp
;
637 xColsSupp
= xColsSupp
.query( xFactory
->createDataDescriptor() );
639 return new ODBTableDecorator(
646 // -----------------------------------------------------------------------------
647 Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
ODBTableDecorator::getPropertySetInfo( ) throw(RuntimeException
)
649 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getPropertySetInfo" );
650 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
652 // -----------------------------------------------------------------------------
653 void ODBTableDecorator::refreshColumns()
655 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::refreshColumns" );
656 ::osl::MutexGuard
aGuard(m_aMutex
);
657 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
659 ::std::vector
< ::rtl::OUString
> aVector
;
661 Reference
<XNameAccess
> xNames
;
664 xNames
= m_xTable
->getColumns();
667 Sequence
< ::rtl::OUString
> aNames
= xNames
->getElementNames();
668 const ::rtl::OUString
* pIter
= aNames
.getConstArray();
669 const ::rtl::OUString
* pEnd
= pIter
+ aNames
.getLength();
670 for(;pIter
!= pEnd
;++pIter
)
671 aVector
.push_back(*pIter
);
676 OColumns
* pCol
= new OColumns(*this,m_aMutex
,xNames
,m_xMetaData
.is() && m_xMetaData
->supportsMixedCaseQuotedIdentifiers(),aVector
,
678 m_xMetaData
.is() && m_xMetaData
->supportsAlterTableWithAddColumn(),
679 m_xMetaData
.is() && m_xMetaData
->supportsAlterTableWithDropColumn());
681 pCol
->setParent(*this);
682 OContainerMediator
* pMediator
= new OContainerMediator( pCol
, m_xColumnDefinitions
, m_xConnection
, OContainerMediator::eColumns
);
683 m_xColumnMediator
= pMediator
;
684 pCol
->setMediator( pMediator
);
688 m_pColumns
->reFill(aVector
);
690 // -----------------------------------------------------------------------------
691 OColumn
* ODBTableDecorator::createColumn(const ::rtl::OUString
& _rName
) const
693 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::createColumn" );
694 OColumn
* pReturn
= NULL
;
696 Reference
<XNameAccess
> xNames
;
699 xNames
= m_xTable
->getColumns();
701 if ( xNames
.is() && xNames
->hasByName(_rName
) )
703 Reference
<XPropertySet
> xProp(xNames
->getByName(_rName
),UNO_QUERY
);
705 Reference
<XPropertySet
> xColumnDefintion
;
706 if ( m_xColumnDefinitions
.is() && m_xColumnDefinitions
->hasByName(_rName
))
707 xColumnDefintion
.set(m_xColumnDefinitions
->getByName(_rName
),UNO_QUERY
);
709 pReturn
= new OTableColumnWrapper(xProp
,xColumnDefintion
);
714 // -----------------------------------------------------------------------------
715 void ODBTableDecorator::columnAppended( const Reference
< XPropertySet
>& /*_rxSourceDescriptor*/ )
717 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::columnAppended" );
720 // -----------------------------------------------------------------------------
721 void ODBTableDecorator::columnDropped(const ::rtl::OUString
& _sName
)
723 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::columnDropped" );
724 Reference
<XDrop
> xDrop(m_xColumnDefinitions
,UNO_QUERY
);
725 if ( xDrop
.is() && m_xColumnDefinitions
->hasByName(_sName
) )
726 xDrop
->dropByName(_sName
);
729 // -----------------------------------------------------------------------------
730 Reference
< XPropertySet
> ODBTableDecorator::createColumnDescriptor()
732 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::createColumnDescriptor" );
733 Reference
<XDataDescriptorFactory
> xNames
;
735 xNames
.set(m_xTable
->getColumns(),UNO_QUERY
);
736 Reference
< XPropertySet
> xRet
;
738 xRet
= new OTableColumnDescriptorWrapper(xNames
->createDataDescriptor());
741 // -----------------------------------------------------------------------------
742 void SAL_CALL
ODBTableDecorator::acquire() throw()
744 OTableDescriptor_BASE::acquire();
746 // -----------------------------------------------------------------------------
747 void SAL_CALL
ODBTableDecorator::release() throw()
749 OTableDescriptor_BASE::release();
752 // -----------------------------------------------------------------------------
753 void SAL_CALL
ODBTableDecorator::setName( const ::rtl::OUString
& /*aName*/ ) throw (::com::sun::star::uno::RuntimeException
)
755 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::setName" );
756 throwFunctionNotSupportedException( "XNamed::setName", *this );
759 // -----------------------------------------------------------------------------