LCOV - code coverage report
Current view: top level - dbaccess/source/core/api - table.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 164 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 28 0.0 %
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 "table.hxx"
      23             : #include <definitioncolumn.hxx>
      24             : #include "dbastrings.hrc"
      25             : #include "core_resource.hxx"
      26             : #include "core_resource.hrc"
      27             : #include "CIndexes.hxx"
      28             : 
      29             : #include <tools/debug.hxx>
      30             : #include <osl/diagnose.h>
      31             : #include <cppuhelper/typeprovider.hxx>
      32             : #include <comphelper/enumhelper.hxx>
      33             : #include <comphelper/container.hxx>
      34             : #include <comphelper/sequence.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/sdbc/XResultSetMetaData.hpp>
      41             : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
      42             : 
      43             : #include <connectivity/TKeys.hxx>
      44             : #include <connectivity/dbtools.hxx>
      45             : #include <connectivity/dbexception.hxx>
      46             : 
      47             : #include "sdbcoretools.hxx"
      48             : #include "ContainerMediator.hxx"
      49             : 
      50             : using namespace dbaccess;
      51             : using namespace connectivity;
      52             : using namespace ::com::sun::star::uno;
      53             : using namespace ::com::sun::star::util;
      54             : using namespace ::com::sun::star::lang;
      55             : using namespace ::com::sun::star::beans;
      56             : using namespace ::com::sun::star::sdbc;
      57             : using namespace ::com::sun::star::sdbcx;
      58             : using namespace ::com::sun::star::container;
      59             : using namespace ::osl;
      60             : using namespace ::comphelper;
      61             : using namespace ::cppu;
      62             : 
      63             : // ODBTable
      64             : 
      65           0 : ODBTable::ODBTable(connectivity::sdbcx::OCollection* _pTables
      66             :         ,const Reference< XConnection >& _rxConn
      67             :         ,const OUString& _rCatalog
      68             :         ,const OUString& _rSchema
      69             :         ,const OUString& _rName
      70             :         ,const OUString& _rType
      71             :         ,const OUString& _rDesc
      72             :         ,const Reference< XNameAccess >& _xColumnDefinitions) throw(SQLException)
      73           0 :     :OTable_Base(_pTables,_rxConn,_rxConn->getMetaData().is() && _rxConn->getMetaData()->supportsMixedCaseQuotedIdentifiers(), _rName, _rType, _rDesc, _rSchema, _rCatalog )
      74             :     ,m_xColumnDefinitions(_xColumnDefinitions)
      75           0 :     ,m_nPrivileges(0)
      76             : {
      77             :     OSL_ENSURE(getMetaData().is(), "ODBTable::ODBTable : invalid conn !");
      78             :     OSL_ENSURE(!_rName.isEmpty(), "ODBTable::ODBTable : name !");
      79             :     // TODO : think about collecting the privileges here, as we can't ensure that in getFastPropertyValue, where
      80             :     // we do this at the moment, the statement needed can be supplied by the connection (for example the SQL-Server
      81             :     // ODBC driver does not allow more than one statement per connection, and in getFastPropertyValue it's more
      82             :     // likely that it's already used up than it's here.)
      83           0 : }
      84             : 
      85           0 : ODBTable::ODBTable(connectivity::sdbcx::OCollection* _pTables
      86             :                    ,const Reference< XConnection >& _rxConn)
      87             :                 throw(SQLException)
      88           0 :     :OTable_Base(_pTables,_rxConn, _rxConn->getMetaData().is() && _rxConn->getMetaData()->supportsMixedCaseQuotedIdentifiers())
      89           0 :     ,m_nPrivileges(-1)
      90             : {
      91           0 : }
      92             : 
      93           0 : ODBTable::~ODBTable()
      94             : {
      95           0 : }
      96             : 
      97           0 : IMPLEMENT_FORWARD_REFCOUNT(ODBTable,OTable_Base)
      98             : 
      99           0 : OColumn* ODBTable::createColumn(const OUString& _rName) const
     100             : {
     101           0 :     OColumn* pReturn = NULL;
     102             : 
     103           0 :     Reference<XPropertySet> xProp;
     104           0 :     if ( m_xDriverColumns.is() && m_xDriverColumns->hasByName(_rName) )
     105             :     {
     106           0 :         xProp.set(m_xDriverColumns->getByName(_rName),UNO_QUERY);
     107             :     }
     108             :     else
     109             :     {
     110           0 :         OColumns* pColumns = static_cast<OColumns*>(m_pColumns);
     111           0 :         xProp.set(pColumns->createBaseObject(_rName),UNO_QUERY);
     112             :     }
     113             : 
     114           0 :     Reference<XPropertySet> xColumnDefintion;
     115           0 :     if ( m_xColumnDefinitions.is() && m_xColumnDefinitions->hasByName(_rName) )
     116           0 :         xColumnDefintion.set(m_xColumnDefinitions->getByName(_rName),UNO_QUERY);
     117           0 :     pReturn = new OTableColumnWrapper( xProp, xColumnDefintion, false );
     118             : 
     119           0 :     return pReturn;
     120             : }
     121             : 
     122           0 : void ODBTable::columnAppended( const Reference< XPropertySet >& /*_rxSourceDescriptor*/ )
     123             : {
     124             :     // not interested in
     125           0 : }
     126             : 
     127           0 : void ODBTable::columnDropped(const OUString& _sName)
     128             : {
     129           0 :     Reference<XDrop> xDrop(m_xColumnDefinitions,UNO_QUERY);
     130           0 :     if ( xDrop.is() && m_xColumnDefinitions->hasByName(_sName) )
     131             :     {
     132           0 :         xDrop->dropByName(_sName);
     133           0 :     }
     134           0 : }
     135             : 
     136           0 : Sequence< sal_Int8 > ODBTable::getImplementationId() throw (RuntimeException, std::exception)
     137             : {
     138           0 :     return css::uno::Sequence<sal_Int8>();
     139             : }
     140             : 
     141             : // OComponentHelper
     142           0 : void SAL_CALL ODBTable::disposing()
     143             : {
     144           0 :     OPropertySetHelper::disposing();
     145           0 :     OTable_Base::disposing();
     146           0 :     m_xColumnDefinitions = NULL;
     147           0 :     m_xDriverColumns = NULL;
     148           0 :     m_pColumnMediator = NULL;
     149           0 : }
     150             : 
     151           0 : void ODBTable::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle) const
     152             : {
     153           0 :     if ((PROPERTY_ID_PRIVILEGES == _nHandle) && (-1 == m_nPrivileges))
     154             :     {   // somebody is asking for the privileges an we do not know them, yet
     155           0 :         const_cast<ODBTable*>(this)->m_nPrivileges = ::dbtools::getTablePrivileges(getMetaData(),m_CatalogName,m_SchemaName, m_Name);
     156             :     }
     157             : 
     158           0 :     OTable_Base::getFastPropertyValue(_rValue, _nHandle);
     159           0 : }
     160             : 
     161           0 : void ODBTable::construct()
     162             : {
     163           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     164             : 
     165             :     // we don't collect the privileges here, this is potentially expensive. Instead we determine them on request.
     166             :     // (see getFastPropertyValue)
     167           0 :     m_nPrivileges = -1;
     168             : 
     169           0 :     OTable_Base::construct();
     170             : 
     171             :     registerProperty(PROPERTY_FILTER, PROPERTY_ID_FILTER, PropertyAttribute::BOUND,
     172           0 :                     &m_sFilter, cppu::UnoType<OUString>::get());
     173             : 
     174             :     registerProperty(PROPERTY_ORDER, PROPERTY_ID_ORDER, PropertyAttribute::BOUND,
     175           0 :                     &m_sOrder, cppu::UnoType<OUString>::get());
     176             : 
     177             :     registerProperty(PROPERTY_APPLYFILTER, PROPERTY_ID_APPLYFILTER, PropertyAttribute::BOUND,
     178           0 :                     &m_bApplyFilter, cppu::UnoType<bool>::get());
     179             : 
     180             :     registerProperty(PROPERTY_FONT, PROPERTY_ID_FONT, PropertyAttribute::BOUND,
     181           0 :                     &m_aFont, cppu::UnoType<com::sun::star::awt::FontDescriptor>::get());
     182             : 
     183             :     registerMayBeVoidProperty(PROPERTY_ROW_HEIGHT, PROPERTY_ID_ROW_HEIGHT, PropertyAttribute::BOUND | PropertyAttribute::MAYBEVOID,
     184           0 :                     &m_aRowHeight, cppu::UnoType<sal_Int32>::get());
     185             : 
     186             :     registerMayBeVoidProperty(PROPERTY_TEXTCOLOR, PROPERTY_ID_TEXTCOLOR, PropertyAttribute::BOUND | PropertyAttribute::MAYBEVOID,
     187           0 :                     &m_aTextColor, cppu::UnoType<sal_Int32>::get());
     188             : 
     189             :     registerProperty(PROPERTY_PRIVILEGES, PROPERTY_ID_PRIVILEGES, PropertyAttribute::BOUND | PropertyAttribute::READONLY,
     190           0 :                     &m_nPrivileges, cppu::UnoType<sal_Int32>::get());
     191             : 
     192             :     registerMayBeVoidProperty(PROPERTY_TEXTLINECOLOR, PROPERTY_ID_TEXTLINECOLOR, PropertyAttribute::BOUND | PropertyAttribute::MAYBEVOID,
     193           0 :                     &m_aTextLineColor, cppu::UnoType<sal_Int32>::get());
     194             : 
     195             :     registerProperty(PROPERTY_TEXTEMPHASIS, PROPERTY_ID_TEXTEMPHASIS, PropertyAttribute::BOUND,
     196           0 :                     &m_nFontEmphasis, cppu::UnoType<sal_Int16>::get());
     197             : 
     198             :     registerProperty(PROPERTY_TEXTRELIEF, PROPERTY_ID_TEXTRELIEF, PropertyAttribute::BOUND,
     199           0 :                     &m_nFontRelief, cppu::UnoType<sal_Int16>::get());
     200             : 
     201           0 :     registerProperty(PROPERTY_FONTNAME,         PROPERTY_ID_FONTNAME,        PropertyAttribute::BOUND,&m_aFont.Name, cppu::UnoType<OUString>::get());
     202           0 :     registerProperty(PROPERTY_FONTHEIGHT,       PROPERTY_ID_FONTHEIGHT,      PropertyAttribute::BOUND,&m_aFont.Height, cppu::UnoType<sal_Int16>::get());
     203           0 :     registerProperty(PROPERTY_FONTWIDTH,        PROPERTY_ID_FONTWIDTH,       PropertyAttribute::BOUND,&m_aFont.Width, cppu::UnoType<sal_Int16>::get());
     204           0 :     registerProperty(PROPERTY_FONTSTYLENAME,    PROPERTY_ID_FONTSTYLENAME,   PropertyAttribute::BOUND,&m_aFont.StyleName, cppu::UnoType<OUString>::get());
     205           0 :     registerProperty(PROPERTY_FONTFAMILY,       PROPERTY_ID_FONTFAMILY,      PropertyAttribute::BOUND,&m_aFont.Family, cppu::UnoType<sal_Int16>::get());
     206           0 :     registerProperty(PROPERTY_FONTCHARSET,      PROPERTY_ID_FONTCHARSET,     PropertyAttribute::BOUND,&m_aFont.CharSet, cppu::UnoType<sal_Int16>::get());
     207           0 :     registerProperty(PROPERTY_FONTPITCH,        PROPERTY_ID_FONTPITCH,       PropertyAttribute::BOUND,&m_aFont.Pitch, cppu::UnoType<sal_Int16>::get());
     208           0 :     registerProperty(PROPERTY_FONTCHARWIDTH,    PROPERTY_ID_FONTCHARWIDTH,   PropertyAttribute::BOUND,&m_aFont.CharacterWidth, cppu::UnoType<float>::get());
     209           0 :     registerProperty(PROPERTY_FONTWEIGHT,       PROPERTY_ID_FONTWEIGHT,      PropertyAttribute::BOUND,&m_aFont.Weight, cppu::UnoType<float>::get());
     210           0 :     registerProperty(PROPERTY_FONTSLANT,        PROPERTY_ID_FONTSLANT,       PropertyAttribute::BOUND,&m_aFont.Slant, cppu::UnoType<css::awt::FontSlant>::get());
     211           0 :     registerProperty(PROPERTY_FONTUNDERLINE,    PROPERTY_ID_FONTUNDERLINE,   PropertyAttribute::BOUND,&m_aFont.Underline, cppu::UnoType<sal_Int16>::get());
     212           0 :     registerProperty(PROPERTY_FONTSTRIKEOUT,    PROPERTY_ID_FONTSTRIKEOUT,   PropertyAttribute::BOUND,&m_aFont.Strikeout, cppu::UnoType<sal_Int16>::get());
     213           0 :     registerProperty(PROPERTY_FONTORIENTATION,  PROPERTY_ID_FONTORIENTATION, PropertyAttribute::BOUND,&m_aFont.Orientation, cppu::UnoType<float>::get());
     214           0 :     registerProperty(PROPERTY_FONTKERNING,      PROPERTY_ID_FONTKERNING,     PropertyAttribute::BOUND,&m_aFont.Kerning, cppu::UnoType<sal_Bool>::get());
     215           0 :     registerProperty(PROPERTY_FONTWORDLINEMODE, PROPERTY_ID_FONTWORDLINEMODE,PropertyAttribute::BOUND,&m_aFont.WordLineMode, cppu::UnoType<sal_Bool>::get());
     216           0 :     registerProperty(PROPERTY_FONTTYPE,         PROPERTY_ID_FONTTYPE,        PropertyAttribute::BOUND,&m_aFont.Type, cppu::UnoType<sal_Int16>::get());
     217             : 
     218           0 :     refreshColumns();
     219           0 : }
     220             : 
     221           0 : ::cppu::IPropertyArrayHelper* ODBTable::createArrayHelper( sal_Int32 _nId) const
     222             : {
     223           0 :     Sequence< Property > aProps;
     224           0 :     describeProperties(aProps);
     225           0 :     if(!_nId)
     226             :     {
     227           0 :         Property* pIter = aProps.getArray();
     228           0 :         Property* pEnd  = pIter + aProps.getLength();
     229           0 :         for(;pIter != pEnd;++pIter)
     230             :         {
     231           0 :             if (pIter->Name == PROPERTY_CATALOGNAME)
     232           0 :                 pIter->Attributes = PropertyAttribute::READONLY;
     233           0 :             else if (pIter->Name == PROPERTY_SCHEMANAME)
     234           0 :                 pIter->Attributes = PropertyAttribute::READONLY;
     235           0 :             else if (pIter->Name == PROPERTY_DESCRIPTION)
     236           0 :                 pIter->Attributes = PropertyAttribute::READONLY;
     237           0 :             else if (pIter->Name == PROPERTY_NAME)
     238           0 :                 pIter->Attributes = PropertyAttribute::READONLY;
     239             :         }
     240             :     }
     241             : 
     242           0 :     return new ::cppu::OPropertyArrayHelper(aProps);
     243             : }
     244             : 
     245           0 : ::cppu::IPropertyArrayHelper & SAL_CALL ODBTable::getInfoHelper()
     246             : {
     247           0 :     return *ODBTable_PROP::getArrayHelper(isNew() ? 1 : 0);
     248             : }
     249             : 
     250             : // XServiceInfo
     251           0 : IMPLEMENT_SERVICE_INFO1(ODBTable, "com.sun.star.sdb.dbaccess.ODBTable", SERVICE_SDBCX_TABLE)
     252             : 
     253           0 : Any SAL_CALL ODBTable::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
     254             : {
     255           0 :     if(rType == cppu::UnoType<XRename>::get()&& !getRenameService().is() )
     256           0 :         return Any();
     257           0 :     if(rType == cppu::UnoType<XAlterTable>::get()&& !getAlterService().is() )
     258           0 :         return Any();
     259           0 :     return OTable_Base::queryInterface( rType);
     260             : }
     261             : 
     262           0 : Sequence< Type > SAL_CALL ODBTable::getTypes(  ) throw(RuntimeException, std::exception)
     263             : {
     264           0 :     Type aRenameType = cppu::UnoType<XRename>::get();
     265           0 :     Type aAlterType = cppu::UnoType<XAlterTable>::get();
     266             : 
     267           0 :     Sequence< Type > aTypes(OTable_Base::getTypes());
     268           0 :     ::std::vector<Type> aOwnTypes;
     269           0 :     aOwnTypes.reserve(aTypes.getLength());
     270             : 
     271           0 :     const Type* pIter = aTypes.getConstArray();
     272           0 :     const Type* pEnd = pIter + aTypes.getLength();
     273           0 :     for(;pIter != pEnd ;++pIter)
     274             :     {
     275           0 :         if( (*pIter != aRenameType || getRenameService().is()) && (*pIter != aAlterType || getAlterService().is()))
     276           0 :             aOwnTypes.push_back(*pIter);
     277             :     }
     278             : 
     279           0 :     return Sequence< Type >(aOwnTypes.data(), aOwnTypes.size());
     280             : }
     281             : 
     282             : // XRename,
     283           0 : void SAL_CALL ODBTable::rename( const OUString& _rNewName ) throw(SQLException, ElementExistException, RuntimeException, std::exception)
     284             : {
     285           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     286           0 :     checkDisposed(connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed);
     287           0 :     if ( !getRenameService().is() )
     288           0 :         throw SQLException(DBACORE_RESSTRING(RID_STR_NO_TABLE_RENAME),*this,SQLSTATE_GENERAL,1000,Any() );
     289             : 
     290           0 :     Reference<XPropertySet> xTable(this);
     291           0 :     getRenameService()->rename(xTable,_rNewName);
     292           0 :     ::connectivity::OTable_TYPEDEF::rename(_rNewName);
     293           0 : }
     294             : 
     295             : // XAlterTable,
     296           0 : void SAL_CALL ODBTable::alterColumnByName( const OUString& _rName, const Reference< XPropertySet >& _rxDescriptor ) throw(SQLException, NoSuchElementException, RuntimeException, std::exception)
     297             : {
     298           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     299           0 :     checkDisposed(connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed);
     300           0 :     if ( !getAlterService().is() )
     301           0 :         throw SQLException(DBACORE_RESSTRING(RID_STR_NO_TABLE_RENAME),*this,SQLSTATE_GENERAL,1000,Any() );
     302             : 
     303           0 :     if ( !m_pColumns->hasByName(_rName) )
     304           0 :         throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_NOT_VALID),*this,SQLSTATE_GENERAL,1000,Any() );
     305             : 
     306           0 :     Reference<XPropertySet> xTable(this);
     307           0 :     getAlterService()->alterColumnByName(xTable,_rName,_rxDescriptor);
     308           0 :     m_pColumns->refresh();
     309           0 : }
     310             : 
     311           0 : sal_Int64 SAL_CALL ODBTable::getSomething( const Sequence< sal_Int8 >& rId ) throw(RuntimeException, std::exception)
     312             : {
     313           0 :     sal_Int64 nRet(0);
     314           0 :     if (rId.getLength() == 16 && 0 == memcmp(getUnoTunnelImplementationId().getConstArray(),  rId.getConstArray(), 16 ) )
     315           0 :         nRet = reinterpret_cast<sal_Int64>(this);
     316             :     else
     317           0 :         nRet = OTable_Base::getSomething(rId);
     318             : 
     319           0 :     return nRet;
     320             : }
     321             : 
     322           0 : Sequence< sal_Int8 > ODBTable::getUnoTunnelImplementationId()
     323             : {
     324             :     static ::cppu::OImplementationId * pId = 0;
     325           0 :     if (! pId)
     326             :     {
     327           0 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     328           0 :         if (! pId)
     329             :         {
     330           0 :             static ::cppu::OImplementationId aId;
     331           0 :             pId = &aId;
     332           0 :         }
     333             :     }
     334           0 :     return pId->getImplementationId();
     335             : }
     336             : 
     337           0 : Reference< XPropertySet > ODBTable::createColumnDescriptor()
     338             : {
     339           0 :     return new OTableColumnDescriptor( true );
     340             : }
     341             : 
     342           0 : sdbcx::OCollection* ODBTable::createColumns(const TStringVector& _rNames)
     343             : {
     344           0 :     Reference<XDatabaseMetaData> xMeta = getMetaData();
     345           0 :     OColumns* pCol = new OColumns(*this, m_aMutex, NULL, isCaseSensitive(), _rNames, this,this,
     346           0 :                                     getAlterService().is() || (xMeta.is() && xMeta->supportsAlterTableWithAddColumn()),
     347           0 :                                     getAlterService().is() || (xMeta.is() && xMeta->supportsAlterTableWithDropColumn()));
     348           0 :     static_cast<OColumnsHelper*>(pCol)->setParent(this);
     349           0 :     pCol->setParent(*this);
     350           0 :     m_pColumnMediator = new OContainerMediator( pCol, m_xColumnDefinitions, getConnection() );
     351           0 :     pCol->setMediator( m_pColumnMediator.get() );
     352           0 :     return pCol;
     353             : }
     354             : 
     355           0 : sdbcx::OCollection* ODBTable::createKeys(const TStringVector& _rNames)
     356             : {
     357           0 :     return new connectivity::OKeysHelper(this,m_aMutex,_rNames);
     358             : }
     359             : 
     360           0 : sdbcx::OCollection* ODBTable::createIndexes(const TStringVector& _rNames)
     361             : {
     362           0 :     return new OIndexes(this,m_aMutex,_rNames,NULL);
     363             : }
     364             : 
     365             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11