xref: /AOO41X/main/dbaccess/source/core/api/querydescriptor.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 
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
58 
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;
68 
69 //........................................................................
70 namespace dbaccess
71 {
72 //........................................................................
73 
74 //==========================================================================
75 //= OQueryDescriptor
76 //==========================================================================
77 DBG_NAME(OQueryDescriptor)
78 //--------------------------------------------------------------------------
79 OQueryDescriptor::OQueryDescriptor()
80 	:OQueryDescriptor_Base(m_aMutex,*this)
81 	,ODataSettings(m_aBHelper,sal_True)
82 {
83 	DBG_CTOR(OQueryDescriptor,NULL);
84 	registerProperties();
85 	ODataSettings::registerPropertiesFor(this);
86 }
87 
88 //--------------------------------------------------------------------------
89 OQueryDescriptor::OQueryDescriptor(const OQueryDescriptor_Base& _rSource)
90 	:OQueryDescriptor_Base(_rSource,*this)
91 	,ODataSettings(m_aBHelper,sal_True)
92 {
93 	DBG_CTOR(OQueryDescriptor,NULL);
94 	registerProperties();
95 	ODataSettings::registerPropertiesFor(this);
96 }
97 // -----------------------------------------------------------------------------
98 OQueryDescriptor::~OQueryDescriptor()
99 {
100     DBG_DTOR(OQueryDescriptor,NULL);
101 }
102 // -----------------------------------------------------------------------------
103 IMPLEMENT_TYPEPROVIDER2(OQueryDescriptor,OQueryDescriptor_Base,ODataSettings);
104 IMPLEMENT_FORWARD_XINTERFACE3( OQueryDescriptor,OWeakObject,OQueryDescriptor_Base,ODataSettings)
105 //--------------------------------------------------------------------------
106 void OQueryDescriptor::registerProperties()
107 {
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));
112 
113 	registerProperty(PROPERTY_COMMAND, PROPERTY_ID_COMMAND, PropertyAttribute::BOUND,
114 					&m_sCommand, ::getCppuType(&m_sCommand));
115 
116 	registerProperty(PROPERTY_ESCAPE_PROCESSING, PROPERTY_ID_ESCAPE_PROCESSING, PropertyAttribute::BOUND,
117 					&m_bEscapeProcessing, ::getBooleanCppuType());
118 
119 	registerProperty(PROPERTY_UPDATE_TABLENAME, PROPERTY_ID_UPDATE_TABLENAME, PropertyAttribute::BOUND,
120 					&m_sUpdateTableName, ::getCppuType(&m_sUpdateTableName));
121 
122 	registerProperty(PROPERTY_UPDATE_SCHEMANAME, PROPERTY_ID_UPDATE_SCHEMANAME, PropertyAttribute::BOUND,
123 					&m_sUpdateSchemaName, ::getCppuType(&m_sUpdateSchemaName));
124 
125 	registerProperty(PROPERTY_UPDATE_CATALOGNAME, PROPERTY_ID_UPDATE_CATALOGNAME, PropertyAttribute::BOUND,
126 					&m_sUpdateCatalogName, ::getCppuType(&m_sUpdateCatalogName));
127 
128 	registerProperty(PROPERTY_LAYOUTINFORMATION, PROPERTY_ID_LAYOUTINFORMATION, PropertyAttribute::BOUND,
129 					&m_aLayoutInformation, ::getCppuType(&m_aLayoutInformation));
130 }
131 // -----------------------------------------------------------------------------
132 //--------------------------------------------------------------------------
133 Reference< XPropertySetInfo > SAL_CALL OQueryDescriptor::getPropertySetInfo(  ) throw(RuntimeException)
134 {
135 	return createPropertySetInfo( getInfoHelper() ) ;
136 }
137 
138 //------------------------------------------------------------------------------
139 ::cppu::IPropertyArrayHelper& OQueryDescriptor::getInfoHelper()
140 {
141 	return *getArrayHelper();
142 }
143 //--------------------------------------------------------------------------
144 ::cppu::IPropertyArrayHelper* OQueryDescriptor::createArrayHelper( ) const
145 {
146 	Sequence< Property > aProps;
147 	describeProperties(aProps);
148 	return new ::cppu::OPropertyArrayHelper(aProps);
149 }
150 
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)
157 {
158 	DBG_CTOR(OQueryDescriptor_Base,NULL);
159 	m_pColumns = new OColumns(_rMySelf, m_rMutex, sal_True,::std::vector< ::rtl::OUString>(), this,this);
160 }
161 //--------------------------------------------------------------------------
162 OQueryDescriptor_Base::OQueryDescriptor_Base(const OQueryDescriptor_Base& _rSource,::cppu::OWeakObject& _rMySelf)
163 	:m_bColumnsOutOfDate(sal_True)
164 	,m_rMutex(_rSource.m_rMutex)
165 {
166 	DBG_CTOR(OQueryDescriptor_Base,NULL);
167 	m_pColumns = new OColumns(_rMySelf, m_rMutex, sal_True,::std::vector< ::rtl::OUString>(), this,this);
168 
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;
175 }
176 
177 //--------------------------------------------------------------------------
178 OQueryDescriptor_Base::~OQueryDescriptor_Base()
179 {
180     m_pColumns->acquire();
181 	m_pColumns->disposing();
182     delete m_pColumns;
183 
184     DBG_DTOR(OQueryDescriptor_Base,NULL);
185 }
186 // -----------------------------------------------------------------------------
187 sal_Int64 SAL_CALL OQueryDescriptor_Base::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw(RuntimeException)
188 {
189 	if (_rIdentifier.getLength() != 16)
190 		return 0;
191 
192 	if (0 == rtl_compareMemory(getImplementationId().getConstArray(),  _rIdentifier.getConstArray(), 16 ) )
193 		return reinterpret_cast<sal_Int64>(this);
194 
195 	return 0;
196 }
197 //--------------------------------------------------------------------------
198 IMPLEMENT_IMPLEMENTATION_ID(OQueryDescriptor_Base)
199 //--------------------------------------------------------------------------
200 void OQueryDescriptor_Base::setColumnsOutOfDate( sal_Bool _bOutOfDate )
201 {
202 	m_bColumnsOutOfDate = _bOutOfDate;
203 	if ( !m_bColumnsOutOfDate )
204 		m_pColumns->setInitialized();
205 }
206 
207 //--------------------------------------------------------------------------
208 void OQueryDescriptor_Base::implAppendColumn( const ::rtl::OUString& _rName, OColumn* _pColumn )
209 {
210 	m_pColumns->append( _rName, _pColumn );
211 }
212 
213 //--------------------------------------------------------------------------
214 void OQueryDescriptor_Base::clearColumns( )
215 {
216 	m_pColumns->clearColumns();
217 
218 	setColumnsOutOfDate();
219 }
220 
221 //--------------------------------------------------------------------------
222 Reference< XNameAccess > SAL_CALL OQueryDescriptor_Base::getColumns( ) throw (RuntimeException)
223 {
224 	MutexGuard aGuard(m_rMutex);
225 
226 	if ( isColumnsOutOfDate() )
227 	{
228         // clear the current columns
229 	    clearColumns();
230 
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 );
236 
237 	    // rebuild them
238         try
239         {
240 	        rebuildColumns();
241         }
242         catch ( const Exception& )
243         {
244             setColumnsOutOfDate( sal_True );
245             throw;
246         }
247 	}
248 
249 	return m_pColumns;
250 }
251 
252 //--------------------------------------------------------------------------
253 ::rtl::OUString SAL_CALL OQueryDescriptor_Base::getImplementationName(  ) throw(RuntimeException)
254 {
255 	return ::rtl::OUString::createFromAscii("com.sun.star.sdb.OQueryDescriptor");
256 }
257 
258 //--------------------------------------------------------------------------
259 sal_Bool SAL_CALL OQueryDescriptor_Base::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
260 {
261 	return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
262 }
263 
264 //--------------------------------------------------------------------------
265 Sequence< ::rtl::OUString > SAL_CALL OQueryDescriptor_Base::getSupportedServiceNames(  ) throw(RuntimeException)
266 {
267 	Sequence< ::rtl::OUString > aSupported(2);
268 	aSupported.getArray()[0] = SERVICE_SDB_DATASETTINGS;
269 	aSupported.getArray()[1] = SERVICE_SDB_QUERYDESCRIPTOR;
270 	return aSupported;
271 }
272 //--------------------------------------------------------------------------
273 void OQueryDescriptor_Base::disposeColumns()
274 {
275 	m_pColumns->disposing();
276 }
277 
278 // -----------------------------------------------------------------------------
279 void OQueryDescriptor_Base::columnAppended( const Reference< XPropertySet >& /*_rxSourceDescriptor*/ )
280 {
281     // not interested in
282 }
283 
284 // -----------------------------------------------------------------------------
285 void OQueryDescriptor_Base::columnDropped(const ::rtl::OUString& /*_sName*/)
286 {
287     // not interested in
288 }
289 
290 // -----------------------------------------------------------------------------
291 Reference< XPropertySet > OQueryDescriptor_Base::createColumnDescriptor()
292 {
293     OSL_ENSURE( false, "OQueryDescriptor_Base::createColumnDescriptor: called why?" );
294 	return NULL;
295 }
296 
297 // -----------------------------------------------------------------------------
298 void OQueryDescriptor_Base::rebuildColumns( )
299 {
300 }
301 
302 // -----------------------------------------------------------------------------
303 // IRefreshableColumns
304 void OQueryDescriptor_Base::refreshColumns()
305 {
306 	MutexGuard aGuard( m_rMutex );
307 
308 	clearColumns();
309 	rebuildColumns();
310 }
311 
312 //------------------------------------------------------------------------------
313 OColumn* OQueryDescriptor_Base::createColumn( const ::rtl::OUString& /*_rName*/ ) const
314 {
315     // creating a column/descriptor for a query/descriptor does not make sense at all
316 	return NULL;
317 }
318 // -----------------------------------------------------------------------------
319 //........................................................................
320 }	// namespace dbaccess
321 //........................................................................
322 
323 
324