1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include "TableDeco.hxx"
23 #include <definitioncolumn.hxx>
24 #include "dbastrings.hrc"
25 #include "core_resource.hxx"
26 #include "core_resource.hrc"
27 #include <tools/debug.hxx>
28 #include <osl/diagnose.h>
30 #include <cppuhelper/typeprovider.hxx>
31 #include <comphelper/enumhelper.hxx>
32 #include <comphelper/container.hxx>
33 #include <comphelper/sequence.hxx>
34 #include <comphelper/property.hxx>
35 #include <comphelper/types.hxx>
36 #include <com/sun/star/util/XRefreshListener.hpp>
37 #include <com/sun/star/sdbc/XConnection.hpp>
38 #include <com/sun/star/sdbc/XRow.hpp>
39 #include <com/sun/star/sdbcx/Privilege.hpp>
40 #include <com/sun/star/beans/PropertyAttribute.hpp>
41 #include <connectivity/dbtools.hxx>
42 #include <connectivity/dbexception.hxx>
43 #include <comphelper/extract.hxx>
44 #include "ContainerMediator.hxx"
45 #include <rtl/logfile.hxx>
47 using namespace dbaccess
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::util
;
50 using namespace ::com::sun::star::lang
;
51 using namespace ::com::sun::star::beans
;
52 using namespace ::com::sun::star::sdbc
;
53 using namespace ::com::sun::star::sdbcx
;
54 using namespace ::com::sun::star::container
;
55 using namespace ::osl
;
56 using namespace ::comphelper
;
57 using namespace ::dbtools
;
58 using namespace ::cppu
;
60 //==========================================================================
62 //==========================================================================
63 DBG_NAME(ODBTableDecorator
)
65 ODBTableDecorator::ODBTableDecorator( const Reference
< XConnection
>& _rxConnection
, const Reference
< XColumnsSupplier
>& _rxNewTable
,
66 const Reference
< XNumberFormatsSupplier
>& _rxNumberFormats
, const Reference
< XNameAccess
>& _xColumnDefinitions
) throw(SQLException
)
67 :OTableDescriptor_BASE(m_aMutex
)
68 ,ODataSettings(OTableDescriptor_BASE::rBHelper
)
69 ,m_xTable(_rxNewTable
)
70 ,m_xColumnDefinitions(_xColumnDefinitions
)
71 ,m_xConnection( _rxConnection
)
72 ,m_xMetaData( _rxConnection
.is() ? _rxConnection
->getMetaData() : Reference
< XDatabaseMetaData
>() )
73 ,m_xNumberFormats( _rxNumberFormats
)
77 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::ODBTableDecorator" );
78 DBG_CTOR(ODBTableDecorator
, NULL
);
79 ODataSettings::registerPropertiesFor(this);
82 ODBTableDecorator::~ODBTableDecorator()
84 DBG_DTOR(ODBTableDecorator
, NULL
);
89 Sequence
< sal_Int8
> ODBTableDecorator::getImplementationId() throw (RuntimeException
)
91 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getImplementationId" );
92 static OImplementationId
* pId
= 0;
95 MutexGuard
aGuard( Mutex::getGlobalMutex() );
98 static OImplementationId aId
;
102 return pId
->getImplementationId();
106 void SAL_CALL
ODBTableDecorator::disposing()
108 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::disposing" );
109 OPropertySetHelper::disposing();
110 OTableDescriptor_BASE::disposing();
112 MutexGuard
aGuard(m_aMutex
);
116 m_xColumnDefinitions
= NULL
;
117 m_xNumberFormats
= NULL
;
119 m_pColumns
->disposing();
120 m_xColumnMediator
= NULL
;
123 sal_Bool SAL_CALL
ODBTableDecorator::convertFastPropertyValue(
124 Any
& rConvertedValue
,
128 throw (::com::sun::star::lang::IllegalArgumentException
)
130 sal_Bool bRet
= sal_True
;
133 case PROPERTY_ID_PRIVILEGES
:
134 case PROPERTY_ID_FILTER
:
135 case PROPERTY_ID_ORDER
:
136 case PROPERTY_ID_APPLYFILTER
:
137 case PROPERTY_ID_FONT
:
138 case PROPERTY_ID_ROW_HEIGHT
:
139 case PROPERTY_ID_TEXTCOLOR
:
140 case PROPERTY_ID_TEXTLINECOLOR
:
141 case PROPERTY_ID_TEXTEMPHASIS
:
142 case PROPERTY_ID_TEXTRELIEF
:
143 case PROPERTY_ID_FONTCHARWIDTH
:
144 case PROPERTY_ID_FONTCHARSET
:
145 case PROPERTY_ID_FONTFAMILY
:
146 case PROPERTY_ID_FONTHEIGHT
:
147 case PROPERTY_ID_FONTKERNING
:
148 case PROPERTY_ID_FONTNAME
:
149 case PROPERTY_ID_FONTORIENTATION
:
150 case PROPERTY_ID_FONTPITCH
:
151 case PROPERTY_ID_FONTSLANT
:
152 case PROPERTY_ID_FONTSTRIKEOUT
:
153 case PROPERTY_ID_FONTSTYLENAME
:
154 case PROPERTY_ID_FONTUNDERLINE
:
155 case PROPERTY_ID_FONTWEIGHT
:
156 case PROPERTY_ID_FONTWIDTH
:
157 case PROPERTY_ID_FONTWORDLINEMODE
:
158 case PROPERTY_ID_FONTTYPE
:
159 bRet
= ODataSettings::convertFastPropertyValue(rConvertedValue
, rOldValue
,nHandle
,rValue
);
165 getFastPropertyValue(aValue
,nHandle
);
166 bRet
= ::comphelper::tryPropertyValue(rConvertedValue
,rOldValue
,rValue
,aValue
,::getCppuType(static_cast< ::rtl::OUString
*>(0)));
168 break; // we assume that it works
173 void ODBTableDecorator::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle
, const Any
& _rValue
) throw (Exception
)
175 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::setFastPropertyValue_NoBroadcast" );
178 case PROPERTY_ID_PRIVILEGES
:
179 OSL_FAIL("Property is readonly!");
180 case PROPERTY_ID_FILTER
:
181 case PROPERTY_ID_ORDER
:
182 case PROPERTY_ID_APPLYFILTER
:
183 case PROPERTY_ID_FONT
:
184 case PROPERTY_ID_ROW_HEIGHT
:
185 case PROPERTY_ID_TEXTCOLOR
:
186 case PROPERTY_ID_TEXTLINECOLOR
:
187 case PROPERTY_ID_TEXTEMPHASIS
:
188 case PROPERTY_ID_TEXTRELIEF
:
189 case PROPERTY_ID_FONTCHARWIDTH
:
190 case PROPERTY_ID_FONTCHARSET
:
191 case PROPERTY_ID_FONTFAMILY
:
192 case PROPERTY_ID_FONTHEIGHT
:
193 case PROPERTY_ID_FONTKERNING
:
194 case PROPERTY_ID_FONTNAME
:
195 case PROPERTY_ID_FONTORIENTATION
:
196 case PROPERTY_ID_FONTPITCH
:
197 case PROPERTY_ID_FONTSLANT
:
198 case PROPERTY_ID_FONTSTRIKEOUT
:
199 case PROPERTY_ID_FONTSTYLENAME
:
200 case PROPERTY_ID_FONTUNDERLINE
:
201 case PROPERTY_ID_FONTWEIGHT
:
202 case PROPERTY_ID_FONTWIDTH
:
203 case PROPERTY_ID_FONTWORDLINEMODE
:
204 case PROPERTY_ID_FONTTYPE
:
206 ODataSettings::setFastPropertyValue_NoBroadcast(_nHandle
, _rValue
);
208 case PROPERTY_ID_CATALOGNAME
:
210 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
211 xProp
->setPropertyValue(PROPERTY_CATALOGNAME
,_rValue
);
214 case PROPERTY_ID_SCHEMANAME
:
216 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
217 xProp
->setPropertyValue(PROPERTY_SCHEMANAME
,_rValue
);
220 case PROPERTY_ID_NAME
:
222 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
223 xProp
->setPropertyValue(PROPERTY_NAME
,_rValue
);
226 case PROPERTY_ID_DESCRIPTION
:
228 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
229 xProp
->setPropertyValue(PROPERTY_DESCRIPTION
,_rValue
);
232 case PROPERTY_ID_TYPE
:
234 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
235 xProp
->setPropertyValue(PROPERTY_TYPE
,_rValue
);
241 void ODBTableDecorator::getFastPropertyValue(Any
& _rValue
, sal_Int32 _nHandle
) const
246 case PROPERTY_ID_PRIVILEGES
:
248 if ( -1 == m_nPrivileges
)
250 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
251 Reference
<XPropertySetInfo
> xInfo
= xProp
->getPropertySetInfo();
252 if ( xInfo
->hasPropertyByName(PROPERTY_PRIVILEGES
) )
254 _rValue
<<= m_nPrivileges
;
260 case PROPERTY_ID_FILTER
:
261 case PROPERTY_ID_ORDER
:
262 case PROPERTY_ID_APPLYFILTER
:
263 case PROPERTY_ID_FONT
:
264 case PROPERTY_ID_ROW_HEIGHT
:
265 case PROPERTY_ID_TEXTCOLOR
:
266 case PROPERTY_ID_TEXTLINECOLOR
:
267 case PROPERTY_ID_TEXTEMPHASIS
:
268 case PROPERTY_ID_TEXTRELIEF
:
269 case PROPERTY_ID_FONTCHARWIDTH
:
270 case PROPERTY_ID_FONTCHARSET
:
271 case PROPERTY_ID_FONTFAMILY
:
272 case PROPERTY_ID_FONTHEIGHT
:
273 case PROPERTY_ID_FONTKERNING
:
274 case PROPERTY_ID_FONTNAME
:
275 case PROPERTY_ID_FONTORIENTATION
:
276 case PROPERTY_ID_FONTPITCH
:
277 case PROPERTY_ID_FONTSLANT
:
278 case PROPERTY_ID_FONTSTRIKEOUT
:
279 case PROPERTY_ID_FONTSTYLENAME
:
280 case PROPERTY_ID_FONTUNDERLINE
:
281 case PROPERTY_ID_FONTWEIGHT
:
282 case PROPERTY_ID_FONTWIDTH
:
283 case PROPERTY_ID_FONTWORDLINEMODE
:
284 case PROPERTY_ID_FONTTYPE
:
285 ODataSettings::getFastPropertyValue(_rValue
, _nHandle
);
287 case PROPERTY_ID_CATALOGNAME
:
289 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
290 _rValue
= xProp
->getPropertyValue(PROPERTY_CATALOGNAME
);
293 case PROPERTY_ID_SCHEMANAME
:
295 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
296 _rValue
= xProp
->getPropertyValue(PROPERTY_SCHEMANAME
);
299 case PROPERTY_ID_NAME
:
301 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
302 _rValue
= xProp
->getPropertyValue(PROPERTY_NAME
);
305 case PROPERTY_ID_DESCRIPTION
:
307 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
308 _rValue
= xProp
->getPropertyValue(PROPERTY_DESCRIPTION
);
311 case PROPERTY_ID_TYPE
:
313 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
314 _rValue
= xProp
->getPropertyValue(PROPERTY_TYPE
);
318 OSL_FAIL("Invalid Handle for table");
322 void ODBTableDecorator::construct()
324 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::construct" );
325 sal_Bool bNotFound
= sal_True
;
326 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
329 Reference
<XPropertySetInfo
> xInfo
= xProp
->getPropertySetInfo();
330 bNotFound
= !xInfo
->hasPropertyByName(PROPERTY_PRIVILEGES
);
333 registerProperty(PROPERTY_PRIVILEGES
, PROPERTY_ID_PRIVILEGES
, PropertyAttribute::BOUND
| PropertyAttribute::READONLY
,
334 &m_nPrivileges
, ::getCppuType(static_cast<sal_Int32
*>(NULL
)));
337 ::cppu::IPropertyArrayHelper
* ODBTableDecorator::createArrayHelper(sal_Int32
/*_nId*/) const
339 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
340 Reference
<XPropertySetInfo
> xInfo
= xProp
->getPropertySetInfo();
342 Sequence
< Property
> aTableProps
= xInfo
->getProperties();
343 Property
* pIter
= aTableProps
.getArray();
344 Property
* pEnd
= pIter
+ aTableProps
.getLength();
345 for (;pIter
!= pEnd
; ++pIter
)
347 if (pIter
->Name
.equalsAsciiL(PROPERTY_CATALOGNAME
.ascii
, PROPERTY_CATALOGNAME
.length
))
348 pIter
->Handle
= PROPERTY_ID_CATALOGNAME
;
349 else if (pIter
->Name
.equalsAsciiL(PROPERTY_SCHEMANAME
.ascii
, PROPERTY_SCHEMANAME
.length
))
350 pIter
->Handle
= PROPERTY_ID_SCHEMANAME
;
351 else if (pIter
->Name
.equalsAsciiL(PROPERTY_NAME
.ascii
, PROPERTY_NAME
.length
))
352 pIter
->Handle
= PROPERTY_ID_NAME
;
353 else if (pIter
->Name
.equalsAsciiL(PROPERTY_DESCRIPTION
.ascii
, PROPERTY_DESCRIPTION
.length
))
354 pIter
->Handle
= PROPERTY_ID_DESCRIPTION
;
355 else if (pIter
->Name
.equalsAsciiL(PROPERTY_TYPE
.ascii
, PROPERTY_TYPE
.length
))
356 pIter
->Handle
= PROPERTY_ID_TYPE
;
357 else if (pIter
->Name
.equalsAsciiL(PROPERTY_PRIVILEGES
.ascii
, PROPERTY_PRIVILEGES
.length
))
358 pIter
->Handle
= PROPERTY_ID_PRIVILEGES
;
361 describeProperties(aTableProps
);
363 return new ::cppu::OPropertyArrayHelper(aTableProps
);
366 ::cppu::IPropertyArrayHelper
& SAL_CALL
ODBTableDecorator::getInfoHelper()
368 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
370 Reference
<XPropertySetInfo
> xInfo
= xProp
->getPropertySetInfo();
371 bool bIsDescriptor
= (xInfo
->getPropertyByName(PROPERTY_NAME
).Attributes
& PropertyAttribute::READONLY
) == 0;
373 return *ODBTableDecorator_PROP::getArrayHelper( bIsDescriptor
? 0 : 1 );
375 // TODO: this is a HACK, and prone to errors
376 // The OIdPropertyArrayUsageHelper is intended for classes where there exists a known, limited
377 // number of different property set infos (distinguished by the ID), all implemented by this very
379 // However, in this case here we have an unknown, potentially unlimited number of different
380 // property set infos: Depending on the table for which we act as decorator, different property
385 IMPLEMENT_SERVICE_INFO1(ODBTableDecorator
, "com.sun.star.sdb.dbaccess.ODBTableDecorator", SERVICE_SDBCX_TABLE
.ascii
)
387 Any SAL_CALL
ODBTableDecorator::queryInterface( const Type
& rType
) throw(RuntimeException
)
392 aRet
= m_xTable
->queryInterface(rType
);
394 { // now we know that our table supports this type so we return ourself
395 aRet
= OTableDescriptor_BASE::queryInterface(rType
);
397 aRet
= ODataSettings::queryInterface(rType
);
404 Sequence
< Type
> SAL_CALL
ODBTableDecorator::getTypes( ) throw(RuntimeException
)
406 Reference
<XTypeProvider
> xTypes(m_xTable
,UNO_QUERY
);
407 OSL_ENSURE(xTypes
.is(),"Table must be a TypePropvider!");
408 return xTypes
->getTypes();
412 void SAL_CALL
ODBTableDecorator::rename( const ::rtl::OUString
& _rNewName
) throw(SQLException
, ElementExistException
, RuntimeException
)
414 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::rename" );
415 ::osl::MutexGuard
aGuard(m_aMutex
);
416 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
417 Reference
<XRename
> xRename(m_xTable
,UNO_QUERY
);
420 xRename
->rename(_rNewName
);
422 else // not supported
423 throw SQLException(DBACORE_RESSTRING(RID_STR_NO_TABLE_RENAME
),*this,SQLSTATE_GENERAL
,1000,Any() );
427 void SAL_CALL
ODBTableDecorator::alterColumnByName( const ::rtl::OUString
& _rName
, const Reference
< XPropertySet
>& _rxDescriptor
) throw(SQLException
, NoSuchElementException
, RuntimeException
)
429 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::alterColumnByName" );
430 ::osl::MutexGuard
aGuard(m_aMutex
);
431 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
432 Reference
<XAlterTable
> xAlter(m_xTable
,UNO_QUERY
);
435 xAlter
->alterColumnByName(_rName
,_rxDescriptor
);
438 throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_ALTER_BY_NAME
),*this,SQLSTATE_GENERAL
,1000,Any() );
440 m_pColumns
->refresh();
443 void SAL_CALL
ODBTableDecorator::alterColumnByIndex( sal_Int32 _nIndex
, const Reference
< XPropertySet
>& _rxDescriptor
) throw(SQLException
, IndexOutOfBoundsException
, RuntimeException
)
445 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::alterColumnByIndex" );
446 ::osl::MutexGuard
aGuard(m_aMutex
);
447 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
448 Reference
<XAlterTable
> xAlter(m_xTable
,UNO_QUERY
);
451 xAlter
->alterColumnByIndex(_nIndex
,_rxDescriptor
);
453 m_pColumns
->refresh();
455 else // not supported
456 throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_ALTER_BY_INDEX
),*this,SQLSTATE_GENERAL
,1000,Any() );
459 Reference
< XNameAccess
> ODBTableDecorator::getIndexes() throw (RuntimeException
)
461 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getIndexes" );
462 ::osl::MutexGuard
aGuard(m_aMutex
);
463 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
464 return Reference
< XIndexesSupplier
>(m_xTable
,UNO_QUERY
)->getIndexes();
467 Reference
< XIndexAccess
> ODBTableDecorator::getKeys() throw (RuntimeException
)
469 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getKeys" );
470 ::osl::MutexGuard
aGuard(m_aMutex
);
471 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
472 return Reference
< XKeysSupplier
>(m_xTable
,UNO_QUERY
)->getKeys();
475 Reference
< XNameAccess
> ODBTableDecorator::getColumns() throw (RuntimeException
)
477 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getColumns" );
478 ::osl::MutexGuard
aGuard(m_aMutex
);
479 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
487 ::rtl::OUString SAL_CALL
ODBTableDecorator::getName() throw(RuntimeException
)
489 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getName" );
490 ::osl::MutexGuard
aGuard(m_aMutex
);
491 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
492 Reference
<XNamed
> xName(m_xTable
,UNO_QUERY
);
493 OSL_ENSURE(xName
.is(),"Table should support the XNamed interface");
494 return xName
->getName();
497 sal_Int64 SAL_CALL
ODBTableDecorator::getSomething( const Sequence
< sal_Int8
>& rId
) throw(RuntimeException
)
499 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getSomething" );
500 if (rId
.getLength() == 16 && 0 == memcmp(getUnoTunnelImplementationId().getConstArray(), rId
.getConstArray(), 16 ) )
501 return reinterpret_cast<sal_Int64
>(this);
504 Reference
<XUnoTunnel
> xTunnel(m_xTable
,UNO_QUERY
);
506 nRet
= xTunnel
->getSomething(rId
);
510 Sequence
< sal_Int8
> ODBTableDecorator::getUnoTunnelImplementationId()
512 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getUnoTunnelImplementationId" );
513 static ::cppu::OImplementationId
* pId
= 0;
516 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
519 static ::cppu::OImplementationId aId
;
523 return pId
->getImplementationId();
526 void ODBTableDecorator::fillPrivileges() const
528 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::fillPrivileges" );
529 // somebody is asking for the privileges and we do not know them, yet
533 Reference
<XPropertySet
> xProp(m_xTable
,UNO_QUERY
);
536 if ( xProp
->getPropertySetInfo()->hasPropertyByName(PROPERTY_PRIVILEGES
) )
538 xProp
->getPropertyValue(PROPERTY_PRIVILEGES
) >>= m_nPrivileges
;
540 if ( m_nPrivileges
== 0 ) // second chance
542 ::rtl::OUString sCatalog
,sSchema
,sName
;
543 xProp
->getPropertyValue(PROPERTY_CATALOGNAME
) >>= sCatalog
;
544 xProp
->getPropertyValue(PROPERTY_SCHEMANAME
) >>= sSchema
;
545 xProp
->getPropertyValue(PROPERTY_NAME
) >>= sName
;
546 m_nPrivileges
= ::dbtools::getTablePrivileges(getMetaData(),sCatalog
,sSchema
, sName
);
550 catch(const SQLException
& e
)
553 OSL_FAIL("ODBTableDecorator::ODBTableDecorator : could not collect the privileges !");
557 Reference
< XPropertySet
> SAL_CALL
ODBTableDecorator::createDataDescriptor( ) throw (RuntimeException
)
559 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::createDataDescriptor" );
560 ::osl::MutexGuard
aGuard(m_aMutex
);
561 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
563 Reference
< XDataDescriptorFactory
> xFactory( m_xTable
, UNO_QUERY
);
564 OSL_ENSURE( xFactory
.is(), "ODBTableDecorator::createDataDescriptor: invalid table!" );
565 Reference
< XColumnsSupplier
> xColsSupp
;
567 xColsSupp
= xColsSupp
.query( xFactory
->createDataDescriptor() );
569 return new ODBTableDecorator(
577 Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
ODBTableDecorator::getPropertySetInfo( ) throw(RuntimeException
)
579 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getPropertySetInfo" );
580 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
583 void ODBTableDecorator::refreshColumns()
585 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::refreshColumns" );
586 ::osl::MutexGuard
aGuard(m_aMutex
);
587 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
589 ::std::vector
< ::rtl::OUString
> aVector
;
591 Reference
<XNameAccess
> xNames
;
594 xNames
= m_xTable
->getColumns();
597 Sequence
< ::rtl::OUString
> aNames
= xNames
->getElementNames();
598 const ::rtl::OUString
* pIter
= aNames
.getConstArray();
599 const ::rtl::OUString
* pEnd
= pIter
+ aNames
.getLength();
600 for(;pIter
!= pEnd
;++pIter
)
601 aVector
.push_back(*pIter
);
606 OColumns
* pCol
= new OColumns(*this,m_aMutex
,xNames
,m_xMetaData
.is() && m_xMetaData
->supportsMixedCaseQuotedIdentifiers(),aVector
,
608 m_xMetaData
.is() && m_xMetaData
->supportsAlterTableWithAddColumn(),
609 m_xMetaData
.is() && m_xMetaData
->supportsAlterTableWithDropColumn());
611 pCol
->setParent(*this);
612 OContainerMediator
* pMediator
= new OContainerMediator( pCol
, m_xColumnDefinitions
, m_xConnection
);
613 m_xColumnMediator
= pMediator
;
614 pCol
->setMediator( pMediator
);
618 m_pColumns
->reFill(aVector
);
621 OColumn
* ODBTableDecorator::createColumn(const ::rtl::OUString
& _rName
) const
623 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::createColumn" );
624 OColumn
* pReturn
= NULL
;
626 Reference
<XNameAccess
> xNames
;
629 xNames
= m_xTable
->getColumns();
631 if ( xNames
.is() && xNames
->hasByName(_rName
) )
633 Reference
<XPropertySet
> xProp(xNames
->getByName(_rName
),UNO_QUERY
);
635 Reference
<XPropertySet
> xColumnDefintion
;
636 if ( m_xColumnDefinitions
.is() && m_xColumnDefinitions
->hasByName(_rName
))
637 xColumnDefintion
.set(m_xColumnDefinitions
->getByName(_rName
),UNO_QUERY
);
639 pReturn
= new OTableColumnWrapper( xProp
, xColumnDefintion
, false );
645 void ODBTableDecorator::columnAppended( const Reference
< XPropertySet
>& /*_rxSourceDescriptor*/ )
647 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::columnAppended" );
651 void ODBTableDecorator::columnDropped(const ::rtl::OUString
& _sName
)
653 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::columnDropped" );
654 Reference
<XDrop
> xDrop(m_xColumnDefinitions
,UNO_QUERY
);
655 if ( xDrop
.is() && m_xColumnDefinitions
->hasByName(_sName
) )
656 xDrop
->dropByName(_sName
);
659 Reference
< XPropertySet
> ODBTableDecorator::createColumnDescriptor()
661 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::createColumnDescriptor" );
662 Reference
<XDataDescriptorFactory
> xNames
;
664 xNames
.set(m_xTable
->getColumns(),UNO_QUERY
);
665 Reference
< XPropertySet
> xRet
;
667 xRet
= new OTableColumnDescriptorWrapper( xNames
->createDataDescriptor(), false, true );
671 void SAL_CALL
ODBTableDecorator::acquire() throw()
673 OTableDescriptor_BASE::acquire();
676 void SAL_CALL
ODBTableDecorator::release() throw()
678 OTableDescriptor_BASE::release();
681 void SAL_CALL
ODBTableDecorator::setName( const ::rtl::OUString
& /*aName*/ ) throw (::com::sun::star::uno::RuntimeException
)
683 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::setName" );
684 throwFunctionNotSupportedException( "XNamed::setName", *this );
686 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */