bump product version to 4.2.0.1
[LibreOffice.git] / include / connectivity / sdbcx / VCollection.hxx
blob3bf79bf212855294d3df63bf0d8b9a2215b360f9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_CONNECTIVITY_SDBCX_VCOLLECTION_HXX
21 #define INCLUDED_CONNECTIVITY_SDBCX_VCOLLECTION_HXX
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 <comphelper/stl_types.hxx>
36 #include <cppuhelper/interfacecontainer.h>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <connectivity/CommonTools.hxx>
39 #include <com/sun/star/container/XContainer.hpp>
40 #include <connectivity/StdTypeDefs.hxx>
41 #include <connectivity/dbtoolsdllapi.hxx>
42 #include <memory>
45 namespace connectivity
47 namespace sdbcx
50 // the class OCollection is base class for collections :-)
51 typedef ::cppu::ImplHelper10< ::com::sun::star::container::XNameAccess,
52 ::com::sun::star::container::XIndexAccess,
53 ::com::sun::star::container::XEnumerationAccess,
54 ::com::sun::star::container::XContainer,
55 ::com::sun::star::sdbc::XColumnLocate,
56 ::com::sun::star::util::XRefreshable,
57 ::com::sun::star::sdbcx::XDataDescriptorFactory,
58 ::com::sun::star::sdbcx::XAppend,
59 ::com::sun::star::sdbcx::XDrop,
60 ::com::sun::star::lang::XServiceInfo> OCollectionBase;
62 typedef ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > ObjectType;
64 class OOO_DLLPUBLIC_DBTOOLS SAL_NO_VTABLE IObjectCollection
66 public:
67 virtual ~IObjectCollection();
68 virtual void reserve(size_t nLength) = 0;
69 virtual bool exists(const OUString& _sName ) = 0;
70 virtual bool empty() = 0;
71 virtual void swapAll() = 0;
72 virtual void swap() = 0;
73 virtual void clear() = 0;
74 virtual void reFill(const TStringVector &_rVector) = 0;
75 virtual void insert(const OUString& _sName,const ObjectType& _xObject) = 0;
76 virtual bool rename(const OUString _sOldName,const OUString _sNewName) = 0;
77 virtual sal_Int32 size() = 0;
78 virtual ::com::sun::star::uno::Sequence< OUString > getElementNames() = 0;
79 virtual OUString getName(sal_Int32 _nIndex) = 0;
80 virtual void disposeAndErase(sal_Int32 _nIndex) = 0;
81 virtual void disposeElements() = 0;
82 virtual sal_Int32 findColumn( const OUString& columnName ) = 0;
83 virtual OUString findColumnAtIndex( sal_Int32 _nIndex) = 0;
84 virtual ObjectType getObject(sal_Int32 _nIndex) = 0;
85 virtual ObjectType getObject(const OUString& columnName) = 0;
86 virtual void setObject(sal_Int32 _nIndex,const ObjectType& _xObject) = 0;
87 virtual sal_Bool isCaseSensitive() const = 0;
89 //************************************************************
90 // OCollection
91 //************************************************************
92 class OOO_DLLPUBLIC_DBTOOLS SAL_NO_VTABLE OCollection :
93 public OCollectionBase
95 protected:
96 ::std::auto_ptr<IObjectCollection> m_pElements;
98 ::cppu::OInterfaceContainerHelper m_aContainerListeners;
99 ::cppu::OInterfaceContainerHelper m_aRefreshListeners;
101 protected:
102 ::cppu::OWeakObject& m_rParent; // parent of the collection
103 ::osl::Mutex& m_rMutex; // mutex of the parent
104 sal_Bool m_bUseIndexOnly; // is only TRUE when only an indexaccess is needed
106 // the implementing class should refresh their elements
107 virtual void impl_refresh() throw(::com::sun::star::uno::RuntimeException) = 0;
109 // will be called when a object was requested by one of the accessing methods like getByIndex
110 virtual ObjectType createObject(const OUString& _rName) = 0;
112 // will be called when a new object should be generated by a call of createDataDescriptor
113 // the returned object is empty will be filled outside and added to the collection
114 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > createDescriptor();
116 /** appends an object described by a descriptor, under a given name
117 @param _rForName
118 is the name under which the object should be appended. Guaranteed to not be empty.
119 This is passed for convenience only, since it's the result of a call of
120 getNameForObject for the given descriptor
121 @param descriptor
122 describes the object to append
123 @return
124 the new object which is to be inserted into the collection. This might be the result
125 of a call of <code>createObject( _rForName )</code>, or a clone of the descriptor.
127 virtual ObjectType appendObject( const OUString& _rForName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor );
129 // called when XDrop was called
130 virtual void dropObject(sal_Int32 _nPos,const OUString _sElementName);
132 /** returns the name for the object. The default implementation ask for the property NAME. If this doesn't satisfy, it has to be overloaded.
133 @param _xObject The object where the name should be extracted.
134 @return The name of the object.
136 virtual OUString getNameForObject(const ObjectType& _xObject);
138 /** clones the given descriptor
140 The method calls createDescriptor to create a new, empty descriptor, and then copies all properties from
141 _descriptor to the new object, which is returned.
143 This method might come handy in derived classes for implementing appendObject, when the object
144 is not actually appended to any backend (e.g. for the columns collection of a descriptor object itself,
145 where there is not yet a database backend to append the column to).
147 ObjectType cloneDescriptor( const ObjectType& _descriptor );
149 OCollection(::cppu::OWeakObject& _rParent,
150 sal_Bool _bCase,
151 ::osl::Mutex& _rMutex,
152 const TStringVector &_rVector,
153 sal_Bool _bUseIndexOnly = sal_False,
154 sal_Bool _bUseHardRef = sal_True);
156 /** clear the name map
157 <p>Does <em>not</em> dispose the objects hold by the collection.</p>
159 void clear_NoDispose();
161 /** insert a new element into the collection
163 void insertElement(const OUString& _sElementName,const ObjectType& _xElement);
165 /** return the name of element at index _nIndex
167 inline OUString getElementName(sal_Int32 _nIndex)
169 return m_pElements->findColumnAtIndex(_nIndex);
173 /** return the object, if not existent it creates it.
174 @param _nIndex
175 The index of the object to create.
176 @return ObjectType
178 ObjectType getObject(sal_Int32 _nIndex);
180 public:
181 virtual ~OCollection();
182 DECLARE_SERVICE_INFO();
184 void reFill(const TStringVector &_rVector);
185 inline sal_Bool isCaseSensitive() const { return m_pElements->isCaseSensitive(); }
186 void renameObject(const OUString _sOldName,const OUString _sNewName);
188 // only the name is identical to ::cppu::OComponentHelper
189 virtual void SAL_CALL disposing(void);
190 // dispatch the refcounting to the parent
191 virtual void SAL_CALL acquire() throw();
192 virtual void SAL_CALL release() throw();
194 // XInterface
195 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException);
196 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException);
198 // ::com::sun::star::container::XElementAccess
199 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException);
200 virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException);
201 // ::com::sun::star::container::XIndexAccess
202 virtual sal_Int32 SAL_CALL getCount( ) throw(::com::sun::star::uno::RuntimeException);
203 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);
205 // ::com::sun::star::container::XNameAccess
206 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);
207 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames( ) throw(::com::sun::star::uno::RuntimeException);
208 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw(::com::sun::star::uno::RuntimeException);
209 // XEnumerationAccess
210 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration( ) throw(::com::sun::star::uno::RuntimeException);
211 // ::com::sun::star::util::XRefreshable
212 virtual void SAL_CALL refresh( ) throw(::com::sun::star::uno::RuntimeException);
213 virtual void SAL_CALL addRefreshListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener >& l ) throw(::com::sun::star::uno::RuntimeException);
214 virtual void SAL_CALL removeRefreshListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener >& l ) throw(::com::sun::star::uno::RuntimeException);
215 // XDataDescriptorFactory
216 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > SAL_CALL createDataDescriptor( ) throw(::com::sun::star::uno::RuntimeException);
217 // XAppend
218 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);
219 // XDrop
220 virtual void SAL_CALL dropByName( const OUString& elementName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
221 virtual void SAL_CALL dropByIndex( sal_Int32 index ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
222 // XColumnLocate
223 virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
224 // ::com::sun::star::container::XContainer
225 virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
226 virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
227 private:
228 void notifyElementRemoved(const OUString& _sName);
229 void disposeElements();
230 void dropImpl(sal_Int32 _nIndex,sal_Bool _bReallyDrop = sal_True);
234 #endif // INCLUDED_CONNECTIVITY_SDBCX_VCOLLECTION_HXX
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */