LCOV - code coverage report
Current view: top level - dbaccess/source/core/api - TableDeco.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 165 277 59.6 %
Date: 2015-06-13 12:38:46 Functions: 22 36 61.1 %
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          32 : 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          64 :     ,m_xMetaData( _rxConnection.is() ? _rxConnection->getMetaData() : Reference< XDatabaseMetaData >() )
      69             :     ,m_xNumberFormats( _rxNumberFormats )
      70             :     ,m_nPrivileges(-1)
      71          96 :     ,m_pColumns(NULL)
      72             : {
      73          32 :     ODataSettings::registerPropertiesFor(this);
      74          32 : }
      75             : 
      76          96 : ODBTableDecorator::~ODBTableDecorator()
      77             : {
      78          32 :     if ( m_pColumns )
      79          32 :         delete m_pColumns;
      80          64 : }
      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          32 : void SAL_CALL ODBTableDecorator::disposing()
      89             : {
      90          32 :     OPropertySetHelper::disposing();
      91          32 :     OTableDescriptor_BASE::disposing();
      92             : 
      93          32 :     MutexGuard aGuard(m_aMutex);
      94          32 :     m_xTable        = NULL;
      95          32 :     m_xMetaData     = NULL;
      96          32 :     m_xColumnDefinitions = NULL;
      97          32 :     m_xNumberFormats = NULL;
      98          32 :     if ( m_pColumns )
      99          32 :         m_pColumns->disposing();
     100          32 :     m_xColumnMediator = NULL;
     101          32 : }
     102             : 
     103        1603 : 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        1603 :     bool bRet = true;
     111        1603 :     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        1603 :             bRet = ODataSettings::convertFastPropertyValue(rConvertedValue, rOldValue,nHandle,rValue);
     140        1603 :             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        1603 :     return bRet;
     151             : }
     152             : 
     153           7 : void ODBTableDecorator::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue) throw (Exception, std::exception)
     154             : {
     155           7 :     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           7 :             ODataSettings::setFastPropertyValue_NoBroadcast(_nHandle, _rValue);
     187           7 :             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           7 : }
     220             : 
     221         105 : void ODBTableDecorator::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle) const
     222             : {
     223             : 
     224         105 :     switch(_nHandle)
     225             :     {
     226             :         case PROPERTY_ID_PRIVILEGES:
     227             :             {
     228           9 :                 if ( -1 == m_nPrivileges )
     229           8 :                     fillPrivileges();
     230           9 :                 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     231           9 :                 Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
     232           9 :                 if ( xInfo->hasPropertyByName(PROPERTY_PRIVILEGES) )
     233             :                 {
     234           9 :                     _rValue <<= m_nPrivileges;
     235           9 :                     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           9 :             ODataSettings::getFastPropertyValue(_rValue, _nHandle);
     266           9 :             break;
     267             :         case PROPERTY_ID_CATALOGNAME:
     268             :             {
     269          29 :                 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     270          29 :                 _rValue = xProp->getPropertyValue(PROPERTY_CATALOGNAME);
     271             :             }
     272          29 :             break;
     273             :         case PROPERTY_ID_SCHEMANAME:
     274             :             {
     275          29 :                 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     276          29 :                 _rValue = xProp->getPropertyValue(PROPERTY_SCHEMANAME);
     277             :             }
     278          29 :             break;
     279             :         case PROPERTY_ID_NAME:
     280             :             {
     281          29 :                 Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     282          29 :                 _rValue = xProp->getPropertyValue(PROPERTY_NAME);
     283             :             }
     284          29 :             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         105 : }
     301             : 
     302          32 : void ODBTableDecorator::construct()
     303             : {
     304          32 :     bool bNotFound = true;
     305          32 :     Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     306          32 :     if ( xProp.is() )
     307             :     {
     308          32 :         Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
     309          32 :         bNotFound = !xInfo->hasPropertyByName(PROPERTY_PRIVILEGES);
     310             :     }
     311          32 :     if ( bNotFound )
     312             :         registerProperty(PROPERTY_PRIVILEGES, PROPERTY_ID_PRIVILEGES, PropertyAttribute::BOUND  | PropertyAttribute::READONLY,
     313          23 :                         &m_nPrivileges, ::cppu::UnoType<sal_Int32>::get());
     314          32 : }
     315             : 
     316          26 : ::cppu::IPropertyArrayHelper* ODBTableDecorator::createArrayHelper(sal_Int32 /*_nId*/) const
     317             : {
     318          26 :     Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     319          52 :     Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
     320             : 
     321          52 :     Sequence< Property > aTableProps = xInfo->getProperties();
     322          26 :     Property* pIter = aTableProps.getArray();
     323          26 :     Property* pEnd = pIter + aTableProps.getLength();
     324         159 :     for (;pIter != pEnd ; ++pIter)
     325             :     {
     326         133 :         if (pIter->Name == PROPERTY_CATALOGNAME)
     327          26 :             pIter->Handle = PROPERTY_ID_CATALOGNAME;
     328         107 :         else if (pIter->Name == PROPERTY_SCHEMANAME)
     329          26 :             pIter->Handle = PROPERTY_ID_SCHEMANAME;
     330          81 :         else if (pIter->Name == PROPERTY_NAME)
     331          26 :             pIter->Handle = PROPERTY_ID_NAME;
     332          55 :         else if (pIter->Name == PROPERTY_DESCRIPTION)
     333          26 :             pIter->Handle = PROPERTY_ID_DESCRIPTION;
     334          29 :         else if (pIter->Name == PROPERTY_TYPE)
     335          26 :             pIter->Handle = PROPERTY_ID_TYPE;
     336           3 :         else if (pIter->Name == PROPERTY_PRIVILEGES)
     337           3 :             pIter->Handle = PROPERTY_ID_PRIVILEGES;
     338             :     }
     339             : 
     340          26 :     describeProperties(aTableProps);
     341             : 
     342          52 :     return new ::cppu::OPropertyArrayHelper(aTableProps);
     343             : }
     344             : 
     345        4355 : ::cppu::IPropertyArrayHelper & SAL_CALL ODBTableDecorator::getInfoHelper()
     346             : {
     347        4355 :     Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     348             : 
     349        8710 :     Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
     350        4355 :     bool bIsDescriptor = (xInfo->getPropertyByName(PROPERTY_NAME).Attributes & PropertyAttribute::READONLY) == 0;
     351             : 
     352        8710 :     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           2 : IMPLEMENT_SERVICE_INFO1(ODBTableDecorator, "com.sun.star.sdb.dbaccess.ODBTableDecorator", SERVICE_SDBCX_TABLE)
     365             : 
     366         948 : Any SAL_CALL ODBTableDecorator::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
     367             : {
     368         948 :     Any aRet;
     369         948 :     if(m_xTable.is())
     370             :     {
     371         948 :         aRet = m_xTable->queryInterface(rType);
     372         948 :         if(aRet.hasValue())
     373             :         {   // now we know that our table supports this type so we return ourself
     374         940 :             aRet = OTableDescriptor_BASE::queryInterface(rType);
     375         940 :             if(!aRet.hasValue())
     376         165 :                 aRet = ODataSettings::queryInterface(rType);
     377             :         }
     378             :     }
     379             : 
     380         948 :     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          21 : Reference< XNameAccess> ODBTableDecorator::getIndexes() throw (RuntimeException, std::exception)
     436             : {
     437          21 :     ::osl::MutexGuard aGuard(m_aMutex);
     438          21 :     ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     439          21 :     return Reference< XIndexesSupplier>(m_xTable,UNO_QUERY)->getIndexes();
     440             : }
     441             : 
     442          39 : Reference< XIndexAccess> ODBTableDecorator::getKeys() throw (RuntimeException, std::exception)
     443             : {
     444          39 :     ::osl::MutexGuard aGuard(m_aMutex);
     445          39 :     ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     446          39 :     return Reference< XKeysSupplier>(m_xTable,UNO_QUERY)->getKeys();
     447             : }
     448             : 
     449         771 : Reference< XNameAccess> ODBTableDecorator::getColumns() throw (RuntimeException, std::exception)
     450             : {
     451         771 :     ::osl::MutexGuard aGuard(m_aMutex);
     452         771 :     ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     453             : 
     454         771 :     if(!m_pColumns)
     455          32 :         refreshColumns();
     456             : 
     457         771 :     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           8 : void ODBTableDecorator::fillPrivileges() const
     497             : {
     498             :     // somebody is asking for the privileges and we do not know them, yet
     499           8 :     m_nPrivileges = 0;
     500             :     try
     501             :     {
     502           8 :         Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
     503           8 :         if ( xProp.is() )
     504             :         {
     505           8 :             if ( xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_PRIVILEGES) )
     506             :             {
     507           8 :                 xProp->getPropertyValue(PROPERTY_PRIVILEGES) >>= m_nPrivileges;
     508             :             }
     509           8 :             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           8 :         }
     518             :     }
     519           0 :     catch(const SQLException& e)
     520             :     {
     521             :         (void)e;
     522             :         SAL_WARN("dbaccess", "ODBTableDecorator::ODBTableDecorator : could not collect the privileges !");
     523             :     }
     524           8 : }
     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         132 : Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL ODBTableDecorator::getPropertySetInfo(  ) throw(RuntimeException, std::exception)
     546             : {
     547         132 :     return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
     548             : }
     549             : 
     550          32 : void ODBTableDecorator::refreshColumns()
     551             : {
     552          32 :     ::osl::MutexGuard aGuard(m_aMutex);
     553          32 :     ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     554             : 
     555          64 :     ::std::vector< OUString> aVector;
     556             : 
     557          64 :     Reference<XNameAccess> xNames;
     558          32 :     if(m_xTable.is())
     559             :     {
     560          32 :         xNames = m_xTable->getColumns();
     561          32 :         if(xNames.is())
     562             :         {
     563          32 :             Sequence< OUString> aNames = xNames->getElementNames();
     564          32 :             const OUString* pIter    = aNames.getConstArray();
     565          32 :             const OUString* pEnd     = pIter + aNames.getLength();
     566         495 :             for(;pIter != pEnd;++pIter)
     567         495 :                 aVector.push_back(*pIter);
     568             :         }
     569             :     }
     570          32 :     if(!m_pColumns)
     571             :     {
     572          32 :         OColumns* pCol = new OColumns(*this,m_aMutex,xNames,m_xMetaData.is() && m_xMetaData->supportsMixedCaseQuotedIdentifiers(),aVector,
     573             :                                     this,this,
     574          32 :                                     m_xMetaData.is() && m_xMetaData->supportsAlterTableWithAddColumn(),
     575          64 :                                     m_xMetaData.is() && m_xMetaData->supportsAlterTableWithDropColumn());
     576             : 
     577          32 :         pCol->setParent(*this);
     578          32 :         OContainerMediator* pMediator = new OContainerMediator( pCol, m_xColumnDefinitions, m_xConnection );
     579          32 :         m_xColumnMediator = pMediator;
     580          32 :         pCol->setMediator( pMediator );
     581          32 :         m_pColumns  = pCol;
     582             :     }
     583             :     else
     584          32 :         m_pColumns->reFill(aVector);
     585          32 : }
     586             : 
     587         373 : OColumn* ODBTableDecorator::createColumn(const OUString& _rName) const
     588             : {
     589         373 :     OColumn* pReturn = NULL;
     590             : 
     591         373 :     Reference<XNameAccess> xNames;
     592         373 :     if ( m_xTable.is() )
     593             :     {
     594         373 :         xNames = m_xTable->getColumns();
     595             : 
     596         373 :         if ( xNames.is() && xNames->hasByName(_rName) )
     597             :         {
     598         373 :             Reference<XPropertySet> xProp(xNames->getByName(_rName),UNO_QUERY);
     599             : 
     600         746 :             Reference<XPropertySet> xColumnDefintion;
     601         373 :             if ( m_xColumnDefinitions.is() && m_xColumnDefinitions->hasByName(_rName))
     602         126 :                 xColumnDefintion.set(m_xColumnDefinitions->getByName(_rName),UNO_QUERY);
     603             : 
     604         746 :             pReturn = new OTableColumnWrapper( xProp, xColumnDefintion, false );
     605             :         }
     606             :     }
     607         373 :     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        6039 : void SAL_CALL ODBTableDecorator::acquire() throw()
     634             : {
     635        6039 :     OTableDescriptor_BASE::acquire();
     636        6039 : }
     637             : 
     638        6039 : void SAL_CALL ODBTableDecorator::release() throw()
     639             : {
     640        6039 :     OTableDescriptor_BASE::release();
     641        6039 : }
     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.11