LCOV - code coverage report
Current view: top level - libreoffice/connectivity/source/sdbcx - VTable.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 33 136 24.3 %
Date: 2012-12-27 Functions: 6 29 20.7 %
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             : 
      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           2 : 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           2 :                 ,m_pTables(_pTables)
      98             : {
      99           2 :     m_Name = _Name;
     100           2 : }
     101             : // -------------------------------------------------------------------------
     102           0 : OTable::~OTable()
     103             : {
     104           0 :     delete m_pKeys;
     105           0 :     delete m_pColumns;
     106           0 :     delete m_pIndexes;
     107           0 : }
     108             : // -------------------------------------------------------------------------
     109           2 : void OTable::construct()
     110             : {
     111           2 :     ODescriptor::construct();
     112             : 
     113           2 :     sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
     114             : 
     115           2 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME),     PROPERTY_ID_CATALOGNAME,nAttrib,&m_CatalogName, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
     116           2 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME),      PROPERTY_ID_SCHEMANAME, nAttrib,&m_SchemaName,  ::getCppuType(static_cast< ::rtl::OUString*>(0)));
     117           2 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION),     PROPERTY_ID_DESCRIPTION,nAttrib,&m_Description, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
     118           2 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),            PROPERTY_ID_TYPE,       nAttrib,&m_Type,        ::getCppuType(static_cast< ::rtl::OUString*>(0)));
     119           2 : }
     120             : // -----------------------------------------------------------------------------
     121          40 : void SAL_CALL OTable::acquire() throw()
     122             : {
     123          40 :     OTableDescriptor_BASE::acquire();
     124          40 : }
     125             : // -----------------------------------------------------------------------------
     126          30 : void SAL_CALL OTable::release() throw()
     127             : {
     128          30 :     OTableDescriptor_BASE::release();
     129          30 : }
     130             : 
     131             : // -------------------------------------------------------------------------
     132           2 : Any SAL_CALL OTable::queryInterface( const Type & rType ) throw(RuntimeException)
     133             : {
     134           2 :     Any aRet = ODescriptor::queryInterface( rType);
     135           2 :     if(!aRet.hasValue())
     136             :     {
     137           2 :         if(!isNew())
     138           2 :             aRet = OTable_BASE::queryInterface( rType);
     139           2 :         if(isNew() && (rType == getCppuType( (Reference<XIndexesSupplier>*)0)))
     140           0 :             return Any();
     141           2 :         if(!aRet.hasValue())
     142           2 :             aRet = OTableDescriptor_BASE::queryInterface( rType);
     143             :     }
     144           2 :     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           0 : void SAL_CALL OTable::disposing(void)
     155             : {
     156           0 :     ODescriptor::disposing();
     157             : 
     158           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     159             : 
     160           0 :     if(m_pKeys)
     161           0 :         m_pKeys->disposing();
     162           0 :     if(m_pColumns)
     163           0 :         m_pColumns->disposing();
     164           0 :     if(m_pIndexes)
     165           0 :         m_pIndexes->disposing();
     166             : 
     167           0 :     m_pTables = NULL;
     168           0 : }
     169             : // -----------------------------------------------------------------------------
     170             : // XColumnsSupplier
     171           7 : Reference< XNameAccess > SAL_CALL OTable::getColumns(  ) throw(RuntimeException)
     172             : {
     173           7 :     ::osl::MutexGuard aGuard(m_aMutex);
     174           7 :     checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     175             : 
     176             :     try
     177             :     {
     178           7 :         if ( !m_pColumns )
     179           2 :             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           7 :     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           0 : cppu::IPropertyArrayHelper* OTable::createArrayHelper( sal_Int32 /*_nId*/ ) const
     223             : {
     224           0 :     return doCreateArrayHelper();
     225             : }
     226             : // -------------------------------------------------------------------------
     227           0 : cppu::IPropertyArrayHelper & OTable::getInfoHelper()
     228             : {
     229           0 :     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           0 : Reference< XNameAccess > SAL_CALL OTable::getIndexes(  ) throw(RuntimeException)
     244             : {
     245           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     246           0 :     checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
     247             : 
     248             :     try
     249             :     {
     250           0 :         if ( !m_pIndexes )
     251           0 :             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           0 :     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           0 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OTable::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
     299             : {
     300           0 :     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