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 : #include "RowSet.hxx"
22 : #include "dbastrings.hrc"
23 : #include "sdbcoretools.hxx"
24 : #include "SingleSelectQueryComposer.hxx"
25 : #include "module_dba.hxx"
26 : #include "CRowSetColumn.hxx"
27 : #include "CRowSetDataColumn.hxx"
28 : #include "RowSetCache.hxx"
29 : #include "core_resource.hrc"
30 : #include "core_resource.hxx"
31 : #include "tablecontainer.hxx"
32 :
33 : #include <com/sun/star/beans/PropertyAttribute.hpp>
34 : #include <com/sun/star/container/XChild.hpp>
35 : #include <com/sun/star/lang/DisposedException.hpp>
36 : #include <com/sun/star/sdb/CommandType.hpp>
37 : #include <com/sun/star/sdb/DatabaseContext.hpp>
38 : #include <com/sun/star/sdb/ErrorCondition.hpp>
39 : #include <com/sun/star/sdb/RowChangeAction.hpp>
40 : #include <com/sun/star/sdb/RowSetVetoException.hpp>
41 : #include <com/sun/star/sdb/XCompletedConnection.hpp>
42 : #include <com/sun/star/sdb/XParametersSupplier.hpp>
43 : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
44 : #include <com/sun/star/sdbc/FetchDirection.hpp>
45 : #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
46 : #include <com/sun/star/sdbc/XDataSource.hpp>
47 : #include <com/sun/star/sdbc/XDriverAccess.hpp>
48 : #include <com/sun/star/sdbcx/CompareBookmark.hpp>
49 : #include <com/sun/star/sdbcx/Privilege.hpp>
50 : #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
51 : #include <com/sun/star/uno/XNamingService.hpp>
52 : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
53 :
54 : #include <comphelper/componentcontext.hxx>
55 : #include <comphelper/extract.hxx>
56 : #include <comphelper/interaction.hxx>
57 : #include <comphelper/property.hxx>
58 : #include <comphelper/seqstream.hxx>
59 : #include <comphelper/sequence.hxx>
60 : #include <comphelper/types.hxx>
61 : #include <comphelper/uno3.hxx>
62 : #include <connectivity/BlobHelper.hxx>
63 : #include <connectivity/dbconversion.hxx>
64 : #include <connectivity/dbexception.hxx>
65 : #include <connectivity/dbtools.hxx>
66 : #include <cppuhelper/exc_hlp.hxx>
67 : #include <cppuhelper/interfacecontainer.h>
68 : #include <cppuhelper/typeprovider.hxx>
69 : #include <rtl/logfile.hxx>
70 : #include <unotools/syslocale.hxx>
71 : #include <tools/debug.hxx>
72 : #include <tools/diagnose_ex.h>
73 : #include <unotools/configmgr.hxx>
74 :
75 : using namespace utl;
76 : using namespace dbaccess;
77 : using namespace connectivity;
78 : using namespace comphelper;
79 : using namespace dbtools;
80 : using namespace ::com::sun::star;
81 : using namespace ::com::sun::star::uno;
82 : using namespace ::com::sun::star::beans;
83 : using namespace ::com::sun::star::sdbc;
84 : using namespace ::com::sun::star::sdb;
85 : using namespace ::com::sun::star::sdbcx;
86 : using namespace ::com::sun::star::container;
87 : using namespace ::com::sun::star::lang;
88 : using namespace ::com::sun::star::task;
89 : using namespace ::com::sun::star::util;
90 : using namespace ::cppu;
91 : using namespace ::osl;
92 :
93 3 : extern "C" void SAL_CALL createRegistryInfo_ORowSet()
94 : {
95 3 : static ::dba::OAutoRegistration< ORowSet > aAutoRegistration;
96 3 : }
97 :
98 : #define NOTIFY_LISTERNERS_CHECK(_rListeners,T,method) \
99 : Sequence< Reference< XInterface > > aListenerSeq = _rListeners.getElements(); \
100 : \
101 : const Reference< XInterface >* pxIntBegin = aListenerSeq.getConstArray(); \
102 : const Reference< XInterface >* pxInt = pxIntBegin + aListenerSeq.getLength(); \
103 : \
104 : _rGuard.clear(); \
105 : sal_Bool bCheck = sal_True; \
106 : while( pxInt > pxIntBegin && bCheck ) \
107 : { \
108 : try \
109 : { \
110 : while( pxInt > pxIntBegin && bCheck ) \
111 : { \
112 : --pxInt; \
113 : bCheck = static_cast< T* >( pxInt->get() )->method(aEvt); \
114 : } \
115 : } \
116 : catch( RuntimeException& ) \
117 : { \
118 : } \
119 : } \
120 : _rGuard.reset();
121 :
122 :
123 : namespace dbaccess
124 : {
125 :
126 4 : Reference< XInterface > ORowSet_CreateInstance(const Reference< XMultiServiceFactory >& _rxFactory)
127 : {
128 4 : return *(new ORowSet(_rxFactory));
129 : }
130 :
131 4 : ORowSet::ORowSet( const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB )
132 : :ORowSet_BASE1(m_aMutex)
133 : ,ORowSetBase( _rxORB, ORowSet_BASE1::rBHelper, &m_aMutex )
134 : ,m_pParameters( NULL )
135 : ,m_aRowsetListeners(*m_pMutex)
136 : ,m_aApproveListeners(*m_pMutex)
137 : ,m_aRowsChangeListener(*m_pMutex)
138 : ,m_pTables(NULL)
139 : ,m_nFetchDirection(FetchDirection::FORWARD)
140 : ,m_nFetchSize(50)
141 : ,m_nMaxFieldSize(0)
142 : ,m_nMaxRows(0)
143 : ,m_nQueryTimeOut(0)
144 : ,m_nCommandType(CommandType::COMMAND)
145 : ,m_nTransactionIsolation(0)
146 : ,m_nPrivileges(0)
147 : ,m_nInAppend(0)
148 : ,m_bUseEscapeProcessing(sal_True)
149 : ,m_bApplyFilter(sal_False)
150 : ,m_bCommandFacetsDirty( sal_True )
151 : ,m_bModified(sal_False)
152 : ,m_bRebuildConnOnExecute(sal_False)
153 : ,m_bIsBookmarkable(sal_True)
154 : ,m_bNew(sal_False)
155 : ,m_bCanUpdateInsertedRows(sal_True)
156 : ,m_bOwnConnection(sal_False)
157 4 : ,m_bPropChangeNotifyEnabled(sal_True)
158 : {
159 4 : m_nResultSetType = ResultSetType::SCROLL_SENSITIVE;
160 4 : m_nResultSetConcurrency = ResultSetConcurrency::UPDATABLE;
161 4 : m_pMySelf = this;
162 4 : m_aActiveConnection <<= m_xActiveConnection;
163 :
164 4 : sal_Int32 nRBT = PropertyAttribute::READONLY | PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT;
165 4 : sal_Int32 nRT = PropertyAttribute::READONLY | PropertyAttribute::TRANSIENT;
166 4 : sal_Int32 nBT = PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT;
167 :
168 4 : m_aPrematureParamValues.get().resize( 0 );
169 :
170 : // sdb.RowSet Properties
171 4 : registerMayBeVoidProperty(PROPERTY_ACTIVE_CONNECTION,PROPERTY_ID_ACTIVE_CONNECTION, PropertyAttribute::MAYBEVOID|PropertyAttribute::TRANSIENT|PropertyAttribute::BOUND, &m_aActiveConnection, ::getCppuType(static_cast< Reference< XConnection >* >(0)));
172 4 : registerProperty(PROPERTY_DATASOURCENAME, PROPERTY_ID_DATASOURCENAME, PropertyAttribute::BOUND, &m_aDataSourceName, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
173 4 : registerProperty(PROPERTY_COMMAND, PROPERTY_ID_COMMAND, PropertyAttribute::BOUND, &m_aCommand, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
174 4 : registerProperty(PROPERTY_COMMAND_TYPE, PROPERTY_ID_COMMAND_TYPE, PropertyAttribute::BOUND, &m_nCommandType, ::getCppuType(static_cast< sal_Int32*>(0)));
175 4 : registerProperty(PROPERTY_ACTIVECOMMAND, PROPERTY_ID_ACTIVECOMMAND, nRBT, &m_aActiveCommand, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
176 4 : registerProperty(PROPERTY_IGNORERESULT, PROPERTY_ID_IGNORERESULT, PropertyAttribute::BOUND, &m_bIgnoreResult, ::getBooleanCppuType());
177 4 : registerProperty(PROPERTY_FILTER, PROPERTY_ID_FILTER, PropertyAttribute::BOUND, &m_aFilter, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
178 4 : registerProperty(PROPERTY_HAVING_CLAUSE, PROPERTY_ID_HAVING_CLAUSE, PropertyAttribute::BOUND, &m_aHavingClause, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
179 4 : registerProperty(PROPERTY_GROUP_BY, PROPERTY_ID_GROUP_BY, PropertyAttribute::BOUND, &m_aGroupBy, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
180 4 : registerProperty(PROPERTY_APPLYFILTER, PROPERTY_ID_APPLYFILTER, PropertyAttribute::BOUND, &m_bApplyFilter, ::getBooleanCppuType());
181 4 : registerProperty(PROPERTY_ORDER, PROPERTY_ID_ORDER, PropertyAttribute::BOUND, &m_aOrder, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
182 4 : registerProperty(PROPERTY_PRIVILEGES, PROPERTY_ID_PRIVILEGES, nRT, &m_nPrivileges, ::getCppuType(static_cast< sal_Int32*>(0)));
183 4 : registerProperty(PROPERTY_ISMODIFIED, PROPERTY_ID_ISMODIFIED, nBT, &m_bModified, ::getBooleanCppuType());
184 4 : registerProperty(PROPERTY_ISNEW, PROPERTY_ID_ISNEW, nRBT, &m_bNew, ::getBooleanCppuType());
185 4 : registerProperty(PROPERTY_SINGLESELECTQUERYCOMPOSER,PROPERTY_ID_SINGLESELECTQUERYCOMPOSER, nRT, &m_xComposer, ::getCppuType(static_cast< Reference< XSingleSelectQueryComposer >* >(0)));
186 :
187 : // sdbcx.ResultSet Properties
188 4 : registerProperty(PROPERTY_ISBOOKMARKABLE, PROPERTY_ID_ISBOOKMARKABLE, nRT, &m_bIsBookmarkable, ::getBooleanCppuType());
189 4 : registerProperty(PROPERTY_CANUPDATEINSERTEDROWS,PROPERTY_ID_CANUPDATEINSERTEDROWS, nRT, &m_bCanUpdateInsertedRows, ::getBooleanCppuType());
190 : // sdbc.ResultSet Properties
191 4 : registerProperty(PROPERTY_RESULTSETCONCURRENCY, PROPERTY_ID_RESULTSETCONCURRENCY, PropertyAttribute::TRANSIENT, &m_nResultSetConcurrency,::getCppuType(static_cast< sal_Int32*>(0)));
192 4 : registerProperty(PROPERTY_RESULTSETTYPE, PROPERTY_ID_RESULTSETTYPE, PropertyAttribute::TRANSIENT, &m_nResultSetType, ::getCppuType(static_cast< sal_Int32*>(0)));
193 4 : registerProperty(PROPERTY_FETCHDIRECTION, PROPERTY_ID_FETCHDIRECTION, PropertyAttribute::TRANSIENT, &m_nFetchDirection, ::getCppuType(static_cast< sal_Int32*>(0)));
194 4 : registerProperty(PROPERTY_FETCHSIZE, PROPERTY_ID_FETCHSIZE, PropertyAttribute::TRANSIENT, &m_nFetchSize, ::getCppuType(static_cast< sal_Int32*>(0)));
195 :
196 : // sdbc.RowSet Properties
197 4 : registerProperty(PROPERTY_URL, PROPERTY_ID_URL, 0, &m_aURL, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
198 4 : registerProperty(PROPERTY_TRANSACTIONISOLATION, PROPERTY_ID_TRANSACTIONISOLATION, PropertyAttribute::TRANSIENT, &m_nTransactionIsolation,::getCppuType(static_cast< sal_Int32*>(0)));
199 4 : registerMayBeVoidProperty(PROPERTY_TYPEMAP, PROPERTY_ID_TYPEMAP, PropertyAttribute::MAYBEVOID|PropertyAttribute::TRANSIENT, &m_aTypeMap, ::getCppuType(static_cast< Reference< XNameAccess >* >(0)));
200 4 : registerProperty(PROPERTY_ESCAPE_PROCESSING,PROPERTY_ID_ESCAPE_PROCESSING, PropertyAttribute::BOUND, &m_bUseEscapeProcessing,::getBooleanCppuType() );
201 4 : registerProperty(PROPERTY_QUERYTIMEOUT, PROPERTY_ID_QUERYTIMEOUT, PropertyAttribute::TRANSIENT, &m_nQueryTimeOut, ::getCppuType(static_cast< sal_Int32*>(0)));
202 4 : registerProperty(PROPERTY_MAXFIELDSIZE, PROPERTY_ID_MAXFIELDSIZE, PropertyAttribute::TRANSIENT, &m_nMaxFieldSize, ::getCppuType(static_cast< sal_Int32*>(0)));
203 4 : registerProperty(PROPERTY_MAXROWS, PROPERTY_ID_MAXROWS, 0, &m_nMaxRows, ::getCppuType(static_cast< sal_Int32*>(0)) );
204 4 : registerProperty(PROPERTY_USER, PROPERTY_ID_USER, PropertyAttribute::TRANSIENT, &m_aUser, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
205 4 : registerProperty(PROPERTY_PASSWORD, PROPERTY_ID_PASSWORD, PropertyAttribute::TRANSIENT, &m_aPassword, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
206 :
207 4 : registerProperty(PROPERTY_UPDATE_CATALOGNAME, PROPERTY_ID_UPDATE_CATALOGNAME, PropertyAttribute::BOUND, &m_aUpdateCatalogName, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
208 4 : registerProperty(PROPERTY_UPDATE_SCHEMANAME, PROPERTY_ID_UPDATE_SCHEMANAME, PropertyAttribute::BOUND, &m_aUpdateSchemaName, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
209 4 : registerProperty(PROPERTY_UPDATE_TABLENAME, PROPERTY_ID_UPDATE_TABLENAME, PropertyAttribute::BOUND, &m_aUpdateTableName, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
210 :
211 : // ???
212 4 : registerProperty(PROPERTY_CHANGE_NOTIFICATION_ENABLED, PROPERTY_ID_PROPCHANGE_NOTIFY, PropertyAttribute::BOUND, &m_bPropChangeNotifyEnabled, ::getBooleanCppuType());
213 4 : }
214 :
215 6 : ORowSet::~ORowSet()
216 : {
217 2 : if ( !m_rBHelper.bDisposed && !m_rBHelper.bInDispose )
218 : {
219 : OSL_FAIL("Please check who doesn't dispose this component!");
220 0 : osl_atomic_increment( &m_refCount );
221 0 : dispose();
222 : }
223 4 : }
224 :
225 0 : void ORowSet::getPropertyDefaultByHandle( sal_Int32 _nHandle, Any& _rDefault ) const
226 : {
227 0 : switch( _nHandle )
228 : {
229 : case PROPERTY_ID_COMMAND_TYPE:
230 0 : _rDefault <<= static_cast<sal_Int32>(CommandType::COMMAND);
231 0 : break;
232 : case PROPERTY_ID_IGNORERESULT:
233 0 : _rDefault <<= sal_False;
234 0 : break;
235 : case PROPERTY_ID_APPLYFILTER:
236 0 : _rDefault <<= sal_False;
237 0 : break;
238 : case PROPERTY_ID_ISMODIFIED:
239 0 : _rDefault <<= sal_False;
240 0 : break;
241 : case PROPERTY_ID_ISBOOKMARKABLE:
242 0 : _rDefault <<= sal_True;
243 0 : break;
244 : case PROPERTY_ID_CANUPDATEINSERTEDROWS:
245 0 : _rDefault <<= sal_True;
246 0 : break;
247 : case PROPERTY_ID_RESULTSETTYPE:
248 0 : _rDefault <<= ResultSetType::SCROLL_INSENSITIVE;
249 0 : break;
250 : case PROPERTY_ID_RESULTSETCONCURRENCY:
251 0 : _rDefault <<= ResultSetConcurrency::UPDATABLE;
252 0 : break;
253 : case PROPERTY_ID_FETCHDIRECTION:
254 0 : _rDefault <<= FetchDirection::FORWARD;
255 0 : break;
256 : case PROPERTY_ID_FETCHSIZE:
257 0 : _rDefault <<= static_cast<sal_Int32>(1);
258 0 : break;
259 : case PROPERTY_ID_ESCAPE_PROCESSING:
260 0 : _rDefault <<= sal_True;
261 0 : break;
262 : case PROPERTY_ID_MAXROWS:
263 0 : _rDefault <<= sal_Int32( 0 );
264 0 : break;
265 : case PROPERTY_ID_FILTER:
266 : case PROPERTY_ID_HAVING_CLAUSE:
267 : case PROPERTY_ID_GROUP_BY:
268 : case PROPERTY_ID_ORDER:
269 : case PROPERTY_ID_UPDATE_CATALOGNAME:
270 : case PROPERTY_ID_UPDATE_SCHEMANAME:
271 : case PROPERTY_ID_UPDATE_TABLENAME:
272 0 : _rDefault <<= ::rtl::OUString();
273 0 : break;
274 : }
275 0 : }
276 :
277 : // typedef ::comphelper::OPropertyArrayUsageHelper<ORowSet> ORowSet_Prop;
278 6 : void SAL_CALL ORowSet::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception)
279 : {
280 6 : switch(nHandle)
281 : {
282 : case PROPERTY_ID_ISMODIFIED:
283 0 : m_bModified = cppu::any2bool(rValue);
284 0 : break;
285 : case PROPERTY_ID_FETCHDIRECTION:
286 0 : if( m_nResultSetType == ResultSetType::FORWARD_ONLY)
287 0 : throw Exception(); // else run through
288 : default:
289 6 : OPropertyStateContainer::setFastPropertyValue_NoBroadcast(nHandle,rValue);
290 : }
291 :
292 6 : if ( ( nHandle == PROPERTY_ID_ACTIVE_CONNECTION )
293 : || ( nHandle == PROPERTY_ID_DATASOURCENAME )
294 : || ( nHandle == PROPERTY_ID_COMMAND )
295 : || ( nHandle == PROPERTY_ID_COMMAND_TYPE )
296 : || ( nHandle == PROPERTY_ID_IGNORERESULT )
297 : || ( nHandle == PROPERTY_ID_FILTER )
298 : || ( nHandle == PROPERTY_ID_HAVING_CLAUSE )
299 : || ( nHandle == PROPERTY_ID_GROUP_BY )
300 : || ( nHandle == PROPERTY_ID_APPLYFILTER )
301 : || ( nHandle == PROPERTY_ID_ORDER )
302 : || ( nHandle == PROPERTY_ID_URL )
303 : || ( nHandle == PROPERTY_ID_USER )
304 : )
305 : {
306 6 : m_bCommandFacetsDirty = sal_True;
307 : }
308 :
309 :
310 6 : switch(nHandle)
311 : {
312 : case PROPERTY_ID_ACTIVE_CONNECTION:
313 : // the new connection
314 : {
315 1 : Reference< XConnection > xNewConnection(m_aActiveConnection,UNO_QUERY);
316 1 : setActiveConnection(xNewConnection, sal_False);
317 : }
318 :
319 1 : m_bOwnConnection = sal_False;
320 1 : m_bRebuildConnOnExecute = sal_False;
321 1 : break;
322 :
323 : case PROPERTY_ID_DATASOURCENAME:
324 0 : if(!m_xStatement.is())
325 : {
326 0 : Reference< XConnection > xNewConn;
327 0 : Any aNewConn;
328 0 : aNewConn <<= xNewConn;
329 0 : setFastPropertyValue(PROPERTY_ID_ACTIVE_CONNECTION, aNewConn);
330 : }
331 : else
332 0 : m_bRebuildConnOnExecute = sal_True;
333 0 : break;
334 : case PROPERTY_ID_FETCHSIZE:
335 0 : if(m_pCache)
336 : {
337 0 : m_pCache->setFetchSize(m_nFetchSize);
338 0 : fireRowcount();
339 : }
340 0 : break;
341 : case PROPERTY_ID_URL:
342 : // is the connection-to-be-built determined by the url (which is the case if m_aDataSourceName is empty) ?
343 0 : if (m_aDataSourceName.isEmpty())
344 : {
345 : // are we active at the moment ?
346 0 : if (m_xStatement.is())
347 : // yes -> the next execute needs to rebuild our connection because of this new property
348 0 : m_bRebuildConnOnExecute = sal_True;
349 : else
350 : { // no -> drop our active connection (if we have one) as it doesn't correspond to this new property value anymore
351 0 : Reference< XConnection > xNewConn;
352 0 : Any aNewConn;
353 0 : aNewConn <<= xNewConn;
354 0 : setFastPropertyValue(PROPERTY_ID_ACTIVE_CONNECTION, aNewConn);
355 : }
356 : }
357 0 : m_bOwnConnection = sal_True;
358 0 : break;
359 : case PROPERTY_ID_TYPEMAP:
360 0 : ::cppu::extractInterface(m_xTypeMap,m_aTypeMap);
361 0 : break;
362 : case PROPERTY_ID_PROPCHANGE_NOTIFY:
363 0 : m_bPropChangeNotifyEnabled = ::cppu::any2bool(rValue);
364 0 : break;
365 : default:
366 5 : break;
367 : };
368 6 : }
369 :
370 5 : void SAL_CALL ORowSet::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const
371 : {
372 5 : if(m_pCache)
373 : {
374 0 : switch(nHandle)
375 : {
376 : case PROPERTY_ID_ISMODIFIED:
377 0 : rValue.setValue(&m_bModified,::getCppuBooleanType());
378 0 : break;
379 : case PROPERTY_ID_ISNEW:
380 0 : rValue.setValue(&m_bNew,::getCppuBooleanType());
381 0 : break;
382 : case PROPERTY_ID_PRIVILEGES:
383 0 : rValue <<= m_pCache->m_nPrivileges;
384 0 : break;
385 : case PROPERTY_ID_ACTIVE_CONNECTION:
386 0 : rValue <<= m_xActiveConnection;
387 0 : break;
388 : case PROPERTY_ID_TYPEMAP:
389 0 : rValue <<= m_xTypeMap;
390 0 : break;
391 : default:
392 0 : ORowSetBase::getFastPropertyValue(rValue,nHandle);
393 : };
394 : }
395 : else
396 : {
397 5 : switch(nHandle)
398 : {
399 : case PROPERTY_ID_ACTIVE_CONNECTION:
400 3 : rValue <<= m_xActiveConnection;
401 3 : break;
402 : case PROPERTY_ID_TYPEMAP:
403 0 : rValue <<= m_xTypeMap;
404 0 : break;
405 : case PROPERTY_ID_PROPCHANGE_NOTIFY:
406 0 : rValue <<= m_bPropChangeNotifyEnabled;
407 0 : break;
408 : default:
409 2 : ORowSetBase::getFastPropertyValue(rValue,nHandle);
410 : }
411 : }
412 5 : }
413 :
414 : // com::sun::star::XTypeProvider
415 0 : Sequence< Type > SAL_CALL ORowSet::getTypes() throw (RuntimeException)
416 : {
417 0 : OTypeCollection aTypes(::getCppuType( (const Reference< XPropertySet > *)0 ),
418 0 : ::getCppuType( (const Reference< XFastPropertySet > *)0 ),
419 0 : ::getCppuType( (const Reference< XMultiPropertySet > *)0 ),
420 0 : ::comphelper::concatSequences(ORowSet_BASE1::getTypes(),ORowSetBase::getTypes()));
421 0 : return aTypes.getTypes();
422 : }
423 :
424 0 : Sequence< sal_Int8 > SAL_CALL ORowSet::getImplementationId() throw (RuntimeException)
425 : {
426 : static OImplementationId * pId = 0;
427 0 : if (! pId)
428 : {
429 0 : MutexGuard aGuard( Mutex::getGlobalMutex() );
430 0 : if (! pId)
431 : {
432 0 : static OImplementationId aId;
433 0 : pId = &aId;
434 0 : }
435 : }
436 0 : return pId->getImplementationId();
437 : }
438 :
439 : // com::sun::star::XInterface
440 38 : Any SAL_CALL ORowSet::queryInterface( const Type & rType ) throw (RuntimeException)
441 : {
442 38 : return ORowSet_BASE1::queryInterface( rType);
443 : }
444 :
445 126 : void SAL_CALL ORowSet::acquire() throw()
446 : {
447 126 : ORowSet_BASE1::acquire();
448 126 : }
449 :
450 107 : void SAL_CALL ORowSet::release() throw()
451 : {
452 107 : ORowSet_BASE1::release();
453 107 : }
454 :
455 : // com::sun::star::XUnoTunnel
456 0 : sal_Int64 SAL_CALL ORowSet::getSomething( const Sequence< sal_Int8 >& rId ) throw(RuntimeException)
457 : {
458 0 : if (rId.getLength() == 16 && 0 == memcmp(getImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
459 0 : return reinterpret_cast<sal_Int64>(this);
460 :
461 0 : return 0;
462 : }
463 :
464 : // com::sun::star::XAggregation
465 52 : Any SAL_CALL ORowSet::queryAggregation( const Type& rType ) throw(RuntimeException)
466 : {
467 52 : Any aRet(ORowSetBase::queryInterface(rType));
468 52 : if (!aRet.hasValue())
469 28 : aRet = ORowSet_BASE1::queryAggregation(rType);
470 52 : return aRet;
471 : }
472 :
473 3 : rtl::OUString ORowSet::getImplementationName_static( ) throw(RuntimeException)
474 : {
475 3 : return rtl::OUString("com.sun.star.comp.dba.ORowSet");
476 : }
477 :
478 : // ::com::sun::star::XServiceInfo
479 0 : ::rtl::OUString SAL_CALL ORowSet::getImplementationName( ) throw(RuntimeException)
480 : {
481 0 : return getImplementationName_static();
482 : }
483 :
484 0 : sal_Bool SAL_CALL ORowSet::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
485 : {
486 0 : return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
487 : }
488 :
489 3 : Sequence< ::rtl::OUString > ORowSet::getSupportedServiceNames_static( ) throw (RuntimeException)
490 : {
491 3 : Sequence< rtl::OUString > aSNS( 5 );
492 3 : aSNS[0] = SERVICE_SDBC_RESULTSET;
493 3 : aSNS[1] = SERVICE_SDBC_ROWSET;
494 3 : aSNS[2] = SERVICE_SDBCX_RESULTSET;
495 3 : aSNS[3] = SERVICE_SDB_RESULTSET;
496 3 : aSNS[4] = SERVICE_SDB_ROWSET;
497 3 : return aSNS;
498 : }
499 :
500 0 : Sequence< ::rtl::OUString > SAL_CALL ORowSet::getSupportedServiceNames( ) throw(RuntimeException)
501 : {
502 0 : return getSupportedServiceNames_static();
503 : }
504 :
505 4 : Reference< XInterface > ORowSet::Create(const Reference< XComponentContext >& _rxContext)
506 : {
507 4 : ::comphelper::ComponentContext aContext( _rxContext );
508 4 : return ORowSet_CreateInstance( aContext.getLegacyServiceFactory() );
509 : }
510 :
511 : // OComponentHelper
512 3 : void SAL_CALL ORowSet::disposing()
513 : {
514 3 : OPropertyStateContainer::disposing();
515 :
516 3 : MutexGuard aGuard(m_aMutex);
517 3 : EventObject aDisposeEvent;
518 3 : aDisposeEvent.Source = static_cast< XComponent* >(this);
519 3 : m_aRowsetListeners.disposeAndClear( aDisposeEvent );
520 3 : m_aApproveListeners.disposeAndClear( aDisposeEvent );
521 3 : m_aRowsChangeListener.disposeAndClear( aDisposeEvent );
522 :
523 3 : freeResources( true );
524 :
525 : // remove myself as dispose listener
526 3 : Reference< XComponent > xComponent(m_xActiveConnection, UNO_QUERY);
527 3 : if (xComponent.is())
528 : {
529 0 : Reference<XEventListener> xEvt;
530 0 : query_aggregation(this,xEvt);
531 0 : xComponent->removeEventListener(xEvt);
532 : }
533 :
534 3 : m_aActiveConnection = Any(); // the any conatains a reference too
535 3 : if(m_bOwnConnection)
536 0 : ::comphelper::disposeComponent(m_xActiveConnection);
537 3 : m_xActiveConnection = NULL;
538 :
539 :
540 3 : ORowSetBase::disposing();
541 3 : }
542 :
543 3 : void ORowSet::freeResources( bool _bComplete )
544 : {
545 3 : MutexGuard aGuard(m_aMutex);
546 :
547 : // free all clones
548 3 : connectivity::OWeakRefArray::iterator aEnd = m_aClones.end();
549 3 : for (connectivity::OWeakRefArray::iterator i = m_aClones.begin(); aEnd != i; ++i)
550 : {
551 0 : Reference< XComponent > xComp(i->get(), UNO_QUERY);
552 0 : if (xComp.is())
553 0 : xComp->dispose();
554 0 : }
555 3 : m_aClones.clear();
556 :
557 3 : if ( _bComplete )
558 : {
559 : // the columns must be disposed before the querycomposer is disposed because
560 : // their owner can be the composer
561 3 : TDataColumns().swap(m_aDataColumns);// clear and resize capacity
562 3 : ::std::vector<bool>().swap(m_aReadOnlyDataColumns);
563 :
564 3 : m_xColumns = NULL;
565 3 : if ( m_pColumns )
566 0 : m_pColumns->disposing();
567 : // dispose the composer to avoid that everbody knows that the querycomposer is eol
568 3 : try { ::comphelper::disposeComponent( m_xComposer ); }
569 0 : catch(Exception&)
570 : {
571 : DBG_UNHANDLED_EXCEPTION();
572 0 : m_xComposer = NULL;
573 : }
574 :
575 : // let our warnings container forget the reference to the (possibly disposed) old result set
576 3 : m_aWarnings.setExternalWarnings( NULL );
577 :
578 3 : DELETEZ(m_pCache);
579 :
580 3 : impl_resetTables_nothrow();
581 :
582 3 : m_xStatement = NULL;
583 3 : m_xTypeMap = NULL;
584 :
585 3 : m_aBookmark = Any();
586 3 : m_bBeforeFirst = sal_True;
587 3 : m_bAfterLast = sal_False;
588 3 : m_bNew = sal_False;
589 3 : m_bModified = sal_False;
590 3 : m_bIsInsertRow = sal_False;
591 3 : m_bLastKnownRowCountFinal = sal_False;
592 3 : m_nLastKnownRowCount = 0;
593 3 : if ( m_aOldRow.is() )
594 0 : m_aOldRow->clearRow();
595 :
596 3 : impl_disposeParametersContainer_nothrow();
597 :
598 3 : m_bCommandFacetsDirty = sal_True;
599 3 : }
600 3 : }
601 :
602 1 : void ORowSet::setActiveConnection( Reference< XConnection >& _rxNewConn, sal_Bool _bFireEvent )
603 : {
604 1 : if (_rxNewConn.get() == m_xActiveConnection.get())
605 : // nothing to do
606 1 : return;
607 :
608 : // remove the event listener for the old connection
609 0 : Reference< XComponent > xComponent(m_xActiveConnection, UNO_QUERY);
610 0 : if (xComponent.is())
611 : {
612 0 : Reference<XEventListener> xListener;
613 0 : query_aggregation(this, xListener);
614 0 : xComponent->removeEventListener(xListener);
615 : }
616 :
617 : // if we owned the connection, remember it for later disposing
618 0 : if(m_bOwnConnection)
619 0 : m_xOldConnection = m_xActiveConnection;
620 :
621 : // for firing the PropertyChangeEvent
622 0 : sal_Int32 nHandle = PROPERTY_ID_ACTIVE_CONNECTION;
623 0 : Any aOldConnection; aOldConnection <<= m_xActiveConnection;
624 0 : Any aNewConnection; aNewConnection <<= _rxNewConn;
625 :
626 : // set the new connection
627 0 : m_xActiveConnection = _rxNewConn;
628 0 : if (m_xActiveConnection.is())
629 0 : m_aActiveConnection <<= m_xActiveConnection;
630 : else
631 0 : m_aActiveConnection.clear();
632 :
633 : // fire the event
634 0 : if (_bFireEvent)
635 0 : fire(&nHandle, &aNewConnection, &aOldConnection, 1, sal_False);
636 :
637 : // register as event listener for the new connection
638 0 : xComponent.set(m_xActiveConnection,UNO_QUERY);
639 0 : if (xComponent.is())
640 : {
641 0 : Reference<XEventListener> xListener;
642 0 : query_aggregation(this, xListener);
643 0 : xComponent->addEventListener(xListener);
644 0 : }
645 : }
646 :
647 : // ::com::sun::star::XEventListener
648 0 : void SAL_CALL ORowSet::disposing( const ::com::sun::star::lang::EventObject& Source ) throw(RuntimeException)
649 : {
650 : // close rowset because the connection is going to be deleted (someone told me :-)
651 0 : Reference<XConnection> xCon(Source.Source,UNO_QUERY);
652 0 : if(m_xActiveConnection == xCon)
653 : {
654 0 : close();
655 : {
656 0 : MutexGuard aGuard( m_aMutex );
657 0 : Reference< XConnection > xXConnection;
658 0 : setActiveConnection( xXConnection );
659 : }
660 0 : }
661 0 : }
662 :
663 : // XCloseable
664 0 : void SAL_CALL ORowSet::close( ) throw(SQLException, RuntimeException)
665 : {
666 : {
667 0 : MutexGuard aGuard( m_aMutex );
668 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
669 : }
670 : // additionals things to set
671 0 : freeResources( true );
672 0 : }
673 :
674 : // comphelper::OPropertyArrayUsageHelper
675 4 : ::cppu::IPropertyArrayHelper* ORowSet::createArrayHelper( ) const
676 : {
677 4 : Sequence< Property > aProps;
678 4 : describeProperties(aProps);
679 4 : return new ::cppu::OPropertyArrayHelper(aProps);
680 : }
681 :
682 : // cppu::OPropertySetHelper
683 47 : ::cppu::IPropertyArrayHelper& SAL_CALL ORowSet::getInfoHelper()
684 : {
685 : typedef ::comphelper::OPropertyArrayUsageHelper<ORowSet> ORowSet_PROP;
686 47 : return *ORowSet_PROP::getArrayHelper();
687 : }
688 :
689 0 : void ORowSet::updateValue(sal_Int32 columnIndex,const ORowSetValue& x)
690 : {
691 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
692 :
693 0 : ::osl::MutexGuard aGuard( *m_pMutex );
694 0 : checkUpdateConditions(columnIndex);
695 0 : checkUpdateIterator();
696 :
697 0 : ORowSetValueVector::Vector& rRow = ((*m_aCurrentRow)->get());
698 0 : ORowSetNotifier aNotify(this,rRow);
699 0 : m_pCache->updateValue(columnIndex,x,rRow,aNotify.getChangedColumns());
700 0 : m_bModified = m_bModified || !aNotify.getChangedColumns().empty();
701 0 : aNotify.firePropertyChange();
702 0 : }
703 :
704 : // XRowUpdate
705 0 : void SAL_CALL ORowSet::updateNull( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
706 : {
707 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
708 :
709 0 : ::osl::MutexGuard aGuard( *m_pMutex );
710 0 : checkUpdateConditions(columnIndex);
711 0 : checkUpdateIterator();
712 :
713 0 : ORowSetValueVector::Vector& rRow = ((*m_aCurrentRow)->get());
714 0 : ORowSetNotifier aNotify(this,rRow);
715 0 : m_pCache->updateNull(columnIndex,rRow,aNotify.getChangedColumns());
716 0 : m_bModified = m_bModified || !aNotify.getChangedColumns().empty();
717 0 : aNotify.firePropertyChange();
718 0 : }
719 :
720 0 : void SAL_CALL ORowSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) throw(SQLException, RuntimeException)
721 : {
722 0 : updateValue(columnIndex,x);
723 0 : }
724 :
725 0 : void SAL_CALL ORowSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
726 : {
727 0 : updateValue(columnIndex,x);
728 0 : }
729 :
730 0 : void SAL_CALL ORowSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
731 : {
732 0 : updateValue(columnIndex,x);
733 0 : }
734 :
735 0 : void SAL_CALL ORowSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
736 : {
737 0 : updateValue(columnIndex,x);
738 0 : }
739 :
740 0 : void SAL_CALL ORowSet::updateLong( sal_Int32 columnIndex, sal_Int64 x ) throw(SQLException, RuntimeException)
741 : {
742 0 : updateValue(columnIndex,x);
743 0 : }
744 :
745 0 : void SAL_CALL ORowSet::updateFloat( sal_Int32 columnIndex, float x ) throw(SQLException, RuntimeException)
746 : {
747 0 : updateValue(columnIndex,x);
748 0 : }
749 :
750 0 : void SAL_CALL ORowSet::updateDouble( sal_Int32 columnIndex, double x ) throw(SQLException, RuntimeException)
751 : {
752 0 : updateValue(columnIndex,x);
753 0 : }
754 :
755 0 : void SAL_CALL ORowSet::updateString( sal_Int32 columnIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
756 : {
757 0 : updateValue(columnIndex,x);
758 0 : }
759 :
760 0 : void SAL_CALL ORowSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
761 : {
762 0 : updateValue(columnIndex,x);
763 0 : }
764 :
765 0 : void SAL_CALL ORowSet::updateDate( sal_Int32 columnIndex, const ::com::sun::star::util::Date& x ) throw(SQLException, RuntimeException)
766 : {
767 0 : updateValue(columnIndex,x);
768 0 : }
769 :
770 0 : void SAL_CALL ORowSet::updateTime( sal_Int32 columnIndex, const ::com::sun::star::util::Time& x ) throw(SQLException, RuntimeException)
771 : {
772 0 : updateValue(columnIndex,x);
773 0 : }
774 :
775 0 : void SAL_CALL ORowSet::updateTimestamp( sal_Int32 columnIndex, const ::com::sun::star::util::DateTime& x ) throw(SQLException, RuntimeException)
776 : {
777 0 : updateValue(columnIndex,x);
778 0 : }
779 :
780 0 : void SAL_CALL ORowSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
781 : {
782 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
783 0 : ::osl::MutexGuard aGuard( *m_pMutex );
784 0 : checkUpdateConditions(columnIndex);
785 0 : checkUpdateIterator();
786 :
787 : {
788 0 : Sequence<sal_Int8> aSeq;
789 0 : if(x.is())
790 0 : x->readBytes(aSeq,length);
791 0 : updateValue(columnIndex,aSeq);
792 0 : }
793 0 : }
794 :
795 0 : void SAL_CALL ORowSet::updateCharacterStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
796 : {
797 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
798 0 : ::osl::MutexGuard aGuard( *m_pMutex );
799 0 : checkUpdateConditions(columnIndex);
800 0 : checkUpdateIterator();
801 0 : ORowSetValueVector::Vector& rRow = ((*m_aCurrentRow)->get());
802 0 : ORowSetNotifier aNotify(this,rRow);
803 0 : m_pCache->updateCharacterStream(columnIndex,x,length,rRow,aNotify.getChangedColumns());
804 0 : m_bModified = m_bModified || !aNotify.getChangedColumns().empty();
805 0 : aNotify.firePropertyChange();
806 0 : }
807 :
808 0 : void SAL_CALL ORowSet::updateObject( sal_Int32 columnIndex, const Any& x ) throw(SQLException, RuntimeException)
809 : {
810 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
811 0 : ::osl::MutexGuard aGuard( *m_pMutex );
812 0 : checkUpdateConditions(columnIndex);
813 0 : checkUpdateIterator();
814 :
815 0 : Any aNewValue = x;
816 :
817 0 : if ( m_pColumns )
818 : {
819 0 : Reference<XPropertySet> xColumn(m_pColumns->getByIndex(columnIndex-1),UNO_QUERY);
820 0 : sal_Int32 nColType = 0;
821 0 : xColumn->getPropertyValue(PROPERTY_TYPE) >>= nColType;
822 0 : switch( nColType )
823 : {
824 : case DataType::DATE:
825 : case DataType::TIME:
826 : case DataType::TIMESTAMP:
827 : {
828 0 : double nValue = 0;
829 0 : if ( x >>= nValue )
830 : {
831 0 : if ( DataType::TIMESTAMP == nColType )
832 0 : aNewValue <<= dbtools::DBTypeConversion::toDateTime( nValue );
833 0 : else if ( DataType::DATE == nColType )
834 0 : aNewValue <<= dbtools::DBTypeConversion::toDate( nValue );
835 : else
836 0 : aNewValue <<= dbtools::DBTypeConversion::toTime( nValue );
837 : }
838 : break;
839 : }
840 0 : }
841 : }
842 :
843 0 : if (!::dbtools::implUpdateObject(this, columnIndex, aNewValue))
844 : { // there is no other updateXXX call which can handle the value in x
845 0 : ORowSetValueVector::Vector& rRow = ((*m_aCurrentRow)->get());
846 0 : ORowSetNotifier aNotify(this,rRow);
847 0 : m_pCache->updateObject(columnIndex,aNewValue,rRow,aNotify.getChangedColumns());
848 0 : m_bModified = m_bModified || !aNotify.getChangedColumns().empty();
849 0 : aNotify.firePropertyChange();
850 0 : }
851 0 : }
852 :
853 0 : void SAL_CALL ORowSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 scale ) throw(SQLException, RuntimeException)
854 : {
855 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
856 0 : ::osl::MutexGuard aGuard( *m_pMutex );
857 0 : checkUpdateConditions(columnIndex);
858 0 : checkUpdateIterator();
859 0 : ORowSetValueVector::Vector& rRow = ((*m_aCurrentRow)->get());
860 0 : ORowSetNotifier aNotify(this,rRow);
861 0 : m_pCache->updateNumericObject(columnIndex,x,scale,rRow,aNotify.getChangedColumns());
862 0 : m_bModified = m_bModified || !aNotify.getChangedColumns().empty();
863 0 : aNotify.firePropertyChange();
864 0 : }
865 :
866 : // XResultSetUpdate
867 0 : void SAL_CALL ORowSet::insertRow( ) throw(SQLException, RuntimeException)
868 : {
869 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
870 : // insertRow is not allowd when
871 : // standing not on the insert row nor
872 : // when the row isn't modified
873 : // or the concurency is read only
874 0 : ::osl::ResettableMutexGuard aGuard( *m_pMutex );
875 :
876 0 : if(!m_pCache || !m_bNew || !m_bModified || m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY)
877 0 : throwFunctionSequenceException(*this);
878 :
879 : // remember old value for fire
880 0 : sal_Bool bOld = m_bNew;
881 :
882 0 : ORowSetRow aOldValues;
883 0 : if ( !m_aCurrentRow.isNull() )
884 0 : aOldValues = new ORowSetValueVector( *(*m_aCurrentRow));
885 0 : Sequence<Any> aChangedBookmarks;
886 0 : RowsChangeEvent aEvt(*this,RowChangeAction::INSERT,1,aChangedBookmarks);
887 0 : notifyAllListenersRowBeforeChange(aGuard,aEvt);
888 :
889 0 : ::std::vector< Any > aBookmarks;
890 0 : sal_Bool bInserted = m_pCache->insertRow(aBookmarks);
891 :
892 : // make sure that our row is set to the new inserted row before clearing the insert flags in the cache
893 0 : m_pCache->resetInsertRow(bInserted);
894 :
895 : // notification order
896 : // - column values
897 0 : setCurrentRow( sal_False, sal_True, aOldValues, aGuard ); // we don't move here
898 :
899 : // read-only flag restored
900 0 : impl_restoreDataColumnsWriteable_throw();
901 :
902 : // - rowChanged
903 0 : notifyAllListenersRowChanged(aGuard,aEvt);
904 :
905 0 : if ( !aBookmarks.empty() )
906 : {
907 0 : RowsChangeEvent aUpEvt(*this,RowChangeAction::UPDATE,aBookmarks.size(),Sequence<Any>(&(*aBookmarks.begin()),aBookmarks.size()));
908 0 : notifyAllListenersRowChanged(aGuard,aUpEvt);
909 : }
910 :
911 : // - IsModified
912 0 : if(!m_bModified)
913 0 : fireProperty(PROPERTY_ID_ISMODIFIED,sal_False,sal_True);
914 : OSL_ENSURE( !m_bModified, "ORowSet::insertRow: just updated, but _still_ modified?" );
915 :
916 : // - IsNew
917 0 : if(m_bNew != bOld)
918 0 : fireProperty(PROPERTY_ID_ISNEW,m_bNew,bOld);
919 :
920 : // - RowCount/IsRowCountFinal
921 0 : fireRowcount();
922 0 : }
923 :
924 0 : sal_Int32 SAL_CALL ORowSet::getRow( ) throw(SQLException, RuntimeException)
925 : {
926 0 : ::osl::MutexGuard aGuard( *m_pMutex );
927 0 : checkCache();
928 :
929 : // check if we are inserting a row
930 0 : return (m_pCache && isInsertRow()) ? 0 : ORowSetBase::getRow();
931 : }
932 :
933 0 : void SAL_CALL ORowSet::updateRow( ) throw(SQLException, RuntimeException)
934 : {
935 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
936 : // not allowed when standing on insert row
937 0 : ::osl::ResettableMutexGuard aGuard( *m_pMutex );
938 0 : if ( !m_pCache || m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY || m_bNew || ((m_pCache->m_nPrivileges & Privilege::UPDATE ) != Privilege::UPDATE) )
939 0 : throwFunctionSequenceException(*this);
940 :
941 :
942 0 : if(m_bModified)
943 : {
944 0 : ORowSetRow aOldValues;
945 0 : if ( !m_aCurrentRow.isNull() )
946 0 : aOldValues = new ORowSetValueVector( *(*m_aCurrentRow) );
947 :
948 0 : Sequence<Any> aChangedBookmarks;
949 0 : RowsChangeEvent aEvt(*this,RowChangeAction::UPDATE,1,aChangedBookmarks);
950 0 : notifyAllListenersRowBeforeChange(aGuard,aEvt);
951 :
952 0 : ::std::vector< Any > aBookmarks;
953 0 : m_pCache->updateRow(m_aCurrentRow.operator ->(),aBookmarks);
954 0 : if ( !aBookmarks.empty() )
955 0 : aEvt.Bookmarks = Sequence<Any>(&(*aBookmarks.begin()),aBookmarks.size());
956 0 : aEvt.Rows += aBookmarks.size();
957 0 : m_aBookmark = m_pCache->getBookmark();
958 0 : m_aCurrentRow = m_pCache->m_aMatrixIter;
959 0 : m_bIsInsertRow = sal_False;
960 0 : if ( m_pCache->m_aMatrixIter != m_pCache->getEnd() && (*m_pCache->m_aMatrixIter).is() )
961 : {
962 0 : if ( m_pCache->isResultSetChanged() )
963 : {
964 0 : impl_rebuild_throw(aGuard);
965 : }
966 : else
967 : {
968 0 : m_aOldRow->setRow(new ORowSetValueVector(*(*m_aCurrentRow)));
969 :
970 : // notification order
971 : // - column values
972 0 : ORowSetBase::firePropertyChange(aOldValues);
973 : }
974 : // - rowChanged
975 0 : notifyAllListenersRowChanged(aGuard,aEvt);
976 :
977 : // - IsModified
978 0 : if(!m_bModified)
979 0 : fireProperty(PROPERTY_ID_ISMODIFIED,sal_False,sal_True);
980 : OSL_ENSURE( !m_bModified, "ORowSet::updateRow: just updated, but _still_ modified?" );
981 :
982 : // - RowCount/IsRowCountFinal
983 0 : fireRowcount();
984 : }
985 0 : else if ( !m_bAfterLast ) // the update went rong
986 : {
987 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_UPDATE_FAILED ), SQL_INVALID_CURSOR_POSITION, *this );
988 0 : }
989 0 : }
990 0 : }
991 :
992 0 : void SAL_CALL ORowSet::deleteRow( ) throw(SQLException, RuntimeException)
993 : {
994 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
995 :
996 0 : ::osl::ResettableMutexGuard aGuard( *m_pMutex );
997 0 : checkCache();
998 :
999 0 : if ( m_bBeforeFirst || m_bAfterLast )
1000 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_DELETE_BEFORE_AFTER ), SQL_INVALID_CURSOR_POSITION, *this );
1001 0 : if ( m_bNew )
1002 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_DELETE_INSERT_ROW ), SQL_INVALID_CURSOR_POSITION, *this );
1003 0 : if ( m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY )
1004 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_RESULT_IS_READONLY ), SQL_FUNCTION_SEQUENCE_ERROR, *this );
1005 0 : if ( ( m_pCache->m_nPrivileges & Privilege::DELETE ) != Privilege::DELETE )
1006 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_DELETE_PRIVILEGE ), SQL_FUNCTION_SEQUENCE_ERROR, *this );
1007 0 : if ( rowDeleted() )
1008 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_ROW_ALREADY_DELETED ), SQL_FUNCTION_SEQUENCE_ERROR, *this );
1009 :
1010 : // this call position the cache indirect
1011 0 : Any aBookmarkToDelete( m_aBookmark );
1012 0 : positionCache( MOVE_NONE_REFRESH_ONLY );
1013 0 : sal_Int32 nDeletePosition = m_pCache->getRow();
1014 :
1015 0 : notifyRowSetAndClonesRowDelete( aBookmarkToDelete );
1016 :
1017 0 : ORowSetRow aOldValues;
1018 0 : if ( m_pCache->m_aMatrixIter != m_pCache->getEnd() && m_pCache->m_aMatrixIter->is() )
1019 0 : aOldValues = new ORowSetValueVector( *(*(m_pCache->m_aMatrixIter)) );
1020 :
1021 0 : Sequence<Any> aChangedBookmarks;
1022 0 : RowsChangeEvent aEvt(*this,RowChangeAction::DELETE,1,aChangedBookmarks);
1023 0 : notifyAllListenersRowBeforeChange(aGuard,aEvt);
1024 :
1025 0 : m_pCache->deleteRow();
1026 0 : notifyRowSetAndClonesRowDeleted( aBookmarkToDelete, nDeletePosition );
1027 :
1028 0 : ORowSetNotifier aNotifier( this );
1029 : // this will call cancelRowModification on the cache if necessary
1030 :
1031 : // notification order
1032 : // - rowChanged
1033 0 : notifyAllListenersRowChanged(aGuard,aEvt);
1034 :
1035 : // - IsModified
1036 : // - IsNew
1037 0 : aNotifier.fire( );
1038 :
1039 : // - RowCount/IsRowCountFinal
1040 0 : fireRowcount();
1041 0 : }
1042 :
1043 0 : void ORowSet::implCancelRowUpdates( sal_Bool _bNotifyModified ) SAL_THROW( ( SQLException, RuntimeException ) )
1044 : {
1045 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1046 :
1047 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1048 0 : if ( m_bBeforeFirst || m_bAfterLast || rowDeleted() )
1049 0 : return; // nothing to do so return
1050 :
1051 0 : checkCache();
1052 : // cancelRowUpdates is not allowed when:
1053 : // - standing on the insert row
1054 : // - the concurrency is read only
1055 : // - the current row is deleted
1056 0 : if ( m_bNew || m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY )
1057 0 : throwFunctionSequenceException(*this);
1058 :
1059 0 : positionCache( MOVE_NONE_REFRESH_ONLY );
1060 :
1061 0 : ORowSetRow aOldValues;
1062 0 : if ( !m_bModified && _bNotifyModified && !m_aCurrentRow.isNull() )
1063 0 : aOldValues = new ORowSetValueVector( *(*m_aCurrentRow) );
1064 :
1065 0 : m_pCache->cancelRowUpdates();
1066 :
1067 0 : m_aBookmark = m_pCache->getBookmark();
1068 0 : m_aCurrentRow = m_pCache->m_aMatrixIter;
1069 0 : m_bIsInsertRow = sal_False;
1070 0 : m_aCurrentRow.setBookmark(m_aBookmark);
1071 :
1072 : // notification order
1073 : // IsModified
1074 0 : if( !m_bModified && _bNotifyModified )
1075 : {
1076 : // - column values
1077 0 : ORowSetBase::firePropertyChange(aOldValues);
1078 0 : fireProperty(PROPERTY_ID_ISMODIFIED,sal_False,sal_True);
1079 0 : }
1080 : }
1081 :
1082 0 : void SAL_CALL ORowSet::cancelRowUpdates( ) throw(SQLException, RuntimeException)
1083 : {
1084 0 : implCancelRowUpdates( sal_True );
1085 0 : }
1086 :
1087 2 : void SAL_CALL ORowSet::addRowSetListener( const Reference< XRowSetListener >& listener ) throw(RuntimeException)
1088 : {
1089 2 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1090 :
1091 2 : ::osl::MutexGuard aGuard( m_aColumnsMutex );
1092 2 : if(listener.is())
1093 2 : m_aRowsetListeners.addInterface(listener);
1094 2 : }
1095 :
1096 4 : void SAL_CALL ORowSet::removeRowSetListener( const Reference< XRowSetListener >& listener ) throw(RuntimeException)
1097 : {
1098 4 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1099 :
1100 4 : ::osl::MutexGuard aGuard( m_aColumnsMutex );
1101 4 : if(listener.is())
1102 4 : m_aRowsetListeners.removeInterface(listener);
1103 4 : }
1104 :
1105 0 : void ORowSet::notifyAllListeners(::osl::ResettableMutexGuard& _rGuard)
1106 : {
1107 0 : EventObject aEvt(*m_pMySelf);
1108 0 : _rGuard.clear();
1109 0 : m_aRowsetListeners.notifyEach( &XRowSetListener::rowSetChanged, aEvt );
1110 0 : _rGuard.reset();
1111 0 : }
1112 :
1113 0 : void ORowSet::notifyAllListenersCursorMoved(::osl::ResettableMutexGuard& _rGuard)
1114 : {
1115 0 : EventObject aEvt(*m_pMySelf);
1116 0 : _rGuard.clear();
1117 0 : m_aRowsetListeners.notifyEach( &XRowSetListener::cursorMoved, aEvt );
1118 0 : _rGuard.reset();
1119 0 : }
1120 :
1121 0 : void ORowSet::notifyAllListenersRowChanged(::osl::ResettableMutexGuard& _rGuard, const RowsChangeEvent& aEvt)
1122 : {
1123 0 : _rGuard.clear();
1124 0 : m_aRowsetListeners.notifyEach( &XRowSetListener::rowChanged, (EventObject)aEvt );
1125 0 : m_aRowsChangeListener.notifyEach( &XRowsChangeListener::rowsChanged, aEvt );
1126 0 : _rGuard.reset();
1127 0 : }
1128 :
1129 0 : sal_Bool ORowSet::notifyAllListenersCursorBeforeMove(::osl::ResettableMutexGuard& _rGuard)
1130 : {
1131 0 : EventObject aEvt(*m_pMySelf);
1132 0 : NOTIFY_LISTERNERS_CHECK(m_aApproveListeners,XRowSetApproveListener,approveCursorMove);
1133 0 : return bCheck;
1134 : }
1135 :
1136 0 : void ORowSet::notifyAllListenersRowBeforeChange(::osl::ResettableMutexGuard& _rGuard,const RowChangeEvent &aEvt)
1137 : {
1138 0 : NOTIFY_LISTERNERS_CHECK(m_aApproveListeners,XRowSetApproveListener,approveRowChange);
1139 0 : if ( !bCheck )
1140 0 : m_aErrors.raiseTypedException( sdb::ErrorCondition::ROW_SET_OPERATION_VETOED, *this, ::cppu::UnoType< RowSetVetoException >::get() );
1141 0 : }
1142 :
1143 0 : void ORowSet::fireRowcount()
1144 : {
1145 0 : sal_Int32 nCurrentRowCount( impl_getRowCount() );
1146 0 : sal_Bool bCurrentRowCountFinal( m_pCache->m_bRowCountFinal );
1147 :
1148 0 : if ( m_nLastKnownRowCount != nCurrentRowCount )
1149 : {
1150 0 : sal_Int32 nHandle = PROPERTY_ID_ROWCOUNT;
1151 0 : Any aNew,aOld;
1152 0 : aNew <<= nCurrentRowCount; aOld <<= m_nLastKnownRowCount;
1153 0 : fire(&nHandle,&aNew,&aOld,1,sal_False);
1154 0 : m_nLastKnownRowCount = nCurrentRowCount;
1155 : }
1156 0 : if ( !m_bLastKnownRowCountFinal && ( m_bLastKnownRowCountFinal != bCurrentRowCountFinal ) )
1157 : {
1158 0 : sal_Int32 nHandle = PROPERTY_ID_ISROWCOUNTFINAL;
1159 0 : Any aNew,aOld;
1160 0 : aNew <<= bCurrentRowCountFinal;
1161 0 : aOld <<= m_bLastKnownRowCountFinal;
1162 0 : fire(&nHandle,&aNew,&aOld,1,sal_False);
1163 0 : m_bLastKnownRowCountFinal = bCurrentRowCountFinal;
1164 : }
1165 0 : }
1166 :
1167 0 : void SAL_CALL ORowSet::moveToInsertRow( ) throw(SQLException, RuntimeException)
1168 : {
1169 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1170 :
1171 0 : ::osl::ResettableMutexGuard aGuard( *m_pMutex );
1172 0 : checkPositioningAllowed();
1173 0 : if ( ( m_pCache->m_nPrivileges & Privilege::INSERT ) != Privilege::INSERT )
1174 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_INSERT_PRIVILEGE ), SQL_GENERAL_ERROR, *this );
1175 :
1176 0 : if ( notifyAllListenersCursorBeforeMove( aGuard ) )
1177 : {
1178 : // remember old value for fire
1179 0 : ORowSetRow aOldValues;
1180 0 : if ( rowDeleted() )
1181 : {
1182 0 : positionCache( MOVE_FORWARD );
1183 0 : m_pCache->next();
1184 0 : setCurrentRow( sal_True, sal_False, aOldValues, aGuard);
1185 : }
1186 : else
1187 0 : positionCache( MOVE_NONE_REFRESH_ONLY );
1188 :
1189 : // check before because the resultset could be empty
1190 0 : if ( !m_bBeforeFirst
1191 0 : && !m_bAfterLast
1192 0 : && m_pCache->m_aMatrixIter != m_pCache->getEnd()
1193 0 : && m_pCache->m_aMatrixIter->is()
1194 : )
1195 0 : aOldValues = new ORowSetValueVector( *(*(m_pCache->m_aMatrixIter)) );
1196 :
1197 0 : const sal_Bool bNewState = m_bNew;
1198 0 : const sal_Bool bModState = m_bModified;
1199 :
1200 0 : m_pCache->moveToInsertRow();
1201 0 : m_aCurrentRow = m_pCache->m_aInsertRow;
1202 0 : m_bIsInsertRow = sal_True;
1203 :
1204 : // set read-only flag to false
1205 0 : impl_setDataColumnsWriteable_throw();
1206 :
1207 : // notification order
1208 : // - column values
1209 0 : ORowSetBase::firePropertyChange(aOldValues);
1210 :
1211 : // - cursorMoved
1212 0 : notifyAllListenersCursorMoved(aGuard);
1213 :
1214 : // - IsModified
1215 0 : if ( bModState != m_bModified )
1216 0 : fireProperty( PROPERTY_ID_ISMODIFIED, m_bModified, bModState );
1217 :
1218 : // - IsNew
1219 0 : if ( bNewState != m_bNew )
1220 0 : fireProperty( PROPERTY_ID_ISNEW, m_bNew, bNewState );
1221 :
1222 : // - RowCount/IsRowCountFinal
1223 0 : fireRowcount();
1224 0 : }
1225 0 : }
1226 :
1227 0 : void ORowSet::impl_setDataColumnsWriteable_throw()
1228 : {
1229 0 : impl_restoreDataColumnsWriteable_throw();
1230 0 : TDataColumns::iterator aIter = m_aDataColumns.begin();
1231 0 : m_aReadOnlyDataColumns.resize(m_aDataColumns.size(),false);
1232 0 : ::std::vector<bool, std::allocator<bool> >::iterator aReadIter = m_aReadOnlyDataColumns.begin();
1233 0 : for(;aIter != m_aDataColumns.end();++aIter,++aReadIter)
1234 : {
1235 0 : sal_Bool bReadOnly = sal_False;
1236 0 : (*aIter)->getPropertyValue(PROPERTY_ISREADONLY) >>= bReadOnly;
1237 0 : *aReadIter = bReadOnly;
1238 :
1239 0 : (*aIter)->setPropertyValue(PROPERTY_ISREADONLY,makeAny(sal_False));
1240 : }
1241 0 : }
1242 :
1243 0 : void ORowSet::impl_restoreDataColumnsWriteable_throw()
1244 : {
1245 : assert(m_aDataColumns.size() == m_aReadOnlyDataColumns.size() || m_aReadOnlyDataColumns.size() == 0 );
1246 0 : TDataColumns::iterator aIter = m_aDataColumns.begin();
1247 0 : ::std::vector<bool, std::allocator<bool> >::iterator aReadIter = m_aReadOnlyDataColumns.begin();
1248 0 : for(;aReadIter != m_aReadOnlyDataColumns.end();++aIter,++aReadIter)
1249 : {
1250 0 : (*aIter)->setPropertyValue(PROPERTY_ISREADONLY,makeAny((sal_Bool)*aReadIter ));
1251 : }
1252 0 : m_aReadOnlyDataColumns.clear();
1253 0 : }
1254 :
1255 0 : void SAL_CALL ORowSet::moveToCurrentRow( ) throw(SQLException, RuntimeException)
1256 : {
1257 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1258 :
1259 0 : ::osl::ResettableMutexGuard aGuard( *m_pMutex );
1260 0 : checkPositioningAllowed();
1261 :
1262 0 : if ( !m_pCache->m_bNew && !m_bModified )
1263 : // nothing to do if we're not on the insertion row, and not modified otherwise
1264 0 : return;
1265 :
1266 0 : if ( rowDeleted() )
1267 : // this would perhaps even justify a RuntimeException ....
1268 : // if the current row is deleted, then no write access to this row should be possible. So,
1269 : // m_bModified should be true. Also, as soon as somebody calls moveToInsertRow,
1270 : // our current row should not be deleted anymore. So, we should not have survived the above
1271 : // check "if ( !m_pCache->m_bNew && !m_bModified )"
1272 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_ROW_ALREADY_DELETED ), SQL_FUNCTION_SEQUENCE_ERROR, *this );
1273 :
1274 0 : if ( notifyAllListenersCursorBeforeMove( aGuard ) )
1275 : {
1276 0 : positionCache( MOVE_NONE_REFRESH_ONLY );
1277 :
1278 0 : ORowSetNotifier aNotifier( this );
1279 :
1280 : // notification order
1281 : // - cursorMoved
1282 0 : notifyAllListenersCursorMoved(aGuard);
1283 :
1284 : // - IsModified
1285 : // - IsNew
1286 0 : aNotifier.fire();
1287 0 : }
1288 : }
1289 :
1290 : // XRow
1291 0 : sal_Bool SAL_CALL ORowSet::wasNull( ) throw(SQLException, RuntimeException)
1292 : {
1293 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1294 0 : checkCache();
1295 :
1296 0 : return ( m_pCache && isInsertRow() ) ? ((*m_pCache->m_aInsertRow)->get())[m_nLastColumnIndex].isNull() : ORowSetBase::wasNull();
1297 : }
1298 :
1299 0 : const ORowSetValue& ORowSet::getInsertValue(sal_Int32 columnIndex)
1300 : {
1301 0 : checkCache();
1302 :
1303 0 : if ( m_pCache && isInsertRow() )
1304 0 : return ((*m_pCache->m_aInsertRow)->get())[m_nLastColumnIndex = columnIndex];
1305 :
1306 0 : return getValue(columnIndex);
1307 : }
1308 :
1309 0 : ::rtl::OUString SAL_CALL ORowSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1310 : {
1311 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1312 0 : return getInsertValue(columnIndex);
1313 : }
1314 :
1315 0 : sal_Bool SAL_CALL ORowSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1316 : {
1317 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1318 0 : return getInsertValue(columnIndex);
1319 : }
1320 :
1321 0 : sal_Int8 SAL_CALL ORowSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1322 : {
1323 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1324 0 : return getInsertValue(columnIndex);
1325 : }
1326 :
1327 0 : sal_Int16 SAL_CALL ORowSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1328 : {
1329 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1330 0 : return getInsertValue(columnIndex);
1331 : }
1332 :
1333 0 : sal_Int32 SAL_CALL ORowSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1334 : {
1335 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1336 0 : return getInsertValue(columnIndex);
1337 : }
1338 :
1339 0 : sal_Int64 SAL_CALL ORowSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1340 : {
1341 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1342 0 : return getInsertValue(columnIndex);
1343 : }
1344 :
1345 0 : float SAL_CALL ORowSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1346 : {
1347 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1348 0 : return getInsertValue(columnIndex);
1349 : }
1350 :
1351 0 : double SAL_CALL ORowSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1352 : {
1353 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1354 0 : return getInsertValue(columnIndex);
1355 : }
1356 :
1357 0 : Sequence< sal_Int8 > SAL_CALL ORowSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1358 : {
1359 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1360 0 : return getInsertValue(columnIndex);
1361 : }
1362 :
1363 0 : ::com::sun::star::util::Date SAL_CALL ORowSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1364 : {
1365 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1366 0 : return getInsertValue(columnIndex);
1367 : }
1368 :
1369 0 : ::com::sun::star::util::Time SAL_CALL ORowSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1370 : {
1371 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1372 0 : return getInsertValue(columnIndex);
1373 : }
1374 :
1375 0 : ::com::sun::star::util::DateTime SAL_CALL ORowSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1376 : {
1377 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1378 0 : return getInsertValue(columnIndex);
1379 : }
1380 :
1381 0 : Reference< ::com::sun::star::io::XInputStream > SAL_CALL ORowSet::getBinaryStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1382 : {
1383 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1384 0 : if ( m_pCache && isInsertRow() )
1385 : {
1386 0 : checkCache();
1387 0 : return new ::comphelper::SequenceInputStream(((*m_pCache->m_aInsertRow)->get())[m_nLastColumnIndex = columnIndex].getSequence());
1388 : }
1389 :
1390 0 : return ORowSetBase::getBinaryStream(columnIndex);
1391 : }
1392 :
1393 0 : Reference< ::com::sun::star::io::XInputStream > SAL_CALL ORowSet::getCharacterStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1394 : {
1395 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1396 0 : if(m_pCache && isInsertRow() )
1397 : {
1398 0 : checkCache();
1399 0 : return new ::comphelper::SequenceInputStream(((*m_pCache->m_aInsertRow)->get())[m_nLastColumnIndex = columnIndex].getSequence());
1400 : }
1401 :
1402 0 : return ORowSetBase::getCharacterStream(columnIndex);
1403 : }
1404 :
1405 0 : Any SAL_CALL ORowSet::getObject( sal_Int32 columnIndex, const Reference< XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
1406 : {
1407 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1408 0 : return getInsertValue(columnIndex).makeAny();
1409 : }
1410 :
1411 0 : Reference< XRef > SAL_CALL ORowSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
1412 : {
1413 0 : return Reference< XRef >();
1414 : }
1415 :
1416 0 : Reference< XBlob > SAL_CALL ORowSet::getBlob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1417 : {
1418 0 : if ( m_pCache && isInsertRow() )
1419 : {
1420 0 : checkCache();
1421 0 : return new ::connectivity::BlobHelper(((*m_pCache->m_aInsertRow)->get())[m_nLastColumnIndex = columnIndex].getSequence());
1422 : }
1423 0 : return ORowSetBase::getBlob(columnIndex);
1424 : }
1425 :
1426 0 : Reference< XClob > SAL_CALL ORowSet::getClob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1427 : {
1428 0 : return Reference< XClob >(getInsertValue(columnIndex).makeAny(),UNO_QUERY);
1429 : }
1430 :
1431 0 : Reference< XArray > SAL_CALL ORowSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
1432 : {
1433 0 : return Reference< XArray >();
1434 : }
1435 :
1436 0 : void SAL_CALL ORowSet::executeWithCompletion( const Reference< XInteractionHandler >& _rxHandler ) throw(SQLException, RuntimeException)
1437 : {
1438 0 : if (!_rxHandler.is())
1439 0 : execute();
1440 :
1441 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1442 :
1443 : // tell everybody that we will change the result set
1444 0 : approveExecution();
1445 :
1446 0 : ResettableMutexGuard aGuard( m_aMutex );
1447 :
1448 : try
1449 : {
1450 0 : freeResources( m_bCommandFacetsDirty );
1451 :
1452 : // calc the connection to be used
1453 0 : if (m_xActiveConnection.is() && m_bRebuildConnOnExecute)
1454 : {
1455 : // there was a setProperty(ActiveConnection), but a setProperty(DataSource) _after_ that, too
1456 0 : Reference< XConnection > xXConnection;
1457 0 : setActiveConnection( xXConnection );
1458 : }
1459 0 : calcConnection( _rxHandler );
1460 0 : m_bRebuildConnOnExecute = sal_False;
1461 :
1462 0 : Reference< XSingleSelectQueryComposer > xComposer = getCurrentSettingsComposer( this, m_aContext.getUNOContext() );
1463 0 : Reference<XParametersSupplier> xParameters(xComposer, UNO_QUERY);
1464 :
1465 0 : Reference<XIndexAccess> xParamsAsIndicies = xParameters.is() ? xParameters->getParameters() : Reference<XIndexAccess>();
1466 0 : const sal_Int32 nParamCount = xParamsAsIndicies.is() ? xParamsAsIndicies->getCount() : 0;
1467 0 : if ( m_aParametersSet.size() < (size_t)nParamCount )
1468 0 : m_aParametersSet.resize( nParamCount ,false);
1469 :
1470 0 : ::dbtools::askForParameters( xComposer, this, m_xActiveConnection, _rxHandler,m_aParametersSet );
1471 : }
1472 : // ensure that only the allowed exceptions leave this block
1473 0 : catch(SQLException&)
1474 : {
1475 0 : throw;
1476 : }
1477 0 : catch(RuntimeException&)
1478 : {
1479 0 : throw;
1480 : }
1481 0 : catch(Exception&)
1482 : {
1483 : OSL_FAIL("ORowSet::executeWithCompletion: caught an unexpected exception type while filling in the parameters!");
1484 : }
1485 :
1486 : // we're done with the parameters, now for the real execution
1487 :
1488 : // do the real execute
1489 0 : execute_NoApprove_NoNewConn(aGuard);
1490 0 : }
1491 :
1492 0 : Reference< XIndexAccess > SAL_CALL ORowSet::getParameters( ) throw (RuntimeException)
1493 : {
1494 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1495 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1496 :
1497 0 : if ( m_bCommandFacetsDirty )
1498 : // need to rebuild the parameters, since some property which contributes to the
1499 : // complete command, and thus the parameters, changed
1500 0 : impl_disposeParametersContainer_nothrow();
1501 :
1502 0 : if ( !m_pParameters.get() && !m_aCommand.isEmpty() )
1503 : {
1504 : try
1505 : {
1506 0 : ::rtl::OUString sNotInterestedIn;
1507 0 : impl_initComposer_throw( sNotInterestedIn );
1508 : }
1509 0 : catch( const Exception& )
1510 : {
1511 : // silence it
1512 : }
1513 : }
1514 :
1515 0 : return m_pParameters.get();
1516 : }
1517 :
1518 0 : void ORowSet::approveExecution() throw (RowSetVetoException, RuntimeException)
1519 : {
1520 0 : ::osl::MutexGuard aGuard( m_aColumnsMutex );
1521 0 : EventObject aEvt(*this);
1522 :
1523 0 : OInterfaceIteratorHelper aApproveIter( m_aApproveListeners );
1524 0 : while ( aApproveIter.hasMoreElements() )
1525 : {
1526 0 : Reference< XRowSetApproveListener > xListener( static_cast< XRowSetApproveListener* >( aApproveIter.next() ) );
1527 : try
1528 : {
1529 0 : if ( xListener.is() && !xListener->approveRowSetChange( aEvt ) )
1530 0 : throw RowSetVetoException();
1531 : }
1532 0 : catch ( const DisposedException& e )
1533 : {
1534 0 : if ( e.Context == xListener )
1535 0 : aApproveIter.remove();
1536 : }
1537 0 : catch ( const RuntimeException& ) { throw; }
1538 0 : catch ( const RowSetVetoException& ) { throw; }
1539 0 : catch ( const Exception& )
1540 : {
1541 : DBG_UNHANDLED_EXCEPTION();
1542 : }
1543 0 : }
1544 0 : }
1545 :
1546 : // XRowSet
1547 0 : void SAL_CALL ORowSet::execute( ) throw(SQLException, RuntimeException)
1548 : {
1549 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1550 :
1551 : // tell everybody that we will change the result set
1552 0 : approveExecution();
1553 :
1554 0 : ResettableMutexGuard aGuard( m_aMutex );
1555 0 : freeResources( m_bCommandFacetsDirty );
1556 :
1557 : // calc the connection to be used
1558 0 : if (m_xActiveConnection.is() && m_bRebuildConnOnExecute) {
1559 : // there was a setProperty(ActiveConnection), but a setProperty(DataSource) _after_ that, too
1560 0 : Reference< XConnection> xXConnection;
1561 0 : setActiveConnection( xXConnection );
1562 : }
1563 :
1564 0 : calcConnection(NULL);
1565 0 : m_bRebuildConnOnExecute = sal_False;
1566 :
1567 : // do the real execute
1568 0 : execute_NoApprove_NoNewConn(aGuard);
1569 0 : }
1570 :
1571 0 : void ORowSet::setStatementResultSetType( const Reference< XPropertySet >& _rxStatement, sal_Int32 _nDesiredResultSetType, sal_Int32 _nDesiredResultSetConcurrency )
1572 : {
1573 : OSL_ENSURE( _rxStatement.is(), "ORowSet::setStatementResultSetType: invalid statement - this will crash!" );
1574 :
1575 0 : sal_Int32 nResultSetType( _nDesiredResultSetType );
1576 0 : sal_Int32 nResultSetConcurrency( _nDesiredResultSetConcurrency );
1577 :
1578 : // there *might* be a data source setting which tells use to be more defensive with those settings
1579 : // #i15113#
1580 0 : sal_Bool bRespectDriverRST = sal_False;
1581 0 : Any aSetting;
1582 0 : if ( getDataSourceSetting( ::dbaccess::getDataSource( m_xActiveConnection ), "RespectDriverResultSetType", aSetting ) )
1583 : {
1584 0 : OSL_VERIFY( aSetting >>= bRespectDriverRST );
1585 : }
1586 :
1587 0 : if ( bRespectDriverRST )
1588 : {
1589 : // try type/concurrency settings with decreasing usefullness, and rely on what the connection claims
1590 : // to support
1591 0 : Reference< XDatabaseMetaData > xMeta( m_xActiveConnection->getMetaData() );
1592 :
1593 : sal_Int32 nCharacteristics[5][2] =
1594 : { { ResultSetType::SCROLL_SENSITIVE, ResultSetConcurrency::UPDATABLE },
1595 : { ResultSetType::SCROLL_INSENSITIVE, ResultSetConcurrency::UPDATABLE },
1596 : { ResultSetType::SCROLL_SENSITIVE, ResultSetConcurrency::READ_ONLY },
1597 : { ResultSetType::SCROLL_INSENSITIVE, ResultSetConcurrency::READ_ONLY },
1598 : { ResultSetType::FORWARD_ONLY, ResultSetConcurrency::READ_ONLY }
1599 0 : };
1600 0 : sal_Int32 i=0;
1601 0 : if ( m_xActiveConnection->getMetaData()->isReadOnly() )
1602 0 : i = 2; // if the database is read-only we only should use read-only concurrency
1603 :
1604 0 : for ( ; i<5; ++i )
1605 : {
1606 0 : nResultSetType = nCharacteristics[i][0];
1607 0 : nResultSetConcurrency = nCharacteristics[i][1];
1608 :
1609 : // don't try type/concurrency pairs which are more featured than what our caller requested
1610 0 : if ( nResultSetType > _nDesiredResultSetType )
1611 0 : continue;
1612 0 : if ( nResultSetConcurrency > _nDesiredResultSetConcurrency )
1613 0 : continue;
1614 :
1615 0 : if ( xMeta.is() && xMeta->supportsResultSetConcurrency( nResultSetType, nResultSetConcurrency ) )
1616 0 : break;
1617 0 : }
1618 : }
1619 :
1620 0 : _rxStatement->setPropertyValue( PROPERTY_RESULTSETTYPE, makeAny( nResultSetType ) );
1621 0 : _rxStatement->setPropertyValue( PROPERTY_RESULTSETCONCURRENCY, makeAny( nResultSetConcurrency ) );
1622 0 : }
1623 :
1624 0 : Reference< XResultSet > ORowSet::impl_prepareAndExecute_throw()
1625 : {
1626 0 : ::rtl::OUString sCommandToExecute;
1627 0 : sal_Bool bUseEscapeProcessing = impl_initComposer_throw( sCommandToExecute );
1628 :
1629 0 : Reference< XResultSet> xResultSet;
1630 : try
1631 : {
1632 0 : m_xStatement = m_xActiveConnection->prepareStatement( sCommandToExecute );
1633 0 : if ( !m_xStatement.is() )
1634 : {
1635 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_INTERNAL_ERROR ), SQL_GENERAL_ERROR, *this );
1636 : }
1637 :
1638 0 : Reference< XPropertySet > xStatementProps( m_xStatement, UNO_QUERY_THROW );
1639 : // set the result set type and concurrency
1640 : try
1641 : {
1642 0 : xStatementProps->setPropertyValue( PROPERTY_USEBOOKMARKS, makeAny( sal_True ) );
1643 0 : xStatementProps->setPropertyValue( PROPERTY_MAXROWS, makeAny( m_nMaxRows ) );
1644 :
1645 0 : setStatementResultSetType( xStatementProps, m_nResultSetType, m_nResultSetConcurrency );
1646 : }
1647 0 : catch ( const Exception& )
1648 : {
1649 : // this exception doesn't matter here because when we catch an exception
1650 : // then the driver doesn't support this feature
1651 : }
1652 0 : m_aParameterValueForCache.get().resize(1);
1653 0 : Reference< XParameters > xParam( m_xStatement, UNO_QUERY_THROW );
1654 0 : size_t nParamCount( m_pParameters.is() ? m_pParameters->size() : m_aPrematureParamValues.get().size() );
1655 0 : for ( size_t i=1; i<=nParamCount; ++i )
1656 : {
1657 0 : ORowSetValue& rParamValue( getParameterStorage( (sal_Int32)i ) );
1658 0 : ::dbtools::setObjectWithInfo( xParam, i, rParamValue.makeAny(), rParamValue.getTypeKind() );
1659 0 : m_aParameterValueForCache.get().push_back(rParamValue);
1660 : }
1661 :
1662 0 : xResultSet = m_xStatement->executeQuery();
1663 : }
1664 0 : catch( const SQLException& )
1665 : {
1666 0 : SQLExceptionInfo aError( ::cppu::getCaughtException() );
1667 : OSL_ENSURE( aError.isValid(), "ORowSet::impl_prepareAndExecute_throw: caught an SQLException which we cannot analyze!" );
1668 :
1669 : // append information about what we were actually going to execute
1670 : try
1671 : {
1672 0 : String sQuery = bUseEscapeProcessing && m_xComposer.is() ? m_xComposer->getQuery() : m_aActiveCommand;
1673 0 : String sInfo( DBA_RES_PARAM( RID_STR_COMMAND_LEADING_TO_ERROR, "$command$", sQuery ) );
1674 0 : aError.append( SQLExceptionInfo::SQL_CONTEXT, sInfo );
1675 : }
1676 0 : catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
1677 :
1678 : // propagate
1679 0 : aError.doThrow();
1680 : }
1681 :
1682 0 : return xResultSet;
1683 : }
1684 :
1685 0 : void ORowSet::impl_initializeColumnSettings_nothrow( const Reference< XPropertySet >& _rxTemplateColumn, const Reference< XPropertySet >& _rxRowSetColumn )
1686 : {
1687 : OSL_ENSURE( _rxTemplateColumn.is() && _rxRowSetColumn.is(),
1688 : "ORowSet::impl_initializeColumnSettings_nothrow: this will crash!" );
1689 :
1690 0 : bool bHaveAnyColumnSetting = false;
1691 : try
1692 : {
1693 0 : Reference< XPropertySetInfo > xInfo( _rxTemplateColumn->getPropertySetInfo(), UNO_QUERY_THROW );
1694 :
1695 : // a number of properties is plain copied
1696 : const ::rtl::OUString aPropertyNames[] = {
1697 : PROPERTY_ALIGN, PROPERTY_RELATIVEPOSITION, PROPERTY_WIDTH, PROPERTY_HIDDEN, PROPERTY_CONTROLMODEL,
1698 : PROPERTY_HELPTEXT, PROPERTY_CONTROLDEFAULT
1699 0 : };
1700 0 : for ( size_t i=0; i<sizeof( aPropertyNames ) / sizeof( aPropertyNames[0] ); ++i )
1701 : {
1702 0 : if ( xInfo->hasPropertyByName( aPropertyNames[i] ) )
1703 : {
1704 0 : _rxRowSetColumn->setPropertyValue( aPropertyNames[i], _rxTemplateColumn->getPropertyValue( aPropertyNames[i] ) );
1705 0 : bHaveAnyColumnSetting = true;
1706 : }
1707 : }
1708 :
1709 : // the format key is slightly more complex
1710 0 : sal_Int32 nFormatKey = 0;
1711 0 : if( xInfo->hasPropertyByName( PROPERTY_NUMBERFORMAT ) )
1712 : {
1713 0 : _rxTemplateColumn->getPropertyValue( PROPERTY_NUMBERFORMAT ) >>= nFormatKey;
1714 0 : bHaveAnyColumnSetting = true;
1715 : }
1716 0 : if ( !nFormatKey && m_xNumberFormatTypes.is() )
1717 0 : nFormatKey = ::dbtools::getDefaultNumberFormat( _rxTemplateColumn, m_xNumberFormatTypes, SvtSysLocale().GetLanguageTag().getLocale() );
1718 0 : _rxRowSetColumn->setPropertyValue( PROPERTY_NUMBERFORMAT, makeAny( nFormatKey ) );
1719 : }
1720 0 : catch(Exception&)
1721 : {
1722 : DBG_UNHANDLED_EXCEPTION();
1723 : return;
1724 : }
1725 :
1726 0 : if ( bHaveAnyColumnSetting )
1727 0 : return;
1728 :
1729 : // the template column could not provide *any* setting. Okay, probably it's a parser column, which
1730 : // does not offer those. However, perhaps the template column referes to a table column, which we
1731 : // can use as new template column
1732 : try
1733 : {
1734 0 : Reference< XPropertySetInfo > xInfo( _rxTemplateColumn->getPropertySetInfo(), UNO_QUERY_THROW );
1735 0 : if ( !xInfo->hasPropertyByName( PROPERTY_TABLENAME ) )
1736 : // no chance
1737 : return;
1738 :
1739 0 : ::rtl::OUString sTableName;
1740 0 : OSL_VERIFY( _rxTemplateColumn->getPropertyValue( PROPERTY_TABLENAME ) >>= sTableName );
1741 :
1742 0 : Reference< XNameAccess > xTables( impl_getTables_throw(), UNO_QUERY_THROW );
1743 0 : if ( !xTables->hasByName( sTableName ) )
1744 : // no chance
1745 : return;
1746 :
1747 0 : Reference< XColumnsSupplier > xTableColSup( xTables->getByName( sTableName ), UNO_QUERY_THROW );
1748 0 : Reference< XNameAccess > xTableCols( xTableColSup->getColumns(), UNO_QUERY_THROW );
1749 :
1750 0 : ::rtl::OUString sTableColumnName;
1751 :
1752 : // get the "Name" or (preferred) "RealName" property of the column
1753 0 : ::rtl::OUString sNamePropertyName( PROPERTY_NAME );
1754 0 : if ( xInfo->hasPropertyByName( PROPERTY_REALNAME ) )
1755 0 : sNamePropertyName = PROPERTY_REALNAME;
1756 0 : OSL_VERIFY( _rxTemplateColumn->getPropertyValue( sNamePropertyName ) >>= sTableColumnName );
1757 :
1758 0 : if ( !xTableCols->hasByName( sTableColumnName ) )
1759 : return;
1760 :
1761 0 : Reference< XPropertySet > xTableColumn( xTableCols->getByName( sTableColumnName ), UNO_QUERY_THROW );
1762 0 : impl_initializeColumnSettings_nothrow( xTableColumn, _rxRowSetColumn );
1763 : }
1764 0 : catch( const Exception& )
1765 : {
1766 : DBG_UNHANDLED_EXCEPTION();
1767 : }
1768 : }
1769 :
1770 0 : void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotification)
1771 : {
1772 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "frank.schoenheit@sun.com", "ORowSet::execute_NoApprove_NoNewConn" );
1773 :
1774 : // now we can dispose our old connection
1775 0 : ::comphelper::disposeComponent(m_xOldConnection);
1776 0 : m_xOldConnection = NULL;
1777 :
1778 : // do we need a new statement
1779 0 : if ( m_bCommandFacetsDirty )
1780 : {
1781 0 : m_xStatement = NULL;
1782 0 : m_xComposer = NULL;
1783 :
1784 0 : Reference< XResultSet > xResultSet( impl_prepareAndExecute_throw() );
1785 :
1786 : // let our warnings container forget the reference to the (possibly disposed) old result set
1787 0 : m_aWarnings.setExternalWarnings( NULL );
1788 : // clear all current warnings
1789 0 : m_aWarnings.clearWarnings();
1790 : // let the warnings container know about the new "external warnings"
1791 0 : m_aWarnings.setExternalWarnings( Reference< XWarningsSupplier >( xResultSet, UNO_QUERY ) );
1792 :
1793 0 : ::rtl::OUString aComposedUpdateTableName;
1794 0 : if ( !m_aUpdateTableName.isEmpty() )
1795 0 : aComposedUpdateTableName = composeTableName( m_xActiveConnection->getMetaData(), m_aUpdateCatalogName, m_aUpdateSchemaName, m_aUpdateTableName, sal_False, ::dbtools::eInDataManipulation );
1796 :
1797 : {
1798 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "frank.schoenheit@sun.com", "ORowSet::execute_NoApprove_NoNewConn: creating cache" );
1799 0 : m_pCache = new ORowSetCache( xResultSet, m_xComposer.get(), m_aContext, aComposedUpdateTableName, m_bModified, m_bNew,m_aParameterValueForCache,m_aFilter,m_nMaxRows );
1800 0 : if ( m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY )
1801 : {
1802 0 : m_nPrivileges = Privilege::SELECT;
1803 0 : m_pCache->m_nPrivileges = Privilege::SELECT;
1804 : }
1805 0 : m_pCache->setFetchSize(m_nFetchSize);
1806 0 : m_aCurrentRow = m_pCache->createIterator(this);
1807 0 : m_bIsInsertRow = sal_False;
1808 0 : m_aOldRow = m_pCache->registerOldRow();
1809 : }
1810 :
1811 : // get the locale
1812 0 : Locale aLocale = SvtSysLocale().GetLanguageTag().getLocale();
1813 :
1814 : // get the numberformatTypes
1815 : OSL_ENSURE(m_xActiveConnection.is(),"No ActiveConnection");
1816 0 : Reference< XNumberFormatTypes> xNumberFormatTypes;
1817 0 : Reference< XNumberFormatsSupplier> xNumberFormat = ::dbtools::getNumberFormats(m_xActiveConnection);
1818 0 : if ( xNumberFormat.is() )
1819 0 : m_xNumberFormatTypes.set(xNumberFormat->getNumberFormats(),UNO_QUERY);
1820 :
1821 0 : ::rtl::Reference< ::connectivity::OSQLColumns> aColumns = new ::connectivity::OSQLColumns();
1822 0 : ::std::vector< ::rtl::OUString> aNames;
1823 0 : ::rtl::OUString aDescription;
1824 :
1825 0 : const ::std::map<sal_Int32,sal_Int32>& rKeyColumns = m_pCache->getKeyColumns();
1826 0 : if(!m_xColumns.is())
1827 : {
1828 : RTL_LOGFILE_CONTEXT_AUTHOR( aColumnCreateLog, "dbaccess", "frank.schoenheit@sun.com", "ORowSet::execute_NoApprove_NoNewConn::creating columns" );
1829 : // use the meta data
1830 0 : Reference<XResultSetMetaDataSupplier> xMetaSup(m_xStatement,UNO_QUERY);
1831 : try
1832 : {
1833 0 : Reference<XResultSetMetaData> xMetaData = xMetaSup->getMetaData();
1834 0 : if ( xMetaData.is() )
1835 : {
1836 0 : sal_Int32 nCount = xMetaData->getColumnCount();
1837 0 : m_aDataColumns.reserve(nCount+1);
1838 0 : aColumns->get().reserve(nCount+1);
1839 : DECLARE_STL_USTRINGACCESS_MAP(int,StringMap);
1840 0 : StringMap aColumnMap;
1841 0 : for (sal_Int32 i = 0 ; i < nCount; ++i)
1842 : {
1843 : // retrieve the name of the column
1844 0 : ::rtl::OUString sName = xMetaData->getColumnName(i + 1);
1845 : // check for duplicate entries
1846 0 : if(aColumnMap.find(sName) != aColumnMap.end())
1847 : {
1848 0 : ::rtl::OUString sAlias(sName);
1849 0 : sal_Int32 searchIndex=1;
1850 0 : while(aColumnMap.find(sAlias) != aColumnMap.end())
1851 : {
1852 0 : (sAlias = sName) += ::rtl::OUString::valueOf(searchIndex++);
1853 : }
1854 0 : sName = sAlias;
1855 : }
1856 0 : ORowSetDataColumn* pColumn = new ORowSetDataColumn( getMetaData(),
1857 : this,
1858 : this,
1859 : i+1,
1860 0 : m_xActiveConnection->getMetaData(),
1861 : aDescription,
1862 : ::rtl::OUString(),
1863 0 : m_aCurrentRow);
1864 0 : aColumnMap.insert(StringMap::value_type(sName,0));
1865 0 : aColumns->get().push_back(pColumn);
1866 0 : pColumn->setName(sName);
1867 0 : aNames.push_back(sName);
1868 0 : m_aDataColumns.push_back(pColumn);
1869 :
1870 0 : pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ISREADONLY,makeAny(rKeyColumns.find(i+1) != rKeyColumns.end()));
1871 :
1872 : try
1873 : {
1874 0 : sal_Int32 nFormatKey = 0;
1875 0 : if(m_xNumberFormatTypes.is())
1876 0 : nFormatKey = ::dbtools::getDefaultNumberFormat(pColumn,m_xNumberFormatTypes,aLocale);
1877 :
1878 :
1879 0 : pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_NUMBERFORMAT,makeAny(nFormatKey));
1880 0 : pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_RELATIVEPOSITION,makeAny(sal_Int32(i+1)));
1881 0 : pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_WIDTH,makeAny(sal_Int32(227)));
1882 0 : pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ALIGN,makeAny((sal_Int32)0));
1883 0 : pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_HIDDEN,::cppu::bool2any(sal_False));
1884 : }
1885 0 : catch(Exception&)
1886 : {
1887 : }
1888 0 : }
1889 0 : }
1890 : }
1891 0 : catch (SQLException&)
1892 : {
1893 0 : }
1894 : }
1895 : else
1896 : {
1897 : // create the rowset columns
1898 0 : Reference< XResultSetMetaData > xMeta( getMetaData(), UNO_QUERY_THROW );
1899 0 : sal_Int32 nCount = xMeta->getColumnCount();
1900 0 : m_aDataColumns.reserve(nCount+1);
1901 0 : aColumns->get().reserve(nCount+1);
1902 0 : ::std::set< Reference< XPropertySet > > aAllColumns;
1903 :
1904 0 : for(sal_Int32 i=1; i <= nCount ;++i)
1905 : {
1906 0 : ::rtl::OUString sName = xMeta->getColumnName(i);
1907 0 : ::rtl::OUString sColumnLabel = xMeta->getColumnLabel(i);
1908 :
1909 : // retrieve the column number |i|
1910 0 : Reference<XPropertySet> xColumn;
1911 : {
1912 0 : sal_Bool bReFetchName = sal_False;
1913 0 : if (m_xColumns->hasByName(sColumnLabel))
1914 0 : m_xColumns->getByName(sColumnLabel) >>= xColumn;
1915 0 : if (!xColumn.is() && m_xColumns->hasByName(sName))
1916 0 : m_xColumns->getByName(sName) >>= xColumn;
1917 :
1918 : // check if column already in the list we need another
1919 0 : if ( aAllColumns.find( xColumn ) != aAllColumns.end() )
1920 : {
1921 0 : xColumn = NULL;
1922 0 : bReFetchName = sal_True;
1923 0 : sColumnLabel = ::rtl::OUString();
1924 : }
1925 0 : if(!xColumn.is())
1926 : {
1927 : // no column found so we could look at the position i
1928 0 : Reference<XIndexAccess> xIndexAccess(m_xColumns,UNO_QUERY);
1929 0 : if(xIndexAccess.is() && i <= xIndexAccess->getCount())
1930 : {
1931 0 : xIndexAccess->getByIndex(i-1) >>= xColumn;
1932 : }
1933 : else
1934 : {
1935 0 : Sequence< ::rtl::OUString> aSeq = m_xColumns->getElementNames();
1936 0 : if( i <= aSeq.getLength())
1937 : {
1938 0 : m_xColumns->getByName(aSeq.getConstArray()[i-1]) >>= xColumn;
1939 0 : }
1940 0 : }
1941 : }
1942 0 : if(bReFetchName && xColumn.is())
1943 0 : xColumn->getPropertyValue(PROPERTY_NAME) >>= sName;
1944 0 : aAllColumns.insert( xColumn );
1945 : }
1946 :
1947 : // create a RowSetDataColumn
1948 : {
1949 0 : Reference<XPropertySetInfo> xInfo = xColumn.is() ? xColumn->getPropertySetInfo() : Reference<XPropertySetInfo>();
1950 0 : if(xInfo.is() && xInfo->hasPropertyByName(PROPERTY_DESCRIPTION))
1951 0 : aDescription = comphelper::getString(xColumn->getPropertyValue(PROPERTY_DESCRIPTION));
1952 :
1953 0 : ::rtl::OUString sParseLabel;
1954 0 : if ( xColumn.is() )
1955 : {
1956 0 : xColumn->getPropertyValue(PROPERTY_LABEL) >>= sParseLabel;
1957 : }
1958 0 : ORowSetDataColumn* pColumn = new ORowSetDataColumn( getMetaData(),
1959 : this,
1960 : this,
1961 : i,
1962 0 : m_xActiveConnection->getMetaData(),
1963 : aDescription,
1964 : sParseLabel,
1965 0 : m_aCurrentRow);
1966 0 : aColumns->get().push_back(pColumn);
1967 :
1968 0 : pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ISREADONLY,makeAny(rKeyColumns.find(i) != rKeyColumns.end()));
1969 :
1970 0 : if(sColumnLabel.isEmpty())
1971 : {
1972 0 : if(xColumn.is())
1973 0 : xColumn->getPropertyValue(PROPERTY_NAME) >>= sColumnLabel;
1974 : else
1975 0 : sColumnLabel = DBACORE_RESSTRING( RID_STR_EXPRESSION1 );
1976 : }
1977 0 : pColumn->setName(sColumnLabel);
1978 0 : aNames.push_back(sColumnLabel);
1979 0 : m_aDataColumns.push_back(pColumn);
1980 :
1981 0 : if ( xColumn.is() )
1982 0 : impl_initializeColumnSettings_nothrow( xColumn, pColumn );
1983 : }
1984 0 : }
1985 : }
1986 : // now create the columns we need
1987 0 : if(m_pColumns)
1988 0 : m_pColumns->assign(aColumns,aNames);
1989 : else
1990 : {
1991 0 : Reference<XDatabaseMetaData> xMeta = m_xActiveConnection->getMetaData();
1992 0 : m_pColumns = new ORowSetDataColumns(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers(),
1993 0 : aColumns,*this,m_aColumnsMutex,aNames);
1994 0 : }
1995 : }
1996 0 : checkCache();
1997 : // notify the rowset listeners
1998 0 : notifyAllListeners(_rClearForNotification);
1999 0 : }
2000 :
2001 : // XRowSetApproveBroadcaster
2002 0 : void SAL_CALL ORowSet::addRowSetApproveListener( const Reference< XRowSetApproveListener >& listener ) throw(RuntimeException)
2003 : {
2004 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2005 :
2006 0 : ::osl::MutexGuard aGuard( m_aColumnsMutex );
2007 :
2008 0 : m_aApproveListeners.addInterface(listener);
2009 0 : }
2010 :
2011 0 : void SAL_CALL ORowSet::removeRowSetApproveListener( const Reference< XRowSetApproveListener >& listener ) throw(RuntimeException)
2012 : {
2013 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2014 :
2015 0 : ::osl::MutexGuard aGuard( m_aColumnsMutex );
2016 :
2017 0 : m_aApproveListeners.removeInterface(listener);
2018 0 : }
2019 : // XRowsChangeBroadcaster
2020 0 : void SAL_CALL ORowSet::addRowsChangeListener( const Reference< XRowsChangeListener >& listener ) throw(RuntimeException)
2021 : {
2022 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2023 :
2024 0 : ::osl::MutexGuard aGuard( m_aColumnsMutex );
2025 :
2026 0 : m_aRowsChangeListener.addInterface(listener);
2027 0 : }
2028 :
2029 0 : void SAL_CALL ORowSet::removeRowsChangeListener( const Reference< XRowsChangeListener >& listener ) throw(RuntimeException)
2030 : {
2031 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2032 :
2033 0 : ::osl::MutexGuard aGuard( m_aColumnsMutex );
2034 :
2035 0 : m_aRowsChangeListener.removeInterface(listener);
2036 0 : }
2037 :
2038 : // XResultSetAccess
2039 0 : Reference< XResultSet > SAL_CALL ORowSet::createResultSet( ) throw(SQLException, RuntimeException)
2040 : {
2041 0 : ::osl::MutexGuard aGuard( m_aColumnsMutex );
2042 :
2043 0 : if(m_xStatement.is())
2044 : {
2045 0 : ORowSetClone* pClone = new ORowSetClone( m_aContext, *this, m_pMutex );
2046 0 : Reference< XResultSet > xRet(pClone);
2047 0 : m_aClones.push_back(WeakReferenceHelper(xRet));
2048 0 : return xRet;
2049 : }
2050 0 : return Reference< XResultSet >();
2051 : }
2052 :
2053 : // ::com::sun::star::util::XCancellable
2054 0 : void SAL_CALL ORowSet::cancel( ) throw(RuntimeException)
2055 : {
2056 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2057 0 : }
2058 :
2059 : // ::com::sun::star::sdbcx::XDeleteRows
2060 0 : Sequence< sal_Int32 > SAL_CALL ORowSet::deleteRows( const Sequence< Any >& rows ) throw(SQLException, RuntimeException)
2061 : {
2062 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2063 :
2064 0 : if(!m_pCache || m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY)
2065 0 : throwFunctionSequenceException(*this);
2066 :
2067 0 : ::osl::ResettableMutexGuard aGuard( *m_pMutex );
2068 :
2069 0 : Sequence<Any> aChangedBookmarks;
2070 0 : RowsChangeEvent aEvt(*this,RowChangeAction::DELETE,rows.getLength(),aChangedBookmarks);
2071 : // notify the rowset listeners
2072 0 : notifyAllListenersRowBeforeChange(aGuard,aEvt);
2073 :
2074 0 : Sequence< sal_Int32 > aResults( rows.getLength() );
2075 0 : const Any* row = rows.getConstArray();
2076 0 : const Any* rowEnd = rows.getConstArray() + rows.getLength();
2077 0 : sal_Int32* result = aResults.getArray();
2078 0 : for ( ; row != rowEnd; ++row, ++result )
2079 : {
2080 0 : *result = 0;
2081 0 : if ( !m_pCache->moveToBookmark( *row ) )
2082 0 : continue;
2083 0 : sal_Int32 nDeletePosition = m_pCache->getRow();
2084 :
2085 : // first notify the clones so that they can save their position
2086 0 : notifyRowSetAndClonesRowDelete( *row );
2087 :
2088 : // now delete the row
2089 0 : if ( !m_pCache->deleteRow() )
2090 0 : continue;
2091 0 : *result = 1;
2092 : // now notify that we have deleted
2093 0 : notifyRowSetAndClonesRowDeleted( *row, nDeletePosition );
2094 : }
2095 0 : aEvt.Rows = aResults.getLength();
2096 :
2097 : // we have to check if we stand on the insert row and if so we have to reset it
2098 0 : ORowSetNotifier aNotifier( this );
2099 : // this will call cancelRowModification on the cache if necessary
2100 : // notification order
2101 : // - rowChanged
2102 0 : notifyAllListenersRowChanged(aGuard,aEvt);
2103 :
2104 : // - IsModified
2105 : // - IsNew
2106 0 : aNotifier.fire();
2107 :
2108 : // - RowCount/IsRowCountFinal
2109 0 : fireRowcount();
2110 :
2111 0 : return aResults;
2112 : }
2113 :
2114 0 : void ORowSet::notifyRowSetAndClonesRowDelete( const Any& _rBookmark )
2115 : {
2116 : // notify ourself
2117 0 : onDeleteRow( _rBookmark );
2118 : // notify the clones
2119 0 : connectivity::OWeakRefArray::iterator aEnd = m_aClones.end();
2120 0 : for (connectivity::OWeakRefArray::iterator i = m_aClones.begin(); aEnd != i; ++i)
2121 : {
2122 0 : Reference< XUnoTunnel > xTunnel(i->get(),UNO_QUERY);
2123 0 : if(xTunnel.is())
2124 : {
2125 0 : ORowSetClone* pClone = reinterpret_cast<ORowSetClone*>(xTunnel->getSomething(ORowSetClone::getUnoTunnelImplementationId()));
2126 0 : if(pClone)
2127 0 : pClone->onDeleteRow( _rBookmark );
2128 : }
2129 0 : }
2130 0 : }
2131 :
2132 0 : void ORowSet::notifyRowSetAndClonesRowDeleted( const Any& _rBookmark, sal_Int32 _nPos )
2133 : {
2134 : // notify ourself
2135 0 : onDeletedRow( _rBookmark, _nPos );
2136 : // notify the clones
2137 0 : connectivity::OWeakRefArray::iterator aEnd = m_aClones.end();
2138 0 : for (connectivity::OWeakRefArray::iterator i = m_aClones.begin(); aEnd != i; ++i)
2139 : {
2140 0 : Reference< XUnoTunnel > xTunnel(i->get(),UNO_QUERY);
2141 0 : if(xTunnel.is())
2142 : {
2143 0 : ORowSetClone* pClone = reinterpret_cast<ORowSetClone*>(xTunnel->getSomething(ORowSetClone::getUnoTunnelImplementationId()));
2144 0 : if(pClone)
2145 0 : pClone->onDeletedRow( _rBookmark, _nPos );
2146 : }
2147 0 : }
2148 0 : }
2149 :
2150 0 : Reference< XConnection > ORowSet::calcConnection(const Reference< XInteractionHandler >& _rxHandler) throw( SQLException, RuntimeException )
2151 : {
2152 0 : MutexGuard aGuard(m_aMutex);
2153 0 : if (!m_xActiveConnection.is())
2154 : {
2155 0 : Reference< XConnection > xNewConn;
2156 0 : if ( !m_aDataSourceName.isEmpty() )
2157 : {
2158 0 : Reference< XDatabaseContext > xDatabaseContext( DatabaseContext::create(m_aContext.getUNOContext()) );
2159 : try
2160 : {
2161 0 : Reference< XDataSource > xDataSource( xDatabaseContext->getByName( m_aDataSourceName ), UNO_QUERY_THROW );
2162 :
2163 : // try connecting with the interaction handler
2164 0 : Reference< XCompletedConnection > xComplConn( xDataSource, UNO_QUERY );
2165 0 : if ( _rxHandler.is() && xComplConn.is() )
2166 : {
2167 0 : xNewConn = xComplConn->connectWithCompletion( _rxHandler );
2168 : }
2169 : else
2170 : {
2171 0 : xNewConn = xDataSource->getConnection( m_aUser, m_aPassword );
2172 0 : }
2173 : }
2174 0 : catch ( const SQLException& )
2175 : {
2176 0 : throw;
2177 : }
2178 0 : catch ( const Exception& )
2179 : {
2180 0 : Any aError = ::cppu::getCaughtException();
2181 : ::rtl::OUString sMessage = ResourceManager::loadString( RID_NO_SUCH_DATA_SOURCE,
2182 0 : "$name$", m_aDataSourceName, "$error$", extractExceptionMessage( m_aContext, aError ) );
2183 0 : ::dbtools::throwGenericSQLException( sMessage, *this );
2184 0 : }
2185 : }
2186 0 : setActiveConnection(xNewConn);
2187 0 : m_bOwnConnection = sal_True;
2188 : }
2189 0 : return m_xActiveConnection;
2190 : }
2191 :
2192 0 : Reference< XNameAccess > ORowSet::impl_getTables_throw()
2193 : {
2194 0 : Reference< XNameAccess > xTables;
2195 :
2196 0 : Reference< XTablesSupplier > xTablesAccess( m_xActiveConnection, UNO_QUERY );
2197 0 : if ( xTablesAccess.is() )
2198 : {
2199 0 : xTables.set( xTablesAccess->getTables(), UNO_QUERY_THROW );
2200 : }
2201 0 : else if ( m_pTables )
2202 : {
2203 0 : xTables = m_pTables;
2204 : }
2205 : else
2206 : {
2207 0 : if ( !m_xActiveConnection.is() )
2208 0 : throw SQLException(DBA_RES(RID_STR_CONNECTION_INVALID),*this,SQLSTATE_GENERAL,1000,Any() );
2209 :
2210 0 : sal_Bool bCase = sal_True;
2211 : try
2212 : {
2213 0 : Reference<XDatabaseMetaData> xMeta = m_xActiveConnection->getMetaData();
2214 0 : bCase = xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers();
2215 : }
2216 0 : catch(SQLException&)
2217 : {
2218 : DBG_UNHANDLED_EXCEPTION();
2219 : }
2220 :
2221 0 : m_pTables = new OTableContainer(*this,m_aMutex,m_xActiveConnection,bCase,NULL,NULL,NULL,m_nInAppend);
2222 0 : xTables = m_pTables;
2223 0 : Sequence< ::rtl::OUString> aTableFilter(1);
2224 0 : aTableFilter[0] = ::rtl::OUString("%");
2225 0 : m_pTables->construct(aTableFilter,Sequence< ::rtl::OUString>());
2226 : }
2227 :
2228 0 : return xTables;
2229 : }
2230 :
2231 3 : void ORowSet::impl_resetTables_nothrow()
2232 : {
2233 3 : if ( !m_pTables )
2234 6 : return;
2235 :
2236 : try
2237 : {
2238 0 : m_pTables->dispose();
2239 : }
2240 0 : catch( const Exception& )
2241 : {
2242 : DBG_UNHANDLED_EXCEPTION();
2243 : }
2244 :
2245 0 : DELETEZ( m_pTables );
2246 : }
2247 :
2248 0 : sal_Bool ORowSet::impl_initComposer_throw( ::rtl::OUString& _out_rCommandToExecute )
2249 : {
2250 0 : sal_Bool bUseEscapeProcessing = impl_buildActiveCommand_throw( );
2251 0 : _out_rCommandToExecute = m_aActiveCommand;
2252 0 : if ( !bUseEscapeProcessing )
2253 0 : return bUseEscapeProcessing;
2254 :
2255 0 : Reference< XMultiServiceFactory > xFactory( m_xActiveConnection, UNO_QUERY );
2256 0 : if ( xFactory.is() )
2257 : {
2258 : try
2259 : {
2260 0 : ::comphelper::disposeComponent( m_xComposer );
2261 0 : m_xComposer.set( xFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
2262 : }
2263 0 : catch (const Exception& ) { m_xComposer = NULL; }
2264 : }
2265 0 : if ( !m_xComposer.is() )
2266 0 : m_xComposer = new OSingleSelectQueryComposer( impl_getTables_throw(), m_xActiveConnection, m_aContext );
2267 :
2268 0 : m_xComposer->setCommand( m_aCommand,m_nCommandType );
2269 0 : m_aActiveCommand = m_xComposer->getQuery();
2270 :
2271 0 : m_xComposer->setFilter( m_bApplyFilter ? m_aFilter : ::rtl::OUString() );
2272 0 : m_xComposer->setHavingClause( m_bApplyFilter ? m_aHavingClause : ::rtl::OUString() );
2273 :
2274 0 : if ( m_bIgnoreResult )
2275 : { // append a "0=1" filter
2276 : // don't simply overwrite an existent filter, this would lead to problems if this existent
2277 : // filter contains parameters (since a keyset may add parameters itself)
2278 0 : m_xComposer->setElementaryQuery( m_xComposer->getQuery( ) );
2279 0 : m_xComposer->setFilter( ::rtl::OUString("0 = 1" ) );
2280 : }
2281 :
2282 0 : m_xComposer->setOrder( m_aOrder );
2283 0 : m_xComposer->setGroup( m_aGroupBy );
2284 :
2285 0 : if ( !m_xColumns.is() )
2286 : {
2287 0 : Reference< XColumnsSupplier > xCols( m_xComposer, UNO_QUERY_THROW );
2288 0 : m_xColumns = xCols->getColumns();
2289 : }
2290 :
2291 0 : impl_initParametersContainer_nothrow();
2292 :
2293 0 : _out_rCommandToExecute = m_xComposer->getQueryWithSubstitution();
2294 :
2295 0 : return bUseEscapeProcessing;
2296 : }
2297 :
2298 0 : sal_Bool ORowSet::impl_buildActiveCommand_throw()
2299 : {
2300 : // create the sql command
2301 : // from a table name or get the command out of a query (not a view)
2302 : // the last use the command as it is
2303 0 : sal_Bool bDoEscapeProcessing = m_bUseEscapeProcessing;
2304 :
2305 0 : m_aActiveCommand = ::rtl::OUString();
2306 0 : ::rtl::OUString sCommand;
2307 :
2308 0 : if ( m_aCommand.isEmpty() )
2309 0 : return bDoEscapeProcessing;
2310 :
2311 0 : switch (m_nCommandType)
2312 : {
2313 : case CommandType::TABLE:
2314 : {
2315 0 : impl_resetTables_nothrow();
2316 0 : if ( bDoEscapeProcessing )
2317 : {
2318 0 : Reference< XNameAccess > xTables( impl_getTables_throw() );
2319 0 : if ( xTables->hasByName(m_aCommand) )
2320 : {
2321 : }
2322 : else
2323 : {
2324 0 : String sMessage( DBACORE_RESSTRING( RID_STR_TABLE_DOES_NOT_EXIST ) );
2325 0 : sMessage.SearchAndReplaceAscii( "$table$", m_aCommand );
2326 0 : throwGenericSQLException(sMessage,*this);
2327 0 : }
2328 : }
2329 : else
2330 : {
2331 0 : sCommand = rtl::OUString("SELECT * FROM ");
2332 0 : ::rtl::OUString sCatalog, sSchema, sTable;
2333 0 : ::dbtools::qualifiedNameComponents( m_xActiveConnection->getMetaData(), m_aCommand, sCatalog, sSchema, sTable, ::dbtools::eInDataManipulation );
2334 0 : sCommand += ::dbtools::composeTableNameForSelect( m_xActiveConnection, sCatalog, sSchema, sTable );
2335 : }
2336 : }
2337 0 : break;
2338 :
2339 : case CommandType::QUERY:
2340 : {
2341 0 : Reference< XQueriesSupplier > xQueriesAccess(m_xActiveConnection, UNO_QUERY);
2342 0 : if (xQueriesAccess.is())
2343 : {
2344 0 : Reference< ::com::sun::star::container::XNameAccess > xQueries(xQueriesAccess->getQueries());
2345 0 : if (xQueries->hasByName(m_aCommand))
2346 : {
2347 0 : Reference< XPropertySet > xQuery(xQueries->getByName(m_aCommand),UNO_QUERY);
2348 : OSL_ENSURE(xQuery.is(),"ORowSet::impl_buildActiveCommand_throw: Query is NULL!");
2349 0 : if ( xQuery.is() )
2350 : {
2351 0 : xQuery->getPropertyValue(PROPERTY_COMMAND) >>= sCommand;
2352 0 : xQuery->getPropertyValue(PROPERTY_ESCAPE_PROCESSING) >>= bDoEscapeProcessing;
2353 0 : if ( bDoEscapeProcessing != m_bUseEscapeProcessing )
2354 : {
2355 0 : sal_Bool bOldValue = m_bUseEscapeProcessing;
2356 0 : m_bUseEscapeProcessing = bDoEscapeProcessing;
2357 0 : fireProperty(PROPERTY_ID_ESCAPE_PROCESSING,bOldValue,bDoEscapeProcessing);
2358 : }
2359 :
2360 0 : ::rtl::OUString aCatalog,aSchema,aTable;
2361 0 : xQuery->getPropertyValue(PROPERTY_UPDATE_CATALOGNAME) >>= aCatalog;
2362 0 : xQuery->getPropertyValue(PROPERTY_UPDATE_SCHEMANAME) >>= aSchema;
2363 0 : xQuery->getPropertyValue(PROPERTY_UPDATE_TABLENAME) >>= aTable;
2364 0 : if(!aTable.isEmpty())
2365 0 : m_aUpdateTableName = composeTableName( m_xActiveConnection->getMetaData(), aCatalog, aSchema, aTable, sal_False, ::dbtools::eInDataManipulation );
2366 0 : }
2367 : }
2368 : else
2369 : {
2370 0 : String sMessage( DBACORE_RESSTRING( RID_STR_QUERY_DOES_NOT_EXIST ) );
2371 0 : sMessage.SearchAndReplaceAscii( "$table$", m_aCommand );
2372 0 : throwGenericSQLException(sMessage,*this);
2373 0 : }
2374 : }
2375 : else
2376 0 : throw SQLException(DBA_RES(RID_STR_NO_XQUERIESSUPPLIER),*this,::rtl::OUString(),0,Any());
2377 : }
2378 0 : break;
2379 :
2380 : default:
2381 0 : sCommand = m_aCommand;
2382 0 : break;
2383 : }
2384 :
2385 0 : m_aActiveCommand = sCommand;
2386 :
2387 0 : if ( m_aActiveCommand.isEmpty() && !bDoEscapeProcessing )
2388 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_SQL_COMMAND ), SQL_FUNCTION_SEQUENCE_ERROR, *this );
2389 :
2390 0 : return bDoEscapeProcessing;
2391 : }
2392 :
2393 0 : void ORowSet::impl_initParametersContainer_nothrow()
2394 : {
2395 : OSL_PRECOND( !m_pParameters.is(), "ORowSet::impl_initParametersContainer_nothrow: already initialized the parameters!" );
2396 :
2397 0 : m_pParameters = new param::ParameterWrapperContainer( m_xComposer.get() );
2398 : // copy the premature parameters into the final ones
2399 0 : size_t nParamCount( ::std::min( m_pParameters->size(), m_aPrematureParamValues.get().size() ) );
2400 0 : for ( size_t i=0; i<nParamCount; ++i )
2401 : {
2402 0 : (*m_pParameters)[i] = m_aPrematureParamValues.get()[i];
2403 : }
2404 0 : }
2405 :
2406 3 : void ORowSet::impl_disposeParametersContainer_nothrow()
2407 : {
2408 3 : if ( !m_pParameters.is() )
2409 6 : return;
2410 :
2411 : // copy the actual values to our "premature" ones, to preserve them for later use
2412 0 : size_t nParamCount( m_pParameters->size() );
2413 0 : m_aPrematureParamValues.get().resize( nParamCount );
2414 0 : for ( size_t i=0; i<nParamCount; ++i )
2415 : {
2416 0 : m_aPrematureParamValues.get()[i] = (*m_pParameters)[i];
2417 : }
2418 :
2419 0 : m_pParameters->dispose();
2420 0 : m_pParameters = NULL;
2421 : }
2422 :
2423 0 : ORowSetValue& ORowSet::getParameterStorage(sal_Int32 parameterIndex)
2424 : {
2425 0 : ::connectivity::checkDisposed( ORowSet_BASE1::rBHelper.bDisposed );
2426 0 : if ( parameterIndex < 1 )
2427 0 : throwInvalidIndexException( *this );
2428 :
2429 0 : if ( m_aParametersSet.size() < (size_t)parameterIndex )
2430 0 : m_aParametersSet.resize( parameterIndex ,false);
2431 0 : m_aParametersSet[parameterIndex - 1] = true;
2432 :
2433 0 : if ( m_aParametersSet.size() < (size_t)parameterIndex )
2434 0 : m_aParametersSet.resize( parameterIndex ,false);
2435 0 : m_aParametersSet[parameterIndex - 1] = true;
2436 :
2437 0 : if ( m_pParameters.is() )
2438 : {
2439 0 : if ( m_bCommandFacetsDirty )
2440 : // need to rebuild the parameters, since some property which contributes to the
2441 : // complete command, and thus the parameters, changed
2442 0 : impl_disposeParametersContainer_nothrow();
2443 0 : if ( m_pParameters.is() )
2444 : {
2445 0 : if ( (size_t)parameterIndex > m_pParameters->size() )
2446 0 : throwInvalidIndexException( *this );
2447 0 : return (*m_pParameters)[ parameterIndex - 1 ];
2448 : }
2449 : }
2450 :
2451 0 : if ( m_aPrematureParamValues.get().size() < (size_t)parameterIndex )
2452 0 : m_aPrematureParamValues.get().resize( parameterIndex );
2453 0 : return m_aPrematureParamValues.get()[ parameterIndex - 1 ];
2454 : }
2455 :
2456 : // XParameters
2457 0 : void SAL_CALL ORowSet::setNull( sal_Int32 parameterIndex, sal_Int32 /*sqlType*/ ) throw(SQLException, RuntimeException)
2458 : {
2459 0 : ::osl::MutexGuard aGuard( m_aColumnsMutex );
2460 :
2461 0 : getParameterStorage( parameterIndex ).setNull();
2462 0 : }
2463 :
2464 0 : void SAL_CALL ORowSet::setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& /*typeName*/ ) throw(SQLException, RuntimeException)
2465 : {
2466 0 : setNull( parameterIndex, sqlType );
2467 0 : }
2468 :
2469 0 : void ORowSet::setParameter(sal_Int32 parameterIndex, const ORowSetValue& x)
2470 : {
2471 0 : ::osl::MutexGuard aGuard( m_aColumnsMutex );
2472 :
2473 0 : getParameterStorage( parameterIndex ) = x;
2474 0 : }
2475 :
2476 0 : void SAL_CALL ORowSet::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(SQLException, RuntimeException)
2477 : {
2478 0 : setParameter(parameterIndex,x);
2479 0 : }
2480 :
2481 0 : void SAL_CALL ORowSet::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
2482 : {
2483 0 : setParameter(parameterIndex,x);
2484 0 : }
2485 :
2486 0 : void SAL_CALL ORowSet::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
2487 : {
2488 0 : setParameter(parameterIndex,x);
2489 0 : }
2490 :
2491 0 : void SAL_CALL ORowSet::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
2492 : {
2493 0 : setParameter(parameterIndex,x);
2494 0 : }
2495 :
2496 0 : void SAL_CALL ORowSet::setLong( sal_Int32 parameterIndex, sal_Int64 x ) throw(SQLException, RuntimeException)
2497 : {
2498 0 : setParameter(parameterIndex,x);
2499 0 : }
2500 :
2501 0 : void SAL_CALL ORowSet::setFloat( sal_Int32 parameterIndex, float x ) throw(SQLException, RuntimeException)
2502 : {
2503 0 : setParameter(parameterIndex,x);
2504 0 : }
2505 :
2506 0 : void SAL_CALL ORowSet::setDouble( sal_Int32 parameterIndex, double x ) throw(SQLException, RuntimeException)
2507 : {
2508 0 : setParameter(parameterIndex,x);
2509 0 : }
2510 :
2511 0 : void SAL_CALL ORowSet::setString( sal_Int32 parameterIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
2512 : {
2513 0 : setParameter(parameterIndex,x);
2514 0 : }
2515 :
2516 0 : void SAL_CALL ORowSet::setBytes( sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
2517 : {
2518 0 : setParameter(parameterIndex,x);
2519 0 : }
2520 :
2521 0 : void SAL_CALL ORowSet::setDate( sal_Int32 parameterIndex, const ::com::sun::star::util::Date& x ) throw(SQLException, RuntimeException)
2522 : {
2523 0 : setParameter(parameterIndex,x);
2524 0 : }
2525 :
2526 0 : void SAL_CALL ORowSet::setTime( sal_Int32 parameterIndex, const ::com::sun::star::util::Time& x ) throw(SQLException, RuntimeException)
2527 : {
2528 0 : setParameter(parameterIndex,x);
2529 0 : }
2530 :
2531 0 : void SAL_CALL ORowSet::setTimestamp( sal_Int32 parameterIndex, const ::com::sun::star::util::DateTime& x ) throw(SQLException, RuntimeException)
2532 : {
2533 0 : setParameter(parameterIndex,x);
2534 0 : }
2535 :
2536 0 : void SAL_CALL ORowSet::setBinaryStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
2537 : {
2538 0 : ::osl::MutexGuard aGuard( m_aColumnsMutex );
2539 0 : ORowSetValue& rParamValue( getParameterStorage( parameterIndex ) );
2540 :
2541 : try
2542 : {
2543 0 : Sequence <sal_Int8> aData;
2544 0 : x->readBytes(aData, length);
2545 0 : rParamValue = aData;
2546 0 : x->closeInput();
2547 : }
2548 0 : catch( Exception& )
2549 : {
2550 0 : throw SQLException();
2551 0 : }
2552 0 : }
2553 :
2554 0 : void SAL_CALL ORowSet::setCharacterStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
2555 : {
2556 0 : ::osl::MutexGuard aGuard( m_aColumnsMutex );
2557 0 : ORowSetValue& rParamValue( getParameterStorage( parameterIndex ) );
2558 : try
2559 : {
2560 0 : Sequence <sal_Int8> aData;
2561 0 : rtl::OUString aDataStr;
2562 : // the data is given as character data and the length defines the character length
2563 0 : sal_Int32 nSize = x->readBytes(aData, length * sizeof(sal_Unicode));
2564 0 : if (nSize / sizeof(sal_Unicode))
2565 0 : aDataStr = rtl::OUString((sal_Unicode*)aData.getConstArray(), nSize / sizeof(sal_Unicode));
2566 0 : rParamValue = aDataStr;
2567 0 : rParamValue.setTypeKind( DataType::LONGVARCHAR );
2568 0 : x->closeInput();
2569 : }
2570 0 : catch( Exception& )
2571 : {
2572 0 : throw SQLException();
2573 0 : }
2574 0 : }
2575 :
2576 0 : void SAL_CALL ORowSet::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException)
2577 : {
2578 0 : if ( !::dbtools::implSetObject( this, parameterIndex, x ) )
2579 : { // there is no other setXXX call which can handle the value in x
2580 0 : throw SQLException();
2581 : }
2582 0 : }
2583 :
2584 0 : void SAL_CALL ORowSet::setObjectWithInfo( sal_Int32 parameterIndex, const Any& x, sal_Int32 targetSqlType, sal_Int32 /*scale*/ ) throw(SQLException, RuntimeException)
2585 : {
2586 0 : ::osl::MutexGuard aGuard( m_aColumnsMutex );
2587 0 : ORowSetValue& rParamValue( getParameterStorage( parameterIndex ) );
2588 0 : setObject( parameterIndex, x );
2589 0 : rParamValue.setTypeKind( targetSqlType );
2590 0 : }
2591 :
2592 0 : void SAL_CALL ORowSet::setRef( sal_Int32 /*parameterIndex*/, const Reference< XRef >& /*x*/ ) throw(SQLException, RuntimeException)
2593 : {
2594 0 : ::dbtools::throwFeatureNotImplementedException( "XParameters::setRef", *this );
2595 0 : }
2596 :
2597 0 : void SAL_CALL ORowSet::setBlob( sal_Int32 /*parameterIndex*/, const Reference< XBlob >& /*x*/ ) throw(SQLException, RuntimeException)
2598 : {
2599 0 : ::dbtools::throwFeatureNotImplementedException( "XParameters::setBlob", *this );
2600 0 : }
2601 :
2602 0 : void SAL_CALL ORowSet::setClob( sal_Int32 /*parameterIndex*/, const Reference< XClob >& /*x*/ ) throw(SQLException, RuntimeException)
2603 : {
2604 0 : ::dbtools::throwFeatureNotImplementedException( "XParameters::setClob", *this );
2605 0 : }
2606 :
2607 0 : void SAL_CALL ORowSet::setArray( sal_Int32 /*parameterIndex*/, const Reference< XArray >& /*x*/ ) throw(SQLException, RuntimeException)
2608 : {
2609 0 : ::dbtools::throwFeatureNotImplementedException( "XParameters::setArray", *this );
2610 0 : }
2611 :
2612 0 : void SAL_CALL ORowSet::clearParameters( ) throw(SQLException, RuntimeException)
2613 : {
2614 0 : ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2615 :
2616 0 : ::osl::MutexGuard aGuard( m_aColumnsMutex );
2617 :
2618 0 : size_t nParamCount( m_pParameters.is() ? m_pParameters->size() : m_aPrematureParamValues.get().size() );
2619 0 : for ( size_t i=1; i<=nParamCount; ++i )
2620 0 : getParameterStorage( (sal_Int32)i ).setNull();
2621 0 : m_aParametersSet.clear();
2622 0 : }
2623 :
2624 0 : Any SAL_CALL ORowSet::getWarnings( ) throw (SQLException, RuntimeException)
2625 : {
2626 0 : return m_aWarnings.getWarnings();
2627 : }
2628 :
2629 0 : void SAL_CALL ORowSet::clearWarnings( ) throw (SQLException, RuntimeException)
2630 : {
2631 0 : m_aWarnings.clearWarnings();
2632 0 : }
2633 :
2634 0 : void ORowSet::doCancelModification( )
2635 : {
2636 0 : if ( isModification() )
2637 : {
2638 : // read-only flag restored
2639 0 : impl_restoreDataColumnsWriteable_throw();
2640 0 : m_pCache->cancelRowModification();
2641 : }
2642 0 : m_bModified = sal_False;
2643 0 : m_bIsInsertRow = sal_False;
2644 0 : }
2645 :
2646 0 : sal_Bool ORowSet::isModification( )
2647 : {
2648 0 : return isNew();
2649 : }
2650 :
2651 0 : sal_Bool ORowSet::isModified( )
2652 : {
2653 0 : return m_bModified;
2654 : }
2655 :
2656 0 : sal_Bool ORowSet::isNew( )
2657 : {
2658 0 : return m_bNew;
2659 : }
2660 :
2661 0 : sal_Bool ORowSet::isPropertyChangeNotificationEnabled() const
2662 : {
2663 0 : return m_bPropChangeNotifyEnabled;
2664 : }
2665 :
2666 0 : void ORowSet::checkUpdateIterator()
2667 : {
2668 0 : if(!m_bIsInsertRow)
2669 : {
2670 0 : m_pCache->setUpdateIterator(m_aCurrentRow);
2671 0 : m_aCurrentRow = m_pCache->m_aInsertRow;
2672 0 : m_bIsInsertRow = sal_True;
2673 : }
2674 0 : }
2675 :
2676 0 : void ORowSet::checkUpdateConditions(sal_Int32 columnIndex)
2677 : {
2678 0 : checkCache();
2679 0 : if ( m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY)
2680 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_RESULT_IS_READONLY ), SQL_GENERAL_ERROR, *this );
2681 :
2682 0 : if ( rowDeleted() )
2683 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_ROW_ALREADY_DELETED ), SQL_INVALID_CURSOR_POSITION, *this );
2684 :
2685 0 : if ( m_aCurrentRow.isNull() )
2686 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_INVALID_CURSOR_STATE ), SQL_INVALID_CURSOR_STATE, *this );
2687 :
2688 0 : if ( columnIndex <= 0 || sal_Int32((*m_aCurrentRow)->get().size()) <= columnIndex )
2689 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_INVALID_INDEX ), SQL_INVALID_DESCRIPTOR_INDEX, *this );
2690 0 : }
2691 :
2692 0 : void SAL_CALL ORowSet::refreshRow( ) throw(SQLException, RuntimeException)
2693 : {
2694 :
2695 0 : ORowSetNotifier aNotifier( this );
2696 : // this will call cancelRowModification on the cache if necessary
2697 :
2698 : // notification order:
2699 0 : if ( m_bModified && m_pCache )
2700 0 : implCancelRowUpdates( sal_False ); // do _not_ notify the IsModify - will do this ourself below
2701 :
2702 : // - column values
2703 0 : ORowSetBase::refreshRow();
2704 :
2705 : // - IsModified
2706 : // - IsNew
2707 0 : aNotifier.fire( );
2708 0 : }
2709 :
2710 0 : void ORowSet::impl_rebuild_throw(::osl::ResettableMutexGuard& _rGuard)
2711 : {
2712 0 : Reference< XResultSet > xResultSet( m_xStatement->executeQuery() );
2713 0 : m_aWarnings.setExternalWarnings( Reference< XWarningsSupplier >( xResultSet, UNO_QUERY ) );
2714 0 : m_pCache->reset(xResultSet);
2715 0 : notifyAllListeners(_rGuard);
2716 0 : }
2717 : // ***********************************************************
2718 : // ORowSetClone
2719 : // ***********************************************************
2720 : DBG_NAME(ORowSetClone);
2721 :
2722 0 : ORowSetClone::ORowSetClone( const ::comphelper::ComponentContext& _rContext, ORowSet& rParent, ::osl::Mutex* _pMutex )
2723 : :OSubComponent(m_aMutex, rParent)
2724 : ,ORowSetBase( _rContext, OComponentHelper::rBHelper, _pMutex )
2725 : ,m_pParent(&rParent)
2726 : ,m_nFetchDirection(rParent.m_nFetchDirection)
2727 : ,m_nFetchSize(rParent.m_nFetchSize)
2728 0 : ,m_bIsBookmarkable(sal_True)
2729 : {
2730 : DBG_CTOR(ORowSetClone, NULL);
2731 :
2732 0 : m_nResultSetType = rParent.m_nResultSetType;
2733 0 : m_nResultSetConcurrency = ResultSetConcurrency::READ_ONLY;
2734 0 : m_pMySelf = this;
2735 0 : m_bClone = sal_True;
2736 0 : m_bBeforeFirst = rParent.m_bBeforeFirst;
2737 0 : m_bAfterLast = rParent.m_bAfterLast;
2738 0 : m_pCache = rParent.m_pCache;
2739 0 : m_aBookmark = rParent.m_aBookmark;
2740 0 : m_aCurrentRow = m_pCache->createIterator(this);
2741 0 : m_xNumberFormatTypes = rParent.m_xNumberFormatTypes;
2742 :
2743 0 : m_aOldRow = m_pCache->registerOldRow();
2744 :
2745 0 : ::rtl::Reference< ::connectivity::OSQLColumns> aColumns = new ::connectivity::OSQLColumns();
2746 0 : ::std::vector< ::rtl::OUString> aNames;
2747 :
2748 0 : ::rtl::OUString aDescription;
2749 0 : Locale aLocale = SvtSysLocale().GetLanguageTag().getLocale();
2750 :
2751 0 : if ( rParent.m_pColumns )
2752 : {
2753 0 : Sequence< ::rtl::OUString> aSeq = rParent.m_pColumns->getElementNames();
2754 0 : const ::rtl::OUString* pIter = aSeq.getConstArray();
2755 0 : const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
2756 0 : aColumns->get().reserve(aSeq.getLength()+1);
2757 0 : for(sal_Int32 i=1;pIter != pEnd ;++pIter,++i)
2758 : {
2759 0 : Reference<XPropertySet> xColumn;
2760 0 : rParent.m_pColumns->getByName(*pIter) >>= xColumn;
2761 0 : if(xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_DESCRIPTION))
2762 0 : aDescription = comphelper::getString(xColumn->getPropertyValue(PROPERTY_DESCRIPTION));
2763 :
2764 0 : ::rtl::OUString sParseLabel;
2765 0 : xColumn->getPropertyValue(PROPERTY_LABEL) >>= sParseLabel;
2766 0 : ORowSetColumn* pColumn = new ORowSetColumn( rParent.getMetaData(),
2767 : this,
2768 : i,
2769 0 : rParent.m_xActiveConnection->getMetaData(),
2770 : aDescription,
2771 : sParseLabel,
2772 0 : m_aCurrentRow);
2773 0 : aColumns->get().push_back(pColumn);
2774 0 : pColumn->setName(*pIter);
2775 0 : aNames.push_back(*pIter);
2776 0 : m_aDataColumns.push_back(pColumn);
2777 :
2778 0 : pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ALIGN,xColumn->getPropertyValue(PROPERTY_ALIGN));
2779 0 : sal_Int32 nFormatKey = 0;
2780 0 : xColumn->getPropertyValue(PROPERTY_NUMBERFORMAT) >>= nFormatKey;
2781 0 : if(!nFormatKey && xColumn.is() && m_xNumberFormatTypes.is())
2782 0 : nFormatKey = ::dbtools::getDefaultNumberFormat(xColumn,m_xNumberFormatTypes,aLocale);
2783 0 : pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_NUMBERFORMAT,makeAny(nFormatKey));
2784 0 : pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_RELATIVEPOSITION,xColumn->getPropertyValue(PROPERTY_RELATIVEPOSITION));
2785 0 : pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_WIDTH,xColumn->getPropertyValue(PROPERTY_WIDTH));
2786 0 : pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_HIDDEN,xColumn->getPropertyValue(PROPERTY_HIDDEN));
2787 0 : pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_CONTROLMODEL,xColumn->getPropertyValue(PROPERTY_CONTROLMODEL));
2788 0 : pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_HELPTEXT,xColumn->getPropertyValue(PROPERTY_HELPTEXT));
2789 0 : pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_CONTROLDEFAULT,xColumn->getPropertyValue(PROPERTY_CONTROLDEFAULT));
2790 :
2791 0 : }
2792 : }
2793 0 : Reference<XDatabaseMetaData> xMeta = rParent.m_xActiveConnection->getMetaData();
2794 0 : m_pColumns = new ORowSetDataColumns(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers(),
2795 0 : aColumns,*this,m_aMutex,aNames);
2796 :
2797 0 : sal_Int32 nRT = PropertyAttribute::READONLY | PropertyAttribute::TRANSIENT;
2798 :
2799 : // sdb.RowSet Properties
2800 0 : registerMayBeVoidProperty(PROPERTY_ACTIVE_CONNECTION,PROPERTY_ID_ACTIVE_CONNECTION, PropertyAttribute::MAYBEVOID|PropertyAttribute::READONLY, &rParent.m_aActiveConnection, ::getCppuType(static_cast< Reference< XConnection >* >(0)));
2801 0 : registerProperty(PROPERTY_RESULTSETCONCURRENCY, PROPERTY_ID_RESULTSETCONCURRENCY, PropertyAttribute::READONLY, &m_nResultSetConcurrency,::getCppuType(static_cast< sal_Int32*>(0)));
2802 0 : registerProperty(PROPERTY_RESULTSETTYPE, PROPERTY_ID_RESULTSETTYPE, PropertyAttribute::READONLY, &m_nResultSetType, ::getCppuType(static_cast< sal_Int32*>(0)));
2803 0 : registerProperty(PROPERTY_FETCHDIRECTION, PROPERTY_ID_FETCHDIRECTION, PropertyAttribute::TRANSIENT, &m_nFetchDirection, ::getCppuType(static_cast< sal_Int32*>(0)));
2804 0 : registerProperty(PROPERTY_FETCHSIZE, PROPERTY_ID_FETCHSIZE, PropertyAttribute::TRANSIENT, &m_nFetchSize, ::getCppuType(static_cast< sal_Int32*>(0)));
2805 0 : registerProperty(PROPERTY_ISBOOKMARKABLE, PROPERTY_ID_ISBOOKMARKABLE, nRT, &m_bIsBookmarkable, ::getBooleanCppuType());
2806 0 : }
2807 :
2808 0 : ORowSetClone::~ORowSetClone()
2809 : {
2810 : DBG_DTOR(ORowSetClone, NULL);
2811 0 : }
2812 :
2813 : // com::sun::star::XTypeProvider
2814 0 : Sequence< Type > ORowSetClone::getTypes() throw (RuntimeException)
2815 : {
2816 0 : return ::comphelper::concatSequences(OSubComponent::getTypes(),ORowSetBase::getTypes());
2817 : }
2818 :
2819 : // com::sun::star::XInterface
2820 0 : Any ORowSetClone::queryInterface( const Type & rType ) throw (RuntimeException)
2821 : {
2822 0 : Any aRet = ORowSetBase::queryInterface(rType);
2823 0 : if(!aRet.hasValue())
2824 0 : aRet = OSubComponent::queryInterface(rType);
2825 0 : return aRet;
2826 : }
2827 :
2828 0 : void ORowSetClone::acquire() throw()
2829 : {
2830 0 : OSubComponent::acquire();
2831 0 : }
2832 :
2833 0 : void ORowSetClone::release() throw()
2834 : {
2835 0 : OSubComponent::release();
2836 0 : }
2837 :
2838 : // XServiceInfo
2839 0 : rtl::OUString ORowSetClone::getImplementationName( ) throw(RuntimeException)
2840 : {
2841 0 : return rtl::OUString("com.sun.star.sdb.ORowSetClone");
2842 : }
2843 :
2844 0 : sal_Bool ORowSetClone::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
2845 : {
2846 0 : return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
2847 : }
2848 :
2849 0 : Sequence< ::rtl::OUString > ORowSetClone::getSupportedServiceNames( ) throw (RuntimeException)
2850 : {
2851 0 : Sequence< ::rtl::OUString > aSNS( 2 );
2852 0 : aSNS[0] = SERVICE_SDBC_RESULTSET;
2853 0 : aSNS[1] = SERVICE_SDB_RESULTSET;
2854 0 : return aSNS;
2855 : }
2856 :
2857 : // OComponentHelper
2858 0 : void ORowSetClone::disposing()
2859 : {
2860 0 : MutexGuard aGuard( m_aMutex );
2861 0 : ORowSetBase::disposing();
2862 :
2863 0 : m_pParent = NULL;
2864 0 : m_pMutex = &m_aMutex; // this must be done here because someone could hold a ref to us and try to do something
2865 0 : OSubComponent::disposing();
2866 0 : }
2867 :
2868 : // XCloseable
2869 0 : void ORowSetClone::close(void) throw( SQLException, RuntimeException )
2870 : {
2871 : {
2872 0 : MutexGuard aGuard( m_aMutex );
2873 0 : if (OComponentHelper::rBHelper.bDisposed)
2874 0 : throw DisposedException();
2875 : }
2876 0 : dispose();
2877 0 : }
2878 :
2879 : // comphelper::OPropertyArrayUsageHelper
2880 0 : ::cppu::IPropertyArrayHelper* ORowSetClone::createArrayHelper( ) const
2881 : {
2882 0 : Sequence< Property > aProps;
2883 0 : describeProperties(aProps);
2884 0 : return new ::cppu::OPropertyArrayHelper(aProps);
2885 : }
2886 :
2887 : // cppu::OPropertySetHelper
2888 0 : ::cppu::IPropertyArrayHelper& SAL_CALL ORowSetClone::getInfoHelper()
2889 : {
2890 : typedef ::comphelper::OPropertyArrayUsageHelper<ORowSetClone> ORowSetClone_PROP;
2891 0 : return *ORowSetClone_PROP::getArrayHelper();
2892 : }
2893 :
2894 0 : Sequence< sal_Int8 > ORowSetClone::getUnoTunnelImplementationId()
2895 : {
2896 : static ::cppu::OImplementationId * pId = 0;
2897 0 : if (! pId)
2898 : {
2899 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
2900 0 : if (! pId)
2901 : {
2902 0 : static ::cppu::OImplementationId aId;
2903 0 : pId = &aId;
2904 0 : }
2905 : }
2906 0 : return pId->getImplementationId();
2907 : }
2908 :
2909 : // com::sun::star::XUnoTunnel
2910 0 : sal_Int64 SAL_CALL ORowSetClone::getSomething( const Sequence< sal_Int8 >& rId ) throw(RuntimeException)
2911 : {
2912 0 : if (rId.getLength() == 16 && 0 == memcmp(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
2913 0 : return reinterpret_cast<sal_Int64>(this);
2914 :
2915 0 : return 0;
2916 : }
2917 :
2918 0 : void SAL_CALL ORowSetClone::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception)
2919 : {
2920 0 : if ( nHandle == PROPERTY_ID_FETCHSIZE )
2921 : {
2922 0 : if ( m_pParent )
2923 0 : m_pParent->setFastPropertyValue_NoBroadcast( nHandle, rValue );
2924 : }
2925 :
2926 0 : OPropertyStateContainer::setFastPropertyValue_NoBroadcast(nHandle,rValue);
2927 0 : }
2928 :
2929 0 : void ORowSetClone::doCancelModification( )
2930 : {
2931 0 : }
2932 :
2933 0 : sal_Bool ORowSetClone::isModification( )
2934 : {
2935 0 : return sal_False;
2936 : }
2937 :
2938 0 : sal_Bool ORowSetClone::isModified( )
2939 : {
2940 0 : return sal_False;
2941 : }
2942 :
2943 0 : sal_Bool ORowSetClone::isNew( )
2944 : {
2945 0 : return sal_False;
2946 : }
2947 :
2948 0 : void SAL_CALL ORowSetClone::execute( ) throw(SQLException, RuntimeException)
2949 : {
2950 0 : throwFunctionNotSupportedException( "RowSetClone::XRowSet::execute", *this );
2951 0 : }
2952 :
2953 0 : void SAL_CALL ORowSetClone::addRowSetListener( const Reference< XRowSetListener >& ) throw(RuntimeException)
2954 : {
2955 0 : throwFunctionNotSupportedException( "RowSetClone::XRowSet", *this );
2956 0 : }
2957 :
2958 0 : void SAL_CALL ORowSetClone::removeRowSetListener( const Reference< XRowSetListener >& ) throw(RuntimeException)
2959 : {
2960 0 : throwFunctionNotSupportedException( "RowSetClone::XRowSet", *this );
2961 0 : }
2962 :
2963 : } // dbaccess
2964 :
2965 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|