merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / core / api / querydescriptor.cxx
blob33ccca7f26f5a95dad1c4fbf0c172132686f3537
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: querydescriptor.cxx,v $
10 * $Revision: 1.34 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef _DBA_COREAPI_QUERYDESCRIPTOR_HXX_
35 #include "querydescriptor.hxx"
36 #endif
37 #ifndef _DBASHARED_APITOOLS_HXX_
38 #include "apitools.hxx"
39 #endif
40 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
41 #include "dbastrings.hrc"
42 #endif
43 #ifndef _COMPHELPER_PROPERTY_HXX_
44 #include <comphelper/property.hxx>
45 #endif
46 #ifndef _COMPHELPER_SEQUENCE_HXX_
47 #include <comphelper/sequence.hxx>
48 #endif
49 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
50 #include <cppuhelper/typeprovider.hxx>
51 #endif
52 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
53 #include <com/sun/star/beans/PropertyAttribute.hpp>
54 #endif
55 #ifndef _DBACORE_DEFINITIONCOLUMN_HXX_
56 #include "definitioncolumn.hxx"
57 #endif
58 #ifndef _TOOLS_DEBUG_HXX
59 #include <tools/debug.hxx>
60 #endif
62 using namespace ::com::sun::star::uno;
63 using namespace ::com::sun::star::awt;
64 using namespace ::com::sun::star::lang;
65 using namespace ::com::sun::star::beans;
66 using namespace ::com::sun::star::container;
67 using namespace ::com::sun::star::util;
68 using namespace ::comphelper;
69 using namespace ::osl;
70 using namespace ::cppu;
72 //........................................................................
73 namespace dbaccess
75 //........................................................................
77 //==========================================================================
78 //= OQueryDescriptor
79 //==========================================================================
80 DBG_NAME(OQueryDescriptor)
81 //--------------------------------------------------------------------------
82 OQueryDescriptor::OQueryDescriptor()
83 :OQueryDescriptor_Base(m_aMutex,*this)
84 ,ODataSettings(m_aBHelper,sal_True)
86 DBG_CTOR(OQueryDescriptor,NULL);
87 registerProperties();
88 ODataSettings::registerPropertiesFor(this);
91 //--------------------------------------------------------------------------
92 OQueryDescriptor::OQueryDescriptor(const Reference< XPropertySet >& _rxCommandDefinition)
93 :OQueryDescriptor_Base(m_aMutex,*this)
94 ,ODataSettings(m_aBHelper,sal_True)
96 DBG_CTOR(OQueryDescriptor,NULL);
97 registerProperties();
98 ODataSettings::registerPropertiesFor(this);
100 osl_incrementInterlockedCount(&m_refCount);
102 OSL_ENSURE(_rxCommandDefinition.is(), "OQueryDescriptor_Base::OQueryDescriptor_Base : invalid source property set !");
105 ::comphelper::copyProperties(_rxCommandDefinition,this);
107 catch(Exception&)
109 OSL_ENSURE(sal_False, "OQueryDescriptor_Base::OQueryDescriptor_Base: caught an exception!");
111 osl_decrementInterlockedCount(&m_refCount);
114 //--------------------------------------------------------------------------
115 OQueryDescriptor::OQueryDescriptor(const OQueryDescriptor_Base& _rSource)
116 :OQueryDescriptor_Base(_rSource,*this)
117 ,ODataSettings(m_aBHelper,sal_True)
119 DBG_CTOR(OQueryDescriptor,NULL);
120 registerProperties();
121 ODataSettings::registerPropertiesFor(this);
123 // -----------------------------------------------------------------------------
124 OQueryDescriptor::~OQueryDescriptor()
126 DBG_DTOR(OQueryDescriptor,NULL);
128 // -----------------------------------------------------------------------------
129 IMPLEMENT_TYPEPROVIDER2(OQueryDescriptor,OQueryDescriptor_Base,ODataSettings);
130 IMPLEMENT_FORWARD_XINTERFACE3( OQueryDescriptor,OWeakObject,OQueryDescriptor_Base,ODataSettings)
131 //--------------------------------------------------------------------------
132 void OQueryDescriptor::registerProperties()
134 // the properties which OCommandBase supplies (it has no own registration, as it's not derived from
135 // a OPropertyStateContainer)
136 registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND|PropertyAttribute::CONSTRAINED,
137 &m_sElementName, ::getCppuType(&m_sElementName));
139 registerProperty(PROPERTY_COMMAND, PROPERTY_ID_COMMAND, PropertyAttribute::BOUND,
140 &m_sCommand, ::getCppuType(&m_sCommand));
142 registerProperty(PROPERTY_ESCAPE_PROCESSING, PROPERTY_ID_ESCAPE_PROCESSING, PropertyAttribute::BOUND,
143 &m_bEscapeProcessing, ::getBooleanCppuType());
145 registerProperty(PROPERTY_UPDATE_TABLENAME, PROPERTY_ID_UPDATE_TABLENAME, PropertyAttribute::BOUND,
146 &m_sUpdateTableName, ::getCppuType(&m_sUpdateTableName));
148 registerProperty(PROPERTY_UPDATE_SCHEMANAME, PROPERTY_ID_UPDATE_SCHEMANAME, PropertyAttribute::BOUND,
149 &m_sUpdateSchemaName, ::getCppuType(&m_sUpdateSchemaName));
151 registerProperty(PROPERTY_UPDATE_CATALOGNAME, PROPERTY_ID_UPDATE_CATALOGNAME, PropertyAttribute::BOUND,
152 &m_sUpdateCatalogName, ::getCppuType(&m_sUpdateCatalogName));
154 registerProperty(PROPERTY_LAYOUTINFORMATION, PROPERTY_ID_LAYOUTINFORMATION, PropertyAttribute::BOUND,
155 &m_aLayoutInformation, ::getCppuType(&m_aLayoutInformation));
157 // -----------------------------------------------------------------------------
158 //--------------------------------------------------------------------------
159 Reference< XPropertySetInfo > SAL_CALL OQueryDescriptor::getPropertySetInfo( ) throw(RuntimeException)
161 return createPropertySetInfo( getInfoHelper() ) ;
164 //------------------------------------------------------------------------------
165 ::cppu::IPropertyArrayHelper& OQueryDescriptor::getInfoHelper()
167 return *getArrayHelper();
169 //--------------------------------------------------------------------------
170 ::cppu::IPropertyArrayHelper* OQueryDescriptor::createArrayHelper( ) const
172 Sequence< Property > aProps;
173 describeProperties(aProps);
174 return new ::cppu::OPropertyArrayHelper(aProps);
177 // -----------------------------------------------------------------------------
178 DBG_NAME(OQueryDescriptor_Base);
179 //--------------------------------------------------------------------------
180 OQueryDescriptor_Base::OQueryDescriptor_Base(::osl::Mutex& _rMutex,::cppu::OWeakObject& _rMySelf)
181 :m_bColumnsOutOfDate(sal_True)
182 ,m_rMutex(_rMutex)
184 DBG_CTOR(OQueryDescriptor_Base,NULL);
185 m_pColumns = new OColumns(_rMySelf, m_rMutex, sal_True,::std::vector< ::rtl::OUString>(), this,this);
187 //--------------------------------------------------------------------------
188 OQueryDescriptor_Base::OQueryDescriptor_Base(const OQueryDescriptor_Base& _rSource,::cppu::OWeakObject& _rMySelf)
189 :m_bColumnsOutOfDate(sal_True)
190 ,m_rMutex(_rSource.m_rMutex)
192 DBG_CTOR(OQueryDescriptor_Base,NULL);
193 m_pColumns = new OColumns(_rMySelf, m_rMutex, sal_True,::std::vector< ::rtl::OUString>(), this,this);
195 m_sCommand = _rSource.m_sCommand;
196 m_bEscapeProcessing = _rSource.m_bEscapeProcessing;
197 m_sUpdateTableName = _rSource.m_sUpdateTableName;
198 m_sUpdateSchemaName = _rSource.m_sUpdateSchemaName;
199 m_sUpdateCatalogName = _rSource.m_sUpdateCatalogName;
200 m_aLayoutInformation = _rSource.m_aLayoutInformation;
203 //--------------------------------------------------------------------------
204 OQueryDescriptor_Base::~OQueryDescriptor_Base()
206 m_pColumns->acquire();
207 m_pColumns->disposing();
208 delete m_pColumns;
210 DBG_DTOR(OQueryDescriptor_Base,NULL);
212 // -----------------------------------------------------------------------------
213 sal_Int64 SAL_CALL OQueryDescriptor_Base::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw(RuntimeException)
215 if (_rIdentifier.getLength() != 16)
216 return 0;
218 if (0 == rtl_compareMemory(getImplementationId().getConstArray(), _rIdentifier.getConstArray(), 16 ) )
219 return reinterpret_cast<sal_Int64>(this);
221 return 0;
223 //--------------------------------------------------------------------------
224 IMPLEMENT_IMPLEMENTATION_ID(OQueryDescriptor_Base)
225 //--------------------------------------------------------------------------
226 void OQueryDescriptor_Base::setColumnsOutOfDate( sal_Bool _bOutOfDate )
228 m_bColumnsOutOfDate = _bOutOfDate;
229 if ( !m_bColumnsOutOfDate )
230 m_pColumns->setInitialized();
233 //--------------------------------------------------------------------------
234 void OQueryDescriptor_Base::implAppendColumn( const ::rtl::OUString& _rName, OColumn* _pColumn )
236 m_pColumns->append( _rName, _pColumn );
239 //--------------------------------------------------------------------------
240 void OQueryDescriptor_Base::clearColumns( )
242 m_pColumns->clearColumns();
244 setColumnsOutOfDate();
247 //--------------------------------------------------------------------------
248 Reference< XNameAccess > SAL_CALL OQueryDescriptor_Base::getColumns( ) throw (RuntimeException)
250 MutexGuard aGuard(m_rMutex);
252 if ( isColumnsOutOfDate() )
254 // clear the current columns
255 clearColumns();
257 // do this before rebuildColumns. This prevents recursion, e.g. in the case where we
258 // have queries with cyclic references:
259 // foo := SELECT * FROM bar
260 // bar := SELECT * FROM foo
261 setColumnsOutOfDate( sal_False );
263 // rebuild them
266 rebuildColumns();
268 catch(...)
270 setColumnsOutOfDate( sal_True );
271 throw;
275 return m_pColumns;
278 //--------------------------------------------------------------------------
279 ::rtl::OUString SAL_CALL OQueryDescriptor_Base::getImplementationName( ) throw(RuntimeException)
281 return ::rtl::OUString::createFromAscii("com.sun.star.sdb.OQueryDescriptor");
284 //--------------------------------------------------------------------------
285 sal_Bool SAL_CALL OQueryDescriptor_Base::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
287 return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
290 //--------------------------------------------------------------------------
291 Sequence< ::rtl::OUString > SAL_CALL OQueryDescriptor_Base::getSupportedServiceNames( ) throw(RuntimeException)
293 Sequence< ::rtl::OUString > aSupported(2);
294 aSupported.getArray()[0] = SERVICE_SDB_DATASETTINGS;
295 aSupported.getArray()[1] = SERVICE_SDB_QUERYDESCRIPTOR;
296 return aSupported;
298 //--------------------------------------------------------------------------
299 void OQueryDescriptor_Base::disposeColumns()
301 m_pColumns->disposing();
304 // -----------------------------------------------------------------------------
305 void OQueryDescriptor_Base::columnAppended( const Reference< XPropertySet >& /*_rxSourceDescriptor*/ )
307 // not interested in
310 // -----------------------------------------------------------------------------
311 void OQueryDescriptor_Base::columnDropped(const ::rtl::OUString& /*_sName*/)
313 // not interested in
316 // -----------------------------------------------------------------------------
317 Reference< XPropertySet > OQueryDescriptor_Base::createColumnDescriptor()
319 OSL_ENSURE( false, "OQueryDescriptor_Base::createColumnDescriptor: called why?" );
320 return NULL;
323 // -----------------------------------------------------------------------------
324 void OQueryDescriptor_Base::rebuildColumns( )
328 // -----------------------------------------------------------------------------
329 // IRefreshableColumns
330 void OQueryDescriptor_Base::refreshColumns()
332 MutexGuard aGuard( m_rMutex );
334 clearColumns();
335 rebuildColumns();
338 //------------------------------------------------------------------------------
339 OColumn* OQueryDescriptor_Base::createColumn(const ::rtl::OUString& _rName) const
341 return new OTableColumn(_rName);
343 // -----------------------------------------------------------------------------
344 //........................................................................
345 } // namespace dbaccess
346 //........................................................................