merged tag ooo/DEV300_m102
[LibreOffice.git] / dbaccess / source / core / api / querydescriptor.cxx
blob0fb61dbd1f64b60bc1cbb1f6876b3761638bbc49
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
31 #ifndef _DBA_COREAPI_QUERYDESCRIPTOR_HXX_
32 #include "querydescriptor.hxx"
33 #endif
34 #ifndef _DBASHARED_APITOOLS_HXX_
35 #include "apitools.hxx"
36 #endif
37 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
38 #include "dbastrings.hrc"
39 #endif
40 #ifndef _COMPHELPER_PROPERTY_HXX_
41 #include <comphelper/property.hxx>
42 #endif
43 #ifndef _COMPHELPER_SEQUENCE_HXX_
44 #include <comphelper/sequence.hxx>
45 #endif
46 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
47 #include <cppuhelper/typeprovider.hxx>
48 #endif
49 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
50 #include <com/sun/star/beans/PropertyAttribute.hpp>
51 #endif
52 #ifndef _DBACORE_DEFINITIONCOLUMN_HXX_
53 #include "definitioncolumn.hxx"
54 #endif
55 #ifndef _TOOLS_DEBUG_HXX
56 #include <tools/debug.hxx>
57 #endif
59 using namespace ::com::sun::star::uno;
60 using namespace ::com::sun::star::awt;
61 using namespace ::com::sun::star::lang;
62 using namespace ::com::sun::star::beans;
63 using namespace ::com::sun::star::container;
64 using namespace ::com::sun::star::util;
65 using namespace ::comphelper;
66 using namespace ::osl;
67 using namespace ::cppu;
69 //........................................................................
70 namespace dbaccess
72 //........................................................................
74 //==========================================================================
75 //= OQueryDescriptor
76 //==========================================================================
77 DBG_NAME(OQueryDescriptor)
78 //--------------------------------------------------------------------------
79 OQueryDescriptor::OQueryDescriptor()
80 :OQueryDescriptor_Base(m_aMutex,*this)
81 ,ODataSettings(m_aBHelper,sal_True)
83 DBG_CTOR(OQueryDescriptor,NULL);
84 registerProperties();
85 ODataSettings::registerPropertiesFor(this);
88 //--------------------------------------------------------------------------
89 OQueryDescriptor::OQueryDescriptor(const OQueryDescriptor_Base& _rSource)
90 :OQueryDescriptor_Base(_rSource,*this)
91 ,ODataSettings(m_aBHelper,sal_True)
93 DBG_CTOR(OQueryDescriptor,NULL);
94 registerProperties();
95 ODataSettings::registerPropertiesFor(this);
97 // -----------------------------------------------------------------------------
98 OQueryDescriptor::~OQueryDescriptor()
100 DBG_DTOR(OQueryDescriptor,NULL);
102 // -----------------------------------------------------------------------------
103 IMPLEMENT_TYPEPROVIDER2(OQueryDescriptor,OQueryDescriptor_Base,ODataSettings);
104 IMPLEMENT_FORWARD_XINTERFACE3( OQueryDescriptor,OWeakObject,OQueryDescriptor_Base,ODataSettings)
105 //--------------------------------------------------------------------------
106 void OQueryDescriptor::registerProperties()
108 // the properties which OCommandBase supplies (it has no own registration, as it's not derived from
109 // a OPropertyStateContainer)
110 registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND|PropertyAttribute::CONSTRAINED,
111 &m_sElementName, ::getCppuType(&m_sElementName));
113 registerProperty(PROPERTY_COMMAND, PROPERTY_ID_COMMAND, PropertyAttribute::BOUND,
114 &m_sCommand, ::getCppuType(&m_sCommand));
116 registerProperty(PROPERTY_ESCAPE_PROCESSING, PROPERTY_ID_ESCAPE_PROCESSING, PropertyAttribute::BOUND,
117 &m_bEscapeProcessing, ::getBooleanCppuType());
119 registerProperty(PROPERTY_UPDATE_TABLENAME, PROPERTY_ID_UPDATE_TABLENAME, PropertyAttribute::BOUND,
120 &m_sUpdateTableName, ::getCppuType(&m_sUpdateTableName));
122 registerProperty(PROPERTY_UPDATE_SCHEMANAME, PROPERTY_ID_UPDATE_SCHEMANAME, PropertyAttribute::BOUND,
123 &m_sUpdateSchemaName, ::getCppuType(&m_sUpdateSchemaName));
125 registerProperty(PROPERTY_UPDATE_CATALOGNAME, PROPERTY_ID_UPDATE_CATALOGNAME, PropertyAttribute::BOUND,
126 &m_sUpdateCatalogName, ::getCppuType(&m_sUpdateCatalogName));
128 registerProperty(PROPERTY_LAYOUTINFORMATION, PROPERTY_ID_LAYOUTINFORMATION, PropertyAttribute::BOUND,
129 &m_aLayoutInformation, ::getCppuType(&m_aLayoutInformation));
131 // -----------------------------------------------------------------------------
132 //--------------------------------------------------------------------------
133 Reference< XPropertySetInfo > SAL_CALL OQueryDescriptor::getPropertySetInfo( ) throw(RuntimeException)
135 return createPropertySetInfo( getInfoHelper() ) ;
138 //------------------------------------------------------------------------------
139 ::cppu::IPropertyArrayHelper& OQueryDescriptor::getInfoHelper()
141 return *getArrayHelper();
143 //--------------------------------------------------------------------------
144 ::cppu::IPropertyArrayHelper* OQueryDescriptor::createArrayHelper( ) const
146 Sequence< Property > aProps;
147 describeProperties(aProps);
148 return new ::cppu::OPropertyArrayHelper(aProps);
151 // -----------------------------------------------------------------------------
152 DBG_NAME(OQueryDescriptor_Base);
153 //--------------------------------------------------------------------------
154 OQueryDescriptor_Base::OQueryDescriptor_Base(::osl::Mutex& _rMutex,::cppu::OWeakObject& _rMySelf)
155 :m_bColumnsOutOfDate(sal_True)
156 ,m_rMutex(_rMutex)
158 DBG_CTOR(OQueryDescriptor_Base,NULL);
159 m_pColumns = new OColumns(_rMySelf, m_rMutex, sal_True,::std::vector< ::rtl::OUString>(), this,this);
161 //--------------------------------------------------------------------------
162 OQueryDescriptor_Base::OQueryDescriptor_Base(const OQueryDescriptor_Base& _rSource,::cppu::OWeakObject& _rMySelf)
163 :m_bColumnsOutOfDate(sal_True)
164 ,m_rMutex(_rSource.m_rMutex)
166 DBG_CTOR(OQueryDescriptor_Base,NULL);
167 m_pColumns = new OColumns(_rMySelf, m_rMutex, sal_True,::std::vector< ::rtl::OUString>(), this,this);
169 m_sCommand = _rSource.m_sCommand;
170 m_bEscapeProcessing = _rSource.m_bEscapeProcessing;
171 m_sUpdateTableName = _rSource.m_sUpdateTableName;
172 m_sUpdateSchemaName = _rSource.m_sUpdateSchemaName;
173 m_sUpdateCatalogName = _rSource.m_sUpdateCatalogName;
174 m_aLayoutInformation = _rSource.m_aLayoutInformation;
177 //--------------------------------------------------------------------------
178 OQueryDescriptor_Base::~OQueryDescriptor_Base()
180 m_pColumns->acquire();
181 m_pColumns->disposing();
182 delete m_pColumns;
184 DBG_DTOR(OQueryDescriptor_Base,NULL);
186 // -----------------------------------------------------------------------------
187 sal_Int64 SAL_CALL OQueryDescriptor_Base::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw(RuntimeException)
189 if (_rIdentifier.getLength() != 16)
190 return 0;
192 if (0 == rtl_compareMemory(getImplementationId().getConstArray(), _rIdentifier.getConstArray(), 16 ) )
193 return reinterpret_cast<sal_Int64>(this);
195 return 0;
197 //--------------------------------------------------------------------------
198 IMPLEMENT_IMPLEMENTATION_ID(OQueryDescriptor_Base)
199 //--------------------------------------------------------------------------
200 void OQueryDescriptor_Base::setColumnsOutOfDate( sal_Bool _bOutOfDate )
202 m_bColumnsOutOfDate = _bOutOfDate;
203 if ( !m_bColumnsOutOfDate )
204 m_pColumns->setInitialized();
207 //--------------------------------------------------------------------------
208 void OQueryDescriptor_Base::implAppendColumn( const ::rtl::OUString& _rName, OColumn* _pColumn )
210 m_pColumns->append( _rName, _pColumn );
213 //--------------------------------------------------------------------------
214 void OQueryDescriptor_Base::clearColumns( )
216 m_pColumns->clearColumns();
218 setColumnsOutOfDate();
221 //--------------------------------------------------------------------------
222 Reference< XNameAccess > SAL_CALL OQueryDescriptor_Base::getColumns( ) throw (RuntimeException)
224 MutexGuard aGuard(m_rMutex);
226 if ( isColumnsOutOfDate() )
228 // clear the current columns
229 clearColumns();
231 // do this before rebuildColumns. This prevents recursion, e.g. in the case where we
232 // have queries with cyclic references:
233 // foo := SELECT * FROM bar
234 // bar := SELECT * FROM foo
235 setColumnsOutOfDate( sal_False );
237 // rebuild them
240 rebuildColumns();
242 catch ( const Exception& )
244 setColumnsOutOfDate( sal_True );
245 throw;
249 return m_pColumns;
252 //--------------------------------------------------------------------------
253 ::rtl::OUString SAL_CALL OQueryDescriptor_Base::getImplementationName( ) throw(RuntimeException)
255 return ::rtl::OUString::createFromAscii("com.sun.star.sdb.OQueryDescriptor");
258 //--------------------------------------------------------------------------
259 sal_Bool SAL_CALL OQueryDescriptor_Base::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
261 return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
264 //--------------------------------------------------------------------------
265 Sequence< ::rtl::OUString > SAL_CALL OQueryDescriptor_Base::getSupportedServiceNames( ) throw(RuntimeException)
267 Sequence< ::rtl::OUString > aSupported(2);
268 aSupported.getArray()[0] = SERVICE_SDB_DATASETTINGS;
269 aSupported.getArray()[1] = SERVICE_SDB_QUERYDESCRIPTOR;
270 return aSupported;
272 //--------------------------------------------------------------------------
273 void OQueryDescriptor_Base::disposeColumns()
275 m_pColumns->disposing();
278 // -----------------------------------------------------------------------------
279 void OQueryDescriptor_Base::columnAppended( const Reference< XPropertySet >& /*_rxSourceDescriptor*/ )
281 // not interested in
284 // -----------------------------------------------------------------------------
285 void OQueryDescriptor_Base::columnDropped(const ::rtl::OUString& /*_sName*/)
287 // not interested in
290 // -----------------------------------------------------------------------------
291 Reference< XPropertySet > OQueryDescriptor_Base::createColumnDescriptor()
293 OSL_ENSURE( false, "OQueryDescriptor_Base::createColumnDescriptor: called why?" );
294 return NULL;
297 // -----------------------------------------------------------------------------
298 void OQueryDescriptor_Base::rebuildColumns( )
302 // -----------------------------------------------------------------------------
303 // IRefreshableColumns
304 void OQueryDescriptor_Base::refreshColumns()
306 MutexGuard aGuard( m_rMutex );
308 clearColumns();
309 rebuildColumns();
312 //------------------------------------------------------------------------------
313 OColumn* OQueryDescriptor_Base::createColumn( const ::rtl::OUString& /*_rName*/ ) const
315 // creating a column/descriptor for a query/descriptor does not make sense at all
316 return NULL;
318 // -----------------------------------------------------------------------------
319 //........................................................................
320 } // namespace dbaccess
321 //........................................................................