1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*96de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*96de5490SAndrew Rist * distributed with this work for additional information
6*96de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*96de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist * with the License. You may obtain a copy of the License at
10*96de5490SAndrew Rist *
11*96de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist *
13*96de5490SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist * software distributed under the License is distributed on an
15*96de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist * KIND, either express or implied. See the License for the
17*96de5490SAndrew Rist * specific language governing permissions and limitations
18*96de5490SAndrew Rist * under the License.
19*96de5490SAndrew Rist *
20*96de5490SAndrew Rist *************************************************************/
21*96de5490SAndrew Rist
22*96de5490SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #ifndef _DBA_CORE_QUERYCONTAINER_HXX_
28cdf0e10cSrcweir #include "querycontainer.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
31cdf0e10cSrcweir #include "dbastrings.hrc"
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #ifndef _DBA_COREAPI_QUERY_HXX_
34cdf0e10cSrcweir #include "query.hxx"
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #ifndef DBACCESS_OBJECTNAMEAPPROVAL_HXX
37cdf0e10cSrcweir #include "objectnameapproval.hxx"
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #ifndef DBA_CONTAINERLISTENER_HXX
40cdf0e10cSrcweir #include "ContainerListener.hxx"
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #ifndef DBACCESS_VETO_HXX
43cdf0e10cSrcweir #include "veto.hxx"
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir
46cdf0e10cSrcweir /** === begin UNO includes === **/
47cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
48cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
49cdf0e10cSrcweir #endif
50cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XCONTAINER_HPP_
51cdf0e10cSrcweir #include <com/sun/star/container/XContainer.hpp>
52cdf0e10cSrcweir #endif
53cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
54cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
55cdf0e10cSrcweir #endif
56cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XCONTAINERAPPROVEBROADCASTER_HPP_
57cdf0e10cSrcweir #include <com/sun/star/container/XContainerApproveBroadcaster.hpp>
58cdf0e10cSrcweir #endif
59cdf0e10cSrcweir /** === end UNO includes === **/
60cdf0e10cSrcweir
61cdf0e10cSrcweir #ifndef _DBHELPER_DBEXCEPTION_HXX_
62cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
63cdf0e10cSrcweir #endif
64cdf0e10cSrcweir
65cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
66cdf0e10cSrcweir #include <tools/debug.hxx>
67cdf0e10cSrcweir #endif
68cdf0e10cSrcweir #ifndef _COMPHELPER_ENUMHELPER_HXX_
69cdf0e10cSrcweir #include <comphelper/enumhelper.hxx>
70cdf0e10cSrcweir #endif
71cdf0e10cSrcweir #ifndef _COMPHELPER_UNO3_HXX_
72cdf0e10cSrcweir #include <comphelper/uno3.hxx>
73cdf0e10cSrcweir #endif
74cdf0e10cSrcweir #ifndef _COMPHELPER_PROPERTY_HXX_
75cdf0e10cSrcweir #include <comphelper/property.hxx>
76cdf0e10cSrcweir #endif
77cdf0e10cSrcweir #ifndef _COMPHELPER_SEQUENCE_HXX_
78cdf0e10cSrcweir #include <comphelper/sequence.hxx>
79cdf0e10cSrcweir #endif
80cdf0e10cSrcweir #ifndef _COMPHELPER_EXTRACT_HXX_
81cdf0e10cSrcweir #include <comphelper/extract.hxx>
82cdf0e10cSrcweir #endif
83cdf0e10cSrcweir #ifndef _CPPUHELPER_EXC_HLP_HXX_
84cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
85cdf0e10cSrcweir #endif
86cdf0e10cSrcweir
87cdf0e10cSrcweir using namespace dbtools;
88cdf0e10cSrcweir using namespace ::com::sun::star::uno;
89cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
90cdf0e10cSrcweir using namespace ::com::sun::star::lang;
91cdf0e10cSrcweir using namespace ::com::sun::star::beans;
92cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
93cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
94cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
95cdf0e10cSrcweir using namespace ::com::sun::star::container;
96cdf0e10cSrcweir using namespace ::com::sun::star::util;
97cdf0e10cSrcweir using namespace ::osl;
98cdf0e10cSrcweir using namespace ::comphelper;
99cdf0e10cSrcweir using namespace ::cppu;
100cdf0e10cSrcweir
101cdf0e10cSrcweir //........................................................................
102cdf0e10cSrcweir namespace dbaccess
103cdf0e10cSrcweir {
104cdf0e10cSrcweir //........................................................................
105cdf0e10cSrcweir
106cdf0e10cSrcweir //==========================================================================
107cdf0e10cSrcweir //= OQueryContainer
108cdf0e10cSrcweir //==========================================================================
DBG_NAME(OQueryContainer)109cdf0e10cSrcweir DBG_NAME(OQueryContainer)
110cdf0e10cSrcweir //------------------------------------------------------------------------------
111cdf0e10cSrcweir OQueryContainer::OQueryContainer(
112cdf0e10cSrcweir const Reference< XNameContainer >& _rxCommandDefinitions
113cdf0e10cSrcweir , const Reference< XConnection >& _rxConn
114cdf0e10cSrcweir , const Reference< XMultiServiceFactory >& _rxORB,
115cdf0e10cSrcweir ::dbtools::IWarningsContainer* _pWarnings)
116cdf0e10cSrcweir :ODefinitionContainer(_rxORB,NULL,TContentPtr(new ODefinitionContainer_Impl))
117cdf0e10cSrcweir ,m_pWarnings( _pWarnings )
118cdf0e10cSrcweir ,m_xCommandDefinitions(_rxCommandDefinitions)
119cdf0e10cSrcweir ,m_xConnection(_rxConn)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir DBG_CTOR(OQueryContainer, NULL);
122cdf0e10cSrcweir
123cdf0e10cSrcweir increment(m_refCount);
124cdf0e10cSrcweir {
125cdf0e10cSrcweir m_pCommandsListener = new OContainerListener( *this, m_aMutex );
126cdf0e10cSrcweir m_pCommandsListener->acquire();
127cdf0e10cSrcweir
128cdf0e10cSrcweir Reference< XContainer > xContainer( m_xCommandDefinitions, UNO_QUERY_THROW );
129cdf0e10cSrcweir xContainer->addContainerListener( m_pCommandsListener );
130cdf0e10cSrcweir
131cdf0e10cSrcweir Reference< XContainerApproveBroadcaster > xContainerApprove( m_xCommandDefinitions, UNO_QUERY_THROW );
132cdf0e10cSrcweir xContainerApprove->addContainerApproveListener( m_pCommandsListener );
133cdf0e10cSrcweir
134cdf0e10cSrcweir // fill my structures
135cdf0e10cSrcweir ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
136cdf0e10cSrcweir Sequence< ::rtl::OUString > sDefinitionNames = m_xCommandDefinitions->getElementNames();
137cdf0e10cSrcweir const ::rtl::OUString* pDefinitionName = sDefinitionNames.getConstArray();
138cdf0e10cSrcweir const ::rtl::OUString* pEnd = pDefinitionName + sDefinitionNames.getLength();
139cdf0e10cSrcweir for ( ; pDefinitionName != pEnd; ++pDefinitionName )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir rDefinitions.insert( *pDefinitionName, TContentPtr() );
142cdf0e10cSrcweir m_aDocuments.push_back(m_aDocumentMap.insert(Documents::value_type(*pDefinitionName,Documents::mapped_type())).first);
143cdf0e10cSrcweir }
144cdf0e10cSrcweir }
145cdf0e10cSrcweir decrement(m_refCount);
146cdf0e10cSrcweir
147cdf0e10cSrcweir setElementApproval( PContainerApprove( new ObjectNameApproval( _rxConn, ObjectNameApproval::TypeQuery ) ) );
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
150cdf0e10cSrcweir //------------------------------------------------------------------------------
~OQueryContainer()151cdf0e10cSrcweir OQueryContainer::~OQueryContainer()
152cdf0e10cSrcweir {
153cdf0e10cSrcweir DBG_DTOR(OQueryContainer, NULL);
154cdf0e10cSrcweir // dispose();
155cdf0e10cSrcweir // maybe we're already disposed, but this should be uncritical
156cdf0e10cSrcweir }
157cdf0e10cSrcweir // -----------------------------------------------------------------------------
IMPLEMENT_FORWARD_XINTERFACE2(OQueryContainer,ODefinitionContainer,OQueryContainer_Base)158cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( OQueryContainer,ODefinitionContainer,OQueryContainer_Base)
159cdf0e10cSrcweir
160cdf0e10cSrcweir //------------------------------------------------------------------------------
161cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( OQueryContainer,ODefinitionContainer,OQueryContainer_Base)
162cdf0e10cSrcweir
163cdf0e10cSrcweir //------------------------------------------------------------------------------
164cdf0e10cSrcweir void OQueryContainer::disposing()
165cdf0e10cSrcweir {
166cdf0e10cSrcweir ODefinitionContainer::disposing();
167cdf0e10cSrcweir MutexGuard aGuard(m_aMutex);
168cdf0e10cSrcweir if ( !m_xCommandDefinitions.is() )
169cdf0e10cSrcweir // already disposed
170cdf0e10cSrcweir return;
171cdf0e10cSrcweir
172cdf0e10cSrcweir if ( m_pCommandsListener )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir Reference< XContainer > xContainer( m_xCommandDefinitions, UNO_QUERY );
175cdf0e10cSrcweir xContainer->removeContainerListener( m_pCommandsListener );
176cdf0e10cSrcweir Reference< XContainerApproveBroadcaster > xContainerApprove( m_xCommandDefinitions, UNO_QUERY );
177cdf0e10cSrcweir xContainerApprove->removeContainerApproveListener( m_pCommandsListener );
178cdf0e10cSrcweir
179cdf0e10cSrcweir m_pCommandsListener->dispose();
180cdf0e10cSrcweir m_pCommandsListener->release();
181cdf0e10cSrcweir m_pCommandsListener = NULL;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir
184cdf0e10cSrcweir m_xCommandDefinitions = NULL;
185cdf0e10cSrcweir m_xConnection = NULL;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir
188cdf0e10cSrcweir // XServiceInfo
189cdf0e10cSrcweir //------------------------------------------------------------------------------
190cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO2(OQueryContainer, "com.sun.star.sdb.dbaccess.OQueryContainer", SERVICE_SDBCX_CONTAINER, SERVICE_SDB_QUERIES)
191cdf0e10cSrcweir
192cdf0e10cSrcweir // XDataDescriptorFactory
193cdf0e10cSrcweir //--------------------------------------------------------------------------
createDataDescriptor()194cdf0e10cSrcweir Reference< XPropertySet > SAL_CALL OQueryContainer::createDataDescriptor( ) throw(RuntimeException)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir return new OQueryDescriptor();
197cdf0e10cSrcweir }
198cdf0e10cSrcweir
199cdf0e10cSrcweir // XAppend
200cdf0e10cSrcweir //------------------------------------------------------------------------------
appendByDescriptor(const Reference<XPropertySet> & _rxDesc)201cdf0e10cSrcweir void SAL_CALL OQueryContainer::appendByDescriptor( const Reference< XPropertySet >& _rxDesc ) throw(SQLException, ElementExistException, RuntimeException)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir ResettableMutexGuard aGuard(m_aMutex);
204cdf0e10cSrcweir if ( !m_xCommandDefinitions.is() )
205cdf0e10cSrcweir throw DisposedException( ::rtl::OUString(), *this );
206cdf0e10cSrcweir
207cdf0e10cSrcweir // first clone this object's CommandDefinition part
208cdf0e10cSrcweir Reference< XPropertySet > xCommandDefinitionPart( m_aContext.createComponent( (::rtl::OUString)SERVICE_SDB_QUERYDEFINITION ), UNO_QUERY_THROW );
209cdf0e10cSrcweir ::comphelper::copyProperties( _rxDesc, xCommandDefinitionPart );
210cdf0e10cSrcweir // TODO : the columns part of the descriptor has to be copied
211cdf0e10cSrcweir
212cdf0e10cSrcweir // create a wrapper for the object (*before* inserting into our command definition container)
213cdf0e10cSrcweir Reference< XContent > xNewObject( implCreateWrapper( Reference< XContent>( xCommandDefinitionPart, UNO_QUERY_THROW ) ) );
214cdf0e10cSrcweir
215cdf0e10cSrcweir ::rtl::OUString sNewObjectName;
216cdf0e10cSrcweir _rxDesc->getPropertyValue(PROPERTY_NAME) >>= sNewObjectName;
217cdf0e10cSrcweir
218cdf0e10cSrcweir try
219cdf0e10cSrcweir {
220cdf0e10cSrcweir notifyByName( aGuard, sNewObjectName, xNewObject, NULL, E_INSERTED, ApproveListeners );
221cdf0e10cSrcweir }
222cdf0e10cSrcweir catch( const Exception& )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir disposeComponent( xNewObject );
225cdf0e10cSrcweir disposeComponent( xCommandDefinitionPart );
226cdf0e10cSrcweir throw;
227cdf0e10cSrcweir }
228cdf0e10cSrcweir
229cdf0e10cSrcweir // insert the basic object into the definition container
230cdf0e10cSrcweir {
231cdf0e10cSrcweir m_eDoingCurrently = INSERTING;
232cdf0e10cSrcweir OAutoActionReset aAutoReset(this);
233cdf0e10cSrcweir m_xCommandDefinitions->insertByName(sNewObjectName, makeAny(xCommandDefinitionPart));
234cdf0e10cSrcweir }
235cdf0e10cSrcweir
236cdf0e10cSrcweir implAppend( sNewObjectName, xNewObject );
237cdf0e10cSrcweir notifyByName( aGuard, sNewObjectName, xNewObject, NULL, E_INSERTED, ContainerListemers );
238cdf0e10cSrcweir }
239cdf0e10cSrcweir
240cdf0e10cSrcweir // XDrop
241cdf0e10cSrcweir //------------------------------------------------------------------------------
dropByName(const::rtl::OUString & _rName)242cdf0e10cSrcweir void SAL_CALL OQueryContainer::dropByName( const ::rtl::OUString& _rName ) throw(SQLException, NoSuchElementException, RuntimeException)
243cdf0e10cSrcweir {
244cdf0e10cSrcweir MutexGuard aGuard(m_aMutex);
245cdf0e10cSrcweir if ( !checkExistence(_rName) )
246cdf0e10cSrcweir throw NoSuchElementException(_rName,*this);
247cdf0e10cSrcweir
248cdf0e10cSrcweir if ( !m_xCommandDefinitions.is() )
249cdf0e10cSrcweir throw DisposedException( ::rtl::OUString(), *this );
250cdf0e10cSrcweir
251cdf0e10cSrcweir // now simply forward the remove request to the CommandDefinition container, we're a listener for the removal
252cdf0e10cSrcweir // and thus we do everything neccessary in ::elementRemoved
253cdf0e10cSrcweir m_xCommandDefinitions->removeByName(_rName);
254cdf0e10cSrcweir }
255cdf0e10cSrcweir
256cdf0e10cSrcweir //------------------------------------------------------------------------------
dropByIndex(sal_Int32 _nIndex)257cdf0e10cSrcweir void SAL_CALL OQueryContainer::dropByIndex( sal_Int32 _nIndex ) throw(SQLException, IndexOutOfBoundsException, RuntimeException)
258cdf0e10cSrcweir {
259cdf0e10cSrcweir MutexGuard aGuard(m_aMutex);
260cdf0e10cSrcweir if ((_nIndex<0) || (_nIndex>getCount()))
261cdf0e10cSrcweir throw IndexOutOfBoundsException();
262cdf0e10cSrcweir
263cdf0e10cSrcweir if ( !m_xCommandDefinitions.is() )
264cdf0e10cSrcweir throw DisposedException( ::rtl::OUString(), *this );
265cdf0e10cSrcweir
266cdf0e10cSrcweir ::rtl::OUString sName;
267cdf0e10cSrcweir Reference<XPropertySet> xProp(Reference<XIndexAccess>(m_xCommandDefinitions,UNO_QUERY)->getByIndex(_nIndex),UNO_QUERY);
268cdf0e10cSrcweir if ( xProp.is() )
269cdf0e10cSrcweir xProp->getPropertyValue(PROPERTY_NAME) >>= sName;
270cdf0e10cSrcweir
271cdf0e10cSrcweir dropByName(sName);
272cdf0e10cSrcweir }
273cdf0e10cSrcweir //------------------------------------------------------------------------------
elementInserted(const::com::sun::star::container::ContainerEvent & _rEvent)274cdf0e10cSrcweir void SAL_CALL OQueryContainer::elementInserted( const ::com::sun::star::container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException)
275cdf0e10cSrcweir {
276cdf0e10cSrcweir Reference< XContent > xNewElement;
277cdf0e10cSrcweir ::rtl::OUString sElementName;
278cdf0e10cSrcweir _rEvent.Accessor >>= sElementName;
279cdf0e10cSrcweir {
280cdf0e10cSrcweir MutexGuard aGuard(m_aMutex);
281cdf0e10cSrcweir if (INSERTING == m_eDoingCurrently)
282cdf0e10cSrcweir // nothing to do, we're inserting via an "appendByDescriptor"
283cdf0e10cSrcweir return;
284cdf0e10cSrcweir
285cdf0e10cSrcweir DBG_ASSERT(sElementName.getLength(), "OQueryContainer::elementInserted : invalid name !");
286cdf0e10cSrcweir DBG_ASSERT(m_aDocumentMap.find(sElementName) == m_aDocumentMap.end(), "OQueryContainer::elementInserted : oops .... we're inconsistent with our master container !");
287cdf0e10cSrcweir if (!sElementName.getLength() || hasByName(sElementName))
288cdf0e10cSrcweir return;
289cdf0e10cSrcweir
290cdf0e10cSrcweir // insert an own new element
291cdf0e10cSrcweir xNewElement = implCreateWrapper(sElementName);
292cdf0e10cSrcweir }
293cdf0e10cSrcweir insertByName(sElementName,makeAny(xNewElement));
294cdf0e10cSrcweir }
295cdf0e10cSrcweir
296cdf0e10cSrcweir //------------------------------------------------------------------------------
elementRemoved(const::com::sun::star::container::ContainerEvent & _rEvent)297cdf0e10cSrcweir void SAL_CALL OQueryContainer::elementRemoved( const ::com::sun::star::container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException)
298cdf0e10cSrcweir {
299cdf0e10cSrcweir ::rtl::OUString sAccessor;
300cdf0e10cSrcweir _rEvent.Accessor >>= sAccessor;
301cdf0e10cSrcweir {
302cdf0e10cSrcweir DBG_ASSERT(sAccessor.getLength(), "OQueryContainer::elementRemoved : invalid name !");
303cdf0e10cSrcweir DBG_ASSERT(m_aDocumentMap.find(sAccessor) != m_aDocumentMap.end(), "OQueryContainer::elementRemoved : oops .... we're inconsistent with our master container !");
304cdf0e10cSrcweir if ( !sAccessor.getLength() || !hasByName(sAccessor) )
305cdf0e10cSrcweir return;
306cdf0e10cSrcweir }
307cdf0e10cSrcweir removeByName(sAccessor);
308cdf0e10cSrcweir }
309cdf0e10cSrcweir
310cdf0e10cSrcweir //------------------------------------------------------------------------------
elementReplaced(const::com::sun::star::container::ContainerEvent & _rEvent)311cdf0e10cSrcweir void SAL_CALL OQueryContainer::elementReplaced( const ::com::sun::star::container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException)
312cdf0e10cSrcweir {
313cdf0e10cSrcweir Reference< XPropertySet > xReplacedElement;
314cdf0e10cSrcweir Reference< XContent > xNewElement;
315cdf0e10cSrcweir ::rtl::OUString sAccessor;
316cdf0e10cSrcweir _rEvent.Accessor >>= sAccessor;
317cdf0e10cSrcweir
318cdf0e10cSrcweir {
319cdf0e10cSrcweir MutexGuard aGuard(m_aMutex);
320cdf0e10cSrcweir DBG_ASSERT(sAccessor.getLength(), "OQueryContainer::elementReplaced : invalid name !");
321cdf0e10cSrcweir DBG_ASSERT(m_aDocumentMap.find(sAccessor) != m_aDocumentMap.end(), "OQueryContainer::elementReplaced : oops .... we're inconsistent with our master container !");
322cdf0e10cSrcweir if (!sAccessor.getLength() || !hasByName(sAccessor))
323cdf0e10cSrcweir return;
324cdf0e10cSrcweir
325cdf0e10cSrcweir xNewElement = implCreateWrapper(sAccessor);
326cdf0e10cSrcweir }
327cdf0e10cSrcweir
328cdf0e10cSrcweir replaceByName(sAccessor,makeAny(xNewElement));
329cdf0e10cSrcweir }
330cdf0e10cSrcweir
331cdf0e10cSrcweir //------------------------------------------------------------------------------
approveInsertElement(const ContainerEvent & Event)332cdf0e10cSrcweir Reference< XVeto > SAL_CALL OQueryContainer::approveInsertElement( const ContainerEvent& Event ) throw (WrappedTargetException, RuntimeException)
333cdf0e10cSrcweir {
334cdf0e10cSrcweir ::rtl::OUString sName;
335cdf0e10cSrcweir OSL_VERIFY( Event.Accessor >>= sName );
336cdf0e10cSrcweir Reference< XContent > xElement( Event.Element, UNO_QUERY_THROW );
337cdf0e10cSrcweir
338cdf0e10cSrcweir Reference< XVeto > xReturn;
339cdf0e10cSrcweir try
340cdf0e10cSrcweir {
341cdf0e10cSrcweir getElementApproval()->approveElement( sName, xElement.get() );
342cdf0e10cSrcweir }
343cdf0e10cSrcweir catch( const Exception& )
344cdf0e10cSrcweir {
345cdf0e10cSrcweir xReturn = new Veto( ::rtl::OUString(), ::cppu::getCaughtException() );
346cdf0e10cSrcweir }
347cdf0e10cSrcweir return xReturn;
348cdf0e10cSrcweir }
349cdf0e10cSrcweir
350cdf0e10cSrcweir //------------------------------------------------------------------------------
approveReplaceElement(const ContainerEvent &)351cdf0e10cSrcweir Reference< XVeto > SAL_CALL OQueryContainer::approveReplaceElement( const ContainerEvent& /*Event*/ ) throw (WrappedTargetException, RuntimeException)
352cdf0e10cSrcweir {
353cdf0e10cSrcweir return NULL;
354cdf0e10cSrcweir }
355cdf0e10cSrcweir
356cdf0e10cSrcweir //------------------------------------------------------------------------------
approveRemoveElement(const ContainerEvent &)357cdf0e10cSrcweir Reference< XVeto > SAL_CALL OQueryContainer::approveRemoveElement( const ContainerEvent& /*Event*/ ) throw (WrappedTargetException, RuntimeException)
358cdf0e10cSrcweir {
359cdf0e10cSrcweir return NULL;
360cdf0e10cSrcweir }
361cdf0e10cSrcweir
362cdf0e10cSrcweir //------------------------------------------------------------------------------
disposing(const::com::sun::star::lang::EventObject & _rSource)363cdf0e10cSrcweir void SAL_CALL OQueryContainer::disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw(::com::sun::star::uno::RuntimeException)
364cdf0e10cSrcweir {
365cdf0e10cSrcweir if (_rSource.Source.get() == Reference< XInterface >(m_xCommandDefinitions, UNO_QUERY).get())
366cdf0e10cSrcweir { // our "master container" (with the command definitions) is beeing disposed
367cdf0e10cSrcweir DBG_ERROR("OQueryContainer::disposing : nobody should dispose the CommandDefinition container before disposing my connection !");
368cdf0e10cSrcweir dispose();
369cdf0e10cSrcweir }
370cdf0e10cSrcweir else
371cdf0e10cSrcweir {
372cdf0e10cSrcweir Reference< XContent > xSource(_rSource.Source, UNO_QUERY);
373cdf0e10cSrcweir // it's one of our documents ....
374cdf0e10cSrcweir Documents::iterator aIter = m_aDocumentMap.begin();
375cdf0e10cSrcweir Documents::iterator aEnd = m_aDocumentMap.end();
376cdf0e10cSrcweir for (;aIter != aEnd;++aIter )
377cdf0e10cSrcweir {
378cdf0e10cSrcweir if ( xSource == aIter->second.get() )
379cdf0e10cSrcweir {
380cdf0e10cSrcweir m_xCommandDefinitions->removeByName(aIter->first);
381cdf0e10cSrcweir break;
382cdf0e10cSrcweir }
383cdf0e10cSrcweir }
384cdf0e10cSrcweir ODefinitionContainer::disposing(_rSource);
385cdf0e10cSrcweir }
386cdf0e10cSrcweir }
387cdf0e10cSrcweir
388cdf0e10cSrcweir // -----------------------------------------------------------------------------
determineContentType() const389cdf0e10cSrcweir ::rtl::OUString OQueryContainer::determineContentType() const
390cdf0e10cSrcweir {
391cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.org.openoffice.DatabaseQueryContainer" ) );
392cdf0e10cSrcweir }
393cdf0e10cSrcweir
394cdf0e10cSrcweir // -----------------------------------------------------------------------------
implCreateWrapper(const::rtl::OUString & _rName)395cdf0e10cSrcweir Reference< XContent > OQueryContainer::implCreateWrapper(const ::rtl::OUString& _rName)
396cdf0e10cSrcweir {
397cdf0e10cSrcweir Reference< XContent > xObject(m_xCommandDefinitions->getByName(_rName),UNO_QUERY);
398cdf0e10cSrcweir return implCreateWrapper(xObject);
399cdf0e10cSrcweir }
400cdf0e10cSrcweir
401cdf0e10cSrcweir //--------------------------------------------------------------------------
implCreateWrapper(const Reference<XContent> & _rxCommandDesc)402cdf0e10cSrcweir Reference< XContent > OQueryContainer::implCreateWrapper(const Reference< XContent >& _rxCommandDesc)
403cdf0e10cSrcweir {
404cdf0e10cSrcweir Reference<XNameContainer> xContainer(_rxCommandDesc,UNO_QUERY);
405cdf0e10cSrcweir Reference< XContent > xReturn;
406cdf0e10cSrcweir if ( xContainer .is() )
407cdf0e10cSrcweir {
408cdf0e10cSrcweir xReturn = new OQueryContainer( xContainer, m_xConnection, m_aContext.getLegacyServiceFactory(), m_pWarnings );
409cdf0e10cSrcweir }
410cdf0e10cSrcweir else
411cdf0e10cSrcweir {
412cdf0e10cSrcweir OQuery* pNewObject = new OQuery( Reference< XPropertySet >( _rxCommandDesc, UNO_QUERY ), m_xConnection, m_aContext.getLegacyServiceFactory() );
413cdf0e10cSrcweir xReturn = pNewObject;
414cdf0e10cSrcweir
415cdf0e10cSrcweir pNewObject->setWarningsContainer( m_pWarnings );
416cdf0e10cSrcweir // pNewObject->getColumns();
417cdf0e10cSrcweir // Why? This is expensive. If you comment this in 'cause you really need it, be sure to run the
418cdf0e10cSrcweir // QueryInQuery test in dbaccess/qa/complex/dbaccess ...
419cdf0e10cSrcweir }
420cdf0e10cSrcweir
421cdf0e10cSrcweir return xReturn;
422cdf0e10cSrcweir }
423cdf0e10cSrcweir //--------------------------------------------------------------------------
createObject(const::rtl::OUString & _rName)424cdf0e10cSrcweir Reference< XContent > OQueryContainer::createObject( const ::rtl::OUString& _rName)
425cdf0e10cSrcweir {
426cdf0e10cSrcweir return implCreateWrapper(_rName);
427cdf0e10cSrcweir }
428cdf0e10cSrcweir // -----------------------------------------------------------------------------
checkExistence(const::rtl::OUString & _rName)429cdf0e10cSrcweir sal_Bool OQueryContainer::checkExistence(const ::rtl::OUString& _rName)
430cdf0e10cSrcweir {
431cdf0e10cSrcweir sal_Bool bRet = sal_False;
432cdf0e10cSrcweir if ( !m_bInPropertyChange )
433cdf0e10cSrcweir {
434cdf0e10cSrcweir bRet = m_xCommandDefinitions->hasByName(_rName);
435cdf0e10cSrcweir Documents::iterator aFind = m_aDocumentMap.find(_rName);
436cdf0e10cSrcweir if ( !bRet && aFind != m_aDocumentMap.end() )
437cdf0e10cSrcweir {
438cdf0e10cSrcweir m_aDocuments.erase( ::std::find(m_aDocuments.begin(),m_aDocuments.end(),aFind));
439cdf0e10cSrcweir m_aDocumentMap.erase(aFind);
440cdf0e10cSrcweir }
441cdf0e10cSrcweir else if ( bRet && aFind == m_aDocumentMap.end() )
442cdf0e10cSrcweir {
443cdf0e10cSrcweir implAppend(_rName,NULL);
444cdf0e10cSrcweir }
445cdf0e10cSrcweir }
446cdf0e10cSrcweir return bRet;
447cdf0e10cSrcweir }
448cdf0e10cSrcweir //--------------------------------------------------------------------------
hasElements()449cdf0e10cSrcweir sal_Bool SAL_CALL OQueryContainer::hasElements( ) throw (RuntimeException)
450cdf0e10cSrcweir {
451cdf0e10cSrcweir MutexGuard aGuard(m_aMutex);
452cdf0e10cSrcweir return m_xCommandDefinitions->hasElements();
453cdf0e10cSrcweir }
454cdf0e10cSrcweir // -----------------------------------------------------------------------------
getCount()455cdf0e10cSrcweir sal_Int32 SAL_CALL OQueryContainer::getCount( ) throw(RuntimeException)
456cdf0e10cSrcweir {
457cdf0e10cSrcweir MutexGuard aGuard(m_aMutex);
458cdf0e10cSrcweir return Reference<XIndexAccess>(m_xCommandDefinitions,UNO_QUERY)->getCount();
459cdf0e10cSrcweir }
460cdf0e10cSrcweir // -----------------------------------------------------------------------------
getElementNames()461cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL OQueryContainer::getElementNames( ) throw(RuntimeException)
462cdf0e10cSrcweir {
463cdf0e10cSrcweir MutexGuard aGuard(m_aMutex);
464cdf0e10cSrcweir
465cdf0e10cSrcweir return m_xCommandDefinitions->getElementNames();
466cdf0e10cSrcweir }
467cdf0e10cSrcweir
468cdf0e10cSrcweir //........................................................................
469cdf0e10cSrcweir } // namespace dbaccess
470cdf0e10cSrcweir //........................................................................
471cdf0e10cSrcweir
472