LCOV - code coverage report
Current view: top level - connectivity/source/sdbcx - VTable.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 69 132 52.3 %
Date: 2015-06-13 12:38:46 Functions: 14 29 48.3 %
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          40 : 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          40 :                 ,m_pTables(_pTables)
      92             : {
      93          40 :     m_Name = _Name;
      94          40 : }
      95             : 
      96          86 : OTable::~OTable()
      97             : {
      98          40 :     delete m_pKeys;
      99          40 :     delete m_pColumns;
     100          40 :     delete m_pIndexes;
     101          46 : }
     102             : 
     103          34 : void OTable::construct()
     104             : {
     105          34 :     ODescriptor::construct();
     106             : 
     107          34 :     sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
     108             : 
     109          34 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME),     PROPERTY_ID_CATALOGNAME,nAttrib,&m_CatalogName, ::cppu::UnoType<OUString>::get());
     110          34 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME),      PROPERTY_ID_SCHEMANAME, nAttrib,&m_SchemaName,  ::cppu::UnoType<OUString>::get());
     111          34 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION),     PROPERTY_ID_DESCRIPTION,nAttrib,&m_Description, ::cppu::UnoType<OUString>::get());
     112          34 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),            PROPERTY_ID_TYPE,       nAttrib,&m_Type,        ::cppu::UnoType<OUString>::get());
     113          34 : }
     114             : 
     115       20105 : void SAL_CALL OTable::acquire() throw()
     116             : {
     117       20105 :     OTableDescriptor_BASE::acquire();
     118       20105 : }
     119             : 
     120       20105 : void SAL_CALL OTable::release() throw()
     121             : {
     122       20105 :     OTableDescriptor_BASE::release();
     123       20105 : }
     124             : 
     125             : 
     126        5895 : Any SAL_CALL OTable::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
     127             : {
     128        5895 :     Any aRet = ODescriptor::queryInterface( rType);
     129        5895 :     if(!aRet.hasValue())
     130             :     {
     131        1110 :         if(!isNew())
     132        1110 :             aRet = OTable_BASE::queryInterface( rType);
     133        1110 :         if(isNew() && (rType == cppu::UnoType<XIndexesSupplier>::get()))
     134           0 :             return Any();
     135        1110 :         if(!aRet.hasValue())
     136        1015 :             aRet = OTableDescriptor_BASE::queryInterface( rType);
     137             :     }
     138        5895 :     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()
     149             : {
     150          40 :     ODescriptor::disposing();
     151             : 
     152          40 :     ::osl::MutexGuard aGuard(m_aMutex);
     153             : 
     154          40 :     if(m_pKeys)
     155           9 :         m_pKeys->disposing();
     156          40 :     if(m_pColumns)
     157          34 :         m_pColumns->disposing();
     158          40 :     if(m_pIndexes)
     159          18 :         m_pIndexes->disposing();
     160             : 
     161          40 :     m_pTables = NULL;
     162          40 : }
     163             : 
     164             : // XColumnsSupplier
     165         568 : Reference< XNameAccess > SAL_CALL OTable::getColumns(  ) throw(RuntimeException, std::exception)
     166             : {
     167         568 :     ::osl::MutexGuard aGuard(m_aMutex);
     168         568 :     checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     169             : 
     170             :     try
     171             :     {
     172         568 :         if ( !m_pColumns )
     173          26 :             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         568 :     return m_pColumns;
     186             : }
     187             : 
     188             : 
     189             : // XKeysSupplier
     190          82 : Reference< XIndexAccess > SAL_CALL OTable::getKeys(  ) throw(RuntimeException, std::exception)
     191             : {
     192          82 :     ::osl::MutexGuard aGuard(m_aMutex);
     193          82 :     checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     194             : 
     195          82 :     Reference< XIndexAccess > xKeys;
     196             : 
     197             :     try
     198             :     {
     199          82 :         if ( !m_pKeys )
     200           9 :             refreshKeys();
     201          82 :         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          82 :     return xKeys;
     214             : }
     215             : 
     216          23 : cppu::IPropertyArrayHelper* OTable::createArrayHelper( sal_Int32 /*_nId*/ ) const
     217             : {
     218          23 :     return doCreateArrayHelper();
     219             : }
     220             : 
     221        3282 : cppu::IPropertyArrayHelper & OTable::getInfoHelper()
     222             : {
     223        3282 :     return *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          64 : Reference< XNameAccess > SAL_CALL OTable::getIndexes(  ) throw(RuntimeException, std::exception)
     238             : {
     239          64 :     ::osl::MutexGuard aGuard(m_aMutex);
     240          64 :     checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     241             : 
     242             :     try
     243             :     {
     244          64 :         if ( !m_pIndexes )
     245          18 :             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          64 :     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        4439 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OTable::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     293             : {
     294        4439 :     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 override getName()!");
     301             :     OSL_ENSURE(m_SchemaName.isEmpty(),"getName(): forgot to override 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.11