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