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,
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 * Version: MPL 1.1 / GPLv3+ / LGPLv2.1+
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/
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
43 * Major Contributor(s):
44 * [ Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu> ]
46 * All Rights Reserved.
48 * For minor contributions see the git repository.
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.
56 ************************************************************************/
58 #ifndef _PQ_CONTAINER_HXX_
59 #define _PQ_CONTAINER_HXX_
60 #include <boost/unordered_map.hpp>
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>
68 #include <com/sun/star/sdbcx/XAppend.hpp>
69 #include <com/sun/star/sdbcx/XDrop.hpp>
70 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
72 #include <com/sun/star/util/XRefreshable.hpp>
74 #include <cppuhelper/compbase8.hxx>
76 #include "pq_connection.hxx"
77 #include "pq_statics.hxx"
79 namespace pq_sdbc_driver
82 class EventBroadcastHelper
85 virtual void fire(com::sun::star::lang::XEventListener
* listener
) const = 0;
86 virtual com::sun::star::uno::Type
getType() const = 0;
87 virtual ~EventBroadcastHelper(){};
90 class RefreshedBroadcaster
: public EventBroadcastHelper
92 com::sun::star::lang::EventObject m_event
;
94 RefreshedBroadcaster(const com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> & source
) :
98 virtual void fire( com::sun::star::lang::XEventListener
* listener
) const
100 ((com::sun::star::util::XRefreshListener
*)listener
)->refreshed( m_event
);
103 virtual com::sun::star::uno::Type
getType() const
106 (com::sun::star::uno::Reference
< com::sun::star::util::XRefreshListener
> *)0 );
110 typedef ::boost::unordered_map
115 ::std::equal_to
< rtl::OUString
>,
116 Allocator
< ::std::pair
< const ::rtl::OUString
, sal_Int32
> >
119 typedef ::cppu::WeakComponentImplHelper8
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
131 class /* abstract */ Container
: public ContainerBase
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
;
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
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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;
207 public: // XRefreshable
208 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
);
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
);
226 virtual void SAL_CALL
disposing();
229 void rename( const rtl::OUString
& oldName
, const rtl::OUString
&newName
);
232 void fire( const EventBroadcastHelper
& helper
);