LCOV - code coverage report
Current view: top level - connectivity/source/sdbcx - VCollection.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 157 270 58.1 %
Date: 2014-11-03 Functions: 55 90 61.1 %
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             : 
      21             : #include <algorithm>
      22             : #include <stdio.h>
      23             : #include <connectivity/sdbcx/VCollection.hxx>
      24             : #include <connectivity/sdbcx/VDescriptor.hxx>
      25             : #include <connectivity/dbexception.hxx>
      26             : #include <comphelper/enumhelper.hxx>
      27             : #include <comphelper/container.hxx>
      28             : #include <comphelper/types.hxx>
      29             : #include <comphelper/property.hxx>
      30             : #include "TConnection.hxx"
      31             : #include <rtl/ustrbuf.hxx>
      32             : #include "resource/common_res.hrc"
      33             : #include "resource/sharedresources.hxx"
      34             : 
      35             : using namespace connectivity::sdbcx;
      36             : using namespace connectivity;
      37             : using namespace comphelper;
      38             : using namespace ::cppu;
      39             : using namespace ::com::sun::star::beans;
      40             : using namespace ::com::sun::star::uno;
      41             : using namespace ::com::sun::star::lang;
      42             : using namespace ::com::sun::star::sdbc;
      43             : using namespace ::com::sun::star::container;
      44             : using namespace ::com::sun::star::util;
      45             : 
      46             : namespace
      47             : {
      48             :     template < typename T> class OHardRefMap : public connectivity::sdbcx::IObjectCollection
      49             :     {
      50             :         typedef ::std::multimap< OUString, T , ::comphelper::UStringMixLess> ObjectMap;
      51             :         typedef typename ObjectMap::iterator   ObjectIter;
      52             :         typedef typename ObjectMap::value_type ObjectEntry;
      53             : 
      54             :     //  private:
      55             :         // this combination of map and vector is used to have a fast name and index access
      56             :         ::std::vector< ObjectIter >             m_aElements;        // hold the iterators which point to map
      57             :         ObjectMap                               m_aNameMap;         // hold the elements and a name
      58             :     public:
      59         766 :         OHardRefMap(bool _bCase)
      60         766 :             : m_aNameMap(_bCase)
      61             :         {
      62         766 :         }
      63        1500 :         virtual ~OHardRefMap()
      64             :         {
      65        1500 :         }
      66             : 
      67           0 :         virtual void reserve(size_t nLength) SAL_OVERRIDE
      68             :         {
      69           0 :             m_aElements.reserve(nLength);
      70           0 :         }
      71             : 
      72       16496 :         virtual bool exists(const OUString& _sName ) SAL_OVERRIDE
      73             :         {
      74       16496 :             return m_aNameMap.find(_sName) != m_aNameMap.end();
      75             :         }
      76             : 
      77         752 :         virtual bool empty() SAL_OVERRIDE
      78             :         {
      79         752 :             return m_aNameMap.empty();
      80             :         }
      81             : 
      82         244 :         virtual void swapAll() SAL_OVERRIDE
      83             :         {
      84         244 :             ::std::vector< ObjectIter >(m_aElements).swap(m_aElements);
      85         244 :             ObjectMap(m_aNameMap).swap(m_aNameMap);
      86         244 :         }
      87             : 
      88         982 :         virtual void swap() SAL_OVERRIDE
      89             :         {
      90         982 :             ::std::vector< ObjectIter >().swap(m_aElements);
      91             : 
      92             :             OSL_ENSURE( m_aNameMap.empty(), "swap: what did disposeElements do?" );
      93         982 :             ObjectMap( m_aNameMap ).swap( m_aNameMap );
      94             :                 // Note that it's /important/ to construct the new ObjectMap from m_aNameMap before
      95             :                 // swapping. This way, it's ensured that the compare object held by these maps is preserved
      96             :                 // during the swap. If we would not do this, the UStringMixLess instance which is used would be
      97             :                 // default constructed (instead of being constructed from the same instance in m_aNameMap), and
      98             :                 // it's case-sensitive flag would have an unpredictable value.
      99         982 :         }
     100             : 
     101         244 :         virtual void clear() SAL_OVERRIDE
     102             :         {
     103         244 :             m_aElements.clear();
     104         244 :             m_aNameMap.clear();
     105         244 :         }
     106             : 
     107         496 :         virtual void insert(const OUString& _sName,const ObjectType& _xObject) SAL_OVERRIDE
     108             :         {
     109         496 :             m_aElements.push_back(m_aNameMap.insert(m_aNameMap.begin(), ObjectEntry(_sName,_xObject)));
     110         496 :         }
     111             : 
     112         836 :         virtual void reFill(const TStringVector &_rVector) SAL_OVERRIDE
     113             :         {
     114             :             OSL_ENSURE(!m_aNameMap.size(),"OCollection::reFill: collection isn't empty");
     115         836 :             m_aElements.reserve(_rVector.size());
     116             : 
     117        4356 :             for(TStringVector::const_iterator i=_rVector.begin(); i != _rVector.end();++i)
     118        3520 :                 m_aElements.push_back(m_aNameMap.insert(m_aNameMap.begin(), ObjectEntry(*i,ObjectType())));
     119         836 :         }
     120             : 
     121           0 :         virtual bool rename(const OUString& _sOldName, const OUString& _sNewName) SAL_OVERRIDE
     122             :         {
     123           0 :             bool bRet = false;
     124           0 :             ObjectIter aIter = m_aNameMap.find(_sOldName);
     125           0 :             if ( aIter != m_aNameMap.end() )
     126             :             {
     127           0 :                 typename ::std::vector< ObjectIter >::iterator aFind = ::std::find(m_aElements.begin(),m_aElements.end(),aIter);
     128           0 :                 if(m_aElements.end() != aFind)
     129             :                 {
     130           0 :                     (*aFind) = m_aNameMap.insert(m_aNameMap.begin(), ObjectEntry(_sNewName,(*aFind)->second));
     131           0 :                     m_aNameMap.erase(aIter);
     132             : 
     133           0 :                     bRet = true;
     134             :                 }
     135             :             }
     136           0 :             return bRet;
     137             :         }
     138             : 
     139        5498 :         virtual sal_Int32 size() SAL_OVERRIDE
     140             :         {
     141        5498 :             return static_cast<sal_Int32>(m_aNameMap.size());
     142             :         }
     143             : 
     144         402 :         virtual Sequence< OUString > getElementNames() SAL_OVERRIDE
     145             :         {
     146         402 :             Sequence< OUString > aNameList(m_aElements.size());
     147             : 
     148         402 :             OUString* pStringArray = aNameList.getArray();
     149         402 :             typename ::std::vector< ObjectIter >::const_iterator aEnd = m_aElements.end();
     150        6730 :             for(typename ::std::vector< ObjectIter >::const_iterator aIter = m_aElements.begin(); aIter != aEnd;++aIter,++pStringArray)
     151        6328 :                 *pStringArray = (*aIter)->first;
     152             : 
     153         402 :             return aNameList;
     154             :         }
     155             : 
     156        3132 :         virtual OUString getName(sal_Int32 _nIndex) SAL_OVERRIDE
     157             :         {
     158        3132 :             return m_aElements[_nIndex]->first;
     159             :         }
     160             : 
     161           0 :         virtual void disposeAndErase(sal_Int32 _nIndex) SAL_OVERRIDE
     162             :         {
     163             :             OSL_ENSURE(_nIndex >= 0 && _nIndex < static_cast<sal_Int32>(m_aElements.size()),"Illegal argument!");
     164           0 :             Reference<XComponent> xComp(m_aElements[_nIndex]->second.get(),UNO_QUERY);
     165           0 :             ::comphelper::disposeComponent(xComp);
     166           0 :             m_aElements[_nIndex]->second = T();
     167             : 
     168           0 :             OUString sName = m_aElements[_nIndex]->first;
     169           0 :             m_aElements.erase(m_aElements.begin()+_nIndex);
     170           0 :             m_aNameMap.erase(sName);
     171           0 :         }
     172             : 
     173         982 :         virtual void disposeElements() SAL_OVERRIDE
     174             :         {
     175        4254 :             for( ObjectIter aIter = m_aNameMap.begin(); aIter != m_aNameMap.end(); ++aIter)
     176             :             {
     177        3272 :                 Reference<XComponent> xComp(aIter->second.get(),UNO_QUERY);
     178        3272 :                 if ( xComp.is() )
     179             :                 {
     180        1562 :                     ::comphelper::disposeComponent(xComp);
     181        1562 :                     (*aIter).second = T();
     182             :                 }
     183             :             }
     184         982 :             m_aElements.clear();
     185         982 :             m_aNameMap.clear();
     186         982 :         }
     187             : 
     188        7546 :         virtual sal_Int32 findColumn( const OUString& columnName ) SAL_OVERRIDE
     189             :         {
     190        7546 :             ObjectIter aIter = m_aNameMap.find(columnName);
     191             :             OSL_ENSURE(aIter != m_aNameMap.end(),"findColumn:: Illegal name!");
     192        7546 :             return m_aElements.size() - (m_aElements.end() - ::std::find(m_aElements.begin(),m_aElements.end(),aIter));
     193             :         }
     194             : 
     195           0 :         virtual OUString findColumnAtIndex(  sal_Int32 _nIndex) SAL_OVERRIDE
     196             :         {
     197             :             OSL_ENSURE(_nIndex >= 0 && _nIndex < static_cast<sal_Int32>(m_aElements.size()),"Illegal argument!");
     198           0 :             return m_aElements[_nIndex]->first;
     199             :         }
     200             : 
     201       12424 :         virtual ObjectType getObject(sal_Int32 _nIndex) SAL_OVERRIDE
     202             :         {
     203             :             OSL_ENSURE(_nIndex >= 0 && _nIndex < static_cast<sal_Int32>(m_aElements.size()),"Illegal argument!");
     204       12424 :             return m_aElements[_nIndex]->second;
     205             :         }
     206             : 
     207           0 :         virtual ObjectType getObject(const OUString& columnName) SAL_OVERRIDE
     208             :         {
     209           0 :             return m_aNameMap.find(columnName)->second;
     210             :         }
     211             : 
     212        3132 :         virtual void setObject(sal_Int32 _nIndex,const ObjectType& _xObject) SAL_OVERRIDE
     213             :         {
     214             :             OSL_ENSURE(_nIndex >= 0 && _nIndex < static_cast<sal_Int32>(m_aElements.size()),"Illegal argument!");
     215        3132 :             m_aElements[_nIndex]->second = _xObject;
     216        3132 :         }
     217             : 
     218        1412 :         bool isCaseSensitive() const SAL_OVERRIDE
     219             :         {
     220        1412 :             return m_aNameMap.key_comp().isCaseSensitive();
     221             :         }
     222             : 
     223             :     };
     224             : }
     225             : 
     226         750 : IObjectCollection::~IObjectCollection() {}
     227             : 
     228           0 : IMPLEMENT_SERVICE_INFO(OCollection,"com.sun.star.sdbcx.VContainer" , "com.sun.star.sdbcx.Container")
     229             : 
     230         766 : OCollection::OCollection(::cppu::OWeakObject& _rParent
     231             :                          , bool _bCase
     232             :                          , ::osl::Mutex& _rMutex
     233             :                          , const TStringVector &_rVector
     234             :                          , bool _bUseIndexOnly
     235             :                          , bool _bUseHardRef)
     236             :                      :m_aContainerListeners(_rMutex)
     237             :                      ,m_aRefreshListeners(_rMutex)
     238             :                      ,m_rParent(_rParent)
     239             :                      ,m_rMutex(_rMutex)
     240         766 :                      ,m_bUseIndexOnly(_bUseIndexOnly)
     241             : {
     242         766 :     if ( _bUseHardRef )
     243             :     {
     244         684 :         m_pElements.reset(new OHardRefMap< ObjectType >(_bCase));
     245             :     }
     246             :     else
     247             :     {
     248          82 :         m_pElements.reset(new OHardRefMap< WeakReference< XPropertySet> >(_bCase));
     249             :     }
     250         766 :     m_pElements->reFill(_rVector);
     251         766 : }
     252             : 
     253         750 : OCollection::~OCollection()
     254             : {
     255         750 : }
     256             : 
     257        5424 : Any SAL_CALL OCollection::queryInterface( const Type & rType ) throw (RuntimeException, std::exception)
     258             : {
     259        5424 :     if ( m_bUseIndexOnly && rType == cppu::UnoType<XNameAccess>::get() )
     260             :     {
     261           0 :         return Any();
     262             :     }
     263        5424 :     return OCollectionBase::queryInterface( rType );
     264             : }
     265             : 
     266           0 : Sequence< Type > SAL_CALL OCollection::getTypes() throw (RuntimeException, std::exception)
     267             : {
     268           0 :     if ( m_bUseIndexOnly )
     269             :     {
     270           0 :         Sequence< Type > aTypes(OCollectionBase::getTypes());
     271           0 :         Type* pBegin    = aTypes.getArray();
     272           0 :         Type* pEnd      = pBegin + aTypes.getLength();
     273             : 
     274           0 :         ::std::vector<Type> aOwnTypes;
     275           0 :         aOwnTypes.reserve(aTypes.getLength());
     276           0 :         Type aType = cppu::UnoType<XNameAccess>::get();
     277           0 :         for(;pBegin != pEnd; ++pBegin)
     278             :         {
     279           0 :             if ( *pBegin != aType )
     280           0 :                 aOwnTypes.push_back(*pBegin);
     281             :         }
     282           0 :         Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0];
     283           0 :         return Sequence< Type >(pTypes,aOwnTypes.size());
     284             :     }
     285           0 :     return OCollectionBase::getTypes( );
     286             : }
     287             : 
     288         244 : void OCollection::clear_NoDispose()
     289             : {
     290         244 :     ::osl::MutexGuard aGuard(m_rMutex);
     291             : 
     292         244 :     m_pElements->clear();
     293         244 :     m_pElements->swapAll();
     294         244 : }
     295             : 
     296             : 
     297         982 : void OCollection::disposing(void)
     298             : {
     299         982 :     m_aContainerListeners.disposeAndClear(EventObject(static_cast<XTypeProvider*>(this)));
     300         982 :     m_aRefreshListeners.disposeAndClear(EventObject(static_cast<XTypeProvider*>(this)));
     301             : 
     302         982 :     ::osl::MutexGuard aGuard(m_rMutex);
     303             : 
     304         982 :     disposeElements();
     305             : 
     306         982 :     m_pElements->swap();
     307         982 : }
     308             : 
     309        4894 : Any SAL_CALL OCollection::getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception)
     310             : {
     311        4894 :     ::osl::MutexGuard aGuard(m_rMutex);
     312        4894 :     if (Index < 0 || Index >= m_pElements->size() )
     313           0 :         throw IndexOutOfBoundsException(OUString::number(Index),static_cast<XTypeProvider*>(this));
     314             : 
     315        4894 :     return makeAny(getObject(Index));
     316             : }
     317             : 
     318        7530 : Any SAL_CALL OCollection::getByName( const OUString& aName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
     319             : {
     320        7530 :     ::osl::MutexGuard aGuard(m_rMutex);
     321             : 
     322        7530 :     if ( !m_pElements->exists(aName) )
     323             :     {
     324           0 :         ::connectivity::SharedResources aResources;
     325             :         const OUString sError( aResources.getResourceStringWithSubstitution(
     326             :                 STR_NO_ELEMENT_NAME,
     327             :                 "$name$", aName
     328           0 :              ) );
     329           0 :         throw NoSuchElementException( sError, static_cast< XTypeProvider* >( this ) );
     330             :     }
     331             : 
     332        7530 :     return makeAny(getObject(m_pElements->findColumn(aName)));
     333             : }
     334             : 
     335         402 : Sequence< OUString > SAL_CALL OCollection::getElementNames(  ) throw(RuntimeException, std::exception)
     336             : {
     337         402 :     ::osl::MutexGuard aGuard(m_rMutex);
     338         402 :     return m_pElements->getElementNames();
     339             : }
     340             : 
     341           0 : void SAL_CALL OCollection::refresh(  ) throw(RuntimeException, std::exception)
     342             : {
     343           0 :     ::osl::MutexGuard aGuard(m_rMutex);
     344             : 
     345           0 :     disposeElements();
     346             : 
     347           0 :     impl_refresh();
     348           0 :     EventObject aEvt(static_cast<XTypeProvider*>(this));
     349           0 :     m_aRefreshListeners.notifyEach( &XRefreshListener::refreshed, aEvt );
     350           0 : }
     351             : 
     352          70 : void OCollection::reFill(const TStringVector &_rVector)
     353             : {
     354          70 :     m_pElements->reFill(_rVector);
     355          70 : }
     356             : 
     357             : // XDataDescriptorFactory
     358         496 : Reference< XPropertySet > SAL_CALL OCollection::createDataDescriptor(  ) throw(RuntimeException, std::exception)
     359             : {
     360         496 :     ::osl::MutexGuard aGuard(m_rMutex);
     361             : 
     362         496 :     return createDescriptor();
     363             : }
     364             : 
     365         992 : OUString OCollection::getNameForObject(const ObjectType& _xObject)
     366             : {
     367             :     OSL_ENSURE(_xObject.is(),"OCollection::getNameForObject: Object is NULL!");
     368         992 :     OUString sName;
     369         992 :     _xObject->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= sName;
     370         992 :     return sName;
     371             : }
     372             : 
     373             : // XAppend
     374         496 : void SAL_CALL OCollection::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException, std::exception)
     375             : {
     376         496 :     ::osl::ClearableMutexGuard aGuard(m_rMutex);
     377             : 
     378         992 :     OUString sName = getNameForObject( descriptor );
     379             : 
     380         496 :     if ( m_pElements->exists(sName) )
     381           0 :         throw ElementExistException(sName,static_cast<XTypeProvider*>(this));
     382             : 
     383         992 :     ObjectType xNewlyCreated = appendObject( sName, descriptor );
     384         496 :     if ( !xNewlyCreated.is() )
     385           0 :         throw RuntimeException();
     386             : 
     387         496 :     ODescriptor* pDescriptor = ODescriptor::getImplementation( xNewlyCreated );
     388         496 :     if ( pDescriptor )
     389           0 :         pDescriptor->setNew( false );
     390             : 
     391         496 :     sName = getNameForObject( xNewlyCreated );
     392         496 :     if ( !m_pElements->exists( sName ) ) // this may happen when the derived class included it itself
     393         496 :         m_pElements->insert( sName, xNewlyCreated );
     394             : 
     395             :     // notify our container listeners
     396         992 :     ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(sName), makeAny(xNewlyCreated), Any());
     397         496 :     aGuard.clear();
     398         992 :     m_aContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvent );
     399         496 : }
     400             : 
     401             : // XDrop
     402           0 : void SAL_CALL OCollection::dropByName( const OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException, std::exception)
     403             : {
     404           0 :     ::osl::MutexGuard aGuard(m_rMutex);
     405             : 
     406           0 :     if ( !m_pElements->exists(elementName) )
     407           0 :         throw NoSuchElementException(elementName,static_cast<XTypeProvider*>(this));
     408             : 
     409           0 :     dropImpl(m_pElements->findColumn(elementName));
     410           0 : }
     411             : 
     412           0 : void SAL_CALL OCollection::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException, std::exception)
     413             : {
     414           0 :     ::osl::MutexGuard aGuard(m_rMutex);
     415           0 :     if(index <0 || index >= getCount())
     416           0 :         throw IndexOutOfBoundsException(OUString::number(index),static_cast<XTypeProvider*>(this));
     417             : 
     418           0 :     dropImpl(index);
     419           0 : }
     420             : 
     421           0 : void OCollection::dropImpl(sal_Int32 _nIndex, bool _bReallyDrop)
     422             : {
     423           0 :     OUString elementName = m_pElements->getName(_nIndex);
     424             : 
     425           0 :     if ( _bReallyDrop )
     426           0 :         dropObject(_nIndex,elementName);
     427             : 
     428           0 :     m_pElements->disposeAndErase(_nIndex);
     429             : 
     430             :     // notify our container listeners
     431           0 :     notifyElementRemoved(elementName);
     432           0 : }
     433             : 
     434           0 : void OCollection::notifyElementRemoved(const OUString& _sName)
     435             : {
     436           0 :     ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_sName), Any(), Any());
     437             :     // note that xExistent may be empty, in case somebody removed the data source while it is not alive at this moment
     438           0 :     OInterfaceIteratorHelper aListenerLoop(m_aContainerListeners);
     439           0 :     while (aListenerLoop.hasMoreElements())
     440           0 :         static_cast<XContainerListener*>(aListenerLoop.next())->elementRemoved(aEvent);
     441           0 : }
     442             : 
     443          16 : sal_Int32 SAL_CALL OCollection::findColumn( const OUString& columnName ) throw(SQLException, RuntimeException, std::exception)
     444             : {
     445          16 :     if ( !m_pElements->exists(columnName) )
     446             :     {
     447           0 :         ::dbtools::throwInvalidColumnException( columnName, static_cast< XIndexAccess*>(this) );
     448             :         assert(false);
     449             :     }
     450             : 
     451          16 :     return m_pElements->findColumn(columnName) + 1; // because columns start at one
     452             : }
     453             : 
     454           0 : Reference< XEnumeration > SAL_CALL OCollection::createEnumeration(  ) throw(RuntimeException, std::exception)
     455             : {
     456           0 :     ::osl::MutexGuard aGuard(m_rMutex);
     457           0 :     return new OEnumerationByIndex( static_cast< XIndexAccess*>(this));
     458             : }
     459             : 
     460         188 : void SAL_CALL OCollection::addContainerListener( const Reference< XContainerListener >& _rxListener ) throw(RuntimeException, std::exception)
     461             : {
     462         188 :     m_aContainerListeners.addInterface(_rxListener);
     463         188 : }
     464             : 
     465             : 
     466         172 : void SAL_CALL OCollection::removeContainerListener( const Reference< XContainerListener >& _rxListener ) throw(RuntimeException, std::exception)
     467             : {
     468         172 :     m_aContainerListeners.removeInterface(_rxListener);
     469         172 : }
     470             : 
     471       30068 : void SAL_CALL OCollection::acquire() throw()
     472             : {
     473       30068 :     m_rParent.acquire();
     474       30068 : }
     475             : 
     476       29864 : void SAL_CALL OCollection::release() throw()
     477             : {
     478       29864 :     m_rParent.release();
     479       29864 : }
     480             : 
     481           0 : Type SAL_CALL OCollection::getElementType(  ) throw(RuntimeException, std::exception)
     482             : {
     483           0 :     return cppu::UnoType<XPropertySet>::get();
     484             : }
     485             : 
     486         752 : sal_Bool SAL_CALL OCollection::hasElements(  ) throw(RuntimeException, std::exception)
     487             : {
     488         752 :     ::osl::MutexGuard aGuard(m_rMutex);
     489         752 :     return !m_pElements->empty();
     490             : }
     491             : 
     492         604 : sal_Int32 SAL_CALL OCollection::getCount(  ) throw(RuntimeException, std::exception)
     493             : {
     494         604 :     ::osl::MutexGuard aGuard(m_rMutex);
     495         604 :     return m_pElements->size();
     496             : }
     497             : 
     498        7958 : sal_Bool SAL_CALL OCollection::hasByName( const OUString& aName ) throw(RuntimeException, std::exception)
     499             : {
     500        7958 :     ::osl::MutexGuard aGuard(m_rMutex);
     501        7958 :     return m_pElements->exists(aName);
     502             : }
     503             : 
     504           0 : void SAL_CALL OCollection::addRefreshListener( const Reference< XRefreshListener >& l ) throw(RuntimeException, std::exception)
     505             : {
     506           0 :     m_aRefreshListeners.addInterface(l);
     507           0 : }
     508             : 
     509           0 : void SAL_CALL OCollection::removeRefreshListener( const Reference< XRefreshListener >& l ) throw(RuntimeException, std::exception)
     510             : {
     511           0 :     m_aRefreshListeners.removeInterface(l);
     512           0 : }
     513             : 
     514           0 : void OCollection::insertElement(const OUString& _sElementName,const ObjectType& _xElement)
     515             : {
     516             :     OSL_ENSURE(!m_pElements->exists(_sElementName),"Element already exists");
     517           0 :     if ( !m_pElements->exists(_sElementName) )
     518           0 :         m_pElements->insert(_sElementName,_xElement);
     519           0 : }
     520             : 
     521           0 : void OCollection::renameObject(const OUString& _sOldName, const OUString& _sNewName)
     522             : {
     523             :     OSL_ENSURE(m_pElements->exists(_sOldName),"Element doesn't exist");
     524             :     OSL_ENSURE(!m_pElements->exists(_sNewName),"Element already exists");
     525             :     OSL_ENSURE(!_sNewName.isEmpty(),"New name must not be empty!");
     526             :     OSL_ENSURE(!_sOldName.isEmpty(),"Old name must not be empty!");
     527             : 
     528           0 :     if ( m_pElements->rename(_sOldName,_sNewName) )
     529             :     {
     530           0 :         ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_sNewName), makeAny(m_pElements->getObject(_sNewName)),makeAny(_sOldName));
     531             :         // note that xExistent may be empty, in case somebody removed the data source while it is not alive at this moment
     532           0 :         OInterfaceIteratorHelper aListenerLoop(m_aContainerListeners);
     533           0 :         while (aListenerLoop.hasMoreElements())
     534           0 :             static_cast<XContainerListener*>(aListenerLoop.next())->elementReplaced(aEvent);
     535             :     }
     536           0 : }
     537             : 
     538       12424 : ObjectType OCollection::getObject(sal_Int32 _nIndex)
     539             : {
     540       12424 :     ObjectType xName = m_pElements->getObject(_nIndex);
     541       12424 :     if ( !xName.is() )
     542             :     {
     543             :         try
     544             :         {
     545        3132 :             xName = createObject(m_pElements->getName(_nIndex));
     546             :         }
     547           0 :         catch(const SQLException& e)
     548             :         {
     549             :             try
     550             :             {
     551           0 :                 dropImpl(_nIndex,false);
     552             :             }
     553           0 :             catch(const Exception& )
     554             :             {
     555             :             }
     556           0 :             throw WrappedTargetException(e.Message,static_cast<XTypeProvider*>(this),makeAny(e));
     557             :         }
     558        3132 :         m_pElements->setObject(_nIndex,xName);
     559             :     }
     560       12424 :     return xName;
     561             : }
     562             : 
     563         982 : void OCollection::disposeElements()
     564             : {
     565         982 :     m_pElements->disposeElements();
     566         982 : }
     567             : 
     568           0 : Reference< XPropertySet > OCollection::createDescriptor()
     569             : {
     570             :     OSL_FAIL("Need to be overloaded when used!");
     571           0 :     throw SQLException();
     572             : }
     573             : 
     574         496 : ObjectType OCollection::cloneDescriptor( const ObjectType& _descriptor )
     575             : {
     576         496 :     ObjectType xNewDescriptor( createDescriptor() );
     577         496 :     ::comphelper::copyProperties( _descriptor, xNewDescriptor );
     578         496 :     return xNewDescriptor;
     579             : }
     580             : 
     581           0 : ObjectType OCollection::appendObject( const OUString& /*_rForName*/, const Reference< XPropertySet >& descriptor )
     582             : {
     583           0 :     return cloneDescriptor( descriptor );
     584             : }
     585             : 
     586           0 : void OCollection::dropObject(sal_Int32 /*_nPos*/, const OUString& /*_sElementName*/)
     587             : {
     588           0 : }
     589             : 
     590             : 
     591             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10