LCOV - code coverage report
Current view: top level - dbaccess/source/core/api - column.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 85 184 46.2 %
Date: 2014-11-03 Functions: 21 37 56.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 "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        3600 : OColumn::OColumn( const bool _bNameIsReadOnly )
      66             :         :OColumnBase( m_aMutex )
      67        3600 :         ,::comphelper::OPropertyContainer( OColumnBase::rBHelper )
      68             : {
      69             : 
      70             :     registerProperty( PROPERTY_NAME, PROPERTY_ID_NAME, _bNameIsReadOnly ? PropertyAttribute::READONLY : 0,
      71        3600 :         &m_sName, ::getCppuType( &m_sName ) );
      72        3600 : }
      73             : 
      74        3588 : OColumn::~OColumn()
      75             : {
      76        3588 : }
      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      165701 : 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        3588 : void OColumn::disposing()
     110             : {
     111        3588 :     OPropertyContainer::disposing();
     112        3588 : }
     113             : 
     114             : // com::sun::star::beans::XPropertySet
     115        8432 : Reference< XPropertySetInfo > OColumn::getPropertySetInfo() throw (RuntimeException, std::exception)
     116             : {
     117        8432 :     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         582 : void SAL_CALL OColumn::setName( const OUString& _rName ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     126             : {
     127         582 :     m_sName = _rName;
     128         582 : }
     129             : 
     130           0 : void OColumn::fireValueChange(const ::connectivity::ORowSetValue& /*_rOldValue*/)
     131             : {
     132             :     OSL_FAIL( "OColumn::fireValueChange: not implemented!" );
     133           0 : }
     134             : 
     135       27750 : void OColumn::registerProperty( const OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void* _pPointerToMember, const Type& _rMemberType )
     136             : {
     137       27750 :     ::comphelper::OPropertyContainer::registerProperty( _rName, _nHandle, _nAttributes, _pPointerToMember, _rMemberType );
     138       27750 : }
     139             : 
     140       21600 : void OColumn::registerMayBeVoidProperty( const OUString& _rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, Any* _pPointerToMember, const Type& _rExpectedType )
     141             : {
     142       21600 :     ::comphelper::OPropertyContainer::registerMayBeVoidProperty( _rName, _nHandle, _nAttributes, _pPointerToMember, _rExpectedType );
     143       21600 : }
     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         224 : 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         224 :     ,m_bDropColumn(_bDropColumn)
     168             : {
     169         224 : }
     170             : 
     171          38 : 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          38 :     ,m_bDropColumn(_bDropColumn)
     187             : {
     188          38 : }
     189             : 
     190         516 : OColumns::~OColumns()
     191             : {
     192         516 : }
     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           0 : void OColumns::append( const OUString& _rName, OColumn* _pColumn )
     213             : {
     214           0 :     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           0 :     _pColumn->m_sName = _rName;
     220             : 
     221             :     // now really insert the column
     222           0 :     insertElement( _rName, _pColumn );
     223           0 : }
     224             : 
     225           0 : void OColumns::clearColumns()
     226             : {
     227           0 :     MutexGuard aGuard(m_rMutex);
     228           0 :     disposing();
     229           0 : }
     230             : 
     231         400 : void SAL_CALL OColumns::disposing(void)
     232             : {
     233         400 :     MutexGuard aGuard(m_rMutex);
     234         400 :     m_xDrvColumns = NULL;
     235         400 :     m_pMediator = NULL;
     236         400 :     m_pColFactoryImpl = NULL;
     237         400 :     OColumns_BASE::disposing();
     238         400 : }
     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        1530 : connectivity::sdbcx::ObjectType OColumns::createObject(const OUString& _rName)
     247             : {
     248             :     OSL_ENSURE(m_pColFactoryImpl, "OColumns::createObject: no column factory!");
     249             : 
     250        1530 :     connectivity::sdbcx::ObjectType xRet;
     251        1530 :     if ( m_pColFactoryImpl )
     252             :     {
     253        1530 :         xRet = m_pColFactoryImpl->createColumn(_rName);
     254        1530 :         Reference<XChild> xChild(xRet,UNO_QUERY);
     255        1530 :         if ( xChild.is() )
     256           0 :             xChild->setParent(static_cast<XChild*>(static_cast<TXChild*>(this)));
     257             :     }
     258             : 
     259        3060 :     Reference<XPropertySet> xDest(xRet,UNO_QUERY);
     260        1530 :     if ( m_pMediator && xDest.is() )
     261         510 :         m_pMediator->notifyElementCreated(_rName,xDest);
     262             : 
     263        3060 :     return xRet;
     264             : }
     265             : 
     266         992 : Reference< XPropertySet > OColumns::createDescriptor()
     267             : {
     268         992 :     if ( m_pColFactoryImpl )
     269             :     {
     270         992 :         Reference<XPropertySet> xRet = m_pColFactoryImpl->createColumnDescriptor();
     271        1984 :         Reference<XChild> xChild(xRet,UNO_QUERY);
     272         992 :         if ( xChild.is() )
     273         992 :             xChild->setParent(static_cast<XChild*>(static_cast<TXChild*>(this)));
     274        1984 :         return xRet;
     275             :     }
     276             :     else
     277           0 :         return Reference< XPropertySet >();
     278             : }
     279             : 
     280        2558 : Any SAL_CALL OColumns::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
     281             : {
     282        2558 :     Any aRet;
     283        2558 :     if(m_xDrvColumns.is())
     284             :     {
     285         500 :         aRet = m_xDrvColumns->queryInterface(rType);
     286         500 :         if ( aRet.hasValue() )
     287         500 :             aRet = OColumns_BASE::queryInterface( rType);
     288         500 :         if ( !aRet.hasValue() )
     289           0 :             aRet = TXChild::queryInterface( rType);
     290         500 :         return aRet;
     291             :     }
     292        2058 :     else if(!m_pTable || (m_pTable && !m_pTable->isNew()))
     293             :     {
     294        2058 :         if(!m_bAddColumn    && rType == cppu::UnoType<XAppend>::get())
     295           0 :             return Any();
     296        2058 :         if(!m_bDropColumn   && rType == cppu::UnoType<XDrop>::get())
     297           0 :             return Any();
     298             :     }
     299             : 
     300        2058 :     aRet = OColumns_BASE::queryInterface( rType);
     301        2058 :     if ( !aRet.hasValue() )
     302         992 :         aRet = TXChild::queryInterface( rType);
     303        2058 :     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         496 : sdbcx::ObjectType OColumns::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
     356             : {
     357         496 :     sdbcx::ObjectType xReturn;
     358             : 
     359         992 :     Reference< XAppend > xAppend( m_xDrvColumns, UNO_QUERY );
     360         496 :     if ( xAppend.is() )
     361             :     {
     362           0 :         xAppend->appendByDescriptor(descriptor);
     363           0 :         xReturn = createObject( _rForName );
     364             :     }
     365         496 :     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         496 :         xReturn = cloneDescriptor( descriptor );
     383             : 
     384         496 :     if ( m_pColFactoryImpl )
     385         496 :         m_pColFactoryImpl->columnAppended( descriptor );
     386             : 
     387         496 :     ::dbaccess::notifyDataSourceModified(m_xParent,true);
     388             : 
     389         992 :     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         992 : Reference< XInterface > SAL_CALL OColumns::getParent(  ) throw (RuntimeException, std::exception)
     421             : {
     422         992 :     ::osl::MutexGuard aGuard(m_rMutex);
     423         992 :     return m_xParent;
     424             : }
     425             : 
     426         120 : void SAL_CALL OColumns::setParent( const Reference< XInterface >& _xParent ) throw (NoSupportException, RuntimeException, std::exception)
     427             : {
     428         120 :     ::osl::MutexGuard aGuard(m_rMutex);
     429         120 :     m_xParent = _xParent;
     430         120 : }
     431             : 
     432             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10