Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / postgresql / pq_xcontainer.hxx
blob0800e09735eab9a26e6cc9dc1b28684a6a72dadb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * Effective License of whole file:
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.
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.
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
20 * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
22 * The Contents of this file are made available subject to the terms of
23 * the GNU Lesser General Public License Version 2.1
25 * Copyright: 2000 by Sun Microsystems, Inc.
27 * Contributor(s): Joerg Budischewski
29 * All parts contributed on or after August 2011:
31 * This Source Code Form is subject to the terms of the Mozilla Public
32 * License, v. 2.0. If a copy of the MPL was not distributed with this
33 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
35 ************************************************************************/
37 #ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XCONTAINER_HXX
38 #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XCONTAINER_HXX
39 #include <boost/unordered_map.hpp>
40 #include <vector>
42 #include <com/sun/star/container/XNameAccess.hpp>
43 #include <com/sun/star/container/XIndexAccess.hpp>
44 #include <com/sun/star/container/XEnumerationAccess.hpp>
45 #include <com/sun/star/container/XContainer.hpp>
47 #include <com/sun/star/sdbcx/XAppend.hpp>
48 #include <com/sun/star/sdbcx/XDrop.hpp>
49 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
51 #include <com/sun/star/util/XRefreshable.hpp>
53 #include <cppuhelper/compbase8.hxx>
55 #include "pq_connection.hxx"
56 #include "pq_statics.hxx"
58 namespace pq_sdbc_driver
61 class EventBroadcastHelper
63 public:
64 virtual void fire(com::sun::star::lang::XEventListener * listener) const = 0;
65 virtual com::sun::star::uno::Type getType() const = 0;
66 virtual ~EventBroadcastHelper(){};
69 class RefreshedBroadcaster : public EventBroadcastHelper
71 com::sun::star::lang::EventObject m_event;
72 public:
73 RefreshedBroadcaster(const com::sun::star::uno::Reference< com::sun::star::uno::XInterface > & source ) :
74 m_event( source )
77 virtual void fire( com::sun::star::lang::XEventListener * listener ) const SAL_OVERRIDE
79 ((com::sun::star::util::XRefreshListener*)listener)->refreshed( m_event );
82 virtual com::sun::star::uno::Type getType() const SAL_OVERRIDE
84 return getCppuType(
85 (com::sun::star::uno::Reference< com::sun::star::util::XRefreshListener > *)0 );
89 typedef ::boost::unordered_map
91 OUString,
92 sal_Int32,
93 OUStringHash,
94 ::std::equal_to< OUString >
95 > String2IntMap;
97 typedef ::cppu::WeakComponentImplHelper8
99 com::sun::star::container::XNameAccess,
100 com::sun::star::container::XIndexAccess,
101 com::sun::star::container::XEnumerationAccess,
102 com::sun::star::sdbcx::XAppend,
103 com::sun::star::sdbcx::XDrop,
104 com::sun::star::util::XRefreshable,
105 com::sun::star::sdbcx::XDataDescriptorFactory,
106 com::sun::star::container::XContainer
107 > ContainerBase;
109 class /* abstract */ Container : public ContainerBase
111 protected:
112 ::rtl::Reference< RefCountedMutex > m_refMutex;
113 ConnectionSettings *m_pSettings;
114 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > m_origin;
115 String2IntMap m_name2index; // maps the element name to an index
116 ::com::sun::star::uno::Sequence< com::sun::star::uno::Any > m_values; // contains the real values
117 OUString m_type;
119 public:
120 Container(
121 const ::rtl::Reference< RefCountedMutex > & refMutex,
122 const ::com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > & origin,
123 ConnectionSettings *pSettings,
124 const OUString & type // for exception messages
127 public: // XIndexAccess
128 virtual sal_Int32 SAL_CALL getCount( )
129 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
130 virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index )
131 throw (::com::sun::star::lang::IndexOutOfBoundsException,
132 ::com::sun::star::lang::WrappedTargetException,
133 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
135 public: // XEnumerationAccess
136 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration >
137 SAL_CALL createEnumeration( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
139 public: // XNameAccess
140 virtual ::com::sun::star::uno::Any SAL_CALL getByName( const OUString& aName )
141 throw (::com::sun::star::container::NoSuchElementException,
142 ::com::sun::star::lang::WrappedTargetException,
143 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
144 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames( )
145 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
146 virtual sal_Bool SAL_CALL hasByName( const OUString& aName )
147 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
148 // Methods
149 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( )
150 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
151 virtual sal_Bool SAL_CALL hasElements( )
152 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
155 public: // XAppend
156 // Must be overridden in Non-Descriptors. May be overridden in descriptors, when
157 // PropertySet.NAME != container name
158 virtual void SAL_CALL appendByDescriptor(
159 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor )
160 throw (::com::sun::star::sdbc::SQLException,
161 ::com::sun::star::container::ElementExistException,
162 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
164 // helper method !
165 void append(
166 const OUString & str,
167 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor )
168 throw ( ::com::sun::star::container::ElementExistException );
171 public: // XDrop
172 virtual void SAL_CALL dropByName( const OUString& elementName )
173 throw (::com::sun::star::sdbc::SQLException,
174 ::com::sun::star::container::NoSuchElementException,
175 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
176 virtual void SAL_CALL dropByIndex( sal_Int32 index )
177 throw (::com::sun::star::sdbc::SQLException,
178 ::com::sun::star::lang::IndexOutOfBoundsException,
179 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
181 public: // XDataDescriptorFactory
182 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > SAL_CALL createDataDescriptor( )
183 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE = 0;
185 public: // XRefreshable
186 virtual void SAL_CALL refresh( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE {}
187 virtual void SAL_CALL addRefreshListener(
188 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener >& l )
189 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
190 virtual void SAL_CALL removeRefreshListener(
191 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener >& l )
192 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
194 public:
195 // Methods
196 virtual void SAL_CALL addContainerListener(
197 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener )
198 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
199 virtual void SAL_CALL removeContainerListener(
200 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener )
201 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
203 public:
204 virtual void SAL_CALL disposing() SAL_OVERRIDE;
206 public:
207 void rename( const OUString & oldName, const OUString &newName );
209 protected:
210 void fire( const EventBroadcastHelper & helper );
214 #endif
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */