LCOV - code coverage report
Current view: top level - dbaccess/source/core/api - column.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 94 184 51.1 %
Date: 2015-06-13 12:38:46 Functions: 23 37 62.2 %
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 "ContainerMediator.hxx"
      21             : #include "apitools.hxx"
      22             : #include "column.hxx"
      23             : #include "core_resource.hrc"
      24             : #include "core_resource.hxx"
      25             : #include "dbastrings.hrc"
      26             : #include "sdbcoretools.hxx"
      27             : 
      28             : #include <com/sun/star/lang/DisposedException.hpp>
      29             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      30             : #include <com/sun/star/sdbc/DataType.hpp>
      31             : 
      32             : #include <comphelper/enumhelper.hxx>
      33             : #include <comphelper/extract.hxx>
      34             : #include <comphelper/property.hxx>
      35             : #include <comphelper/seqstream.hxx>
      36             : #include <comphelper/sequence.hxx>
      37             : #include <comphelper/types.hxx>
      38             : #include <connectivity/TTableHelper.hxx>
      39             : #include <connectivity/dbexception.hxx>
      40             : #include <connectivity/dbtools.hxx>
      41             : #include <cppuhelper/supportsservice.hxx>
      42             : #include <cppuhelper/typeprovider.hxx>
      43             : #include <osl/diagnose.h>
      44             : #include <tools/debug.hxx>
      45             : 
      46             : #include <algorithm>
      47             : 
      48             : using namespace dbaccess;
      49             : using namespace connectivity;
      50             : using namespace ::com::sun::star::sdbc;
      51             : using namespace ::com::sun::star::sdbcx;
      52             : using namespace ::com::sun::star::beans;
      53             : using namespace ::com::sun::star::uno;
      54             : using namespace ::com::sun::star::lang;
      55             : using namespace ::com::sun::star::awt;
      56             : using namespace ::com::sun::star::io;
      57             : using namespace ::com::sun::star::container;
      58             : using namespace ::com::sun::star::util;
      59             : using namespace ::osl;
      60             : using namespace ::comphelper;
      61             : using namespace ::cppu;
      62             : 
      63             : 
      64             : // OColumn
      65        2145 : OColumn::OColumn( const bool _bNameIsReadOnly )
      66             :         :OColumnBase( m_aMutex )
      67        2145 :         ,::comphelper::OPropertyContainer( OColumnBase::rBHelper )
      68             : {
      69             : 
      70             :     registerProperty( PROPERTY_NAME, PROPERTY_ID_NAME, _bNameIsReadOnly ? PropertyAttribute::READONLY : 0,
      71        2145 :         &m_sName, cppu::UnoType<decltype(m_sName)>::get() );
      72        2145 : }
      73             : 
      74        2145 : OColumn::~OColumn()
      75             : {
      76        2145 : }
      77             : 
      78             : // com::sun::star::lang::XTypeProvider
      79           0 : Sequence< Type > OColumn::getTypes() throw (RuntimeException, std::exception)
      80             : {
      81             :     return ::comphelper::concatSequences(
      82             :         OColumnBase::getTypes(),
      83             :         getBaseTypes()
      84           0 :     );
      85             : }
      86             : 
      87             : // com::sun::star::uno::XInterface
      88      128292 : IMPLEMENT_FORWARD_XINTERFACE2( OColumn, OColumnBase, ::comphelper::OPropertyContainer )
      89             : 
      90             : // ::com::sun::star::lang::XServiceInfo
      91           0 : OUString OColumn::getImplementationName(  ) throw(RuntimeException, std::exception)
      92             : {
      93           0 :     return OUString("com.sun.star.sdb.OColumn");
      94             : }
      95             : 
      96           0 : sal_Bool OColumn::supportsService( const OUString& _rServiceName ) throw (RuntimeException, std::exception)
      97             : {
      98           0 :     return cppu::supportsService(this, _rServiceName);
      99             : }
     100             : 
     101           0 : Sequence< OUString > OColumn::getSupportedServiceNames(  ) throw (RuntimeException, std::exception)
     102             : {
     103           0 :     Sequence< OUString > aSNS( 1 );
     104           0 :     aSNS[0] = SERVICE_SDBCX_COLUMN;
     105           0 :     return aSNS;
     106             : }
     107             : 
     108             : // OComponentHelper
     109        2145 : void OColumn::disposing()
     110             : {
     111        2145 :     OPropertyContainer::disposing();
     112        2145 : }
     113             : 
     114             : // com::sun::star::beans::XPropertySet
     115        4410 : Reference< XPropertySetInfo > OColumn::getPropertySetInfo() throw (RuntimeException, std::exception)
     116             : {
     117        4410 :     return createPropertySetInfo( getInfoHelper() ) ;
     118             : }
     119             : 
     120           0 : OUString SAL_CALL OColumn::getName(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     121             : {
     122           0 :     return m_sName;
     123             : }
     124             : 
     125         665 : void SAL_CALL OColumn::setName( const OUString& _rName ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     126             : {
     127         665 :     m_sName = _rName;
     128         665 : }
     129             : 
     130           0 : void OColumn::fireValueChange(const ::connectivity::ORowSetValue& /*_rOldValue*/)
     131             : {
     132             :     OSL_FAIL( "OColumn::fireValueChange: not implemented!" );
     133           0 : }
     134             : 
     135       14174 : void OColumn::registerProperty( const OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void* _pPointerToMember, const Type& _rMemberType )
     136             : {
     137       14174 :     ::comphelper::OPropertyContainer::registerProperty( _rName, _nHandle, _nAttributes, _pPointerToMember, _rMemberType );
     138       14174 : }
     139             : 
     140       12870 : void OColumn::registerMayBeVoidProperty( const OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, Any* _pPointerToMember, const Type& _rExpectedType )
     141             : {
     142       12870 :     ::comphelper::OPropertyContainer::registerMayBeVoidProperty( _rName, _nHandle, _nAttributes, _pPointerToMember, _rExpectedType );
     143       12870 : }
     144             : 
     145           0 : void OColumn::registerPropertyNoMember( const OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, const Type& _rType, const void* _pInitialValue )
     146             : {
     147           0 :     ::comphelper::OPropertyContainer::registerPropertyNoMember( _rName, _nHandle, _nAttributes, _rType, _pInitialValue );
     148           0 : }
     149             : 
     150             : // OColumns
     151             : 
     152       13686 : OColumns::OColumns(::cppu::OWeakObject& _rParent,
     153             :                    ::osl::Mutex& _rMutex,
     154             :                    bool _bCaseSensitive,const ::std::vector< OUString> &_rVector,
     155             :                    IColumnFactory* _pColFactory,
     156             :                    ::connectivity::sdbcx::IRefreshableColumns* _pRefresh,
     157             :                    bool _bAddColumn,
     158             :                    bool _bDropColumn,
     159             :                    bool _bUseHardRef)
     160             :                    : OColumns_BASE(_rParent,_bCaseSensitive,_rMutex,_rVector,_bUseHardRef)
     161             :     ,m_pMediator(NULL)
     162             :     ,m_xDrvColumns(NULL)
     163             :     ,m_pColFactoryImpl(_pColFactory)
     164             :     ,m_pRefreshColumns(_pRefresh)
     165             :     ,m_bInitialized(false)
     166             :     ,m_bAddColumn(_bAddColumn)
     167       13686 :     ,m_bDropColumn(_bDropColumn)
     168             : {
     169       13686 : }
     170             : 
     171          32 : OColumns::OColumns(::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex,
     172             :         const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxDrvColumns,
     173             :         bool _bCaseSensitive,const ::std::vector< OUString> &_rVector,
     174             :         IColumnFactory* _pColFactory,
     175             :         ::connectivity::sdbcx::IRefreshableColumns* _pRefresh,
     176             :         bool _bAddColumn,
     177             :         bool _bDropColumn,
     178             :         bool _bUseHardRef)
     179             :        : OColumns_BASE(_rParent,_bCaseSensitive,_rMutex,_rVector,_bUseHardRef)
     180             :     ,m_pMediator(NULL)
     181             :     ,m_xDrvColumns(_rxDrvColumns)
     182             :     ,m_pColFactoryImpl(_pColFactory)
     183             :     ,m_pRefreshColumns(_pRefresh)
     184             :     ,m_bInitialized(false)
     185             :     ,m_bAddColumn(_bAddColumn)
     186          32 :     ,m_bDropColumn(_bDropColumn)
     187             : {
     188          32 : }
     189             : 
     190       27436 : OColumns::~OColumns()
     191             : {
     192       27436 : }
     193             : 
     194             : // XServiceInfo
     195           0 : OUString OColumns::getImplementationName(  ) throw(RuntimeException, std::exception)
     196             : {
     197           0 :     return OUString("com.sun.star.sdb.OColumns");
     198             : }
     199             : 
     200           0 : sal_Bool OColumns::supportsService( const OUString& _rServiceName ) throw (RuntimeException, std::exception)
     201             : {
     202           0 :     return cppu::supportsService(this, _rServiceName);
     203             : }
     204             : 
     205           0 : Sequence< OUString > OColumns::getSupportedServiceNames(  ) throw (RuntimeException, std::exception)
     206             : {
     207           0 :     Sequence< OUString > aSNS( 1 );
     208           0 :     aSNS[0] = SERVICE_SDBCX_CONTAINER;
     209           0 :     return aSNS;
     210             : }
     211             : 
     212           3 : void OColumns::append( const OUString& _rName, OColumn* _pColumn )
     213             : {
     214           3 :     MutexGuard aGuard(m_rMutex);
     215             : 
     216             :     OSL_ENSURE( _pColumn, "OColumns::append: invalid column!" );
     217             :     OSL_ENSURE( !m_pElements->exists( _rName ),"OColumns::append: Column already exists");
     218             : 
     219           3 :     _pColumn->m_sName = _rName;
     220             : 
     221             :     // now really insert the column
     222           3 :     insertElement( _rName, _pColumn );
     223           3 : }
     224             : 
     225           1 : void OColumns::clearColumns()
     226             : {
     227           1 :     MutexGuard aGuard(m_rMutex);
     228           1 :     disposing();
     229           1 : }
     230             : 
     231       27352 : void SAL_CALL OColumns::disposing()
     232             : {
     233       27352 :     MutexGuard aGuard(m_rMutex);
     234       27352 :     m_xDrvColumns = NULL;
     235       27352 :     m_pMediator = NULL;
     236       27352 :     m_pColFactoryImpl = NULL;
     237       27352 :     OColumns_BASE::disposing();
     238       27352 : }
     239             : 
     240           0 : void OColumns::impl_refresh() throw(::com::sun::star::uno::RuntimeException)
     241             : {
     242           0 :     if (m_pRefreshColumns)
     243           0 :         m_pRefreshColumns->refreshColumns();
     244           0 : }
     245             : 
     246         838 : connectivity::sdbcx::ObjectType OColumns::createObject(const OUString& _rName)
     247             : {
     248             :     OSL_ENSURE(m_pColFactoryImpl, "OColumns::createObject: no column factory!");
     249             : 
     250         838 :     connectivity::sdbcx::ObjectType xRet;
     251         838 :     if ( m_pColFactoryImpl )
     252             :     {
     253         838 :         xRet = m_pColFactoryImpl->createColumn(_rName);
     254         838 :         Reference<XChild> xChild(xRet,UNO_QUERY);
     255         838 :         if ( xChild.is() )
     256           0 :             xChild->setParent(static_cast<XChild*>(static_cast<TXChild*>(this)));
     257             :     }
     258             : 
     259        1676 :     Reference<XPropertySet> xDest(xRet,UNO_QUERY);
     260         838 :     if ( m_pMediator && xDest.is() )
     261         373 :         m_pMediator->notifyElementCreated(_rName,xDest);
     262             : 
     263        1676 :     return xRet;
     264             : }
     265             : 
     266         426 : Reference< XPropertySet > OColumns::createDescriptor()
     267             : {
     268         426 :     if ( m_pColFactoryImpl )
     269             :     {
     270         426 :         Reference<XPropertySet> xRet = m_pColFactoryImpl->createColumnDescriptor();
     271         852 :         Reference<XChild> xChild(xRet,UNO_QUERY);
     272         426 :         if ( xChild.is() )
     273         426 :             xChild->setParent(static_cast<XChild*>(static_cast<TXChild*>(this)));
     274         852 :         return xRet;
     275             :     }
     276             :     else
     277           0 :         return Reference< XPropertySet >();
     278             : }
     279             : 
     280        1298 : Any SAL_CALL OColumns::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
     281             : {
     282        1298 :     Any aRet;
     283        1298 :     if(m_xDrvColumns.is())
     284             :     {
     285         380 :         aRet = m_xDrvColumns->queryInterface(rType);
     286         380 :         if ( aRet.hasValue() )
     287         380 :             aRet = OColumns_BASE::queryInterface( rType);
     288         380 :         if ( !aRet.hasValue() )
     289           0 :             aRet = TXChild::queryInterface( rType);
     290         380 :         return aRet;
     291             :     }
     292         918 :     else if(!m_pTable || (m_pTable && !m_pTable->isNew()))
     293             :     {
     294         918 :         if(!m_bAddColumn    && rType == cppu::UnoType<XAppend>::get())
     295           0 :             return Any();
     296         918 :         if(!m_bDropColumn   && rType == cppu::UnoType<XDrop>::get())
     297           0 :             return Any();
     298             :     }
     299             : 
     300         918 :     aRet = OColumns_BASE::queryInterface( rType);
     301         918 :     if ( !aRet.hasValue() )
     302         426 :         aRet = TXChild::queryInterface( rType);
     303         918 :     return aRet;
     304             : }
     305             : 
     306           0 : Sequence< Type > SAL_CALL OColumns::getTypes(  ) throw(RuntimeException, std::exception)
     307             : {
     308           0 :     bool bAppendFound = false,bDropFound = false;
     309             : 
     310           0 :     sal_Int32 nSize = 0;
     311           0 :     Type aAppendType = cppu::UnoType<XAppend>::get();
     312           0 :     Type aDropType   = cppu::UnoType<XDrop>::get();
     313           0 :     if(m_xDrvColumns.is())
     314             :     {
     315           0 :         Reference<XTypeProvider> xTypes(m_xDrvColumns,UNO_QUERY);
     316           0 :         Sequence< Type > aTypes(xTypes->getTypes());
     317             : 
     318           0 :         const Type* pBegin = aTypes.getConstArray();
     319           0 :         const Type* pEnd = pBegin + aTypes.getLength();
     320           0 :         for (;pBegin != pEnd ; ++pBegin)
     321             :         {
     322           0 :             if(aAppendType == *pBegin)
     323           0 :                 bAppendFound = true;
     324           0 :             else if(aDropType == *pBegin)
     325           0 :                 bDropFound = true;
     326             :         }
     327           0 :         nSize = (bDropFound ? (bAppendFound ? 0 : 1) : (bAppendFound ? 1 : 2));
     328             :     }
     329             :     else
     330             :     {
     331           0 :         nSize = ((m_pTable && m_pTable->isNew()) ? 0 :
     332             :                     ((m_bDropColumn ?
     333           0 :                         (m_bAddColumn ? 0 : 1) : (m_bAddColumn ? 1 : 2))));
     334           0 :         bDropFound      = (m_pTable && m_pTable->isNew()) || m_bDropColumn;
     335           0 :         bAppendFound    = (m_pTable && m_pTable->isNew()) || m_bAddColumn;
     336             :     }
     337           0 :     Sequence< Type > aTypes(::comphelper::concatSequences(OColumns_BASE::getTypes(),TXChild::getTypes()));
     338           0 :     Sequence< Type > aRet(aTypes.getLength() - nSize);
     339             : 
     340           0 :     const Type* pBegin = aTypes.getConstArray();
     341           0 :     const Type* pEnd = pBegin + aTypes.getLength();
     342           0 :     for(sal_Int32 i=0;pBegin != pEnd ;++pBegin)
     343             :     {
     344           0 :         if(*pBegin != aAppendType && *pBegin != aDropType)
     345           0 :             aRet.getArray()[i++] = *pBegin;
     346           0 :         else if(bDropFound && *pBegin == aDropType)
     347           0 :             aRet.getArray()[i++] = *pBegin;
     348           0 :         else if(bAppendFound && *pBegin == aAppendType)
     349           0 :             aRet.getArray()[i++] = *pBegin;
     350             :     }
     351           0 :     return aRet;
     352             : }
     353             : 
     354             : // XAppend
     355         213 : sdbcx::ObjectType OColumns::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
     356             : {
     357         213 :     sdbcx::ObjectType xReturn;
     358             : 
     359         426 :     Reference< XAppend > xAppend( m_xDrvColumns, UNO_QUERY );
     360         213 :     if ( xAppend.is() )
     361             :     {
     362           0 :         xAppend->appendByDescriptor(descriptor);
     363           0 :         xReturn = createObject( _rForName );
     364             :     }
     365         213 :     else if ( m_pTable && !m_pTable->isNew() )
     366             :     {
     367           0 :         if ( m_bAddColumn )
     368             :         {
     369           0 :             Reference< ::com::sun::star::sdb::tools::XTableAlteration> xAlterService = m_pTable->getAlterService();
     370           0 :             if ( xAlterService.is() )
     371             :             {
     372           0 :                 xAlterService->addColumn(m_pTable,descriptor);
     373           0 :                 xReturn = createObject( _rForName );
     374             :             }
     375             :             else
     376           0 :                 xReturn = OColumns_BASE::appendObject( _rForName, descriptor );
     377             :         }
     378             :         else
     379           0 :             ::dbtools::throwGenericSQLException( DBA_RES( RID_STR_NO_COLUMN_ADD ), static_cast<XChild*>(static_cast<TXChild*>(this)) );
     380             :     }
     381             :     else
     382         213 :         xReturn = cloneDescriptor( descriptor );
     383             : 
     384         213 :     if ( m_pColFactoryImpl )
     385         213 :         m_pColFactoryImpl->columnAppended( descriptor );
     386             : 
     387         213 :     ::dbaccess::notifyDataSourceModified(m_xParent,true);
     388             : 
     389         426 :     return xReturn;
     390             : }
     391             : 
     392             : // XDrop
     393           0 : void OColumns::dropObject(sal_Int32 _nPos, const OUString& _sElementName)
     394             : {
     395           0 :     Reference< XDrop > xDrop( m_xDrvColumns, UNO_QUERY );
     396           0 :     if ( xDrop.is() )
     397             :     {
     398           0 :         xDrop->dropByName( _sElementName );
     399             :     }
     400           0 :     else if ( m_pTable && !m_pTable->isNew() )
     401             :     {
     402           0 :         if ( m_bDropColumn )
     403             :         {
     404           0 :             Reference< ::com::sun::star::sdb::tools::XTableAlteration> xAlterService = m_pTable->getAlterService();
     405           0 :             if ( xAlterService.is() )
     406           0 :                 xAlterService->dropColumn(m_pTable,_sElementName);
     407             :             else
     408           0 :                 OColumns_BASE::dropObject(_nPos,_sElementName);
     409             :         }
     410             :         else
     411           0 :             ::dbtools::throwGenericSQLException( DBA_RES( RID_STR_NO_COLUMN_DROP ), static_cast<XChild*>(static_cast<TXChild*>(this)) );
     412             :     }
     413             : 
     414           0 :     if ( m_pColFactoryImpl )
     415           0 :         m_pColFactoryImpl->columnDropped(_sElementName);
     416             : 
     417           0 :     ::dbaccess::notifyDataSourceModified(m_xParent,true);
     418           0 : }
     419             : 
     420         426 : Reference< XInterface > SAL_CALL OColumns::getParent(  ) throw (RuntimeException, std::exception)
     421             : {
     422         426 :     ::osl::MutexGuard aGuard(m_rMutex);
     423         426 :     return m_xParent;
     424             : }
     425             : 
     426          85 : void SAL_CALL OColumns::setParent( const Reference< XInterface >& _xParent ) throw (NoSupportException, RuntimeException, std::exception)
     427             : {
     428          85 :     ::osl::MutexGuard aGuard(m_rMutex);
     429          85 :     m_xParent = _xParent;
     430          85 : }
     431             : 
     432             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11