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