LCOV - code coverage report
Current view: top level - include/connectivity/sdbcx - VCollection.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 2 2 100.0 %
Date: 2015-06-13 12:38:46 Functions: 2 2 100.0 %
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             : #ifndef INCLUDED_CONNECTIVITY_SDBCX_VCOLLECTION_HXX
      21             : #define INCLUDED_CONNECTIVITY_SDBCX_VCOLLECTION_HXX
      22             : 
      23             : #include <cppuhelper/implbase10.hxx>
      24             : #include <com/sun/star/container/XNameAccess.hpp>
      25             : #include <com/sun/star/container/XIndexAccess.hpp>
      26             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      27             : #include <com/sun/star/container/XEnumeration.hpp>
      28             : #include <com/sun/star/beans/XPropertySet.hpp>
      29             : #include <com/sun/star/util/XRefreshable.hpp>
      30             : #include <com/sun/star/lang/XComponent.hpp>
      31             : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
      32             : #include <com/sun/star/sdbcx/XAppend.hpp>
      33             : #include <com/sun/star/sdbcx/XDrop.hpp>
      34             : #include <com/sun/star/sdbc/XColumnLocate.hpp>
      35             : #include <cppuhelper/interfacecontainer.h>
      36             : #include <com/sun/star/lang/XServiceInfo.hpp>
      37             : #include <connectivity/CommonTools.hxx>
      38             : #include <com/sun/star/container/XContainer.hpp>
      39             : #include <connectivity/StdTypeDefs.hxx>
      40             : #include <connectivity/dbtoolsdllapi.hxx>
      41             : #include <memory>
      42             : 
      43             : 
      44             : namespace connectivity
      45             : {
      46             :     namespace sdbcx
      47             :     {
      48             : 
      49             :         // the class OCollection is base class for collections :-)
      50             :         typedef ::cppu::ImplHelper10< ::com::sun::star::container::XNameAccess,
      51             :                                          ::com::sun::star::container::XIndexAccess,
      52             :                                          ::com::sun::star::container::XEnumerationAccess,
      53             :                                          ::com::sun::star::container::XContainer,
      54             :                                          ::com::sun::star::sdbc::XColumnLocate,
      55             :                                          ::com::sun::star::util::XRefreshable,
      56             :                                          ::com::sun::star::sdbcx::XDataDescriptorFactory,
      57             :                                          ::com::sun::star::sdbcx::XAppend,
      58             :                                          ::com::sun::star::sdbcx::XDrop,
      59             :                                          ::com::sun::star::lang::XServiceInfo> OCollectionBase;
      60             : 
      61             :         typedef ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > ObjectType;
      62             : 
      63       14232 :         class OOO_DLLPUBLIC_DBTOOLS SAL_NO_VTABLE IObjectCollection
      64             :         {
      65             :         public:
      66             :             virtual ~IObjectCollection();
      67             :             virtual void reserve(size_t nLength) = 0;
      68             :             virtual bool exists(const OUString& _sName ) = 0;
      69             :             virtual bool empty() = 0;
      70             :             virtual void swapAll() = 0;
      71             :             virtual void swap() = 0;
      72             :             virtual void clear() = 0;
      73             :             virtual void reFill(const TStringVector &_rVector) = 0;
      74             :             virtual void insert(const OUString& _sName, const ObjectType& _xObject) = 0;
      75             :             virtual bool rename(const OUString& _sOldName, const OUString& _sNewName) = 0;
      76             :             virtual sal_Int32 size() = 0;
      77             :             virtual ::com::sun::star::uno::Sequence< OUString > getElementNames() = 0;
      78             :             virtual OUString getName(sal_Int32 _nIndex) = 0;
      79             :             virtual void disposeAndErase(sal_Int32 _nIndex) = 0;
      80             :             virtual void disposeElements() = 0;
      81             :             virtual sal_Int32 findColumn( const OUString& columnName ) = 0;
      82             :             virtual OUString findColumnAtIndex(  sal_Int32 _nIndex) = 0;
      83             :             virtual ObjectType getObject(sal_Int32 _nIndex) = 0;
      84             :             virtual ObjectType getObject(const OUString& columnName) = 0;
      85             :             virtual void setObject(sal_Int32 _nIndex,const ObjectType& _xObject) = 0;
      86             :             virtual bool isCaseSensitive() const = 0;
      87             :         };
      88             : 
      89             :         //  OCollection
      90             : 
      91             :         class OOO_DLLPUBLIC_DBTOOLS SAL_NO_VTABLE OCollection :
      92             :             public OCollectionBase
      93             :         {
      94             :         protected:
      95             :             ::std::unique_ptr<IObjectCollection>    m_pElements;
      96             : 
      97             :             ::cppu::OInterfaceContainerHelper       m_aContainerListeners;
      98             :             ::cppu::OInterfaceContainerHelper       m_aRefreshListeners;
      99             : 
     100             :         protected:
     101             :             ::cppu::OWeakObject&                    m_rParent;          // parent of the collection
     102             :             ::osl::Mutex&                           m_rMutex;           // mutex of the parent
     103             :             bool                                    m_bUseIndexOnly;    // is only TRUE when only an indexaccess is needed
     104             : 
     105             :             // the implementing class should refresh their elements
     106             :             virtual void impl_refresh() throw(::com::sun::star::uno::RuntimeException) = 0;
     107             : 
     108             :             // will be called when a object was requested by one of the accessing methods like getByIndex
     109             :             virtual ObjectType createObject(const OUString& _rName) = 0;
     110             : 
     111             :             // will be called when a new object should be generated by a call of createDataDescriptor
     112             :             // the returned object is empty will be filled outside and added to the collection
     113             :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > createDescriptor();
     114             : 
     115             :             /** appends an object described by a descriptor, under a given name
     116             :                 @param _rForName
     117             :                     is the name under which the object should be appended. Guaranteed to not be empty.
     118             :                     This is passed for convenience only, since it's the result of a call of
     119             :                     getNameForObject for the given descriptor
     120             :                 @param descriptor
     121             :                     describes the object to append
     122             :                 @return
     123             :                     the new object which is to be inserted into the collection. This might be the result
     124             :                     of a call of <code>createObject( _rForName )</code>, or a clone of the descriptor.
     125             :             */
     126             :             virtual ObjectType appendObject( const OUString& _rForName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor );
     127             : 
     128             :             // called when XDrop was called
     129             :             virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName);
     130             : 
     131             :             /** returns the name for the object. The default implementation ask for the property NAME. If this doesn't satisfy, it has to be overridden.
     132             :                 @param  _xObject    The object where the name should be extracted.
     133             :                 @return The name of the object.
     134             :             */
     135             :             virtual OUString getNameForObject(const ObjectType& _xObject);
     136             : 
     137             :             /** clones the given descriptor
     138             : 
     139             :                 The method calls createDescriptor to create a new, empty descriptor, and then copies all properties from
     140             :                 _descriptor to the new object, which is returned.
     141             : 
     142             :                 This method might come handy in derived classes for implementing appendObject, when the object
     143             :                 is not actually appended to any backend (e.g. for the columns collection of a descriptor object itself,
     144             :                 where there is not yet a database backend to append the column to).
     145             :             */
     146             :             ObjectType cloneDescriptor( const ObjectType& _descriptor );
     147             : 
     148             :             OCollection(::cppu::OWeakObject& _rParent,
     149             :                         bool _bCase,
     150             :                         ::osl::Mutex& _rMutex,
     151             :                         const TStringVector &_rVector,
     152             :                         bool _bUseIndexOnly = false,
     153             :                         bool _bUseHardRef = true);
     154             : 
     155             :             /** clear the name map
     156             :                 <p>Does <em>not</em> dispose the objects hold by the collection.</p>
     157             :             */
     158             :             void clear_NoDispose();
     159             : 
     160             :             /**  insert a new element into the collection
     161             :             */
     162             :             void insertElement(const OUString& _sElementName,const ObjectType& _xElement);
     163             : 
     164             :             /** return the name of element at index _nIndex
     165             :             */
     166             :             inline OUString getElementName(sal_Int32 _nIndex)
     167             :             {
     168             :                 return m_pElements->findColumnAtIndex(_nIndex);
     169             :             }
     170             : 
     171             : 
     172             :             /** return the object, if not existent it creates it.
     173             :                 @param  _nIndex
     174             :                     The index of the object to create.
     175             :                 @return ObjectType
     176             :             */
     177             :             ObjectType getObject(sal_Int32 _nIndex);
     178             : 
     179             :         public:
     180             :             virtual ~OCollection();
     181             :             DECLARE_SERVICE_INFO();
     182             : 
     183             :             void reFill(const TStringVector &_rVector);
     184       14545 :             inline bool isCaseSensitive() const { return m_pElements->isCaseSensitive(); }
     185             :             void renameObject(const OUString& _sOldName, const OUString& _sNewName);
     186             : 
     187             :             // only the name is identical to ::cppu::OComponentHelper
     188             :             virtual void SAL_CALL disposing();
     189             :             // dispatch the refcounting to the parent
     190             :             virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
     191             :             virtual void SAL_CALL release() throw() SAL_OVERRIDE;
     192             : 
     193             :             // XInterface
     194             :             virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     195             :             virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     196             : 
     197             :             // ::com::sun::star::container::XElementAccess
     198             :             virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     199             :             virtual sal_Bool SAL_CALL hasElements(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     200             :             // ::com::sun::star::container::XIndexAccess
     201             :             virtual sal_Int32 SAL_CALL getCount(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     202             :             virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     203             : 
     204             :                 // ::com::sun::star::container::XNameAccess
     205             :             virtual ::com::sun::star::uno::Any SAL_CALL getByName( const OUString& aName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     206             :             virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     207             :             virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     208             :             // XEnumerationAccess
     209             :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     210             :                         // ::com::sun::star::util::XRefreshable
     211             :             virtual void SAL_CALL refresh(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     212             :             virtual void SAL_CALL addRefreshListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener >& l ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     213             :             virtual void SAL_CALL removeRefreshListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener >& l ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     214             :             // XDataDescriptorFactory
     215             :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > SAL_CALL createDataDescriptor(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     216             :             // XAppend
     217             :             virtual void SAL_CALL appendByDescriptor( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     218             :             // XDrop
     219             :             virtual void SAL_CALL dropByName( const OUString& elementName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     220             :             virtual void SAL_CALL dropByIndex( sal_Int32 index ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     221             :             // XColumnLocate
     222             :             virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     223             :             // ::com::sun::star::container::XContainer
     224             :             virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     225             :             virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     226             :         private:
     227             :             void notifyElementRemoved(const OUString& _sName);
     228             :             void disposeElements();
     229             :             void dropImpl(sal_Int32 _nIndex, bool _bReallyDrop = true);
     230             :         };
     231             :     }
     232             : }
     233             : #endif // INCLUDED_CONNECTIVITY_SDBCX_VCOLLECTION_HXX
     234             : 
     235             : 
     236             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11