1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26
27 #ifndef _DBA_COREAPI_QUERYDESCRIPTOR_HXX_
28 #include "querydescriptor.hxx"
29 #endif
30 #ifndef _DBASHARED_APITOOLS_HXX_
31 #include "apitools.hxx"
32 #endif
33 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
34 #include "dbastrings.hrc"
35 #endif
36 #ifndef _COMPHELPER_PROPERTY_HXX_
37 #include <comphelper/property.hxx>
38 #endif
39 #ifndef _COMPHELPER_SEQUENCE_HXX_
40 #include <comphelper/sequence.hxx>
41 #endif
42 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
43 #include <cppuhelper/typeprovider.hxx>
44 #endif
45 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
46 #include <com/sun/star/beans/PropertyAttribute.hpp>
47 #endif
48 #ifndef _DBACORE_DEFINITIONCOLUMN_HXX_
49 #include "definitioncolumn.hxx"
50 #endif
51 #ifndef _TOOLS_DEBUG_HXX
52 #include <tools/debug.hxx>
53 #endif
54
55 using namespace ::com::sun::star::uno;
56 using namespace ::com::sun::star::awt;
57 using namespace ::com::sun::star::lang;
58 using namespace ::com::sun::star::beans;
59 using namespace ::com::sun::star::container;
60 using namespace ::com::sun::star::util;
61 using namespace ::comphelper;
62 using namespace ::osl;
63 using namespace ::cppu;
64
65 //........................................................................
66 namespace dbaccess
67 {
68 //........................................................................
69
70 //==========================================================================
71 //= OQueryDescriptor
72 //==========================================================================
DBG_NAME(OQueryDescriptor)73 DBG_NAME(OQueryDescriptor)
74 //--------------------------------------------------------------------------
75 OQueryDescriptor::OQueryDescriptor()
76 :OQueryDescriptor_Base(m_aMutex,*this)
77 ,ODataSettings(m_aBHelper,sal_True)
78 {
79 DBG_CTOR(OQueryDescriptor,NULL);
80 registerProperties();
81 ODataSettings::registerPropertiesFor(this);
82 }
83
84 //--------------------------------------------------------------------------
OQueryDescriptor(const OQueryDescriptor_Base & _rSource)85 OQueryDescriptor::OQueryDescriptor(const OQueryDescriptor_Base& _rSource)
86 :OQueryDescriptor_Base(_rSource,*this)
87 ,ODataSettings(m_aBHelper,sal_True)
88 {
89 DBG_CTOR(OQueryDescriptor,NULL);
90 registerProperties();
91 ODataSettings::registerPropertiesFor(this);
92 }
93 // -----------------------------------------------------------------------------
~OQueryDescriptor()94 OQueryDescriptor::~OQueryDescriptor()
95 {
96 DBG_DTOR(OQueryDescriptor,NULL);
97 }
98 // -----------------------------------------------------------------------------
99 IMPLEMENT_TYPEPROVIDER2(OQueryDescriptor,OQueryDescriptor_Base,ODataSettings);
IMPLEMENT_FORWARD_XINTERFACE3(OQueryDescriptor,OWeakObject,OQueryDescriptor_Base,ODataSettings)100 IMPLEMENT_FORWARD_XINTERFACE3( OQueryDescriptor,OWeakObject,OQueryDescriptor_Base,ODataSettings)
101 //--------------------------------------------------------------------------
102 void OQueryDescriptor::registerProperties()
103 {
104 // the properties which OCommandBase supplies (it has no own registration, as it's not derived from
105 // a OPropertyStateContainer)
106 registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND|PropertyAttribute::CONSTRAINED,
107 &m_sElementName, ::getCppuType(&m_sElementName));
108
109 registerProperty(PROPERTY_COMMAND, PROPERTY_ID_COMMAND, PropertyAttribute::BOUND,
110 &m_sCommand, ::getCppuType(&m_sCommand));
111
112 registerProperty(PROPERTY_ESCAPE_PROCESSING, PROPERTY_ID_ESCAPE_PROCESSING, PropertyAttribute::BOUND,
113 &m_bEscapeProcessing, ::getBooleanCppuType());
114
115 registerProperty(PROPERTY_UPDATE_TABLENAME, PROPERTY_ID_UPDATE_TABLENAME, PropertyAttribute::BOUND,
116 &m_sUpdateTableName, ::getCppuType(&m_sUpdateTableName));
117
118 registerProperty(PROPERTY_UPDATE_SCHEMANAME, PROPERTY_ID_UPDATE_SCHEMANAME, PropertyAttribute::BOUND,
119 &m_sUpdateSchemaName, ::getCppuType(&m_sUpdateSchemaName));
120
121 registerProperty(PROPERTY_UPDATE_CATALOGNAME, PROPERTY_ID_UPDATE_CATALOGNAME, PropertyAttribute::BOUND,
122 &m_sUpdateCatalogName, ::getCppuType(&m_sUpdateCatalogName));
123
124 registerProperty(PROPERTY_LAYOUTINFORMATION, PROPERTY_ID_LAYOUTINFORMATION, PropertyAttribute::BOUND,
125 &m_aLayoutInformation, ::getCppuType(&m_aLayoutInformation));
126 }
127 // -----------------------------------------------------------------------------
128 //--------------------------------------------------------------------------
getPropertySetInfo()129 Reference< XPropertySetInfo > SAL_CALL OQueryDescriptor::getPropertySetInfo( ) throw(RuntimeException)
130 {
131 return createPropertySetInfo( getInfoHelper() ) ;
132 }
133
134 //------------------------------------------------------------------------------
getInfoHelper()135 ::cppu::IPropertyArrayHelper& OQueryDescriptor::getInfoHelper()
136 {
137 return *getArrayHelper();
138 }
139 //--------------------------------------------------------------------------
createArrayHelper() const140 ::cppu::IPropertyArrayHelper* OQueryDescriptor::createArrayHelper( ) const
141 {
142 Sequence< Property > aProps;
143 describeProperties(aProps);
144 return new ::cppu::OPropertyArrayHelper(aProps);
145 }
146
147 // -----------------------------------------------------------------------------
148 DBG_NAME(OQueryDescriptor_Base);
149 //--------------------------------------------------------------------------
OQueryDescriptor_Base(::osl::Mutex & _rMutex,::cppu::OWeakObject & _rMySelf)150 OQueryDescriptor_Base::OQueryDescriptor_Base(::osl::Mutex& _rMutex,::cppu::OWeakObject& _rMySelf)
151 :m_bColumnsOutOfDate(sal_True)
152 ,m_rMutex(_rMutex)
153 {
154 DBG_CTOR(OQueryDescriptor_Base,NULL);
155 m_pColumns = new OColumns(_rMySelf, m_rMutex, sal_True,::std::vector< ::rtl::OUString>(), this,this);
156 }
157 //--------------------------------------------------------------------------
OQueryDescriptor_Base(const OQueryDescriptor_Base & _rSource,::cppu::OWeakObject & _rMySelf)158 OQueryDescriptor_Base::OQueryDescriptor_Base(const OQueryDescriptor_Base& _rSource,::cppu::OWeakObject& _rMySelf)
159 :m_bColumnsOutOfDate(sal_True)
160 ,m_rMutex(_rSource.m_rMutex)
161 {
162 DBG_CTOR(OQueryDescriptor_Base,NULL);
163 m_pColumns = new OColumns(_rMySelf, m_rMutex, sal_True,::std::vector< ::rtl::OUString>(), this,this);
164
165 m_sCommand = _rSource.m_sCommand;
166 m_bEscapeProcessing = _rSource.m_bEscapeProcessing;
167 m_sUpdateTableName = _rSource.m_sUpdateTableName;
168 m_sUpdateSchemaName = _rSource.m_sUpdateSchemaName;
169 m_sUpdateCatalogName = _rSource.m_sUpdateCatalogName;
170 m_aLayoutInformation = _rSource.m_aLayoutInformation;
171 }
172
173 //--------------------------------------------------------------------------
~OQueryDescriptor_Base()174 OQueryDescriptor_Base::~OQueryDescriptor_Base()
175 {
176 m_pColumns->acquire();
177 m_pColumns->disposing();
178 delete m_pColumns;
179
180 DBG_DTOR(OQueryDescriptor_Base,NULL);
181 }
182 // -----------------------------------------------------------------------------
getSomething(const Sequence<sal_Int8> & _rIdentifier)183 sal_Int64 SAL_CALL OQueryDescriptor_Base::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw(RuntimeException)
184 {
185 if (_rIdentifier.getLength() != 16)
186 return 0;
187
188 if (0 == rtl_compareMemory(getImplementationId().getConstArray(), _rIdentifier.getConstArray(), 16 ) )
189 return reinterpret_cast<sal_Int64>(this);
190
191 return 0;
192 }
193 //--------------------------------------------------------------------------
IMPLEMENT_IMPLEMENTATION_ID(OQueryDescriptor_Base)194 IMPLEMENT_IMPLEMENTATION_ID(OQueryDescriptor_Base)
195 //--------------------------------------------------------------------------
196 void OQueryDescriptor_Base::setColumnsOutOfDate( sal_Bool _bOutOfDate )
197 {
198 m_bColumnsOutOfDate = _bOutOfDate;
199 if ( !m_bColumnsOutOfDate )
200 m_pColumns->setInitialized();
201 }
202
203 //--------------------------------------------------------------------------
implAppendColumn(const::rtl::OUString & _rName,OColumn * _pColumn)204 void OQueryDescriptor_Base::implAppendColumn( const ::rtl::OUString& _rName, OColumn* _pColumn )
205 {
206 m_pColumns->append( _rName, _pColumn );
207 }
208
209 //--------------------------------------------------------------------------
clearColumns()210 void OQueryDescriptor_Base::clearColumns( )
211 {
212 m_pColumns->clearColumns();
213
214 setColumnsOutOfDate();
215 }
216
217 //--------------------------------------------------------------------------
getColumns()218 Reference< XNameAccess > SAL_CALL OQueryDescriptor_Base::getColumns( ) throw (RuntimeException)
219 {
220 MutexGuard aGuard(m_rMutex);
221
222 if ( isColumnsOutOfDate() )
223 {
224 // clear the current columns
225 clearColumns();
226
227 // do this before rebuildColumns. This prevents recursion, e.g. in the case where we
228 // have queries with cyclic references:
229 // foo := SELECT * FROM bar
230 // bar := SELECT * FROM foo
231 setColumnsOutOfDate( sal_False );
232
233 // rebuild them
234 try
235 {
236 rebuildColumns();
237 }
238 catch ( const Exception& )
239 {
240 setColumnsOutOfDate( sal_True );
241 throw;
242 }
243 }
244
245 return m_pColumns;
246 }
247
248 //--------------------------------------------------------------------------
getImplementationName()249 ::rtl::OUString SAL_CALL OQueryDescriptor_Base::getImplementationName( ) throw(RuntimeException)
250 {
251 return ::rtl::OUString::createFromAscii("com.sun.star.sdb.OQueryDescriptor");
252 }
253
254 //--------------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)255 sal_Bool SAL_CALL OQueryDescriptor_Base::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
256 {
257 return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
258 }
259
260 //--------------------------------------------------------------------------
getSupportedServiceNames()261 Sequence< ::rtl::OUString > SAL_CALL OQueryDescriptor_Base::getSupportedServiceNames( ) throw(RuntimeException)
262 {
263 Sequence< ::rtl::OUString > aSupported(2);
264 aSupported.getArray()[0] = SERVICE_SDB_DATASETTINGS;
265 aSupported.getArray()[1] = SERVICE_SDB_QUERYDESCRIPTOR;
266 return aSupported;
267 }
268 //--------------------------------------------------------------------------
disposeColumns()269 void OQueryDescriptor_Base::disposeColumns()
270 {
271 m_pColumns->disposing();
272 }
273
274 // -----------------------------------------------------------------------------
columnAppended(const Reference<XPropertySet> &)275 void OQueryDescriptor_Base::columnAppended( const Reference< XPropertySet >& /*_rxSourceDescriptor*/ )
276 {
277 // not interested in
278 }
279
280 // -----------------------------------------------------------------------------
columnDropped(const::rtl::OUString &)281 void OQueryDescriptor_Base::columnDropped(const ::rtl::OUString& /*_sName*/)
282 {
283 // not interested in
284 }
285
286 // -----------------------------------------------------------------------------
createColumnDescriptor()287 Reference< XPropertySet > OQueryDescriptor_Base::createColumnDescriptor()
288 {
289 OSL_ENSURE( false, "OQueryDescriptor_Base::createColumnDescriptor: called why?" );
290 return NULL;
291 }
292
293 // -----------------------------------------------------------------------------
rebuildColumns()294 void OQueryDescriptor_Base::rebuildColumns( )
295 {
296 }
297
298 // -----------------------------------------------------------------------------
299 // IRefreshableColumns
refreshColumns()300 void OQueryDescriptor_Base::refreshColumns()
301 {
302 MutexGuard aGuard( m_rMutex );
303
304 clearColumns();
305 rebuildColumns();
306 }
307
308 //------------------------------------------------------------------------------
createColumn(const::rtl::OUString &) const309 OColumn* OQueryDescriptor_Base::createColumn( const ::rtl::OUString& /*_rName*/ ) const
310 {
311 // creating a column/descriptor for a query/descriptor does not make sense at all
312 return NULL;
313 }
314 // -----------------------------------------------------------------------------
315 //........................................................................
316 } // namespace dbaccess
317 //........................................................................
318
319
320