LCOV - code coverage report
Current view: top level - connectivity/source/sdbcx - VTable.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 60 136 44.1 %
Date: 2012-08-25 Functions: 12 29 41.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 51 205 24.9 %

           Branch data     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 "connectivity/sdbcx/VTable.hxx"
      21                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      22                 :            : #include "connectivity/sdbcx/VIndex.hxx"
      23                 :            : #include <comphelper/sequence.hxx>
      24                 :            : #include "connectivity/sdbcx/VCollection.hxx"
      25                 :            : #include "TConnection.hxx"
      26                 :            : #include "connectivity/sdbcx/VColumn.hxx"
      27                 :            : #include "connectivity/sdbcx/VKey.hxx"
      28                 :            : #include "connectivity/dbtools.hxx"
      29                 :            : #include <connectivity/dbexception.hxx>
      30                 :            : 
      31                 :            : // -------------------------------------------------------------------------
      32                 :            : using namespace ::connectivity;
      33                 :            : using namespace ::connectivity::sdbcx;
      34                 :            : using namespace ::dbtools;
      35                 :            : using namespace ::com::sun::star::beans;
      36                 :            : using namespace ::com::sun::star::uno;
      37                 :            : using namespace ::com::sun::star::sdbc;
      38                 :            : using namespace ::com::sun::star::sdbcx;
      39                 :            : using namespace ::com::sun::star::container;
      40                 :            : using namespace ::com::sun::star::lang;
      41                 :            : 
      42                 :            : // -----------------------------------------------------------------------------
      43                 :          0 : ::rtl::OUString SAL_CALL OTable::getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException)
      44                 :            : {
      45         [ #  # ]:          0 :     if(isNew())
      46                 :          0 :         return ::rtl::OUString("com.sun.star.sdbcx.VTableDescriptor");
      47                 :          0 :     return ::rtl::OUString("com.sun.star.sdbcx.Table");
      48                 :            : }
      49                 :            : 
      50                 :            : // -----------------------------------------------------------------------------
      51                 :          0 : ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OTable::getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException)
      52                 :            : {
      53                 :          0 :     ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1);
      54         [ #  # ]:          0 :     if(isNew())
      55         [ #  # ]:          0 :         aSupported[0] = ::rtl::OUString("com.sun.star.sdbcx.TableDescriptor");
      56                 :            :     else
      57         [ #  # ]:          0 :         aSupported[0] = ::rtl::OUString("com.sun.star.sdbcx.Table");
      58                 :            : 
      59                 :          0 :     return aSupported;
      60                 :            : }
      61                 :            : // -----------------------------------------------------------------------------
      62                 :          0 : sal_Bool SAL_CALL OTable::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException)
      63                 :            : {
      64         [ #  # ]:          0 :     Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
      65                 :          0 :     const ::rtl::OUString* pSupported = aSupported.getConstArray();
      66                 :          0 :     const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
      67 [ #  # ][ #  # ]:          0 :     for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
                 [ #  # ]
      68                 :            :         ;
      69                 :            : 
      70         [ #  # ]:          0 :     return pSupported != pEnd;
      71                 :            : }
      72                 :            : // -------------------------------------------------------------------------
      73                 :          0 : OTable::OTable(OCollection* _pTables,
      74                 :            :                sal_Bool _bCase)
      75                 :            :                : OTableDescriptor_BASE(m_aMutex)
      76                 :            :                 ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase,sal_True)
      77                 :            :                 ,m_pKeys(NULL)
      78                 :            :                 ,m_pColumns(NULL)
      79                 :            :                 ,m_pIndexes(NULL)
      80 [ #  # ][ #  # ]:          0 :                 ,m_pTables(_pTables)
      81                 :            : {
      82                 :          0 : }
      83                 :            : // -----------------------------------------------------------------------------
      84                 :         28 : OTable::OTable( OCollection*    _pTables,
      85                 :            :                 sal_Bool _bCase,
      86                 :            :                 const ::rtl::OUString& _Name,       const ::rtl::OUString& _Type,
      87                 :            :                 const ::rtl::OUString& _Description,const ::rtl::OUString& _SchemaName,
      88                 :            :                 const ::rtl::OUString& _CatalogName) :  OTableDescriptor_BASE(m_aMutex)
      89                 :            :                 ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase)
      90                 :            :                 ,m_CatalogName(_CatalogName)
      91                 :            :                 ,m_SchemaName(_SchemaName)
      92                 :            :                 ,m_Description(_Description)
      93                 :            :                 ,m_Type(_Type)
      94                 :            :                 ,m_pKeys(NULL)
      95                 :            :                 ,m_pColumns(NULL)
      96                 :            :                 ,m_pIndexes(NULL)
      97 [ +  - ][ +  - ]:         28 :                 ,m_pTables(_pTables)
      98                 :            : {
      99                 :         28 :     m_Name = _Name;
     100                 :         28 : }
     101                 :            : // -------------------------------------------------------------------------
     102 [ +  - ][ +  - ]:         28 : OTable::~OTable()
                 [ +  - ]
     103                 :            : {
     104 [ -  + ][ #  # ]:         28 :     delete m_pKeys;
     105 [ +  - ][ +  - ]:         28 :     delete m_pColumns;
     106 [ +  - ][ +  - ]:         28 :     delete m_pIndexes;
     107         [ -  + ]:         28 : }
     108                 :            : // -------------------------------------------------------------------------
     109                 :         28 : void OTable::construct()
     110                 :            : {
     111                 :         28 :     ODescriptor::construct();
     112                 :            : 
     113         [ -  + ]:         28 :     sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
     114                 :            : 
     115         [ +  - ]:         28 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME),     PROPERTY_ID_CATALOGNAME,nAttrib,&m_CatalogName, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
     116         [ +  - ]:         28 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME),      PROPERTY_ID_SCHEMANAME, nAttrib,&m_SchemaName,  ::getCppuType(static_cast< ::rtl::OUString*>(0)));
     117         [ +  - ]:         28 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION),     PROPERTY_ID_DESCRIPTION,nAttrib,&m_Description, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
     118         [ +  - ]:         28 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),            PROPERTY_ID_TYPE,       nAttrib,&m_Type,        ::getCppuType(static_cast< ::rtl::OUString*>(0)));
     119                 :         28 : }
     120                 :            : // -----------------------------------------------------------------------------
     121                 :      21704 : void SAL_CALL OTable::acquire() throw()
     122                 :            : {
     123                 :      21704 :     OTableDescriptor_BASE::acquire();
     124                 :      21704 : }
     125                 :            : // -----------------------------------------------------------------------------
     126                 :      21704 : void SAL_CALL OTable::release() throw()
     127                 :            : {
     128                 :      21704 :     OTableDescriptor_BASE::release();
     129                 :      21704 : }
     130                 :            : 
     131                 :            : // -------------------------------------------------------------------------
     132                 :       5248 : Any SAL_CALL OTable::queryInterface( const Type & rType ) throw(RuntimeException)
     133                 :            : {
     134         [ +  - ]:       5248 :     Any aRet = ODescriptor::queryInterface( rType);
     135         [ +  + ]:       5248 :     if(!aRet.hasValue())
     136                 :            :     {
     137         [ +  - ]:       1082 :         if(!isNew())
     138         [ +  - ]:       1082 :             aRet = OTable_BASE::queryInterface( rType);
     139 [ -  + ][ #  # ]:       1082 :         if(isNew() && (rType == getCppuType( (Reference<XIndexesSupplier>*)0)))
         [ #  # ][ -  + ]
     140                 :          0 :             return Any();
     141         [ +  + ]:       1082 :         if(!aRet.hasValue())
     142         [ +  - ]:        974 :             aRet = OTableDescriptor_BASE::queryInterface( rType);
     143                 :            :     }
     144                 :       5248 :     return aRet;
     145                 :            : }
     146                 :            : // -------------------------------------------------------------------------
     147                 :          0 : Sequence< Type > SAL_CALL OTable::getTypes(  ) throw(RuntimeException)
     148                 :            : {
     149         [ #  # ]:          0 :     if(isNew())
     150 [ #  # ][ #  # ]:          0 :         return ::comphelper::concatSequences(ODescriptor::getTypes(),OTableDescriptor_BASE::getTypes());
                 [ #  # ]
     151 [ #  # ][ #  # ]:          0 :     return ::comphelper::concatSequences(ODescriptor::getTypes(),OTableDescriptor_BASE::getTypes(),OTable_BASE::getTypes());
         [ #  # ][ #  # ]
                 [ #  # ]
     152                 :            : }
     153                 :            : // -------------------------------------------------------------------------
     154                 :         28 : void SAL_CALL OTable::disposing(void)
     155                 :            : {
     156         [ +  - ]:         28 :     ODescriptor::disposing();
     157                 :            : 
     158         [ +  - ]:         28 :     ::osl::MutexGuard aGuard(m_aMutex);
     159                 :            : 
     160         [ -  + ]:         28 :     if(m_pKeys)
     161         [ #  # ]:          0 :         m_pKeys->disposing();
     162         [ +  - ]:         28 :     if(m_pColumns)
     163         [ +  - ]:         28 :         m_pColumns->disposing();
     164         [ +  - ]:         28 :     if(m_pIndexes)
     165         [ +  - ]:         28 :         m_pIndexes->disposing();
     166                 :            : 
     167         [ +  - ]:         28 :     m_pTables = NULL;
     168                 :         28 : }
     169                 :            : // -----------------------------------------------------------------------------
     170                 :            : // XColumnsSupplier
     171                 :        710 : Reference< XNameAccess > SAL_CALL OTable::getColumns(  ) throw(RuntimeException)
     172                 :            : {
     173         [ +  - ]:        710 :     ::osl::MutexGuard aGuard(m_aMutex);
     174         [ +  - ]:        710 :     checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     175                 :            : 
     176                 :            :     try
     177                 :            :     {
     178         [ +  + ]:        710 :         if ( !m_pColumns )
     179         [ +  - ]:         28 :             refreshColumns();
     180                 :            :     }
     181      [ #  #  # ]:          0 :     catch( const RuntimeException& )
     182                 :            :     {
     183                 :            :         // allowed to leave this method
     184                 :          0 :         throw;
     185                 :            :     }
     186         [ #  # ]:          0 :     catch( const Exception& )
     187                 :            :     {
     188                 :            :         // allowed
     189                 :            :     }
     190                 :            : 
     191 [ +  - ][ +  - ]:        710 :     return m_pColumns;
                 [ +  - ]
     192                 :            : }
     193                 :            : 
     194                 :            : // -------------------------------------------------------------------------
     195                 :            : // XKeysSupplier
     196                 :          0 : Reference< XIndexAccess > SAL_CALL OTable::getKeys(  ) throw(RuntimeException)
     197                 :            : {
     198         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_aMutex);
     199         [ #  # ]:          0 :     checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     200                 :            : 
     201                 :          0 :     Reference< XIndexAccess > xKeys;
     202                 :            : 
     203                 :            :     try
     204                 :            :     {
     205         [ #  # ]:          0 :         if ( !m_pKeys )
     206         [ #  # ]:          0 :             refreshKeys();
     207 [ #  # ][ #  # ]:          0 :         xKeys = m_pKeys;
     208                 :            :     }
     209      [ #  #  # ]:          0 :     catch( const RuntimeException& )
     210                 :            :     {
     211                 :            :         // allowed to leave this method
     212                 :          0 :         throw;
     213                 :            :     }
     214         [ #  # ]:          0 :     catch( const Exception& )
     215                 :            :     {
     216                 :            :         // allowed
     217                 :            :     }
     218                 :            : 
     219         [ #  # ]:          0 :     return xKeys;
     220                 :            : }
     221                 :            : // -----------------------------------------------------------------------------
     222                 :         28 : cppu::IPropertyArrayHelper* OTable::createArrayHelper( sal_Int32 /*_nId*/ ) const
     223                 :            : {
     224                 :         28 :     return doCreateArrayHelper();
     225                 :            : }
     226                 :            : // -------------------------------------------------------------------------
     227                 :       4014 : cppu::IPropertyArrayHelper & OTable::getInfoHelper()
     228                 :            : {
     229         [ -  + ]:       4014 :     return *const_cast<OTable*>(this)->getArrayHelper(isNew() ? 1 : 0);
     230                 :            : }
     231                 :            : // -------------------------------------------------------------------------
     232                 :          0 : Reference< XPropertySet > SAL_CALL OTable::createDataDescriptor(  ) throw(RuntimeException)
     233                 :            : {
     234         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_aMutex);
     235         [ #  # ]:          0 :     checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     236                 :            : 
     237         [ #  # ]:          0 :     OTable* pTable = new OTable(m_pTables,isCaseSensitive(),m_Name,m_Type,m_Description,m_SchemaName,m_CatalogName);
     238         [ #  # ]:          0 :     pTable->setNew(sal_True);
     239 [ #  # ][ #  # ]:          0 :     return pTable;
                 [ #  # ]
     240                 :            : }
     241                 :            : // -------------------------------------------------------------------------
     242                 :            : // XIndexesSupplier
     243                 :         90 : Reference< XNameAccess > SAL_CALL OTable::getIndexes(  ) throw(RuntimeException)
     244                 :            : {
     245         [ +  - ]:         90 :     ::osl::MutexGuard aGuard(m_aMutex);
     246         [ +  - ]:         90 :     checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     247                 :            : 
     248                 :            :     try
     249                 :            :     {
     250         [ +  + ]:         90 :         if ( !m_pIndexes )
     251         [ +  - ]:         28 :             refreshIndexes();
     252                 :            :     }
     253      [ #  #  # ]:          0 :     catch( const RuntimeException& )
     254                 :            :     {
     255                 :            :         // allowed to leave this method
     256                 :          0 :         throw;
     257                 :            :     }
     258         [ #  # ]:          0 :     catch( const Exception& )
     259                 :            :     {
     260                 :            :         // allowed
     261                 :            :     }
     262                 :            : 
     263 [ +  - ][ +  - ]:         90 :     return m_pIndexes;
                 [ +  - ]
     264                 :            : }
     265                 :            : // -------------------------------------------------------------------------
     266                 :            : // XRename
     267                 :          0 : void SAL_CALL OTable::rename( const ::rtl::OUString& newName ) throw(SQLException, ElementExistException, RuntimeException)
     268                 :            : {
     269         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_aMutex);
     270         [ #  # ]:          0 :     checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     271                 :            : 
     272         [ #  # ]:          0 :     const ::rtl::OUString sOldComposedName = getName();
     273         [ #  # ]:          0 :     const Reference< XDatabaseMetaData> xMetaData = getMetaData();
     274         [ #  # ]:          0 :     if ( xMetaData.is() )
     275         [ #  # ]:          0 :         ::dbtools::qualifiedNameComponents(xMetaData,newName,m_CatalogName,m_SchemaName,m_Name,::dbtools::eInDataManipulation);
     276                 :            :     else
     277                 :          0 :         m_Name = newName;
     278                 :            : 
     279 [ #  # ][ #  # ]:          0 :     m_pTables->renameObject(sOldComposedName,newName);
     280                 :          0 : }
     281                 :            : // -----------------------------------------------------------------------------
     282                 :          0 : Reference< XDatabaseMetaData> OTable::getMetaData() const
     283                 :            : {
     284                 :          0 :     return NULL;
     285                 :            : }
     286                 :            : // -------------------------------------------------------------------------
     287                 :            : // XAlterTable
     288                 :          0 : void SAL_CALL OTable::alterColumnByName( const ::rtl::OUString& /*colName*/, const Reference< XPropertySet >& /*descriptor*/ ) throw(SQLException, NoSuchElementException, RuntimeException)
     289                 :            : {
     290         [ #  # ]:          0 :     throwFeatureNotImplementedException( "XAlterTable::alterColumnByName", *this );
     291                 :          0 : }
     292                 :            : // -------------------------------------------------------------------------
     293                 :          0 : void SAL_CALL OTable::alterColumnByIndex( sal_Int32 /*index*/, const Reference< XPropertySet >& /*descriptor*/ ) throw(SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, RuntimeException)
     294                 :            : {
     295         [ #  # ]:          0 :     throwFeatureNotImplementedException( "XAlterTable::alterColumnByIndex", *this );
     296                 :          0 : }
     297                 :            : // -------------------------------------------------------------------------
     298                 :       3870 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OTable::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
     299                 :            : {
     300                 :       3870 :     return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
     301                 :            : }
     302                 :            : // -----------------------------------------------------------------------------
     303                 :          0 : ::rtl::OUString SAL_CALL OTable::getName() throw(::com::sun::star::uno::RuntimeException)
     304                 :            : {
     305                 :            :     // this is only correct for tables who haven't a schema or catalog name
     306                 :            :     OSL_ENSURE(m_CatalogName.isEmpty(),"getName(): forgot to overload getName()!");
     307                 :            :     OSL_ENSURE(m_SchemaName.isEmpty(),"getName(): forgot to overload getName()!");
     308                 :          0 :     return m_Name;
     309                 :            : }
     310                 :            : // -----------------------------------------------------------------------------
     311                 :          0 : void SAL_CALL OTable::setName( const ::rtl::OUString& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException)
     312                 :            : {
     313                 :          0 : }
     314                 :            : // -----------------------------------------------------------------------------
     315                 :          0 : void OTable::refreshColumns()
     316                 :            : {
     317                 :          0 : }
     318                 :            : // -----------------------------------------------------------------------------
     319                 :          0 : void OTable::refreshKeys()
     320                 :            : {
     321                 :          0 : }
     322                 :            : // -----------------------------------------------------------------------------
     323                 :          0 : void OTable::refreshIndexes()
     324                 :            : {
     325                 :          0 : }
     326                 :            : // -----------------------------------------------------------------------------
     327                 :            : 
     328                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10