1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _DBA_CORE_QUERYCONTAINER_HXX_
29 #define _DBA_CORE_QUERYCONTAINER_HXX_
30 
31 #ifndef _CPPUHELPER_IMPLBASE5_HXX_
32 #include <cppuhelper/implbase5.hxx>
33 #endif
34 #ifndef _COMPHELPER_STLTYPES_HXX_
35 #include <comphelper/stl_types.hxx>
36 #endif
37 #ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_
38 #include <cppuhelper/interfacecontainer.hxx>
39 #endif
40 
41 /** === begin UNO includes == **/
42 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #endif
45 #ifndef _COM_SUN_STAR_CONTAINER_XENUMERATIONACCESS_HPP_
46 #include <com/sun/star/container/XEnumerationAccess.hpp>
47 #endif
48 #ifndef _COM_SUN_STAR_CONTAINER_XCONTAINERLISTENER_HPP_
49 #include <com/sun/star/container/XContainerListener.hpp>
50 #endif
51 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
52 #include <com/sun/star/container/XNameContainer.hpp>
53 #endif
54 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
55 #include <com/sun/star/container/XNameAccess.hpp>
56 #endif
57 #ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_
58 #include <com/sun/star/container/XIndexAccess.hpp>
59 #endif
60 #ifndef _COM_SUN_STAR_CONTAINER_XCONTAINER_HPP_
61 #include <com/sun/star/container/XContainer.hpp>
62 #endif
63 #ifndef _COM_SUN_STAR_UTIL_XREFRESHABLE_HPP_
64 #include <com/sun/star/util/XRefreshable.hpp>
65 #endif
66 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
67 #include <com/sun/star/lang/XServiceInfo.hpp>
68 #endif
69 #ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_
70 #include <com/sun/star/uno/Sequence.hxx>
71 #endif
72 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
73 #include <com/sun/star/container/XNameContainer.hpp>
74 #endif
75 #ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_
76 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
77 #endif
78 #ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_
79 #include <com/sun/star/sdbcx/XAppend.hpp>
80 #endif
81 #ifndef _COM_SUN_STAR_SDBCX_XDROP_HPP_
82 #include <com/sun/star/sdbcx/XDrop.hpp>
83 #endif
84 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
85 #include <com/sun/star/sdbc/XConnection.hpp>
86 #endif
87 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYCHANGELISTENER_HPP_
88 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
89 #endif
90 #ifndef _COM_SUN_STAR_CONTAINER_XCONTAINERAPPROVELISTENER_HPP_
91 #include <com/sun/star/container/XContainerApproveListener.hpp>
92 #endif
93 /** === end UNO includes === **/
94 
95 #ifndef _DBA_CORE_DEFINITIONCONTAINER_HXX_
96 #include "definitioncontainer.hxx"
97 #endif
98 #ifndef _DBASHARED_APITOOLS_HXX_
99 #include "apitools.hxx"
100 #endif
101 
102 namespace dbtools
103 {
104 	class IWarningsContainer;
105 }
106 
107 //........................................................................
108 namespace dbaccess
109 {
110 //........................................................................
111 
112 	typedef ::cppu::ImplHelper5 <   ::com::sun::star::container::XContainerListener
113                                 ,   ::com::sun::star::container::XContainerApproveListener
114                                 ,   ::com::sun::star::sdbcx::XDataDescriptorFactory
115                                 ,   ::com::sun::star::sdbcx::XAppend
116                                 ,   ::com::sun::star::sdbcx::XDrop
117                                 >   OQueryContainer_Base;
118 
119 	//==========================================================================
120 	//= OQueryContainer
121 	//==========================================================================
122 	class OQueryContainer;
123     class OContainerListener;
124 	class OQuery;
125 	class OQueryContainer	: public ODefinitionContainer
126 							, public OQueryContainer_Base
127 	{
128 	protected:
129         ::dbtools::IWarningsContainer*  m_pWarnings;
130         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
131                                         m_xCommandDefinitions;
132         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >
133                                         m_xConnection;
134 		// possible actions on our "aggregate"
135 		enum AGGREGATE_ACTION { NONE, INSERTING, FLUSHING };
136 		AGGREGATE_ACTION		m_eDoingCurrently;
137 
138 		OContainerListener*     m_pCommandsListener;
139 
140 		// ------------------------------------------------------------------------
141 		/** a class which automatically resets m_eDoingCurrently in it's destructor
142 		*/
143 		class OAutoActionReset;	// just for the following friend declaration
144 		friend class OAutoActionReset;
145 		class OAutoActionReset
146 		{
147 			OQueryContainer*		m_pActor;
148 		public:
149 			OAutoActionReset(OQueryContainer* _pActor) : m_pActor(_pActor) { }
150 			~OAutoActionReset() { m_pActor->m_eDoingCurrently = NONE; }
151 		};
152 
153 		// ODefinitionContainer
154 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent > createObject( const ::rtl::OUString& _rName);
155 		virtual	sal_Bool checkExistence(const ::rtl::OUString& _rName);
156 
157 		// helper
158 		virtual void SAL_CALL disposing();
159 		virtual ~OQueryContainer();
160 	public:
161 		/** ctor of the container. The parent has to support the <type scope="com::sun::star::sdbc">XConnection</type>
162 			interface.<BR>
163 
164             @param _pWarnings
165 				specifies a warnings container (May be <NULL/>)
166 
167                 Any errors which occur during the lifetime of the query container,
168 				which cannot be reported as exceptionts (for instance in methods where throwing an SQLException is
169 				not allowed) will be appended to this container.</p>
170 				<p>The caller is responsible for ensuring the lifetime of the object pointed to by this parameter.
171 		*/
172 		OQueryContainer(
173 			const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& _rxCommandDefinitions,
174 			const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConn,
175 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
176 			::dbtools::IWarningsContainer* _pWarnings
177 			);
178 
179 		DECLARE_XINTERFACE( )
180 		DECLARE_XTYPEPROVIDER( )
181 		DECLARE_SERVICE_INFO();
182 
183 	// ::com::sun::star::container::XContainerListener
184 		virtual void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
185 		virtual void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
186 		virtual void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
187 
188         // XContainerApproveListener
189         virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XVeto > SAL_CALL approveInsertElement( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
190         virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XVeto > SAL_CALL approveReplaceElement( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
191         virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XVeto > SAL_CALL approveRemoveElement( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
192 
193 	// ::com::sun::star::lang::XEventListener
194 		virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
195 
196 	// ::com::sun::star::sdbcx::XDataDescriptorFactory
197 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > SAL_CALL createDataDescriptor(  ) throw(::com::sun::star::uno::RuntimeException);
198 
199 	// ::com::sun::star::sdbcx::XAppend
200 		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);
201 
202 	// ::com::sun::star::sdbcx::XDrop
203 		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);
204 		virtual void SAL_CALL dropByIndex( sal_Int32 index ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
205 
206 	// ::com::sun::star::container::XElementAccess
207 		virtual sal_Bool SAL_CALL hasElements(  ) throw(::com::sun::star::uno::RuntimeException);
208 	// ::com::sun::star::container::XIndexAccess
209 		virtual sal_Int32 SAL_CALL getCount(  ) throw(::com::sun::star::uno::RuntimeException);
210 	// ::com::sun::star::container::XNameAccess
211 		virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  ) throw(::com::sun::star::uno::RuntimeException);
212 
213     protected:
214         // OContentHelper overridables
215         virtual ::rtl::OUString determineContentType() const;
216 
217 	private:
218 		// helper
219 		/** create a query object wrapping a CommandDefinition given by name. To retrieve the object, the CommandDescription
220 			container will be asked for the given name.<BR>
221 			The returned object is acquired once.
222 		*/
223 		::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent > implCreateWrapper(const ::rtl::OUString& _rName);
224 		/// create a query object wrapping a CommandDefinition. The returned object is acquired once.
225 		::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent > implCreateWrapper(const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _rxCommandDesc);
226 
227 	};
228 //........................................................................
229 }	// namespace dbaccess
230 //........................................................................
231 
232 #endif // _DBA_CORE_QUERYCONTAINER_HXX_
233 
234 
235