bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / connectivity / sdbcx / VCollection.hxx
blobbe79da04a8b70a256d44a7853749c493f70ed1d5
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/beans/XPropertySet.hpp>
28 #include <com/sun/star/util/XRefreshable.hpp>
29 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
30 #include <com/sun/star/sdbcx/XAppend.hpp>
31 #include <com/sun/star/sdbcx/XDrop.hpp>
32 #include <com/sun/star/sdbc/XColumnLocate.hpp>
33 #include <comphelper/interfacecontainer2.hxx>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <connectivity/CommonTools.hxx>
36 #include <com/sun/star/container/XContainer.hpp>
37 #include <connectivity/dbtoolsdllapi.hxx>
38 #include <memory>
40 namespace com::sun::star::container { class XEnumeration; }
43 namespace connectivity
45 namespace sdbcx
48 // the class OCollection is base class for collections :-)
49 typedef ::cppu::ImplHelper10< css::container::XNameAccess,
50 css::container::XIndexAccess,
51 css::container::XEnumerationAccess,
52 css::container::XContainer,
53 css::sdbc::XColumnLocate,
54 css::util::XRefreshable,
55 css::sdbcx::XDataDescriptorFactory,
56 css::sdbcx::XAppend,
57 css::sdbcx::XDrop,
58 css::lang::XServiceInfo> OCollectionBase;
60 typedef css::uno::Reference< css::beans::XPropertySet > ObjectType;
62 class OOO_DLLPUBLIC_DBTOOLS SAL_NO_VTABLE IObjectCollection
64 public:
65 virtual ~IObjectCollection();
66 virtual bool exists(const OUString& _sName ) = 0;
67 virtual bool empty() = 0;
68 virtual void swapAll() = 0;
69 virtual void swap() = 0;
70 virtual void clear() = 0;
71 virtual void reFill(const ::std::vector< OUString> &_rVector) = 0;
72 virtual void insert(const OUString& _sName, const ObjectType& _xObject) = 0;
73 virtual bool rename(const OUString& _sOldName, const OUString& _sNewName) = 0;
74 virtual sal_Int32 size() = 0;
75 virtual css::uno::Sequence< OUString > getElementNames() = 0;
76 virtual OUString getName(sal_Int32 _nIndex) = 0;
77 virtual void disposeAndErase(sal_Int32 _nIndex) = 0;
78 virtual void disposeElements() = 0;
79 virtual sal_Int32 findColumn( const OUString& columnName ) = 0;
80 virtual ObjectType getObject(sal_Int32 _nIndex) = 0;
81 virtual ObjectType getObject(const OUString& columnName) = 0;
82 virtual void setObject(sal_Int32 _nIndex,const ObjectType& _xObject) = 0;
83 virtual bool isCaseSensitive() const = 0;
86 // OCollection
88 class OOO_DLLPUBLIC_DBTOOLS SAL_NO_VTABLE OCollection :
89 public OCollectionBase
91 protected:
92 ::std::unique_ptr<IObjectCollection> m_pElements;
94 ::comphelper::OInterfaceContainerHelper2 m_aContainerListeners;
95 ::comphelper::OInterfaceContainerHelper2 m_aRefreshListeners;
97 protected:
98 ::cppu::OWeakObject& m_rParent; // parent of the collection
99 ::osl::Mutex& m_rMutex; // mutex of the parent
100 bool m_bUseIndexOnly; // is only TRUE when only an indexaccess is needed
102 // the implementing class should refresh their elements
103 /// @throws css::uno::RuntimeException
104 virtual void impl_refresh() = 0;
106 // will be called when a object was requested by one of the accessing methods like getByIndex
107 virtual ObjectType createObject(const OUString& _rName) = 0;
109 // will be called when a new object should be generated by a call of createDataDescriptor
110 // the returned object is empty will be filled outside and added to the collection
111 virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor();
113 /** appends an object described by a descriptor, under a given name
114 @param _rForName
115 is the name under which the object should be appended. Guaranteed to not be empty.
116 This is passed for convenience only, since it's the result of a call of
117 getNameForObject for the given descriptor
118 @param descriptor
119 describes the object to append
120 @return
121 the new object which is to be inserted into the collection. This might be the result
122 of a call of <code>createObject( _rForName )</code>, or a clone of the descriptor.
124 virtual ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor );
126 // called when XDrop was called
127 virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName);
129 /** returns the name for the object. The default implementation ask for the property NAME. If this doesn't satisfy, it has to be overridden.
130 @param _xObject The object where the name should be extracted.
131 @return The name of the object.
133 virtual OUString getNameForObject(const ObjectType& _xObject);
135 /** clones the given descriptor
137 The method calls createDescriptor to create a new, empty descriptor, and then copies all properties from
138 _descriptor to the new object, which is returned.
140 This method might come handy in derived classes for implementing appendObject, when the object
141 is not actually appended to any backend (e.g. for the columns collection of a descriptor object itself,
142 where there is not yet a database backend to append the column to).
144 ObjectType cloneDescriptor( const ObjectType& _descriptor );
146 OCollection(::cppu::OWeakObject& _rParent,
147 bool _bCase,
148 ::osl::Mutex& _rMutex,
149 const ::std::vector< OUString> &_rVector,
150 bool _bUseIndexOnly = false,
151 bool _bUseHardRef = true);
153 /** clear the name map
154 <p>Does <em>not</em> dispose the objects hold by the collection.</p>
156 void clear_NoDispose();
158 /** insert a new element into the collection
160 void insertElement(const OUString& _sElementName,const ObjectType& _xElement);
162 /** return the object, if not existent it creates it.
163 @param _nIndex
164 The index of the object to create.
165 @return ObjectType
167 ObjectType getObject(sal_Int32 _nIndex);
169 public:
170 virtual ~OCollection();
171 DECLARE_SERVICE_INFO();
173 void reFill(const ::std::vector< OUString> &_rVector);
174 bool isCaseSensitive() const { return m_pElements->isCaseSensitive(); }
175 void renameObject(const OUString& _sOldName, const OUString& _sNewName);
177 // only the name is identical to ::cppu::OComponentHelper
178 virtual void disposing();
179 // dispatch the refcounting to the parent
180 virtual void SAL_CALL acquire() throw() override;
181 virtual void SAL_CALL release() throw() override;
183 // XInterface
184 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
185 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
187 // css::container::XElementAccess
188 virtual css::uno::Type SAL_CALL getElementType( ) override;
189 virtual sal_Bool SAL_CALL hasElements( ) override;
190 // css::container::XIndexAccess
191 virtual sal_Int32 SAL_CALL getCount( ) override;
192 virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
194 // css::container::XNameAccess
195 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
196 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override;
197 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
198 // XEnumerationAccess
199 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration( ) override;
200 // css::util::XRefreshable
201 virtual void SAL_CALL refresh( ) override;
202 virtual void SAL_CALL addRefreshListener( const css::uno::Reference< css::util::XRefreshListener >& l ) override;
203 virtual void SAL_CALL removeRefreshListener( const css::uno::Reference< css::util::XRefreshListener >& l ) override;
204 // XDataDescriptorFactory
205 virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL createDataDescriptor( ) override;
206 // XAppend
207 virtual void SAL_CALL appendByDescriptor( const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override;
208 // XDrop
209 virtual void SAL_CALL dropByName( const OUString& elementName ) override;
210 virtual void SAL_CALL dropByIndex( sal_Int32 index ) override;
211 // XColumnLocate
212 virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) override;
213 // css::container::XContainer
214 virtual void SAL_CALL addContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
215 virtual void SAL_CALL removeContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
216 private:
217 void notifyElementRemoved(const OUString& _sName);
218 void disposeElements();
219 void dropImpl(sal_Int32 _nIndex, bool _bReallyDrop = true);
223 #endif // INCLUDED_CONNECTIVITY_SDBCX_VCOLLECTION_HXX
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */