Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * Effective License of whole file:
5 : : *
6 : : * This library is free software; you can redistribute it and/or
7 : : * modify it under the terms of the GNU Lesser General Public
8 : : * License version 2.1, as published by the Free Software Foundation.
9 : : *
10 : : * This library is distributed in the hope that it will be useful,
11 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 : : * Lesser General Public License for more details.
14 : : *
15 : : * You should have received a copy of the GNU Lesser General Public
16 : : * License along with this library; if not, write to the Free Software
17 : : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 : : * MA 02111-1307 USA
19 : : *
20 : : * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
21 : : *
22 : : * The Contents of this file are made available subject to the terms of
23 : : * the GNU Lesser General Public License Version 2.1
24 : : *
25 : : * Copyright: 2000 by Sun Microsystems, Inc.
26 : : *
27 : : * Contributor(s): Joerg Budischewski
28 : : *
29 : : * All parts contributed on or after August 2011:
30 : : *
31 : : * Version: MPL 1.1 / GPLv3+ / LGPLv2.1+
32 : : *
33 : : * The contents of this file are subject to the Mozilla Public License Version
34 : : * 1.1 (the "License"); you may not use this file except in compliance with
35 : : * the License or as specified alternatively below. You may obtain a copy of
36 : : * the License at http://www.mozilla.org/MPL/
37 : : *
38 : : * Software distributed under the License is distributed on an "AS IS" basis,
39 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
40 : : * for the specific language governing rights and limitations under the
41 : : * License.
42 : : *
43 : : * Major Contributor(s):
44 : : * [ Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu> ]
45 : : *
46 : : * All Rights Reserved.
47 : : *
48 : : * For minor contributions see the git repository.
49 : : *
50 : : * Alternatively, the contents of this file may be used under the terms of
51 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
52 : : * the GNU Lesser General Public License Version 2.1 or later (the "LGPLv2.1+"),
53 : : * in which case the provisions of the GPLv3+ or the LGPLv2.1+ are applicable
54 : : * instead of those above.
55 : : *
56 : : ************************************************************************/
57 : :
58 : : #ifndef _PQ_CONTAINER_HXX_
59 : : #define _PQ_CONTAINER_HXX_
60 : : #include <boost/unordered_map.hpp>
61 : : #include <vector>
62 : :
63 : : #include <com/sun/star/container/XNameAccess.hpp>
64 : : #include <com/sun/star/container/XIndexAccess.hpp>
65 : : #include <com/sun/star/container/XEnumerationAccess.hpp>
66 : : #include <com/sun/star/container/XContainer.hpp>
67 : :
68 : : #include <com/sun/star/sdbcx/XAppend.hpp>
69 : : #include <com/sun/star/sdbcx/XDrop.hpp>
70 : : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
71 : :
72 : : #include <com/sun/star/util/XRefreshable.hpp>
73 : :
74 : : #include <cppuhelper/compbase8.hxx>
75 : :
76 : : #include "pq_connection.hxx"
77 : : #include "pq_statics.hxx"
78 : :
79 : : namespace pq_sdbc_driver
80 : : {
81 : :
82 : 0 : class EventBroadcastHelper
83 : : {
84 : : public:
85 : : virtual void fire(com::sun::star::lang::XEventListener * listener) const = 0;
86 : : virtual com::sun::star::uno::Type getType() const = 0;
87 : 0 : virtual ~EventBroadcastHelper(){};
88 : : };
89 : :
90 : 0 : class RefreshedBroadcaster : public EventBroadcastHelper
91 : : {
92 : : com::sun::star::lang::EventObject m_event;
93 : : public:
94 : 0 : RefreshedBroadcaster(const com::sun::star::uno::Reference< com::sun::star::uno::XInterface > & source ) :
95 : 0 : m_event( source )
96 : 0 : {}
97 : :
98 : 0 : virtual void fire( com::sun::star::lang::XEventListener * listener ) const
99 : : {
100 : 0 : ((com::sun::star::util::XRefreshListener*)listener)->refreshed( m_event );
101 : 0 : }
102 : :
103 : 0 : virtual com::sun::star::uno::Type getType() const
104 : : {
105 : : return getCppuType(
106 : 0 : (com::sun::star::uno::Reference< com::sun::star::util::XRefreshListener > *)0 );
107 : : }
108 : : };
109 : :
110 : : typedef ::boost::unordered_map
111 : : <
112 : : rtl::OUString,
113 : : sal_Int32,
114 : : rtl::OUStringHash,
115 : : ::std::equal_to< rtl::OUString >,
116 : : Allocator< ::std::pair< const ::rtl::OUString , sal_Int32 > >
117 : : > String2IntMap;
118 : :
119 : : typedef ::cppu::WeakComponentImplHelper8
120 : : <
121 : : com::sun::star::container::XNameAccess,
122 : : com::sun::star::container::XIndexAccess,
123 : : com::sun::star::container::XEnumerationAccess,
124 : : com::sun::star::sdbcx::XAppend,
125 : : com::sun::star::sdbcx::XDrop,
126 : : com::sun::star::util::XRefreshable,
127 : : com::sun::star::sdbcx::XDataDescriptorFactory,
128 : : com::sun::star::container::XContainer
129 : : > ContainerBase;
130 : :
131 : 0 : class /* abstract */ Container : public ContainerBase
132 : : {
133 : : protected:
134 : : ::rtl::Reference< RefCountedMutex > m_refMutex;
135 : : ConnectionSettings *m_pSettings;
136 : : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > m_origin;
137 : : String2IntMap m_name2index; // maps the element name to an index
138 : : ::com::sun::star::uno::Sequence< com::sun::star::uno::Any > m_values; // contains the real values
139 : : ::rtl::OUString m_type;
140 : :
141 : : public:
142 : : Container(
143 : : const ::rtl::Reference< RefCountedMutex > & refMutex,
144 : : const ::com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > & origin,
145 : : ConnectionSettings *pSettings,
146 : : const ::rtl::OUString & type // for exception messages
147 : : );
148 : :
149 : : public: // XIndexAccess
150 : : virtual sal_Int32 SAL_CALL getCount( )
151 : : throw (::com::sun::star::uno::RuntimeException);
152 : : virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index )
153 : : throw (::com::sun::star::lang::IndexOutOfBoundsException,
154 : : ::com::sun::star::lang::WrappedTargetException,
155 : : ::com::sun::star::uno::RuntimeException);
156 : :
157 : : public: // XEnumerationAccess
158 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration >
159 : : SAL_CALL createEnumeration( ) throw (::com::sun::star::uno::RuntimeException);
160 : :
161 : : public: // XNameAccess
162 : : virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
163 : : throw (::com::sun::star::container::NoSuchElementException,
164 : : ::com::sun::star::lang::WrappedTargetException,
165 : : ::com::sun::star::uno::RuntimeException);
166 : : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( )
167 : : throw (::com::sun::star::uno::RuntimeException);
168 : : virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
169 : : throw (::com::sun::star::uno::RuntimeException);
170 : : // Methods
171 : : virtual ::com::sun::star::uno::Type SAL_CALL getElementType( )
172 : : throw (::com::sun::star::uno::RuntimeException);
173 : : virtual sal_Bool SAL_CALL hasElements( )
174 : : throw (::com::sun::star::uno::RuntimeException);
175 : :
176 : :
177 : : public: // XAppend
178 : : // Must be overriden in Non-Descriptors. May be overriden in descriptors, when
179 : : // PropertySet.NAME != container name
180 : : virtual void SAL_CALL appendByDescriptor(
181 : : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor )
182 : : throw (::com::sun::star::sdbc::SQLException,
183 : : ::com::sun::star::container::ElementExistException,
184 : : ::com::sun::star::uno::RuntimeException);
185 : :
186 : : // helper method !
187 : : void append(
188 : : const rtl::OUString & str,
189 : : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor )
190 : : throw ( ::com::sun::star::container::ElementExistException );
191 : :
192 : :
193 : : public: // XDrop
194 : : virtual void SAL_CALL dropByName( const ::rtl::OUString& elementName )
195 : : throw (::com::sun::star::sdbc::SQLException,
196 : : ::com::sun::star::container::NoSuchElementException,
197 : : ::com::sun::star::uno::RuntimeException);
198 : : virtual void SAL_CALL dropByIndex( sal_Int32 index )
199 : : throw (::com::sun::star::sdbc::SQLException,
200 : : ::com::sun::star::lang::IndexOutOfBoundsException,
201 : : ::com::sun::star::uno::RuntimeException);
202 : :
203 : : public: // XDataDescriptorFactory
204 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > SAL_CALL createDataDescriptor( )
205 : : throw (::com::sun::star::uno::RuntimeException) = 0;
206 : :
207 : : public: // XRefreshable
208 : 0 : virtual void SAL_CALL refresh( ) throw (::com::sun::star::uno::RuntimeException) {}
209 : : virtual void SAL_CALL addRefreshListener(
210 : : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener >& l )
211 : : throw (::com::sun::star::uno::RuntimeException);
212 : : virtual void SAL_CALL removeRefreshListener(
213 : : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener >& l )
214 : : throw (::com::sun::star::uno::RuntimeException);
215 : :
216 : : public:
217 : : // Methods
218 : : virtual void SAL_CALL addContainerListener(
219 : : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener )
220 : : throw (::com::sun::star::uno::RuntimeException);
221 : : virtual void SAL_CALL removeContainerListener(
222 : : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener )
223 : : throw (::com::sun::star::uno::RuntimeException);
224 : :
225 : : public:
226 : : virtual void SAL_CALL disposing();
227 : :
228 : : public:
229 : : void rename( const rtl::OUString & oldName, const rtl::OUString &newName );
230 : :
231 : : protected:
232 : : void fire( const EventBroadcastHelper & helper );
233 : : };
234 : :
235 : : }
236 : : #endif
|