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

Generated by: LCOV version 1.10