Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <string.h>
21 :
22 : #include "querydescriptor.hxx"
23 : #include "apitools.hxx"
24 : #include "dbastrings.hrc"
25 : #include <comphelper/property.hxx>
26 : #include <comphelper/sequence.hxx>
27 : #include <cppuhelper/typeprovider.hxx>
28 : #include <com/sun/star/beans/PropertyAttribute.hpp>
29 : #include "definitioncolumn.hxx"
30 : #include <tools/debug.hxx>
31 :
32 : using namespace ::com::sun::star::uno;
33 : using namespace ::com::sun::star::awt;
34 : using namespace ::com::sun::star::lang;
35 : using namespace ::com::sun::star::beans;
36 : using namespace ::com::sun::star::container;
37 : using namespace ::com::sun::star::util;
38 : using namespace ::comphelper;
39 : using namespace ::osl;
40 : using namespace ::cppu;
41 :
42 : namespace dbaccess
43 : {
44 :
45 : //==========================================================================
46 : //= OQueryDescriptor
47 : //==========================================================================
48 : DBG_NAME(OQueryDescriptor)
49 :
50 0 : OQueryDescriptor::OQueryDescriptor()
51 : :OQueryDescriptor_Base(m_aMutex,*this)
52 0 : ,ODataSettings(m_aBHelper,sal_True)
53 : {
54 : DBG_CTOR(OQueryDescriptor,NULL);
55 0 : registerProperties();
56 0 : ODataSettings::registerPropertiesFor(this);
57 0 : }
58 :
59 0 : OQueryDescriptor::OQueryDescriptor(const OQueryDescriptor_Base& _rSource)
60 : :OQueryDescriptor_Base(_rSource,*this)
61 0 : ,ODataSettings(m_aBHelper,sal_True)
62 : {
63 : DBG_CTOR(OQueryDescriptor,NULL);
64 0 : registerProperties();
65 0 : ODataSettings::registerPropertiesFor(this);
66 0 : }
67 :
68 0 : OQueryDescriptor::~OQueryDescriptor()
69 : {
70 : DBG_DTOR(OQueryDescriptor,NULL);
71 0 : }
72 :
73 0 : IMPLEMENT_TYPEPROVIDER2(OQueryDescriptor,OQueryDescriptor_Base,ODataSettings);
74 0 : IMPLEMENT_FORWARD_XINTERFACE3( OQueryDescriptor,OWeakObject,OQueryDescriptor_Base,ODataSettings)
75 :
76 0 : void OQueryDescriptor::registerProperties()
77 : {
78 : // the properties which OCommandBase supplies (it has no own registration, as it's not derived from
79 : // a OPropertyStateContainer)
80 : registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND|PropertyAttribute::CONSTRAINED,
81 0 : &m_sElementName, ::getCppuType(&m_sElementName));
82 :
83 : registerProperty(PROPERTY_COMMAND, PROPERTY_ID_COMMAND, PropertyAttribute::BOUND,
84 0 : &m_sCommand, ::getCppuType(&m_sCommand));
85 :
86 : registerProperty(PROPERTY_ESCAPE_PROCESSING, PROPERTY_ID_ESCAPE_PROCESSING, PropertyAttribute::BOUND,
87 0 : &m_bEscapeProcessing, ::getBooleanCppuType());
88 :
89 : registerProperty(PROPERTY_UPDATE_TABLENAME, PROPERTY_ID_UPDATE_TABLENAME, PropertyAttribute::BOUND,
90 0 : &m_sUpdateTableName, ::getCppuType(&m_sUpdateTableName));
91 :
92 : registerProperty(PROPERTY_UPDATE_SCHEMANAME, PROPERTY_ID_UPDATE_SCHEMANAME, PropertyAttribute::BOUND,
93 0 : &m_sUpdateSchemaName, ::getCppuType(&m_sUpdateSchemaName));
94 :
95 : registerProperty(PROPERTY_UPDATE_CATALOGNAME, PROPERTY_ID_UPDATE_CATALOGNAME, PropertyAttribute::BOUND,
96 0 : &m_sUpdateCatalogName, ::getCppuType(&m_sUpdateCatalogName));
97 :
98 : registerProperty(PROPERTY_LAYOUTINFORMATION, PROPERTY_ID_LAYOUTINFORMATION, PropertyAttribute::BOUND,
99 0 : &m_aLayoutInformation, ::getCppuType(&m_aLayoutInformation));
100 0 : }
101 :
102 0 : Reference< XPropertySetInfo > SAL_CALL OQueryDescriptor::getPropertySetInfo( ) throw(RuntimeException)
103 : {
104 0 : return createPropertySetInfo( getInfoHelper() ) ;
105 : }
106 :
107 0 : ::cppu::IPropertyArrayHelper& OQueryDescriptor::getInfoHelper()
108 : {
109 0 : return *getArrayHelper();
110 : }
111 :
112 0 : ::cppu::IPropertyArrayHelper* OQueryDescriptor::createArrayHelper( ) const
113 : {
114 0 : Sequence< Property > aProps;
115 0 : describeProperties(aProps);
116 0 : return new ::cppu::OPropertyArrayHelper(aProps);
117 : }
118 :
119 : DBG_NAME(OQueryDescriptor_Base);
120 :
121 0 : OQueryDescriptor_Base::OQueryDescriptor_Base(::osl::Mutex& _rMutex,::cppu::OWeakObject& _rMySelf)
122 : :m_bColumnsOutOfDate(sal_True)
123 0 : ,m_rMutex(_rMutex)
124 : {
125 : DBG_CTOR(OQueryDescriptor_Base,NULL);
126 0 : m_pColumns = new OColumns(_rMySelf, m_rMutex, sal_True,::std::vector< ::rtl::OUString>(), this,this);
127 0 : }
128 :
129 0 : OQueryDescriptor_Base::OQueryDescriptor_Base(const OQueryDescriptor_Base& _rSource,::cppu::OWeakObject& _rMySelf)
130 : :m_bColumnsOutOfDate(sal_True)
131 0 : ,m_rMutex(_rSource.m_rMutex)
132 : {
133 : DBG_CTOR(OQueryDescriptor_Base,NULL);
134 0 : m_pColumns = new OColumns(_rMySelf, m_rMutex, sal_True,::std::vector< ::rtl::OUString>(), this,this);
135 :
136 0 : m_sCommand = _rSource.m_sCommand;
137 0 : m_bEscapeProcessing = _rSource.m_bEscapeProcessing;
138 0 : m_sUpdateTableName = _rSource.m_sUpdateTableName;
139 0 : m_sUpdateSchemaName = _rSource.m_sUpdateSchemaName;
140 0 : m_sUpdateCatalogName = _rSource.m_sUpdateCatalogName;
141 0 : m_aLayoutInformation = _rSource.m_aLayoutInformation;
142 0 : }
143 :
144 0 : OQueryDescriptor_Base::~OQueryDescriptor_Base()
145 : {
146 0 : m_pColumns->acquire();
147 0 : m_pColumns->disposing();
148 0 : delete m_pColumns;
149 :
150 : DBG_DTOR(OQueryDescriptor_Base,NULL);
151 0 : }
152 :
153 0 : sal_Int64 SAL_CALL OQueryDescriptor_Base::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw(RuntimeException)
154 : {
155 0 : if (_rIdentifier.getLength() != 16)
156 0 : return 0;
157 :
158 0 : if (0 == memcmp(getImplementationId().getConstArray(), _rIdentifier.getConstArray(), 16 ) )
159 0 : return reinterpret_cast<sal_Int64>(this);
160 :
161 0 : return 0;
162 : }
163 :
164 0 : IMPLEMENT_IMPLEMENTATION_ID(OQueryDescriptor_Base)
165 :
166 0 : void OQueryDescriptor_Base::setColumnsOutOfDate( sal_Bool _bOutOfDate )
167 : {
168 0 : m_bColumnsOutOfDate = _bOutOfDate;
169 0 : if ( !m_bColumnsOutOfDate )
170 0 : m_pColumns->setInitialized();
171 0 : }
172 :
173 0 : void OQueryDescriptor_Base::implAppendColumn( const ::rtl::OUString& _rName, OColumn* _pColumn )
174 : {
175 0 : m_pColumns->append( _rName, _pColumn );
176 0 : }
177 :
178 0 : void OQueryDescriptor_Base::clearColumns( )
179 : {
180 0 : m_pColumns->clearColumns();
181 :
182 0 : setColumnsOutOfDate();
183 0 : }
184 :
185 0 : Reference< XNameAccess > SAL_CALL OQueryDescriptor_Base::getColumns( ) throw (RuntimeException)
186 : {
187 0 : MutexGuard aGuard(m_rMutex);
188 :
189 0 : if ( isColumnsOutOfDate() )
190 : {
191 : // clear the current columns
192 0 : clearColumns();
193 :
194 : // do this before rebuildColumns. This prevents recursion, e.g. in the case where we
195 : // have queries with cyclic references:
196 : // foo := SELECT * FROM bar
197 : // bar := SELECT * FROM foo
198 0 : setColumnsOutOfDate( sal_False );
199 :
200 : // rebuild them
201 : try
202 : {
203 0 : rebuildColumns();
204 : }
205 0 : catch ( const Exception& )
206 : {
207 0 : setColumnsOutOfDate( sal_True );
208 0 : throw;
209 : }
210 : }
211 :
212 0 : return m_pColumns;
213 : }
214 :
215 0 : ::rtl::OUString SAL_CALL OQueryDescriptor_Base::getImplementationName( ) throw(RuntimeException)
216 : {
217 0 : return ::rtl::OUString("com.sun.star.sdb.OQueryDescriptor");
218 : }
219 :
220 0 : sal_Bool SAL_CALL OQueryDescriptor_Base::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
221 : {
222 0 : return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
223 : }
224 :
225 0 : Sequence< ::rtl::OUString > SAL_CALL OQueryDescriptor_Base::getSupportedServiceNames( ) throw(RuntimeException)
226 : {
227 0 : Sequence< ::rtl::OUString > aSupported(2);
228 0 : aSupported.getArray()[0] = SERVICE_SDB_DATASETTINGS;
229 0 : aSupported.getArray()[1] = SERVICE_SDB_QUERYDESCRIPTOR;
230 0 : return aSupported;
231 : }
232 :
233 0 : void OQueryDescriptor_Base::disposeColumns()
234 : {
235 0 : m_pColumns->disposing();
236 0 : }
237 :
238 0 : void OQueryDescriptor_Base::columnAppended( const Reference< XPropertySet >& /*_rxSourceDescriptor*/ )
239 : {
240 : // not interested in
241 0 : }
242 :
243 0 : void OQueryDescriptor_Base::columnDropped(const ::rtl::OUString& /*_sName*/)
244 : {
245 : // not interested in
246 0 : }
247 :
248 0 : Reference< XPropertySet > OQueryDescriptor_Base::createColumnDescriptor()
249 : {
250 : OSL_FAIL( "OQueryDescriptor_Base::createColumnDescriptor: called why?" );
251 0 : return NULL;
252 : }
253 :
254 0 : void OQueryDescriptor_Base::rebuildColumns( )
255 : {
256 0 : }
257 :
258 : // IRefreshableColumns
259 0 : void OQueryDescriptor_Base::refreshColumns()
260 : {
261 0 : MutexGuard aGuard( m_rMutex );
262 :
263 0 : clearColumns();
264 0 : rebuildColumns();
265 0 : }
266 :
267 0 : OColumn* OQueryDescriptor_Base::createColumn( const ::rtl::OUString& /*_rName*/ ) const
268 : {
269 : // creating a column/descriptor for a query/descriptor does not make sense at all
270 0 : return NULL;
271 : }
272 :
273 : }
274 :
275 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|