update dev300-m58
[ooovba.git] / dbaccess / source / core / api / TableDeco.cxx
blobb3742ae59e840d04d81119faf76ba6f73452877d
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: TableDeco.cxx,v $
10 * $Revision: 1.33 $
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"
36 #endif
37 #ifndef _DBACORE_DEFINITIONCOLUMN_HXX_
38 #include <definitioncolumn.hxx>
39 #endif
40 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
41 #include "dbastrings.hrc"
42 #endif
43 #ifndef _DBA_CORE_RESOURCE_HXX_
44 #include "core_resource.hxx"
45 #endif
46 #ifndef _DBA_CORE_RESOURCE_HRC_
47 #include "core_resource.hrc"
48 #endif
49 #ifndef _TOOLS_DEBUG_HXX
50 #include <tools/debug.hxx>
51 #endif
53 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
54 #include <cppuhelper/typeprovider.hxx>
55 #endif
56 #ifndef _COMPHELPER_ENUMHELPER_HXX_
57 #include <comphelper/enumhelper.hxx>
58 #endif
59 #ifndef _COMPHELPER_CONTAINER_HXX_
60 #include <comphelper/container.hxx>
61 #endif
62 #ifndef _COMPHELPER_SEQUENCE_HXX_
63 #include <comphelper/sequence.hxx>
64 #endif
65 #ifndef _COMPHELPER_PROPERTY_HXX_
66 #include <comphelper/property.hxx>
67 #endif
68 #ifndef _COMPHELPER_TYPES_HXX_
69 #include <comphelper/types.hxx>
70 #endif
71 #ifndef _COM_SUN_STAR_UTIL_XREFRESHLISTENER_HPP_
72 #include <com/sun/star/util/XRefreshListener.hpp>
73 #endif
74 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
75 #include <com/sun/star/sdbc/XConnection.hpp>
76 #endif
77 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
78 #include <com/sun/star/sdbc/XRow.hpp>
79 #endif
80 #ifndef _COM_SUN_STAR_SDBCX_PRIVILEGE_HPP_
81 #include <com/sun/star/sdbcx/Privilege.hpp>
82 #endif
83 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
84 #include <com/sun/star/beans/PropertyAttribute.hpp>
85 #endif
86 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
87 #include <connectivity/dbtools.hxx>
88 #endif
89 #ifndef _DBHELPER_DBEXCEPTION_HXX_
90 #include <connectivity/dbexception.hxx>
91 #endif
92 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
93 #include <connectivity/dbtools.hxx>
94 #endif
95 #ifndef _COMPHELPER_EXTRACT_HXX_
96 #include <comphelper/extract.hxx>
97 #endif
98 #ifndef DBA_CONTAINERMEDIATOR_HXX
99 #include "ContainerMediator.hxx"
100 #endif
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 )
130 ,m_nPrivileges(-1)
131 ,m_pColumns(NULL)
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);
141 if ( m_pColumns )
142 delete m_pColumns;
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;
150 if (! pId)
152 MutexGuard aGuard( Mutex::getGlobalMutex() );
153 if (! pId)
155 static OImplementationId aId;
156 pId = &aId;
159 return pId->getImplementationId();
162 // OComponentHelper
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);
171 m_xTable = NULL;
172 m_xMetaData = NULL;
173 m_pTables = NULL;
174 m_xColumnDefinitions = NULL;
175 m_xNumberFormats = NULL;
176 if ( m_pColumns )
177 m_pColumns->disposing();
178 m_xColumnMediator = NULL;
180 // -----------------------------------------------------------------------------
181 sal_Bool SAL_CALL ODBTableDecorator::convertFastPropertyValue(
182 Any & rConvertedValue,
183 Any & rOldValue,
184 sal_Int32 nHandle,
185 const Any& rValue )
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;
190 switch(nHandle)
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);
219 break;
221 default:
223 Any aValue;
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
229 return bRet;
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" );
235 switch(_nHandle)
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);
266 break;
267 case PROPERTY_ID_CATALOGNAME:
269 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
270 xProp->setPropertyValue(PROPERTY_CATALOGNAME,_rValue);
272 break;
273 case PROPERTY_ID_SCHEMANAME:
275 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
276 xProp->setPropertyValue(PROPERTY_SCHEMANAME,_rValue);
278 break;
279 case PROPERTY_ID_NAME:
281 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
282 xProp->setPropertyValue(PROPERTY_NAME,_rValue);
284 break;
285 case PROPERTY_ID_DESCRIPTION:
287 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
288 xProp->setPropertyValue(PROPERTY_DESCRIPTION,_rValue);
290 break;
291 case PROPERTY_ID_TYPE:
293 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
294 xProp->setPropertyValue(PROPERTY_TYPE,_rValue);
296 break;
299 //------------------------------------------------------------------------------
300 void ODBTableDecorator::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle) const
302 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getFastPropertyValue" );
303 switch(_nHandle)
305 case PROPERTY_ID_PRIVILEGES:
307 if ( -1 == m_nPrivileges )
308 fillPrivileges();
309 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
310 Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
311 if ( xInfo->hasPropertyByName(PROPERTY_PRIVILEGES) )
313 _rValue <<= m_nPrivileges;
314 break;
317 // run through
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);
345 break;
346 case PROPERTY_ID_CATALOGNAME:
348 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
349 _rValue = xProp->getPropertyValue(PROPERTY_CATALOGNAME);
351 break;
352 case PROPERTY_ID_SCHEMANAME:
354 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
355 _rValue = xProp->getPropertyValue(PROPERTY_SCHEMANAME);
357 break;
358 case PROPERTY_ID_NAME:
360 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
361 _rValue = xProp->getPropertyValue(PROPERTY_NAME);
363 break;
364 case PROPERTY_ID_DESCRIPTION:
366 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
367 _rValue = xProp->getPropertyValue(PROPERTY_DESCRIPTION);
369 break;
370 case PROPERTY_ID_TYPE:
372 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
373 _rValue = xProp->getPropertyValue(PROPERTY_TYPE);
375 break;
376 default:
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);
386 if ( xProp.is() )
388 Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
389 bNotFound = !xInfo->hasPropertyByName(PROPERTY_PRIVILEGES);
391 if ( bNotFound )
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
439 // same class.
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
442 // sets might exist.
444 // -------------------------------------------------------------------------
445 // XServiceInfo
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" );
451 Any aRet;
452 if(m_xTable.is())
454 aRet = m_xTable->queryInterface(rType);
455 if(aRet.hasValue())
456 { // now we know that our table supports this type so we return ourself
457 aRet = OTableDescriptor_BASE::queryInterface(rType);
458 if(!aRet.hasValue())
459 aRet = ODataSettings::queryInterface(rType);
463 return aRet;
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 // -----------------------------------------------------------------------------
475 // XRename,
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);
483 if(xRename.is())
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() );
494 // XAlterTable,
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);
502 if(xAlter.is())
504 xAlter->alterColumnByName(_rName,_rxDescriptor);
506 else
507 throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_ALTER_BY_NAME),*this,SQLSTATE_GENERAL,1000,Any() );
508 if(m_pColumns)
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);
519 if(xAlter.is())
521 xAlter->alterColumnByIndex(_nIndex,_rxDescriptor);
522 if(m_pColumns)
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);
551 if(!m_pColumns)
552 refreshColumns();
554 return m_pColumns;
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);
573 sal_Int64 nRet = 0;
574 Reference<XUnoTunnel> xTunnel(m_xTable,UNO_QUERY);
575 if(xTunnel.is())
576 nRet = xTunnel->getSomething(rId);
577 return nRet;
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;
584 if (! pId)
586 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
587 if (! pId)
589 static ::cppu::OImplementationId aId;
590 pId = &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
600 m_nPrivileges = 0;
603 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
604 if ( xProp.is() )
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)
622 (void)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;
636 if ( xFactory.is() )
637 xColsSupp = xColsSupp.query( xFactory->createDataDescriptor() );
639 return new ODBTableDecorator(
640 m_xConnection,
641 xColsSupp,
642 m_xNumberFormats,
643 NULL
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;
662 if(m_xTable.is())
664 xNames = m_xTable->getColumns();
665 if(xNames.is())
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);
674 if(!m_pColumns)
676 OColumns* pCol = new OColumns(*this,m_aMutex,xNames,m_xMetaData.is() && m_xMetaData->supportsMixedCaseQuotedIdentifiers(),aVector,
677 this,this,
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 );
685 m_pColumns = pCol;
687 else
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;
697 if ( m_xTable.is() )
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);
712 return pReturn;
714 // -----------------------------------------------------------------------------
715 void ODBTableDecorator::columnAppended( const Reference< XPropertySet >& /*_rxSourceDescriptor*/ )
717 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::columnAppended" );
718 // not interested in
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;
734 if(m_xTable.is())
735 xNames.set(m_xTable->getColumns(),UNO_QUERY);
736 Reference< XPropertySet > xRet;
737 if(xNames.is())
738 xRet = new OTableColumnDescriptorWrapper(xNames->createDataDescriptor());
739 return xRet;
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 // -----------------------------------------------------------------------------