LCOV - code coverage report
Current view: top level - dbaccess/source/core/api - TableDeco.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 141 277 50.9 %
Date: 2014-11-03 Functions: 19 36 52.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <string.h>
      21             : 
      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>
      29             : 
      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             : 
      46             : using namespace dbaccess;
      47             : using namespace ::com::sun::star::uno;
      48             : using namespace ::com::sun::star::util;
      49             : using namespace ::com::sun::star::lang;
      50             : using namespace ::com::sun::star::beans;
      51             : using namespace ::com::sun::star::sdbc;
      52             : using namespace ::com::sun::star::sdbcx;
      53             : using namespace ::com::sun::star::container;
      54             : using namespace ::osl;
      55             : using namespace ::comphelper;
      56             : using namespace ::dbtools;
      57             : using namespace ::cppu;
      58             : 
      59             : // ODBTableDecorator
      60             : 
      61          38 : ODBTableDecorator::ODBTableDecorator( const Reference< XConnection >& _rxConnection, const Reference< XColumnsSupplier >& _rxNewTable,
      62             :         const Reference< XNumberFormatsSupplier >& _rxNumberFormats, const Reference< XNameAccess >& _xColumnDefinitions ) throw(SQLException)
      63             :     :OTableDescriptor_BASE(m_aMutex)
      64             :     ,ODataSettings(OTableDescriptor_BASE::rBHelper)
      65             :     ,m_xTable(_rxNewTable)
      66             :     ,m_xColumnDefinitions(_xColumnDefinitions)
      67             :     ,m_xConnection( _rxConnection )
      68          76 :     ,m_xMetaData( _rxConnection.is() ? _rxConnection->getMetaData() : Reference< XDatabaseMetaData >() )
      69             :     ,m_xNumberFormats( _rxNumberFormats )
      70             :     ,m_nPrivileges(-1)
      71         114 :     ,m_pColumns(NULL)
      72             : {
      73          38 :     ODataSettings::registerPropertiesFor(this);
      74          38 : }
      75             : 
      76         108 : ODBTableDecorator::~ODBTableDecorator()
      77             : {
      78          36 :     if ( m_pColumns )
      79          36 :         delete m_pColumns;
      80          72 : }
      81             : 
      82           0 : Sequence< sal_Int8 > ODBTableDecorator::getImplementationId() throw (RuntimeException, std::exception)
      83             : {
      84           0 :     return css::uno::Sequence<sal_Int8>();
      85             : }
      86             : 
      87             : // OComponentHelper
      88          36 : void SAL_CALL ODBTableDecorator::disposing()
      89             : {
      90          36 :     OPropertySetHelper::disposing();
      91          36 :     OTableDescriptor_BASE::disposing();
      92             : 
      93          36 :     MutexGuard aGuard(m_aMutex);
      94          36 :     m_xTable        = NULL;
      95          36 :     m_xMetaData     = NULL;
      96          36 :     m_xColumnDefinitions = NULL;
      97          36 :     m_xNumberFormats = NULL;
      98          36 :     if ( m_pColumns )
      99          36 :         m_pColumns->disposing();
     100          36 :     m_xColumnMediator = NULL;
     101          36 : }
     102             : 
     103        1906 : sal_Bool SAL_CALL ODBTableDecorator::convertFastPropertyValue(
     104             :                             Any & rConvertedValue,
     105             :                             Any & rOldValue,
     106             :                             sal_Int32 nHandle,
     107             :                             const Any& rValue )
     108             :                                 throw (::com::sun::star::lang::IllegalArgumentException)
     109             : {
     110        1906 :     bool bRet = true;
     111        1906 :     switch(nHandle)
     112             :     {
     113             :         case PROPERTY_ID_PRIVILEGES:
     114             :         case PROPERTY_ID_FILTER:
     115             :         case PROPERTY_ID_ORDER:
     116             :         case PROPERTY_ID_APPLYFILTER:
     117             :         case PROPERTY_ID_FONT:
     118             :         case PROPERTY_ID_ROW_HEIGHT:
     119             :         case PROPERTY_ID_TEXTCOLOR:
     120             :         case PROPERTY_ID_TEXTLINECOLOR:
     121             :         case PROPERTY_ID_TEXTEMPHASIS:
     122             :         case PROPERTY_ID_TEXTRELIEF:
     123             :         case PROPERTY_ID_FONTCHARWIDTH:
     124             :         case PROPERTY_ID_FONTCHARSET:
     125             :         case PROPERTY_ID_FONTFAMILY:
     126             :         case PROPERTY_ID_FONTHEIGHT:
     127             :         case PROPERTY_ID_FONTKERNING:
     128             :         case PROPERTY_ID_FONTNAME:
     129             :         case PROPERTY_ID_FONTORIENTATION:
     130             :         case PROPERTY_ID_FONTPITCH:
     131             :         case PROPERTY_ID_FONTSLANT:
     132             :         case PROPERTY_ID_FONTSTRIKEOUT:
     133             :         case PROPERTY_ID_FONTSTYLENAME:
     134             :         case PROPERTY_ID_FONTUNDERLINE:
     135             :         case PROPERTY_ID_FONTWEIGHT:
     136             :         case PROPERTY_ID_FONTWIDTH:
     137             :         case PROPERTY_ID_FONTWORDLINEMODE:
     138             :         case PROPERTY_ID_FONTTYPE:
     139        1906 :             bRet = ODataSettings::convertFastPropertyValue(rConvertedValue, rOldValue,nHandle,rValue);
     140        1906 :             break;
     141             : 
     142             :         default:
     143             :             {
     144           0 :                 Any aValue;
     145           0 :                 getFastPropertyValue(aValue,nHandle);
     146           0 :                 bRet = ::comphelper::tryPropertyValue(rConvertedValue,rOldValue,rValue,aValue,::cppu::UnoType<OUString>::get());
     147             :             }
     148           0 :             break; // we assume that it works
     149             :     }
     150        1906 :     return bRet;
     151             : }
     152             : 
     153          14 : void ODBTableDecorator::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue) throw (Exception, std::exception)
     154             : {
     155          14 :     switch(_nHandle)
     156             :     {
     157             :         case PROPERTY_ID_PRIVILEGES:
     158             :             SAL_WARN("dbaccess", "Property is readonly!");
     159             :             /* Fall through */
     160             :         case PROPERTY_ID_FILTER:
     161             :         case PROPERTY_ID_ORDER:
     162             :         case PROPERTY_ID_APPLYFILTER:
     163             :         case PROPERTY_ID_FONT:
     164             :         case PROPERTY_ID_ROW_HEIGHT:
     165             :         case PROPERTY_ID_TEXTCOLOR:
     166             :         case PROPERTY_ID_TEXTLINECOLOR:
     167             :         case PROPERTY_ID_TEXTEMPHASIS:
     168             :         case PROPERTY_ID_TEXTRELIEF:
     169             :         case PROPERTY_ID_FONTCHARWIDTH:
     170             :         case PROPERTY_ID_FONTCHARSET:
     171             :         case PROPERTY_ID_FONTFAMILY:
     172             :         case PROPERTY_ID_FONTHEIGHT:
     173             :         case PROPERTY_ID_FONTKERNING:
     174             :         case PROPERTY_ID_FONTNAME:
     175             :         case PROPERTY_ID_FONTORIENTATION:
     176             :         case PROPERTY_ID_FONTPITCH:
     177             :         case PROPERTY_ID_FONTSLANT:
     178             :         case PROPERTY_ID_FONTSTRIKEOUT:
     179             :         case PROPERTY_ID_FONTSTYLENAME:
     180             :         case PROPERTY_ID_FONTUNDERLINE:
     181             :         case PROPERTY_ID_FONTWEIGHT:
     182             :         case PROPERTY_ID_FONTWIDTH:
     183             :         case PROPERTY_ID_FONTWORDLINEMODE:
     184             :         case PROPERTY_ID_FONTTYPE:
     185             : 
     186          14 :             ODataSettings::setFastPropertyValue_NoBroadcast(_nHandle, _rValue);
     187          14 :             break;
     188             :         case PROPERTY_ID_CATALOGNAME:
     189             :             {
     190           0 :                 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     191           0 :                 xProp->setPropertyValue(PROPERTY_CATALOGNAME,_rValue);
     192             :             }
     193           0 :             break;
     194             :         case PROPERTY_ID_SCHEMANAME:
     195             :             {
     196           0 :                 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     197           0 :                 xProp->setPropertyValue(PROPERTY_SCHEMANAME,_rValue);
     198             :             }
     199           0 :             break;
     200             :         case PROPERTY_ID_NAME:
     201             :             {
     202           0 :                 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     203           0 :                 xProp->setPropertyValue(PROPERTY_NAME,_rValue);
     204             :             }
     205           0 :             break;
     206             :         case PROPERTY_ID_DESCRIPTION:
     207             :             {
     208           0 :                 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     209           0 :                 xProp->setPropertyValue(PROPERTY_DESCRIPTION,_rValue);
     210             :             }
     211           0 :             break;
     212             :         case PROPERTY_ID_TYPE:
     213             :             {
     214           0 :                 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     215           0 :                 xProp->setPropertyValue(PROPERTY_TYPE,_rValue);
     216             :             }
     217           0 :             break;
     218             :     }
     219          14 : }
     220             : 
     221         102 : void ODBTableDecorator::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle) const
     222             : {
     223             : 
     224         102 :     switch(_nHandle)
     225             :     {
     226             :         case PROPERTY_ID_PRIVILEGES:
     227             :             {
     228           0 :                 if ( -1 == m_nPrivileges )
     229           0 :                     fillPrivileges();
     230           0 :                 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     231           0 :                 Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
     232           0 :                 if ( xInfo->hasPropertyByName(PROPERTY_PRIVILEGES) )
     233             :                 {
     234           0 :                     _rValue <<= m_nPrivileges;
     235           0 :                     break;
     236           0 :                 }
     237             :             }
     238             :             // run through
     239             : 
     240             :         case PROPERTY_ID_FILTER:
     241             :         case PROPERTY_ID_ORDER:
     242             :         case PROPERTY_ID_APPLYFILTER:
     243             :         case PROPERTY_ID_FONT:
     244             :         case PROPERTY_ID_ROW_HEIGHT:
     245             :         case PROPERTY_ID_TEXTCOLOR:
     246             :         case PROPERTY_ID_TEXTLINECOLOR:
     247             :         case PROPERTY_ID_TEXTEMPHASIS:
     248             :         case PROPERTY_ID_TEXTRELIEF:
     249             :         case PROPERTY_ID_FONTCHARWIDTH:
     250             :         case PROPERTY_ID_FONTCHARSET:
     251             :         case PROPERTY_ID_FONTFAMILY:
     252             :         case PROPERTY_ID_FONTHEIGHT:
     253             :         case PROPERTY_ID_FONTKERNING:
     254             :         case PROPERTY_ID_FONTNAME:
     255             :         case PROPERTY_ID_FONTORIENTATION:
     256             :         case PROPERTY_ID_FONTPITCH:
     257             :         case PROPERTY_ID_FONTSLANT:
     258             :         case PROPERTY_ID_FONTSTRIKEOUT:
     259             :         case PROPERTY_ID_FONTSTYLENAME:
     260             :         case PROPERTY_ID_FONTUNDERLINE:
     261             :         case PROPERTY_ID_FONTWEIGHT:
     262             :         case PROPERTY_ID_FONTWIDTH:
     263             :         case PROPERTY_ID_FONTWORDLINEMODE:
     264             :         case PROPERTY_ID_FONTTYPE:
     265          18 :             ODataSettings::getFastPropertyValue(_rValue, _nHandle);
     266          18 :             break;
     267             :         case PROPERTY_ID_CATALOGNAME:
     268             :             {
     269          28 :                 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     270          28 :                 _rValue = xProp->getPropertyValue(PROPERTY_CATALOGNAME);
     271             :             }
     272          28 :             break;
     273             :         case PROPERTY_ID_SCHEMANAME:
     274             :             {
     275          28 :                 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     276          28 :                 _rValue = xProp->getPropertyValue(PROPERTY_SCHEMANAME);
     277             :             }
     278          28 :             break;
     279             :         case PROPERTY_ID_NAME:
     280             :             {
     281          28 :                 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     282          28 :                 _rValue = xProp->getPropertyValue(PROPERTY_NAME);
     283             :             }
     284          28 :             break;
     285             :         case PROPERTY_ID_DESCRIPTION:
     286             :             {
     287           0 :                 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     288           0 :                 _rValue = xProp->getPropertyValue(PROPERTY_DESCRIPTION);
     289             :             }
     290           0 :             break;
     291             :         case PROPERTY_ID_TYPE:
     292             :             {
     293           0 :                 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     294           0 :                 _rValue = xProp->getPropertyValue(PROPERTY_TYPE);
     295             :             }
     296           0 :             break;
     297             :         default:
     298             :             SAL_WARN("dbaccess", "Invalid Handle for table");
     299             :     }
     300         102 : }
     301             : 
     302          38 : void ODBTableDecorator::construct()
     303             : {
     304          38 :     bool bNotFound = true;
     305          38 :     Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     306          38 :     if ( xProp.is() )
     307             :     {
     308          38 :         Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
     309          38 :         bNotFound = !xInfo->hasPropertyByName(PROPERTY_PRIVILEGES);
     310             :     }
     311          38 :     if ( bNotFound )
     312             :         registerProperty(PROPERTY_PRIVILEGES, PROPERTY_ID_PRIVILEGES, PropertyAttribute::BOUND  | PropertyAttribute::READONLY,
     313          34 :                         &m_nPrivileges, ::cppu::UnoType<sal_Int32>::get());
     314          38 : }
     315             : 
     316          38 : ::cppu::IPropertyArrayHelper* ODBTableDecorator::createArrayHelper(sal_Int32 /*_nId*/) const
     317             : {
     318          38 :     Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     319          76 :     Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
     320             : 
     321          76 :     Sequence< Property > aTableProps = xInfo->getProperties();
     322          38 :     Property* pIter = aTableProps.getArray();
     323          38 :     Property* pEnd = pIter + aTableProps.getLength();
     324         232 :     for (;pIter != pEnd ; ++pIter)
     325             :     {
     326         194 :         if (pIter->Name == PROPERTY_CATALOGNAME)
     327          38 :             pIter->Handle = PROPERTY_ID_CATALOGNAME;
     328         156 :         else if (pIter->Name == PROPERTY_SCHEMANAME)
     329          38 :             pIter->Handle = PROPERTY_ID_SCHEMANAME;
     330         118 :         else if (pIter->Name == PROPERTY_NAME)
     331          38 :             pIter->Handle = PROPERTY_ID_NAME;
     332          80 :         else if (pIter->Name == PROPERTY_DESCRIPTION)
     333          38 :             pIter->Handle = PROPERTY_ID_DESCRIPTION;
     334          42 :         else if (pIter->Name == PROPERTY_TYPE)
     335          38 :             pIter->Handle = PROPERTY_ID_TYPE;
     336           4 :         else if (pIter->Name == PROPERTY_PRIVILEGES)
     337           4 :             pIter->Handle = PROPERTY_ID_PRIVILEGES;
     338             :     }
     339             : 
     340          38 :     describeProperties(aTableProps);
     341             : 
     342          76 :     return new ::cppu::OPropertyArrayHelper(aTableProps);
     343             : }
     344             : 
     345        5124 : ::cppu::IPropertyArrayHelper & SAL_CALL ODBTableDecorator::getInfoHelper()
     346             : {
     347        5124 :     Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     348             : 
     349       10248 :     Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
     350        5124 :     bool bIsDescriptor = (xInfo->getPropertyByName(PROPERTY_NAME).Attributes & PropertyAttribute::READONLY) == 0;
     351             : 
     352       10248 :     return *ODBTableDecorator_PROP::getArrayHelper( bIsDescriptor ? 0 : 1 );
     353             : 
     354             :     // TODO: this is a HACK, and prone to errors
     355             :     // The OIdPropertyArrayUsageHelper is intended for classes where there exists a known, limited
     356             :     // number of different property set infos (distinguished by the ID), all implemented by this very
     357             :     // same class.
     358             :     // However, in this case here we have an unknown, potentially unlimited number of different
     359             :     // property set infos: Depending on the table for which we act as decorator, different property
     360             :     // sets might exist.
     361             : }
     362             : 
     363             : // XServiceInfo
     364           4 : IMPLEMENT_SERVICE_INFO1(ODBTableDecorator, "com.sun.star.sdb.dbaccess.ODBTableDecorator", SERVICE_SDBCX_TABLE)
     365             : 
     366         982 : Any SAL_CALL ODBTableDecorator::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
     367             : {
     368         982 :     Any aRet;
     369         982 :     if(m_xTable.is())
     370             :     {
     371         982 :         aRet = m_xTable->queryInterface(rType);
     372         982 :         if(aRet.hasValue())
     373             :         {   // now we know that our table supports this type so we return ourself
     374         978 :             aRet = OTableDescriptor_BASE::queryInterface(rType);
     375         978 :             if(!aRet.hasValue())
     376          94 :                 aRet = ODataSettings::queryInterface(rType);
     377             :         }
     378             :     }
     379             : 
     380         982 :     return aRet;
     381             : }
     382             : 
     383           0 : Sequence< Type > SAL_CALL ODBTableDecorator::getTypes(  ) throw(RuntimeException, std::exception)
     384             : {
     385           0 :     Reference<XTypeProvider> xTypes(m_xTable,UNO_QUERY);
     386             :     OSL_ENSURE(xTypes.is(),"Table must be a TypePropvider!");
     387           0 :     return xTypes->getTypes();
     388             : }
     389             : 
     390             : // XRename,
     391           0 : void SAL_CALL ODBTableDecorator::rename( const OUString& _rNewName ) throw(SQLException, ElementExistException, RuntimeException, std::exception)
     392             : {
     393           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     394           0 :     ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     395           0 :     Reference<XRename> xRename(m_xTable,UNO_QUERY);
     396           0 :     if(xRename.is())
     397             :     {
     398           0 :         xRename->rename(_rNewName);
     399             :     }
     400             :     else // not supported
     401           0 :         throw SQLException(DBACORE_RESSTRING(RID_STR_NO_TABLE_RENAME),*this,SQLSTATE_GENERAL,1000,Any() );
     402           0 : }
     403             : 
     404             : // XAlterTable,
     405           0 : void SAL_CALL ODBTableDecorator::alterColumnByName( const OUString& _rName, const Reference< XPropertySet >& _rxDescriptor ) throw(SQLException, NoSuchElementException, RuntimeException, std::exception)
     406             : {
     407           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     408           0 :     ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     409           0 :     Reference<XAlterTable> xAlter(m_xTable,UNO_QUERY);
     410           0 :     if(xAlter.is())
     411             :     {
     412           0 :         xAlter->alterColumnByName(_rName,_rxDescriptor);
     413             :     }
     414             :     else
     415           0 :         throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_ALTER_BY_NAME),*this,SQLSTATE_GENERAL,1000,Any() );
     416           0 :     if(m_pColumns)
     417           0 :         m_pColumns->refresh();
     418           0 : }
     419             : 
     420           0 : void SAL_CALL ODBTableDecorator::alterColumnByIndex( sal_Int32 _nIndex, const Reference< XPropertySet >& _rxDescriptor ) throw(SQLException, IndexOutOfBoundsException, RuntimeException, std::exception)
     421             : {
     422           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     423           0 :     ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     424           0 :     Reference<XAlterTable> xAlter(m_xTable,UNO_QUERY);
     425           0 :     if(xAlter.is())
     426             :     {
     427           0 :         xAlter->alterColumnByIndex(_nIndex,_rxDescriptor);
     428           0 :         if(m_pColumns)
     429           0 :             m_pColumns->refresh();
     430             :     }
     431             :     else // not supported
     432           0 :         throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_ALTER_BY_INDEX),*this,SQLSTATE_GENERAL,1000,Any() );
     433           0 : }
     434             : 
     435           0 : Reference< XNameAccess> ODBTableDecorator::getIndexes() throw (RuntimeException, std::exception)
     436             : {
     437           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     438           0 :     ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     439           0 :     return Reference< XIndexesSupplier>(m_xTable,UNO_QUERY)->getIndexes();
     440             : }
     441             : 
     442           0 : Reference< XIndexAccess> ODBTableDecorator::getKeys() throw (RuntimeException, std::exception)
     443             : {
     444           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     445           0 :     ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     446           0 :     return Reference< XKeysSupplier>(m_xTable,UNO_QUERY)->getKeys();
     447             : }
     448             : 
     449        1012 : Reference< XNameAccess> ODBTableDecorator::getColumns() throw (RuntimeException, std::exception)
     450             : {
     451        1012 :     ::osl::MutexGuard aGuard(m_aMutex);
     452        1012 :     ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     453             : 
     454        1012 :     if(!m_pColumns)
     455          38 :         refreshColumns();
     456             : 
     457        1012 :     return m_pColumns;
     458             : }
     459             : 
     460           0 : OUString SAL_CALL ODBTableDecorator::getName() throw(RuntimeException, std::exception)
     461             : {
     462           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     463           0 :     ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     464           0 :     Reference<XNamed> xName(m_xTable,UNO_QUERY);
     465             :     OSL_ENSURE(xName.is(),"Table should support the XNamed interface");
     466           0 :     return xName->getName();
     467             : }
     468             : 
     469           0 : sal_Int64 SAL_CALL ODBTableDecorator::getSomething( const Sequence< sal_Int8 >& rId ) throw(RuntimeException, std::exception)
     470             : {
     471           0 :     if (rId.getLength() == 16 && 0 == memcmp(getUnoTunnelImplementationId().getConstArray(),  rId.getConstArray(), 16 ) )
     472           0 :         return reinterpret_cast<sal_Int64>(this);
     473             : 
     474           0 :     sal_Int64 nRet = 0;
     475           0 :     Reference<XUnoTunnel> xTunnel(m_xTable,UNO_QUERY);
     476           0 :     if(xTunnel.is())
     477           0 :         nRet = xTunnel->getSomething(rId);
     478           0 :     return nRet;
     479             : }
     480             : 
     481           0 : Sequence< sal_Int8 > ODBTableDecorator::getUnoTunnelImplementationId()
     482             : {
     483             :     static ::cppu::OImplementationId * pId = 0;
     484           0 :     if (! pId)
     485             :     {
     486           0 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     487           0 :         if (! pId)
     488             :         {
     489           0 :             static ::cppu::OImplementationId aId;
     490           0 :             pId = &aId;
     491           0 :         }
     492             :     }
     493           0 :     return pId->getImplementationId();
     494             : }
     495             : 
     496           0 : void ODBTableDecorator::fillPrivileges() const
     497             : {
     498             :     // somebody is asking for the privileges and we do not know them, yet
     499           0 :     m_nPrivileges = 0;
     500             :     try
     501             :     {
     502           0 :         Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     503           0 :         if ( xProp.is() )
     504             :         {
     505           0 :             if ( xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_PRIVILEGES) )
     506             :             {
     507           0 :                 xProp->getPropertyValue(PROPERTY_PRIVILEGES) >>= m_nPrivileges;
     508             :             }
     509           0 :             if ( m_nPrivileges == 0 ) // second chance
     510             :             {
     511           0 :                 OUString sCatalog,sSchema,sName;
     512           0 :                 xProp->getPropertyValue(PROPERTY_CATALOGNAME)   >>= sCatalog;
     513           0 :                 xProp->getPropertyValue(PROPERTY_SCHEMANAME)    >>= sSchema;
     514           0 :                 xProp->getPropertyValue(PROPERTY_NAME)          >>= sName;
     515           0 :                 m_nPrivileges = ::dbtools::getTablePrivileges(getMetaData(),sCatalog,sSchema, sName);
     516             :             }
     517           0 :         }
     518             :     }
     519           0 :     catch(const SQLException& e)
     520             :     {
     521             :         (void)e;
     522             :         SAL_WARN("dbaccess", "ODBTableDecorator::ODBTableDecorator : could not collect the privileges !");
     523             :     }
     524           0 : }
     525             : 
     526           0 : Reference< XPropertySet > SAL_CALL ODBTableDecorator::createDataDescriptor(  ) throw (RuntimeException, std::exception)
     527             : {
     528           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     529           0 :     ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     530             : 
     531           0 :     Reference< XDataDescriptorFactory > xFactory( m_xTable, UNO_QUERY );
     532             :     OSL_ENSURE( xFactory.is(), "ODBTableDecorator::createDataDescriptor: invalid table!" );
     533           0 :     Reference< XColumnsSupplier > xColsSupp;
     534           0 :     if ( xFactory.is() )
     535           0 :         xColsSupp.set(xFactory->createDataDescriptor(), css::uno::UNO_QUERY);
     536             : 
     537             :     return new ODBTableDecorator(
     538             :         m_xConnection,
     539             :         xColsSupp,
     540             :         m_xNumberFormats,
     541             :         NULL
     542           0 :     );
     543             : }
     544             : 
     545         144 : Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL ODBTableDecorator::getPropertySetInfo(  ) throw(RuntimeException, std::exception)
     546             : {
     547         144 :     return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
     548             : }
     549             : 
     550          38 : void ODBTableDecorator::refreshColumns()
     551             : {
     552          38 :     ::osl::MutexGuard aGuard(m_aMutex);
     553          38 :     ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     554             : 
     555          76 :     ::std::vector< OUString> aVector;
     556             : 
     557          76 :     Reference<XNameAccess> xNames;
     558          38 :     if(m_xTable.is())
     559             :     {
     560          38 :         xNames = m_xTable->getColumns();
     561          38 :         if(xNames.is())
     562             :         {
     563          38 :             Sequence< OUString> aNames = xNames->getElementNames();
     564          38 :             const OUString* pIter    = aNames.getConstArray();
     565          38 :             const OUString* pEnd     = pIter + aNames.getLength();
     566         728 :             for(;pIter != pEnd;++pIter)
     567         728 :                 aVector.push_back(*pIter);
     568             :         }
     569             :     }
     570          38 :     if(!m_pColumns)
     571             :     {
     572          38 :         OColumns* pCol = new OColumns(*this,m_aMutex,xNames,m_xMetaData.is() && m_xMetaData->supportsMixedCaseQuotedIdentifiers(),aVector,
     573             :                                     this,this,
     574          38 :                                     m_xMetaData.is() && m_xMetaData->supportsAlterTableWithAddColumn(),
     575          76 :                                     m_xMetaData.is() && m_xMetaData->supportsAlterTableWithDropColumn());
     576             : 
     577          38 :         pCol->setParent(*this);
     578          38 :         OContainerMediator* pMediator = new OContainerMediator( pCol, m_xColumnDefinitions, m_xConnection );
     579          38 :         m_xColumnMediator = pMediator;
     580          38 :         pCol->setMediator( pMediator );
     581          38 :         m_pColumns  = pCol;
     582             :     }
     583             :     else
     584          38 :         m_pColumns->reFill(aVector);
     585          38 : }
     586             : 
     587         510 : OColumn* ODBTableDecorator::createColumn(const OUString& _rName) const
     588             : {
     589         510 :     OColumn* pReturn = NULL;
     590             : 
     591         510 :     Reference<XNameAccess> xNames;
     592         510 :     if ( m_xTable.is() )
     593             :     {
     594         510 :         xNames = m_xTable->getColumns();
     595             : 
     596         510 :         if ( xNames.is() && xNames->hasByName(_rName) )
     597             :         {
     598         510 :             Reference<XPropertySet> xProp(xNames->getByName(_rName),UNO_QUERY);
     599             : 
     600        1020 :             Reference<XPropertySet> xColumnDefintion;
     601         510 :             if ( m_xColumnDefinitions.is() && m_xColumnDefinitions->hasByName(_rName))
     602         262 :                 xColumnDefintion.set(m_xColumnDefinitions->getByName(_rName),UNO_QUERY);
     603             : 
     604        1020 :             pReturn = new OTableColumnWrapper( xProp, xColumnDefintion, false );
     605             :         }
     606             :     }
     607         510 :     return pReturn;
     608             : }
     609             : 
     610           0 : void ODBTableDecorator::columnAppended( const Reference< XPropertySet >& /*_rxSourceDescriptor*/ )
     611             : {
     612             :     // not interested in
     613           0 : }
     614             : 
     615           0 : void ODBTableDecorator::columnDropped(const OUString& _sName)
     616             : {
     617           0 :     Reference<XDrop> xDrop(m_xColumnDefinitions,UNO_QUERY);
     618           0 :     if ( xDrop.is() && m_xColumnDefinitions->hasByName(_sName) )
     619           0 :         xDrop->dropByName(_sName);
     620           0 : }
     621             : 
     622           0 : Reference< XPropertySet > ODBTableDecorator::createColumnDescriptor()
     623             : {
     624           0 :     Reference<XDataDescriptorFactory> xNames;
     625           0 :     if(m_xTable.is())
     626           0 :         xNames.set(m_xTable->getColumns(),UNO_QUERY);
     627           0 :     Reference< XPropertySet > xRet;
     628           0 :     if ( xNames.is() )
     629           0 :         xRet = new OTableColumnDescriptorWrapper( xNames->createDataDescriptor(), false, true );
     630           0 :     return xRet;
     631             : }
     632             : 
     633        7176 : void SAL_CALL ODBTableDecorator::acquire() throw()
     634             : {
     635        7176 :     OTableDescriptor_BASE::acquire();
     636        7176 : }
     637             : 
     638        7170 : void SAL_CALL ODBTableDecorator::release() throw()
     639             : {
     640        7170 :     OTableDescriptor_BASE::release();
     641        7170 : }
     642             : 
     643           0 : void SAL_CALL ODBTableDecorator::setName( const OUString& /*aName*/ ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     644             : {
     645           0 :     throwFunctionNotSupportedRuntimeException( "XNamed::setName", *this );
     646           0 : }
     647             : 
     648             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10