1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26
27 #ifndef _DBA_CORE_TABLEDECORATOR_HXX_
28 #include "TableDeco.hxx"
29 #endif
30 #ifndef _DBACORE_DEFINITIONCOLUMN_HXX_
31 #include <definitioncolumn.hxx>
32 #endif
33 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
34 #include "dbastrings.hrc"
35 #endif
36 #ifndef _DBA_CORE_RESOURCE_HXX_
37 #include "core_resource.hxx"
38 #endif
39 #ifndef _DBA_CORE_RESOURCE_HRC_
40 #include "core_resource.hrc"
41 #endif
42 #ifndef _TOOLS_DEBUG_HXX
43 #include <tools/debug.hxx>
44 #endif
45
46 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
47 #include <cppuhelper/typeprovider.hxx>
48 #endif
49 #ifndef _COMPHELPER_ENUMHELPER_HXX_
50 #include <comphelper/enumhelper.hxx>
51 #endif
52 #ifndef _COMPHELPER_CONTAINER_HXX_
53 #include <comphelper/container.hxx>
54 #endif
55 #ifndef _COMPHELPER_SEQUENCE_HXX_
56 #include <comphelper/sequence.hxx>
57 #endif
58 #ifndef _COMPHELPER_PROPERTY_HXX_
59 #include <comphelper/property.hxx>
60 #endif
61 #ifndef _COMPHELPER_TYPES_HXX_
62 #include <comphelper/types.hxx>
63 #endif
64 #ifndef _COM_SUN_STAR_UTIL_XREFRESHLISTENER_HPP_
65 #include <com/sun/star/util/XRefreshListener.hpp>
66 #endif
67 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
68 #include <com/sun/star/sdbc/XConnection.hpp>
69 #endif
70 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
71 #include <com/sun/star/sdbc/XRow.hpp>
72 #endif
73 #ifndef _COM_SUN_STAR_SDBCX_PRIVILEGE_HPP_
74 #include <com/sun/star/sdbcx/Privilege.hpp>
75 #endif
76 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
77 #include <com/sun/star/beans/PropertyAttribute.hpp>
78 #endif
79 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
80 #include <connectivity/dbtools.hxx>
81 #endif
82 #ifndef _DBHELPER_DBEXCEPTION_HXX_
83 #include <connectivity/dbexception.hxx>
84 #endif
85 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
86 #include <connectivity/dbtools.hxx>
87 #endif
88 #ifndef _COMPHELPER_EXTRACT_HXX_
89 #include <comphelper/extract.hxx>
90 #endif
91 #ifndef DBA_CONTAINERMEDIATOR_HXX
92 #include "ContainerMediator.hxx"
93 #endif
94 #include <rtl/logfile.hxx>
95
96 using namespace dbaccess;
97 using namespace ::com::sun::star::uno;
98 using namespace ::com::sun::star::util;
99 using namespace ::com::sun::star::lang;
100 using namespace ::com::sun::star::beans;
101 using namespace ::com::sun::star::sdbc;
102 using namespace ::com::sun::star::sdbcx;
103 using namespace ::com::sun::star::container;
104 using namespace ::osl;
105 using namespace ::comphelper;
106 using namespace ::dbtools;
107 using namespace ::cppu;
108
109 //==========================================================================
110 //= ODBTableDecorator
111 //==========================================================================
DBG_NAME(ODBTableDecorator)112 DBG_NAME(ODBTableDecorator)
113 // -----------------------------------------------------------------------------
114 ODBTableDecorator::ODBTableDecorator( const Reference< XConnection >& _rxConnection, const Reference< XColumnsSupplier >& _rxNewTable,
115 const Reference< XNumberFormatsSupplier >& _rxNumberFormats, const Reference< XNameAccess >& _xColumnDefinitions )
116 :OTableDescriptor_BASE(m_aMutex)
117 ,ODataSettings(OTableDescriptor_BASE::rBHelper)
118 ,m_xTable(_rxNewTable)
119 ,m_xColumnDefinitions(_xColumnDefinitions)
120 ,m_xConnection( _rxConnection )
121 ,m_xMetaData( _rxConnection.is() ? _rxConnection->getMetaData() : Reference< XDatabaseMetaData >() )
122 ,m_xNumberFormats( _rxNumberFormats )
123 ,m_nPrivileges(-1)
124 ,m_pColumns(NULL)
125 {
126 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::ODBTableDecorator" );
127 DBG_CTOR(ODBTableDecorator, NULL);
128 ODataSettings::registerPropertiesFor(this);
129 }
130 // -------------------------------------------------------------------------
~ODBTableDecorator()131 ODBTableDecorator::~ODBTableDecorator()
132 {
133 DBG_DTOR(ODBTableDecorator, NULL);
134 if ( m_pColumns )
135 delete m_pColumns;
136 }
137
138 //--------------------------------------------------------------------------
getImplementationId()139 Sequence< sal_Int8 > ODBTableDecorator::getImplementationId()
140 {
141 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getImplementationId" );
142 static OImplementationId * pId = 0;
143 if (! pId)
144 {
145 MutexGuard aGuard( Mutex::getGlobalMutex() );
146 if (! pId)
147 {
148 static OImplementationId aId;
149 pId = &aId;
150 }
151 }
152 return pId->getImplementationId();
153 }
154
155 // OComponentHelper
156 //------------------------------------------------------------------------------
disposing()157 void SAL_CALL ODBTableDecorator::disposing()
158 {
159 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::disposing" );
160 OPropertySetHelper::disposing();
161 OTableDescriptor_BASE::disposing();
162
163 MutexGuard aGuard(m_aMutex);
164 m_xTable = NULL;
165 m_xMetaData = NULL;
166 m_pTables = NULL;
167 m_xColumnDefinitions = NULL;
168 m_xNumberFormats = NULL;
169 if ( m_pColumns )
170 m_pColumns->disposing();
171 m_xColumnMediator = NULL;
172 }
173 // -----------------------------------------------------------------------------
convertFastPropertyValue(Any & rConvertedValue,Any & rOldValue,sal_Int32 nHandle,const Any & rValue)174 sal_Bool SAL_CALL ODBTableDecorator::convertFastPropertyValue(
175 Any & rConvertedValue,
176 Any & rOldValue,
177 sal_Int32 nHandle,
178 const Any& rValue )
179 {
180 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::convertFastPropertyValue" );
181 sal_Bool bRet = sal_True;
182 switch(nHandle)
183 {
184 case PROPERTY_ID_PRIVILEGES:
185 case PROPERTY_ID_FILTER:
186 case PROPERTY_ID_ORDER:
187 case PROPERTY_ID_APPLYFILTER:
188 case PROPERTY_ID_FONT:
189 case PROPERTY_ID_ROW_HEIGHT:
190 case PROPERTY_ID_TEXTCOLOR:
191 case PROPERTY_ID_TEXTLINECOLOR:
192 case PROPERTY_ID_TEXTEMPHASIS:
193 case PROPERTY_ID_TEXTRELIEF:
194 case PROPERTY_ID_FONTCHARWIDTH:
195 case PROPERTY_ID_FONTCHARSET:
196 case PROPERTY_ID_FONTFAMILY:
197 case PROPERTY_ID_FONTHEIGHT:
198 case PROPERTY_ID_FONTKERNING:
199 case PROPERTY_ID_FONTNAME:
200 case PROPERTY_ID_FONTORIENTATION:
201 case PROPERTY_ID_FONTPITCH:
202 case PROPERTY_ID_FONTSLANT:
203 case PROPERTY_ID_FONTSTRIKEOUT:
204 case PROPERTY_ID_FONTSTYLENAME:
205 case PROPERTY_ID_FONTUNDERLINE:
206 case PROPERTY_ID_FONTWEIGHT:
207 case PROPERTY_ID_FONTWIDTH:
208 case PROPERTY_ID_FONTWORDLINEMODE:
209 case PROPERTY_ID_FONTTYPE:
210 bRet = ODataSettings::convertFastPropertyValue(rConvertedValue, rOldValue,nHandle,rValue);
211 break;
212
213 default:
214 {
215 Any aValue;
216 getFastPropertyValue(aValue,nHandle);
217 bRet = ::comphelper::tryPropertyValue(rConvertedValue,rOldValue,rValue,aValue,::getCppuType(static_cast< ::rtl::OUString*>(NULL)));
218 }
219 break; // we assume that it works
220 }
221 return bRet;
222 }
223 // -----------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle,const Any & _rValue)224 void ODBTableDecorator::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue)
225 {
226 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::setFastPropertyValue_NoBroadcast" );
227 switch(_nHandle)
228 {
229 case PROPERTY_ID_PRIVILEGES:
230 OSL_ENSURE(0,"Property is readonly!");
231 case PROPERTY_ID_FILTER:
232 case PROPERTY_ID_ORDER:
233 case PROPERTY_ID_APPLYFILTER:
234 case PROPERTY_ID_FONT:
235 case PROPERTY_ID_ROW_HEIGHT:
236 case PROPERTY_ID_TEXTCOLOR:
237 case PROPERTY_ID_TEXTLINECOLOR:
238 case PROPERTY_ID_TEXTEMPHASIS:
239 case PROPERTY_ID_TEXTRELIEF:
240 case PROPERTY_ID_FONTCHARWIDTH:
241 case PROPERTY_ID_FONTCHARSET:
242 case PROPERTY_ID_FONTFAMILY:
243 case PROPERTY_ID_FONTHEIGHT:
244 case PROPERTY_ID_FONTKERNING:
245 case PROPERTY_ID_FONTNAME:
246 case PROPERTY_ID_FONTORIENTATION:
247 case PROPERTY_ID_FONTPITCH:
248 case PROPERTY_ID_FONTSLANT:
249 case PROPERTY_ID_FONTSTRIKEOUT:
250 case PROPERTY_ID_FONTSTYLENAME:
251 case PROPERTY_ID_FONTUNDERLINE:
252 case PROPERTY_ID_FONTWEIGHT:
253 case PROPERTY_ID_FONTWIDTH:
254 case PROPERTY_ID_FONTWORDLINEMODE:
255 case PROPERTY_ID_FONTTYPE:
256
257 ODataSettings::setFastPropertyValue_NoBroadcast(_nHandle, _rValue);
258 break;
259 case PROPERTY_ID_CATALOGNAME:
260 {
261 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
262 xProp->setPropertyValue(PROPERTY_CATALOGNAME,_rValue);
263 }
264 break;
265 case PROPERTY_ID_SCHEMANAME:
266 {
267 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
268 xProp->setPropertyValue(PROPERTY_SCHEMANAME,_rValue);
269 }
270 break;
271 case PROPERTY_ID_NAME:
272 {
273 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
274 xProp->setPropertyValue(PROPERTY_NAME,_rValue);
275 }
276 break;
277 case PROPERTY_ID_DESCRIPTION:
278 {
279 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
280 xProp->setPropertyValue(PROPERTY_DESCRIPTION,_rValue);
281 }
282 break;
283 case PROPERTY_ID_TYPE:
284 {
285 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
286 xProp->setPropertyValue(PROPERTY_TYPE,_rValue);
287 }
288 break;
289 }
290 }
291 //------------------------------------------------------------------------------
getFastPropertyValue(Any & _rValue,sal_Int32 _nHandle) const292 void ODBTableDecorator::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle) const
293 {
294 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getFastPropertyValue" );
295 switch(_nHandle)
296 {
297 case PROPERTY_ID_PRIVILEGES:
298 {
299 if ( -1 == m_nPrivileges )
300 fillPrivileges();
301 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
302 Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
303 if ( xInfo->hasPropertyByName(PROPERTY_PRIVILEGES) )
304 {
305 _rValue <<= m_nPrivileges;
306 break;
307 }
308 }
309 // run through
310
311 case PROPERTY_ID_FILTER:
312 case PROPERTY_ID_ORDER:
313 case PROPERTY_ID_APPLYFILTER:
314 case PROPERTY_ID_FONT:
315 case PROPERTY_ID_ROW_HEIGHT:
316 case PROPERTY_ID_TEXTCOLOR:
317 case PROPERTY_ID_TEXTLINECOLOR:
318 case PROPERTY_ID_TEXTEMPHASIS:
319 case PROPERTY_ID_TEXTRELIEF:
320 case PROPERTY_ID_FONTCHARWIDTH:
321 case PROPERTY_ID_FONTCHARSET:
322 case PROPERTY_ID_FONTFAMILY:
323 case PROPERTY_ID_FONTHEIGHT:
324 case PROPERTY_ID_FONTKERNING:
325 case PROPERTY_ID_FONTNAME:
326 case PROPERTY_ID_FONTORIENTATION:
327 case PROPERTY_ID_FONTPITCH:
328 case PROPERTY_ID_FONTSLANT:
329 case PROPERTY_ID_FONTSTRIKEOUT:
330 case PROPERTY_ID_FONTSTYLENAME:
331 case PROPERTY_ID_FONTUNDERLINE:
332 case PROPERTY_ID_FONTWEIGHT:
333 case PROPERTY_ID_FONTWIDTH:
334 case PROPERTY_ID_FONTWORDLINEMODE:
335 case PROPERTY_ID_FONTTYPE:
336 ODataSettings::getFastPropertyValue(_rValue, _nHandle);
337 break;
338 case PROPERTY_ID_CATALOGNAME:
339 {
340 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
341 _rValue = xProp->getPropertyValue(PROPERTY_CATALOGNAME);
342 }
343 break;
344 case PROPERTY_ID_SCHEMANAME:
345 {
346 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
347 _rValue = xProp->getPropertyValue(PROPERTY_SCHEMANAME);
348 }
349 break;
350 case PROPERTY_ID_NAME:
351 {
352 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
353 _rValue = xProp->getPropertyValue(PROPERTY_NAME);
354 }
355 break;
356 case PROPERTY_ID_DESCRIPTION:
357 {
358 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
359 _rValue = xProp->getPropertyValue(PROPERTY_DESCRIPTION);
360 }
361 break;
362 case PROPERTY_ID_TYPE:
363 {
364 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
365 _rValue = xProp->getPropertyValue(PROPERTY_TYPE);
366 }
367 break;
368 default:
369 OSL_ENSURE(0,"Invalid Handle for table");
370 }
371 }
372 // -------------------------------------------------------------------------
construct()373 void ODBTableDecorator::construct()
374 {
375 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::construct" );
376 sal_Bool bNotFound = sal_True;
377 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
378 if ( xProp.is() )
379 {
380 Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
381 bNotFound = !xInfo->hasPropertyByName(PROPERTY_PRIVILEGES);
382 }
383 if ( bNotFound )
384 registerProperty(PROPERTY_PRIVILEGES, PROPERTY_ID_PRIVILEGES, PropertyAttribute::BOUND | PropertyAttribute::READONLY,
385 &m_nPrivileges, ::getCppuType(static_cast<sal_Int32*>(NULL)));
386 }
387 // -----------------------------------------------------------------------------
createArrayHelper(sal_Int32) const388 ::cppu::IPropertyArrayHelper* ODBTableDecorator::createArrayHelper(sal_Int32 /*_nId*/) const
389 {
390 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::createArrayHelper" );
391 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
392 Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
393
394 Sequence< Property > aTableProps = xInfo->getProperties();
395 Property* pIter = aTableProps.getArray();
396 Property* pEnd = pIter + aTableProps.getLength();
397 for (;pIter != pEnd ; ++pIter)
398 {
399 if (0 == pIter->Name.compareToAscii(PROPERTY_CATALOGNAME))
400 pIter->Handle = PROPERTY_ID_CATALOGNAME;
401 else if (0 ==pIter->Name.compareToAscii(PROPERTY_SCHEMANAME))
402 pIter->Handle = PROPERTY_ID_SCHEMANAME;
403 else if (0 ==pIter->Name.compareToAscii(PROPERTY_NAME))
404 pIter->Handle = PROPERTY_ID_NAME;
405 else if (0 ==pIter->Name.compareToAscii(PROPERTY_DESCRIPTION))
406 pIter->Handle = PROPERTY_ID_DESCRIPTION;
407 else if (0 ==pIter->Name.compareToAscii(PROPERTY_TYPE))
408 pIter->Handle = PROPERTY_ID_TYPE;
409 else if (0 ==pIter->Name.compareToAscii(PROPERTY_PRIVILEGES))
410 pIter->Handle = PROPERTY_ID_PRIVILEGES;
411 }
412
413 describeProperties(aTableProps);
414
415 return new ::cppu::OPropertyArrayHelper(aTableProps);
416 }
417 // -----------------------------------------------------------------------------
getInfoHelper()418 ::cppu::IPropertyArrayHelper & SAL_CALL ODBTableDecorator::getInfoHelper()
419 {
420 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getInfoHelper" );
421 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
422
423 Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
424 bool bIsDescriptor = (xInfo->getPropertyByName(PROPERTY_NAME).Attributes & PropertyAttribute::READONLY) == 0;
425
426 return *ODBTableDecorator_PROP::getArrayHelper( bIsDescriptor ? 0 : 1 );
427
428 // TODO: this is a HACK, and prone to errors
429 // The OIdPropertyArrayUsageHelper is intended for classes where there exists a known, limited
430 // number of different property set infos (distinguished by the ID), all implemented by this very
431 // same class.
432 // However, in this case here we have an unknown, potentially unlimited number of different
433 // property set infos: Depending on the table for which we act as decorator, different property
434 // sets might exist.
435 }
436 // -------------------------------------------------------------------------
437 // XServiceInfo
438 IMPLEMENT_SERVICE_INFO1(ODBTableDecorator, "com.sun.star.sdb.dbaccess.ODBTableDecorator", SERVICE_SDBCX_TABLE)
439 // -------------------------------------------------------------------------
queryInterface(const Type & rType)440 Any SAL_CALL ODBTableDecorator::queryInterface( const Type & rType )
441 {
442 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::queryInterface" );
443 Any aRet;
444 if(m_xTable.is())
445 {
446 aRet = m_xTable->queryInterface(rType);
447 if(aRet.hasValue())
448 { // now we know that our table supports this type so we return ourself
449 aRet = OTableDescriptor_BASE::queryInterface(rType);
450 if(!aRet.hasValue())
451 aRet = ODataSettings::queryInterface(rType);
452 }
453 }
454
455 return aRet;
456 }
457 // -------------------------------------------------------------------------
getTypes()458 Sequence< Type > SAL_CALL ODBTableDecorator::getTypes( )
459 {
460 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getTypes" );
461 Reference<XTypeProvider> xTypes(m_xTable,UNO_QUERY);
462 OSL_ENSURE(xTypes.is(),"Table must be a TypePropvider!");
463 return xTypes->getTypes();
464 }
465
466 // -----------------------------------------------------------------------------
467 // XRename,
468 //------------------------------------------------------------------------------
rename(const::rtl::OUString & _rNewName)469 void SAL_CALL ODBTableDecorator::rename( const ::rtl::OUString& _rNewName )
470 {
471 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::rename" );
472 ::osl::MutexGuard aGuard(m_aMutex);
473 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
474 Reference<XRename> xRename(m_xTable,UNO_QUERY);
475 if(xRename.is())
476 {
477 // ::rtl::OUString sOldName;
478 // Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
479 // xProp->getPropertyValue(PROPERTY_NAME) >>= sOldName;
480 xRename->rename(_rNewName);
481 }
482 else // not supported
483 throw SQLException(DBACORE_RESSTRING(RID_STR_NO_TABLE_RENAME),*this,SQLSTATE_GENERAL,1000,Any() );
484 }
485
486 // XAlterTable,
487 //------------------------------------------------------------------------------
alterColumnByName(const::rtl::OUString & _rName,const Reference<XPropertySet> & _rxDescriptor)488 void SAL_CALL ODBTableDecorator::alterColumnByName( const ::rtl::OUString& _rName, const Reference< XPropertySet >& _rxDescriptor )
489 {
490 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::alterColumnByName" );
491 ::osl::MutexGuard aGuard(m_aMutex);
492 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
493 Reference<XAlterTable> xAlter(m_xTable,UNO_QUERY);
494 if(xAlter.is())
495 {
496 xAlter->alterColumnByName(_rName,_rxDescriptor);
497 }
498 else
499 throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_ALTER_BY_NAME),*this,SQLSTATE_GENERAL,1000,Any() );
500 if(m_pColumns)
501 m_pColumns->refresh();
502 }
503
504 //------------------------------------------------------------------------------
alterColumnByIndex(sal_Int32 _nIndex,const Reference<XPropertySet> & _rxDescriptor)505 void SAL_CALL ODBTableDecorator::alterColumnByIndex( sal_Int32 _nIndex, const Reference< XPropertySet >& _rxDescriptor )
506 {
507 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::alterColumnByIndex" );
508 ::osl::MutexGuard aGuard(m_aMutex);
509 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
510 Reference<XAlterTable> xAlter(m_xTable,UNO_QUERY);
511 if(xAlter.is())
512 {
513 xAlter->alterColumnByIndex(_nIndex,_rxDescriptor);
514 if(m_pColumns)
515 m_pColumns->refresh();
516 }
517 else // not supported
518 throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_ALTER_BY_INDEX),*this,SQLSTATE_GENERAL,1000,Any() );
519 }
520 // -----------------------------------------------------------------------------
getIndexes()521 Reference< XNameAccess> ODBTableDecorator::getIndexes()
522 {
523 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getIndexes" );
524 ::osl::MutexGuard aGuard(m_aMutex);
525 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
526 return Reference< XIndexesSupplier>(m_xTable,UNO_QUERY)->getIndexes();
527 }
528 // -------------------------------------------------------------------------
getKeys()529 Reference< XIndexAccess> ODBTableDecorator::getKeys()
530 {
531 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getKeys" );
532 ::osl::MutexGuard aGuard(m_aMutex);
533 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
534 return Reference< XKeysSupplier>(m_xTable,UNO_QUERY)->getKeys();
535 }
536 // -------------------------------------------------------------------------
getColumns()537 Reference< XNameAccess> ODBTableDecorator::getColumns()
538 {
539 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getColumns" );
540 ::osl::MutexGuard aGuard(m_aMutex);
541 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
542
543 if(!m_pColumns)
544 refreshColumns();
545
546 return m_pColumns;
547 }
548 // -----------------------------------------------------------------------------
getName()549 ::rtl::OUString SAL_CALL ODBTableDecorator::getName()
550 {
551 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getName" );
552 ::osl::MutexGuard aGuard(m_aMutex);
553 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
554 Reference<XNamed> xName(m_xTable,UNO_QUERY);
555 OSL_ENSURE(xName.is(),"Table should support the XNamed interface");
556 return xName->getName();
557 }
558 // -----------------------------------------------------------------------------
getSomething(const Sequence<sal_Int8> & rId)559 sal_Int64 SAL_CALL ODBTableDecorator::getSomething( const Sequence< sal_Int8 >& rId )
560 {
561 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getSomething" );
562 if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
563 return reinterpret_cast<sal_Int64>(this);
564
565 sal_Int64 nRet = 0;
566 Reference<XUnoTunnel> xTunnel(m_xTable,UNO_QUERY);
567 if(xTunnel.is())
568 nRet = xTunnel->getSomething(rId);
569 return nRet;
570 }
571 // -----------------------------------------------------------------------------
getUnoTunnelImplementationId()572 Sequence< sal_Int8 > ODBTableDecorator::getUnoTunnelImplementationId()
573 {
574 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getUnoTunnelImplementationId" );
575 static ::cppu::OImplementationId * pId = 0;
576 if (! pId)
577 {
578 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
579 if (! pId)
580 {
581 static ::cppu::OImplementationId aId;
582 pId = &aId;
583 }
584 }
585 return pId->getImplementationId();
586 }
587 // -----------------------------------------------------------------------------
fillPrivileges() const588 void ODBTableDecorator::fillPrivileges() const
589 {
590 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::fillPrivileges" );
591 // somebody is asking for the privileges an we do not know them, yet
592 m_nPrivileges = 0;
593 try
594 {
595 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
596 if ( xProp.is() )
597 {
598 if ( xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_PRIVILEGES) )
599 {
600 xProp->getPropertyValue(PROPERTY_PRIVILEGES) >>= m_nPrivileges;
601 }
602 if ( m_nPrivileges == 0 ) // second chance
603 {
604 ::rtl::OUString sCatalog,sSchema,sName;
605 xProp->getPropertyValue(PROPERTY_CATALOGNAME) >>= sCatalog;
606 xProp->getPropertyValue(PROPERTY_SCHEMANAME) >>= sSchema;
607 xProp->getPropertyValue(PROPERTY_NAME) >>= sName;
608 m_nPrivileges = ::dbtools::getTablePrivileges(getMetaData(),sCatalog,sSchema, sName);
609 }
610 }
611 }
612 catch(const SQLException& e)
613 {
614 (void)e;
615 DBG_ERROR("ODBTableDecorator::ODBTableDecorator : could not collect the privileges !");
616 }
617 }
618 // -----------------------------------------------------------------------------
createDataDescriptor()619 Reference< XPropertySet > SAL_CALL ODBTableDecorator::createDataDescriptor( )
620 {
621 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::createDataDescriptor" );
622 ::osl::MutexGuard aGuard(m_aMutex);
623 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
624
625 Reference< XDataDescriptorFactory > xFactory( m_xTable, UNO_QUERY );
626 DBG_ASSERT( xFactory.is(), "ODBTableDecorator::createDataDescriptor: invalid table!" );
627 Reference< XColumnsSupplier > xColsSupp;
628 if ( xFactory.is() )
629 xColsSupp = xColsSupp.query( xFactory->createDataDescriptor() );
630
631 return new ODBTableDecorator(
632 m_xConnection,
633 xColsSupp,
634 m_xNumberFormats,
635 NULL
636 );
637 }
638 // -----------------------------------------------------------------------------
getPropertySetInfo()639 Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL ODBTableDecorator::getPropertySetInfo( )
640 {
641 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getPropertySetInfo" );
642 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
643 }
644 // -----------------------------------------------------------------------------
refreshColumns()645 void ODBTableDecorator::refreshColumns()
646 {
647 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::refreshColumns" );
648 ::osl::MutexGuard aGuard(m_aMutex);
649 ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
650
651 ::std::vector< ::rtl::OUString> aVector;
652
653 Reference<XNameAccess> xNames;
654 if(m_xTable.is())
655 {
656 xNames = m_xTable->getColumns();
657 if(xNames.is())
658 {
659 Sequence< ::rtl::OUString> aNames = xNames->getElementNames();
660 const ::rtl::OUString* pIter = aNames.getConstArray();
661 const ::rtl::OUString* pEnd = pIter + aNames.getLength();
662 for(;pIter != pEnd;++pIter)
663 aVector.push_back(*pIter);
664 }
665 }
666 if(!m_pColumns)
667 {
668 OColumns* pCol = new OColumns(*this,m_aMutex,xNames,m_xMetaData.is() && m_xMetaData->supportsMixedCaseQuotedIdentifiers(),aVector,
669 this,this,
670 m_xMetaData.is() && m_xMetaData->supportsAlterTableWithAddColumn(),
671 m_xMetaData.is() && m_xMetaData->supportsAlterTableWithDropColumn());
672
673 pCol->setParent(*this);
674 OContainerMediator* pMediator = new OContainerMediator( pCol, m_xColumnDefinitions, m_xConnection, OContainerMediator::eColumns );
675 m_xColumnMediator = pMediator;
676 pCol->setMediator( pMediator );
677 m_pColumns = pCol;
678 }
679 else
680 m_pColumns->reFill(aVector);
681 }
682 // -----------------------------------------------------------------------------
createColumn(const::rtl::OUString & _rName) const683 OColumn* ODBTableDecorator::createColumn(const ::rtl::OUString& _rName) const
684 {
685 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::createColumn" );
686 OColumn* pReturn = NULL;
687
688 Reference<XNameAccess> xNames;
689 if ( m_xTable.is() )
690 {
691 xNames = m_xTable->getColumns();
692
693 if ( xNames.is() && xNames->hasByName(_rName) )
694 {
695 Reference<XPropertySet> xProp(xNames->getByName(_rName),UNO_QUERY);
696
697 Reference<XPropertySet> xColumnDefintion;
698 if ( m_xColumnDefinitions.is() && m_xColumnDefinitions->hasByName(_rName))
699 xColumnDefintion.set(m_xColumnDefinitions->getByName(_rName),UNO_QUERY);
700
701 pReturn = new OTableColumnWrapper( xProp, xColumnDefintion, false );
702 }
703 }
704 return pReturn;
705 }
706 // -----------------------------------------------------------------------------
columnAppended(const Reference<XPropertySet> &)707 void ODBTableDecorator::columnAppended( const Reference< XPropertySet >& /*_rxSourceDescriptor*/ )
708 {
709 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::columnAppended" );
710 // not interested in
711 }
712 // -----------------------------------------------------------------------------
columnDropped(const::rtl::OUString & _sName)713 void ODBTableDecorator::columnDropped(const ::rtl::OUString& _sName)
714 {
715 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::columnDropped" );
716 Reference<XDrop> xDrop(m_xColumnDefinitions,UNO_QUERY);
717 if ( xDrop.is() && m_xColumnDefinitions->hasByName(_sName) )
718 xDrop->dropByName(_sName);
719 }
720
721 // -----------------------------------------------------------------------------
createColumnDescriptor()722 Reference< XPropertySet > ODBTableDecorator::createColumnDescriptor()
723 {
724 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::createColumnDescriptor" );
725 Reference<XDataDescriptorFactory> xNames;
726 if(m_xTable.is())
727 xNames.set(m_xTable->getColumns(),UNO_QUERY);
728 Reference< XPropertySet > xRet;
729 if ( xNames.is() )
730 xRet = new OTableColumnDescriptorWrapper( xNames->createDataDescriptor(), false, true );
731 return xRet;
732 }
733 // -----------------------------------------------------------------------------
acquire()734 void SAL_CALL ODBTableDecorator::acquire() throw()
735 {
736 OTableDescriptor_BASE::acquire();
737 }
738 // -----------------------------------------------------------------------------
release()739 void SAL_CALL ODBTableDecorator::release() throw()
740 {
741 OTableDescriptor_BASE::release();
742 }
743
744 // -----------------------------------------------------------------------------
setName(const::rtl::OUString &)745 void SAL_CALL ODBTableDecorator::setName( const ::rtl::OUString& /*aName*/ )
746 {
747 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::setName" );
748 throwFunctionNotSupportedException( "XNamed::setName", *this );
749 }
750
751 // -----------------------------------------------------------------------------
752