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 _CONNECTIVITY_SDBCX_COLLECTION_HXX_
21 : #define _CONNECTIVITY_SDBCX_COLLECTION_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 <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>
43 :
44 :
45 : namespace connectivity
46 : {
47 : namespace sdbcx
48 : {
49 :
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;
61 :
62 : typedef ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > ObjectType;
63 :
64 4 : class OOO_DLLPUBLIC_DBTOOLS SAL_NO_VTABLE IObjectCollection
65 : {
66 : public:
67 : virtual ~IObjectCollection();
68 : virtual void reserve(size_t nLength) = 0;
69 : virtual bool exists(const ::rtl::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 ::rtl::OUString& _sName,const ObjectType& _xObject) = 0;
76 : virtual bool rename(const ::rtl::OUString _sOldName,const ::rtl::OUString _sNewName) = 0;
77 : virtual sal_Int32 size() = 0;
78 : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > getElementNames() = 0;
79 : virtual ::rtl::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 ::rtl::OUString& columnName ) = 0;
83 : virtual ::rtl::OUString findColumnAtIndex( sal_Int32 _nIndex) = 0;
84 : virtual ObjectType getObject(sal_Int32 _nIndex) = 0;
85 : virtual ObjectType getObject(const ::rtl::OUString& columnName) = 0;
86 : virtual void setObject(sal_Int32 _nIndex,const ObjectType& _xObject) = 0;
87 : virtual sal_Bool isCaseSensitive() const = 0;
88 : };
89 : //************************************************************
90 : // OCollection
91 : //************************************************************
92 : class OOO_DLLPUBLIC_DBTOOLS SAL_NO_VTABLE OCollection :
93 : public OCollectionBase
94 : {
95 : protected:
96 : ::std::auto_ptr<IObjectCollection> m_pElements;
97 :
98 : ::cppu::OInterfaceContainerHelper m_aContainerListeners;
99 : ::cppu::OInterfaceContainerHelper m_aRefreshListeners;
100 :
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
105 :
106 : // the implementing class should refresh their elements
107 : virtual void impl_refresh() throw(::com::sun::star::uno::RuntimeException) = 0;
108 :
109 : // will be called when a object was requested by one of the accessing methods like getByIndex
110 : virtual ObjectType createObject(const ::rtl::OUString& _rName) = 0;
111 :
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();
115 :
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.
126 : */
127 : virtual ObjectType appendObject( const ::rtl::OUString& _rForName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor );
128 :
129 : // called when XDrop was called
130 : virtual void dropObject(sal_Int32 _nPos,const ::rtl::OUString _sElementName);
131 :
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.
135 : */
136 : virtual ::rtl::OUString getNameForObject(const ObjectType& _xObject);
137 :
138 : /** clones the given descriptor
139 :
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.
142 :
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).
146 : */
147 : ObjectType cloneDescriptor( const ObjectType& _descriptor );
148 :
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);
155 :
156 : /** clear the name map
157 : <p>Does <em>not</em> dispose the objects hold by the collection.</p>
158 : */
159 : void clear_NoDispose();
160 :
161 : /** insert a new element into the collection
162 : */
163 : void insertElement(const ::rtl::OUString& _sElementName,const ObjectType& _xElement);
164 :
165 : /** return the name of element at index _nIndex
166 : */
167 : inline ::rtl::OUString getElementName(sal_Int32 _nIndex)
168 : {
169 : return m_pElements->findColumnAtIndex(_nIndex);
170 : }
171 :
172 :
173 : /** return the object, if not existent it creates it.
174 : @param _nIndex
175 : The index of the object to create.
176 : @return ObjectType
177 : */
178 : ObjectType getObject(sal_Int32 _nIndex);
179 :
180 : public:
181 : virtual ~OCollection();
182 : DECLARE_SERVICE_INFO();
183 :
184 : void reFill(const TStringVector &_rVector);
185 0 : inline sal_Bool isCaseSensitive() const { return m_pElements->isCaseSensitive(); }
186 : void renameObject(const ::rtl::OUString _sOldName,const ::rtl::OUString _sNewName);
187 :
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();
193 :
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);
197 :
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);
204 :
205 : // ::com::sun::star::container::XNameAccess
206 : virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::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< ::rtl::OUString > SAL_CALL getElementNames( ) throw(::com::sun::star::uno::RuntimeException);
208 : virtual sal_Bool SAL_CALL hasByName( const ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::OUString& _sName);
229 : void disposeElements();
230 : void dropImpl(sal_Int32 _nIndex,sal_Bool _bReallyDrop = sal_True);
231 : };
232 : }
233 : }
234 : #endif // _CONNECTIVITY_SDBCX_COLLECTION_HXX_
235 :
236 :
237 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|