merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / core / api / RowSet.cxx
blob1a0a6cbbc20d55ca6117a6d1e6aebf9a0340541a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RowSet.cxx,v $
10 * $Revision: 1.159 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #include "RowSet.hxx"
35 #include "dbastrings.hrc"
36 #include "sdbcoretools.hxx"
37 #include "SingleSelectQueryComposer.hxx"
38 #include "module_dba.hxx"
40 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
41 #include <com/sun/star/beans/PropertyAttribute.hpp>
42 #endif
43 #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
44 #include <com/sun/star/lang/DisposedException.hpp>
45 #endif
46 #ifndef _CPPUHELPER_INTERFACECONTAINER_H_
47 #include <cppuhelper/interfacecontainer.h>
48 #endif
49 #ifndef _CPPUHELPER_EXC_HLP_HXX_
50 #include <cppuhelper/exc_hlp.hxx>
51 #endif
52 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
53 #include <cppuhelper/typeprovider.hxx>
54 #endif
55 #ifndef _COMPHELPER_SEQUENCE_HXX_
56 #include <comphelper/sequence.hxx>
57 #endif
58 #ifndef COMPHELPER_COMPONENTCONTEXT_HXX
59 #include <comphelper/componentcontext.hxx>
60 #endif
61 #ifndef _COM_SUN_STAR_SDB_XCOMPLETEDCONNECTION_HPP_
62 #include <com/sun/star/sdb/XCompletedConnection.hpp>
63 #endif
64 #ifndef _COM_SUN_STAR_SDB_ROWSETVETOEXCEPTION_HPP_
65 #include <com/sun/star/sdb/RowSetVetoException.hpp>
66 #endif
67 #ifndef _COM_SUN_STAR_SDBC_FETCHDIRECTION_HPP_
68 #include <com/sun/star/sdbc/FetchDirection.hpp>
69 #endif
70 #ifndef _COM_SUN_STAR_SDBC_RESULTSETCONCURRENCY_HPP_
71 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
72 #endif
73 #ifndef _COM_SUN_STAR_SDBCX_PRIVILEGE_HPP_
74 #include <com/sun/star/sdbcx/Privilege.hpp>
75 #endif
76 #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
77 #include <com/sun/star/sdb/CommandType.hpp>
78 #endif
79 #ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
80 #include <com/sun/star/sdbc/XDataSource.hpp>
81 #endif
82 #ifndef _COM_SUN_STAR_SDB_XQUERIESSUPPLIER_HPP_
83 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
84 #endif
85 #ifndef _COM_SUN_STAR_SDB_ROWCHANGEACTION_HPP_
86 #include <com/sun/star/sdb/RowChangeAction.hpp>
87 #endif
88 #ifndef _COM_SUN_STAR_SDB_ERRORCONDITION_HPP_
89 #include <com/sun/star/sdb/ErrorCondition.hpp>
90 #endif
91 #ifndef _COM_SUN_STAR_SDBC_XDRIVERACCESS_HPP_
92 #include <com/sun/star/sdbc/XDriverAccess.hpp>
93 #endif
94 #ifndef _COM_SUN_STAR_SDBCX_XDATADEFINITIONSUPPLIER_HPP_
95 #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
96 #endif
97 #ifndef _COM_SUN_STAR_SDBCX_COMPAREBOOKMARK_HPP_
98 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
99 #endif
100 #ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_
101 #include <com/sun/star/uno/XNamingService.hpp>
102 #endif
103 #ifndef _COM_SUN_STAR_SDBCX_PRIVILEGE_HPP_
104 #include <com/sun/star/sdbcx/Privilege.hpp>
105 #endif
106 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
107 #include <connectivity/dbtools.hxx>
108 #endif
109 #ifndef _COMPHELPER_EXTRACT_HXX_
110 #include <comphelper/extract.hxx>
111 #endif
112 #ifndef DBACCESS_CORE_API_ROWSETCACHE_HXX
113 #include "RowSetCache.hxx"
114 #endif
115 #if OSL_DEBUG_LEVEL > 1
116 #ifndef _COM_SUN_STAR_SDBC_XDRIVERMANAGER_HPP_
117 #include <com/sun/star/sdbc/XDriverManager.hpp>
118 #endif
119 #endif
120 #ifndef _DBACORE_DATACOLUMN_HXX_
121 #include "CRowSetDataColumn.hxx"
122 #endif
123 #ifndef DBACCESS_CORE_API_CROWSETCOLUMN_HXX
124 #include "CRowSetColumn.hxx"
125 #endif
126 #ifndef _COMPHELPER_TYPES_HXX_
127 #include <comphelper/types.hxx>
128 #endif
129 #ifndef _COMPHELPER_SEQSTREAM_HXX
130 #include <comphelper/seqstream.hxx>
131 #endif
132 #ifndef _TOOLS_DEBUG_HXX
133 #include <tools/debug.hxx>
134 #endif
135 #ifndef TOOLS_DIAGNOSE_EX_H
136 #include <tools/diagnose_ex.h>
137 #endif
138 #ifndef _DBHELPER_DBEXCEPTION_HXX_
139 #include <connectivity/dbexception.hxx>
140 #endif
141 #ifndef _DBA_CORE_TABLECONTAINER_HXX_
142 #include "tablecontainer.hxx"
143 #endif
144 #ifndef _COM_SUN_STAR_SDB_PARAMETERSREQUEST_HPP_
145 #include <com/sun/star/sdb/ParametersRequest.hpp>
146 #endif
147 #ifndef _COM_SUN_STAR_SDB_PARAMETERSREQUEST_HPP_
148 #include <com/sun/star/sdb/ParametersRequest.hpp>
149 #endif
150 #ifndef _COM_SUN_STAR_SDB_XPARAMETERSSUPPLIER_HPP_
151 #include <com/sun/star/sdb/XParametersSupplier.hpp>
152 #endif
153 #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
154 #include <com/sun/star/container/XChild.hpp>
155 #endif
156 #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATSSUPPLIER_HPP_
157 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
158 #endif
159 #ifndef _COMPHELPER_INTERACTION_HXX_
160 #include <comphelper/interaction.hxx>
161 #endif
162 #ifndef _COMPHELPER_PROPERTY_HXX_
163 #include <comphelper/property.hxx>
164 #endif
165 #ifndef _UTL_CONFIGMGR_HXX_
166 #include <unotools/configmgr.hxx>
167 #endif
168 #ifndef _COMPHELPER_UNO3_HXX_
169 #include <comphelper/uno3.hxx>
170 #endif
171 #ifndef _COM_SUN_STAR_SDBCX_COMPAREBOOKMARK_HPP_
172 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
173 #endif
174 #ifndef _DBA_CORE_RESOURCE_HXX_
175 #include "core_resource.hxx"
176 #endif
177 #ifndef _DBA_CORE_RESOURCE_HRC_
178 #include "core_resource.hrc"
179 #endif
180 #ifndef _DBHELPER_DBCONVERSION_HXX_
181 #include <connectivity/dbconversion.hxx>
182 #endif
183 #ifndef INCLUDED_SVTOOLS_SYSLOCALE_HXX
184 #include <svtools/syslocale.hxx>
185 #endif
186 #ifndef _RTL_LOGFILE_HXX_
187 #include <rtl/logfile.hxx>
188 #endif
190 using namespace utl;
191 using namespace dbaccess;
192 using namespace connectivity;
193 using namespace comphelper;
194 using namespace dbtools;
195 using namespace ::com::sun::star;
196 using namespace ::com::sun::star::uno;
197 using namespace ::com::sun::star::beans;
198 using namespace ::com::sun::star::sdbc;
199 using namespace ::com::sun::star::sdb;
200 using namespace ::com::sun::star::sdbcx;
201 using namespace ::com::sun::star::container;
202 using namespace ::com::sun::star::lang;
203 using namespace ::com::sun::star::task;
204 using namespace ::com::sun::star::util;
205 using namespace ::cppu;
206 using namespace ::osl;
208 //--------------------------------------------------------------------------
209 extern "C" void SAL_CALL createRegistryInfo_ORowSet()
211 static ::dba::OAutoRegistration< ORowSet > aAutoRegistration;
213 // -----------------------------------------------------------------------------
215 #define NOTIFY_LISTERNERS_CHECK(_rListeners,T,method) \
216 Sequence< Reference< XInterface > > aListenerSeq = _rListeners.getElements(); \
218 const Reference< XInterface >* pxIntBegin = aListenerSeq.getConstArray(); \
219 const Reference< XInterface >* pxInt = pxIntBegin + aListenerSeq.getLength(); \
221 _rGuard.clear(); \
222 sal_Bool bCheck = sal_True; \
223 while( pxInt > pxIntBegin && bCheck ) \
225 try \
227 while( pxInt > pxIntBegin && bCheck ) \
229 --pxInt; \
230 bCheck = static_cast< T* >( pxInt->get() )->method(aEvt); \
233 catch( RuntimeException& ) \
237 _rGuard.reset();
240 //..................................................................
241 namespace dbaccess
243 //..................................................................
246 //--------------------------------------------------------------------------
247 Reference< XInterface > ORowSet_CreateInstance(const Reference< XMultiServiceFactory >& _rxFactory)
249 return *(new ORowSet(_rxFactory));
251 //--------------------------------------------------------------------------
252 ORowSet::ORowSet( const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB )
253 :ORowSet_BASE1(m_aMutex)
254 ,ORowSetBase( _rxORB, ORowSet_BASE1::rBHelper, &m_aMutex )
255 ,m_pParameters( NULL )
256 ,m_aRowsetListeners(*m_pMutex)
257 ,m_aApproveListeners(*m_pMutex)
258 ,m_pTables(NULL)
259 ,m_nFetchDirection(FetchDirection::FORWARD)
260 ,m_nFetchSize(50)
261 ,m_nMaxFieldSize(0)
262 ,m_nMaxRows(0)
263 ,m_nQueryTimeOut(0)
264 ,m_nCommandType(CommandType::COMMAND)
265 ,m_nTransactionIsolation(0)
266 ,m_nPrivileges(0)
267 ,m_nInAppend(0)
268 ,m_bUseEscapeProcessing(sal_True)
269 ,m_bApplyFilter(sal_False)
270 ,m_bCommandFacetsDirty( sal_True )
271 ,m_bModified(sal_False)
272 ,m_bRebuildConnOnExecute(sal_False)
273 ,m_bIsBookmarable(sal_True)
274 ,m_bNew(sal_False)
275 ,m_bCanUpdateInsertedRows(sal_True)
276 ,m_bOwnConnection(sal_False)
278 m_nResultSetType = ResultSetType::SCROLL_SENSITIVE;
279 m_nResultSetConcurrency = ResultSetConcurrency::UPDATABLE;
280 m_pMySelf = this;
281 m_aActiveConnection <<= m_xActiveConnection;
283 sal_Int32 nRBT = PropertyAttribute::READONLY | PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT;
284 sal_Int32 nRT = PropertyAttribute::READONLY | PropertyAttribute::TRANSIENT;
285 sal_Int32 nBT = PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT;
287 m_aPrematureParamValues.get().resize( 0 );
289 // sdb.RowSet Properties
290 registerMayBeVoidProperty(PROPERTY_ACTIVE_CONNECTION,PROPERTY_ID_ACTIVE_CONNECTION, PropertyAttribute::MAYBEVOID|PropertyAttribute::TRANSIENT|PropertyAttribute::BOUND, &m_aActiveConnection, ::getCppuType(reinterpret_cast< Reference< XConnection >* >(NULL)));
291 registerProperty(PROPERTY_DATASOURCENAME, PROPERTY_ID_DATASOURCENAME, PropertyAttribute::BOUND, &m_aDataSourceName, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
292 registerProperty(PROPERTY_COMMAND, PROPERTY_ID_COMMAND, PropertyAttribute::BOUND, &m_aCommand, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
293 registerProperty(PROPERTY_COMMAND_TYPE, PROPERTY_ID_COMMAND_TYPE, PropertyAttribute::BOUND, &m_nCommandType, ::getCppuType(reinterpret_cast< sal_Int32*>(NULL)));
294 registerProperty(PROPERTY_ACTIVECOMMAND, PROPERTY_ID_ACTIVECOMMAND, nRBT, &m_aActiveCommand, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
295 registerProperty(PROPERTY_IGNORERESULT, PROPERTY_ID_IGNORERESULT, PropertyAttribute::BOUND, &m_bIgnoreResult, ::getBooleanCppuType());
296 registerProperty(PROPERTY_FILTER, PROPERTY_ID_FILTER, PropertyAttribute::BOUND, &m_aFilter, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
297 registerProperty(PROPERTY_HAVING_CLAUSE, PROPERTY_ID_HAVING_CLAUSE, PropertyAttribute::BOUND, &m_aHavingClause, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
298 registerProperty(PROPERTY_GROUP_BY, PROPERTY_ID_GROUP_BY, PropertyAttribute::BOUND, &m_aGroupBy, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
299 registerProperty(PROPERTY_APPLYFILTER, PROPERTY_ID_APPLYFILTER, PropertyAttribute::BOUND, &m_bApplyFilter, ::getBooleanCppuType());
300 registerProperty(PROPERTY_ORDER, PROPERTY_ID_ORDER, PropertyAttribute::BOUND, &m_aOrder, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
301 registerProperty(PROPERTY_PRIVILEGES, PROPERTY_ID_PRIVILEGES, nRT, &m_nPrivileges, ::getCppuType(reinterpret_cast< sal_Int32*>(NULL)));
302 registerProperty(PROPERTY_ISMODIFIED, PROPERTY_ID_ISMODIFIED, nBT, &m_bModified, ::getBooleanCppuType());
303 registerProperty(PROPERTY_ISNEW, PROPERTY_ID_ISNEW, nRBT, &m_bNew, ::getBooleanCppuType());
305 // sdbcx.ResultSet Properties
306 registerProperty(PROPERTY_ISBOOKMARKABLE, PROPERTY_ID_ISBOOKMARKABLE, nRT, &m_bIsBookmarable, ::getBooleanCppuType());
307 registerProperty(PROPERTY_CANUPDATEINSERTEDROWS,PROPERTY_ID_CANUPDATEINSERTEDROWS, nRT, &m_bCanUpdateInsertedRows, ::getBooleanCppuType());
308 // sdbc.ResultSet Properties
309 registerProperty(PROPERTY_RESULTSETCONCURRENCY, PROPERTY_ID_RESULTSETCONCURRENCY, PropertyAttribute::TRANSIENT, &m_nResultSetConcurrency,::getCppuType(reinterpret_cast< sal_Int32*>(NULL)));
310 registerProperty(PROPERTY_RESULTSETTYPE, PROPERTY_ID_RESULTSETTYPE, PropertyAttribute::TRANSIENT, &m_nResultSetType, ::getCppuType(reinterpret_cast< sal_Int32*>(NULL)));
311 registerProperty(PROPERTY_FETCHDIRECTION, PROPERTY_ID_FETCHDIRECTION, PropertyAttribute::TRANSIENT, &m_nFetchDirection, ::getCppuType(reinterpret_cast< sal_Int32*>(NULL)));
312 registerProperty(PROPERTY_FETCHSIZE, PROPERTY_ID_FETCHSIZE, PropertyAttribute::TRANSIENT, &m_nFetchSize, ::getCppuType(reinterpret_cast< sal_Int32*>(NULL)));
314 // sdbc.RowSet Properties
315 registerProperty(PROPERTY_URL, PROPERTY_ID_URL, 0, &m_aURL, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
316 registerProperty(PROPERTY_TRANSACTIONISOLATION, PROPERTY_ID_TRANSACTIONISOLATION, PropertyAttribute::TRANSIENT, &m_nTransactionIsolation,::getCppuType(reinterpret_cast< sal_Int32*>(NULL)));
317 registerMayBeVoidProperty(PROPERTY_TYPEMAP, PROPERTY_ID_TYPEMAP, PropertyAttribute::MAYBEVOID|PropertyAttribute::TRANSIENT, &m_aTypeMap, ::getCppuType(reinterpret_cast< Reference< XNameAccess >* >(NULL)));
318 registerProperty(PROPERTY_ESCAPE_PROCESSING,PROPERTY_ID_ESCAPE_PROCESSING, PropertyAttribute::BOUND, &m_bUseEscapeProcessing,::getBooleanCppuType() );
319 registerProperty(PROPERTY_QUERYTIMEOUT, PROPERTY_ID_QUERYTIMEOUT, PropertyAttribute::TRANSIENT, &m_nQueryTimeOut, ::getCppuType(reinterpret_cast< sal_Int32*>(NULL)));
320 registerProperty(PROPERTY_MAXFIELDSIZE, PROPERTY_ID_MAXFIELDSIZE, PropertyAttribute::TRANSIENT, &m_nMaxFieldSize, ::getCppuType(reinterpret_cast< sal_Int32*>(NULL)));
321 registerProperty(PROPERTY_MAXROWS, PROPERTY_ID_MAXROWS, 0, &m_nMaxRows, ::getCppuType(reinterpret_cast< sal_Int32*>(NULL)) );
322 registerProperty(PROPERTY_USER, PROPERTY_ID_USER, PropertyAttribute::TRANSIENT, &m_aUser, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
323 registerProperty(PROPERTY_PASSWORD, PROPERTY_ID_PASSWORD, PropertyAttribute::TRANSIENT, &m_aPassword, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
325 registerProperty(PROPERTY_UPDATE_CATALOGNAME, PROPERTY_ID_UPDATE_CATALOGNAME, PropertyAttribute::BOUND, &m_aUpdateCatalogName, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
326 registerProperty(PROPERTY_UPDATE_SCHEMANAME, PROPERTY_ID_UPDATE_SCHEMANAME, PropertyAttribute::BOUND, &m_aUpdateSchemaName, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
327 registerProperty(PROPERTY_UPDATE_TABLENAME, PROPERTY_ID_UPDATE_TABLENAME, PropertyAttribute::BOUND, &m_aUpdateTableName, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
330 ORowSet::~ORowSet()
332 if ( !m_rBHelper.bDisposed && !m_rBHelper.bInDispose )
334 OSL_ENSURE(0, "Please check who doesn't dispose this component!");
335 osl_incrementInterlockedCount( &m_refCount );
336 dispose();
340 // -----------------------------------------------------------------------------
341 void ORowSet::getPropertyDefaultByHandle( sal_Int32 _nHandle, Any& _rDefault ) const
343 switch( _nHandle )
345 case PROPERTY_ID_COMMAND_TYPE:
346 _rDefault <<= static_cast<sal_Int32>(CommandType::COMMAND);
347 break;
348 case PROPERTY_ID_IGNORERESULT:
349 _rDefault <<= sal_False;
350 break;
351 case PROPERTY_ID_APPLYFILTER:
352 _rDefault <<= sal_False;
353 break;
354 case PROPERTY_ID_ISMODIFIED:
355 _rDefault <<= sal_False;
356 break;
357 case PROPERTY_ID_ISBOOKMARKABLE:
358 _rDefault <<= sal_True;
359 break;
360 case PROPERTY_ID_CANUPDATEINSERTEDROWS:
361 _rDefault <<= sal_True;
362 break;
363 case PROPERTY_ID_RESULTSETTYPE:
364 _rDefault <<= ResultSetType::SCROLL_INSENSITIVE;
365 break;
366 case PROPERTY_ID_RESULTSETCONCURRENCY:
367 _rDefault <<= ResultSetConcurrency::UPDATABLE;
368 break;
369 case PROPERTY_ID_FETCHDIRECTION:
370 _rDefault <<= FetchDirection::FORWARD;
371 break;
372 case PROPERTY_ID_FETCHSIZE:
373 _rDefault <<= static_cast<sal_Int32>(1);
374 break;
375 case PROPERTY_ID_ESCAPE_PROCESSING:
376 _rDefault <<= sal_True;
377 break;
378 case PROPERTY_ID_MAXROWS:
379 _rDefault <<= sal_Int32( 0 );
380 break;
381 case PROPERTY_ID_FILTER:
382 case PROPERTY_ID_HAVING_CLAUSE:
383 case PROPERTY_ID_GROUP_BY:
384 case PROPERTY_ID_ORDER:
385 case PROPERTY_ID_UPDATE_CATALOGNAME:
386 case PROPERTY_ID_UPDATE_SCHEMANAME:
387 case PROPERTY_ID_UPDATE_TABLENAME:
388 _rDefault <<= ::rtl::OUString();
389 break;
392 // -------------------------------------------------------------------------
393 // typedef ::comphelper::OPropertyArrayUsageHelper<ORowSet> ORowSet_Prop;
395 void SAL_CALL ORowSet::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception)
397 switch(nHandle)
399 case PROPERTY_ID_ISMODIFIED:
400 m_bModified = cppu::any2bool(rValue);
401 break;
402 case PROPERTY_ID_FETCHDIRECTION:
403 if( m_nResultSetType == ResultSetType::FORWARD_ONLY)
404 throw Exception(); // else run through
405 default:
406 OPropertyStateContainer::setFastPropertyValue_NoBroadcast(nHandle,rValue);
409 if ( ( nHandle == PROPERTY_ID_ACTIVE_CONNECTION )
410 || ( nHandle == PROPERTY_ID_DATASOURCENAME )
411 || ( nHandle == PROPERTY_ID_COMMAND )
412 || ( nHandle == PROPERTY_ID_COMMAND_TYPE )
413 || ( nHandle == PROPERTY_ID_IGNORERESULT )
414 || ( nHandle == PROPERTY_ID_FILTER )
415 || ( nHandle == PROPERTY_ID_HAVING_CLAUSE )
416 || ( nHandle == PROPERTY_ID_GROUP_BY )
417 || ( nHandle == PROPERTY_ID_APPLYFILTER )
418 || ( nHandle == PROPERTY_ID_ORDER )
419 || ( nHandle == PROPERTY_ID_URL )
420 || ( nHandle == PROPERTY_ID_USER )
423 m_bCommandFacetsDirty = sal_True;
427 switch(nHandle)
429 case PROPERTY_ID_ACTIVE_CONNECTION:
430 // the new connection
432 Reference< XConnection > xNewConnection(m_aActiveConnection,UNO_QUERY);
433 setActiveConnection(xNewConnection, sal_False);
436 m_bOwnConnection = sal_False;
437 m_bRebuildConnOnExecute = sal_False;
438 break;
440 case PROPERTY_ID_DATASOURCENAME:
441 if(!m_xStatement.is())
443 Reference< XConnection > xNewConn;
444 Any aNewConn;
445 aNewConn <<= xNewConn;
446 setFastPropertyValue(PROPERTY_ID_ACTIVE_CONNECTION, aNewConn);
448 else
449 m_bRebuildConnOnExecute = sal_True;
450 break;
451 case PROPERTY_ID_FETCHSIZE:
452 if(m_pCache)
454 m_pCache->setMaxRowSize(m_nFetchSize);
455 fireRowcount();
457 break;
458 case PROPERTY_ID_URL:
459 // is the connection-to-be-built determined by the url (which is the case if m_aDataSourceName is empty) ?
460 if (!m_aDataSourceName.getLength())
462 // are we active at the moment ?
463 if (m_xStatement.is())
464 // yes -> the next execute needs to rebuild our connection because of this new property
465 m_bRebuildConnOnExecute = sal_True;
466 else
467 { // no -> drop our active connection (if we have one) as it doesn't correspond to this new property value anymore
468 Reference< XConnection > xNewConn;
469 Any aNewConn;
470 aNewConn <<= xNewConn;
471 setFastPropertyValue(PROPERTY_ID_ACTIVE_CONNECTION, aNewConn);
474 m_bOwnConnection = sal_True;
475 break;
476 case PROPERTY_ID_TYPEMAP:
477 ::cppu::extractInterface(m_xTypeMap,m_aTypeMap);
478 break;
479 default:
480 break;
483 // -------------------------------------------------------------------------
484 void SAL_CALL ORowSet::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const
486 if(m_pCache)
488 switch(nHandle)
490 case PROPERTY_ID_ISMODIFIED:
491 rValue.setValue(&m_bModified,::getCppuBooleanType());
492 break;
493 case PROPERTY_ID_ISNEW:
494 rValue.setValue(&m_bNew,::getCppuBooleanType());
495 break;
496 case PROPERTY_ID_PRIVILEGES:
497 rValue <<= m_pCache->m_nPrivileges;
498 break;
499 case PROPERTY_ID_ACTIVE_CONNECTION:
500 rValue <<= m_xActiveConnection;
501 break;
502 case PROPERTY_ID_TYPEMAP:
503 rValue <<= m_xTypeMap;
504 break;
505 default:
506 ORowSetBase::getFastPropertyValue(rValue,nHandle);
509 else
511 switch(nHandle)
513 case PROPERTY_ID_ACTIVE_CONNECTION:
514 rValue <<= m_xActiveConnection;
515 break;
516 case PROPERTY_ID_TYPEMAP:
517 rValue <<= m_xTypeMap;
518 break;
519 default:
520 ORowSetBase::getFastPropertyValue(rValue,nHandle);
524 // -------------------------------------------------------------------------
525 // com::sun::star::XTypeProvider
526 Sequence< Type > SAL_CALL ORowSet::getTypes() throw (RuntimeException)
528 OTypeCollection aTypes(::getCppuType( (const Reference< XPropertySet > *)0 ),
529 ::getCppuType( (const Reference< XFastPropertySet > *)0 ),
530 ::getCppuType( (const Reference< XMultiPropertySet > *)0 ),
531 ::comphelper::concatSequences(ORowSet_BASE1::getTypes(),ORowSetBase::getTypes()));
532 return aTypes.getTypes();
534 // -------------------------------------------------------------------------
535 Sequence< sal_Int8 > SAL_CALL ORowSet::getImplementationId() throw (RuntimeException)
537 static OImplementationId * pId = 0;
538 if (! pId)
540 MutexGuard aGuard( Mutex::getGlobalMutex() );
541 if (! pId)
543 static OImplementationId aId;
544 pId = &aId;
547 return pId->getImplementationId();
549 // -------------------------------------------------------------------------
551 // com::sun::star::XInterface
552 Any SAL_CALL ORowSet::queryInterface( const Type & rType ) throw (RuntimeException)
554 return ORowSet_BASE1::queryInterface( rType);
556 // -------------------------------------------------------------------------
557 void SAL_CALL ORowSet::acquire() throw()
559 ORowSet_BASE1::acquire();
561 // -------------------------------------------------------------------------
562 void SAL_CALL ORowSet::release() throw()
564 ORowSet_BASE1::release();
566 // -------------------------------------------------------------------------
568 // com::sun::star::XUnoTunnel
569 sal_Int64 SAL_CALL ORowSet::getSomething( const Sequence< sal_Int8 >& rId ) throw(RuntimeException)
571 if (rId.getLength() == 16 && 0 == rtl_compareMemory(getImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
572 return reinterpret_cast<sal_Int64>(this);
574 return 0;
576 // -------------------------------------------------------------------------
577 // com::sun::star::XAggregation
578 Any SAL_CALL ORowSet::queryAggregation( const Type& rType ) throw(RuntimeException)
580 Any aRet(ORowSetBase::queryInterface(rType));
581 if (!aRet.hasValue())
582 aRet = ORowSet_BASE1::queryAggregation(rType);
583 return aRet;
585 //------------------------------------------------------------------------------
586 rtl::OUString ORowSet::getImplementationName_static( ) throw(RuntimeException)
588 return rtl::OUString::createFromAscii("com.sun.star.comp.dba.ORowSet");
590 // -------------------------------------------------------------------------
591 // ::com::sun::star::XServiceInfo
592 ::rtl::OUString SAL_CALL ORowSet::getImplementationName( ) throw(RuntimeException)
594 return getImplementationName_static();
596 // -------------------------------------------------------------------------
597 sal_Bool SAL_CALL ORowSet::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
599 return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
601 //------------------------------------------------------------------------------
602 Sequence< ::rtl::OUString > ORowSet::getSupportedServiceNames_static( ) throw (RuntimeException)
604 Sequence< rtl::OUString > aSNS( 5 );
605 aSNS[0] = SERVICE_SDBC_RESULTSET;
606 aSNS[1] = SERVICE_SDBC_ROWSET;
607 aSNS[2] = SERVICE_SDBCX_RESULTSET;
608 aSNS[3] = SERVICE_SDB_RESULTSET;
609 aSNS[4] = SERVICE_SDB_ROWSET;
610 return aSNS;
612 // -------------------------------------------------------------------------
613 Sequence< ::rtl::OUString > SAL_CALL ORowSet::getSupportedServiceNames( ) throw(RuntimeException)
615 return getSupportedServiceNames_static();
617 //------------------------------------------------------------------------------
618 Reference< XInterface > ORowSet::Create(const Reference< XComponentContext >& _rxContext)
620 ::comphelper::ComponentContext aContext( _rxContext );
621 return ORowSet_CreateInstance( aContext.getLegacyServiceFactory() );
623 // -------------------------------------------------------------------------
624 // OComponentHelper
625 void SAL_CALL ORowSet::disposing()
627 OPropertyStateContainer::disposing();
629 MutexGuard aGuard(m_aMutex);
630 EventObject aDisposeEvent;
631 aDisposeEvent.Source = static_cast< XComponent* >(this);
632 m_aRowsetListeners.disposeAndClear( aDisposeEvent );
633 m_aApproveListeners.disposeAndClear( aDisposeEvent );
635 freeResources( true );
637 // remove myself as dispose listener
638 Reference< XComponent > xComponent(m_xActiveConnection, UNO_QUERY);
639 if (xComponent.is())
641 Reference<XEventListener> xEvt;
642 query_aggregation(this,xEvt);
643 xComponent->removeEventListener(xEvt);
646 m_aActiveConnection = Any(); // the any conatains a reference too
647 if(m_bOwnConnection)
648 ::comphelper::disposeComponent(m_xActiveConnection);
649 m_xActiveConnection = NULL;
652 ORowSetBase::disposing();
654 // -------------------------------------------------------------------------
655 void ORowSet::freeResources( bool _bComplete )
657 MutexGuard aGuard(m_aMutex);
659 // free all clones
660 connectivity::OWeakRefArray::iterator aEnd = m_aClones.end();
661 for (connectivity::OWeakRefArray::iterator i = m_aClones.begin(); aEnd != i; i++)
663 Reference< XComponent > xComp(i->get(), UNO_QUERY);
664 if (xComp.is())
665 xComp->dispose();
667 m_aClones.clear();
669 if ( _bComplete )
671 // the columns must be disposed before the querycomposer is disposed because
672 // their owner can be the composer
673 TDataColumns().swap(m_aDataColumns);// clear and resize capacity
674 m_xColumns = NULL;
675 if ( m_pColumns )
676 m_pColumns->disposing();
677 // dispose the composer to avoid that everbody knows that the querycomposer is eol
678 try { ::comphelper::disposeComponent( m_xComposer ); }
679 catch(Exception&)
681 DBG_UNHANDLED_EXCEPTION();
682 m_xComposer = NULL;
685 DELETEZ(m_pCache);
687 impl_resetTables_nothrow();
689 m_xStatement = NULL;
690 m_xTypeMap = NULL;
692 m_aBookmark = Any();
693 m_bBeforeFirst = sal_True;
694 m_bAfterLast = sal_False;
695 m_bNew = sal_False;
696 m_bModified = sal_False;
697 m_bLastKnownRowCountFinal = sal_False;
698 m_nLastKnownRowCount = 0;
699 if ( m_aOldRow.isValid() )
700 m_aOldRow->clearRow();
702 impl_disposeParametersContainer_nothrow();
704 m_bCommandFacetsDirty = sal_True;
708 // -------------------------------------------------------------------------
709 void ORowSet::setActiveConnection( Reference< XConnection >& _rxNewConn, sal_Bool _bFireEvent )
711 if (_rxNewConn.get() == m_xActiveConnection.get())
712 // nothing to do
713 return;
715 // remove the event listener for the old connection
716 Reference< XComponent > xComponent(m_xActiveConnection, UNO_QUERY);
717 if (xComponent.is())
719 Reference<XEventListener> xListener;
720 query_aggregation(this, xListener);
721 xComponent->removeEventListener(xListener);
724 // if we owned the connection, remember it for later disposing
725 if(m_bOwnConnection)
726 m_xOldConnection = m_xActiveConnection;
728 // for firing the PropertyChangeEvent
729 sal_Int32 nHandle = PROPERTY_ID_ACTIVE_CONNECTION;
730 Any aOldConnection; aOldConnection <<= m_xActiveConnection;
731 Any aNewConnection; aNewConnection <<= _rxNewConn;
733 // set the new connection
734 m_xActiveConnection = _rxNewConn;
735 if (m_xActiveConnection.is())
736 m_aActiveConnection <<= m_xActiveConnection;
737 else
738 m_aActiveConnection.clear();
740 // fire the event
741 if (_bFireEvent)
742 fire(&nHandle, &aNewConnection, &aOldConnection, 1, sal_False);
744 // register as event listener for the new connection
745 xComponent.set(m_xActiveConnection,UNO_QUERY);
746 if (xComponent.is())
748 Reference<XEventListener> xListener;
749 query_aggregation(this, xListener);
750 xComponent->addEventListener(xListener);
754 // -------------------------------------------------------------------------
755 // ::com::sun::star::XEventListener
756 void SAL_CALL ORowSet::disposing( const ::com::sun::star::lang::EventObject& Source ) throw(RuntimeException)
758 // close rowset because the connection is going to be deleted (someone told me :-)
759 Reference<XConnection> xCon(Source.Source,UNO_QUERY);
760 if(m_xActiveConnection == xCon)
762 close();
764 MutexGuard aGuard( m_aMutex );
765 Reference< XConnection > xXConnection;
766 setActiveConnection( xXConnection );
770 // -------------------------------------------------------------------------
772 // XCloseable
773 void SAL_CALL ORowSet::close( ) throw(SQLException, RuntimeException)
776 MutexGuard aGuard( m_aMutex );
777 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
779 // additionals things to set
780 freeResources( true );
782 // -------------------------------------------------------------------------
783 // comphelper::OPropertyArrayUsageHelper
784 ::cppu::IPropertyArrayHelper* ORowSet::createArrayHelper( ) const
786 Sequence< Property > aProps;
787 describeProperties(aProps);
788 return new ::cppu::OPropertyArrayHelper(aProps);
790 // -------------------------------------------------------------------------
791 // cppu::OPropertySetHelper
792 ::cppu::IPropertyArrayHelper& SAL_CALL ORowSet::getInfoHelper()
794 typedef ::comphelper::OPropertyArrayUsageHelper<ORowSet> ORowSet_PROP;
795 return *ORowSet_PROP::getArrayHelper();
797 // -----------------------------------------------------------------------------
798 void ORowSet::updateValue(sal_Int32 columnIndex,const ORowSetValue& x)
800 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
802 ::osl::MutexGuard aGuard( *m_pMutex );
803 checkUpdateConditions(columnIndex);
804 checkUpdateIterator();
806 ::connectivity::ORowSetValue aOldValue(((*m_aCurrentRow)->get())[columnIndex]);
807 m_pCache->updateValue(columnIndex,x);
808 // we have to notify all listeners
809 ((*m_aCurrentRow)->get())[columnIndex] = x;
810 firePropertyChange(columnIndex-1 ,aOldValue);
811 fireProperty(PROPERTY_ID_ISMODIFIED,sal_True,sal_False);
813 // -------------------------------------------------------------------------
814 // XRowUpdate
815 void SAL_CALL ORowSet::updateNull( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
817 updateValue(columnIndex,ORowSetValue());
819 // -------------------------------------------------------------------------
820 void SAL_CALL ORowSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) throw(SQLException, RuntimeException)
822 updateValue(columnIndex,x);
824 // -------------------------------------------------------------------------
825 void SAL_CALL ORowSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
827 updateValue(columnIndex,x);
829 // -------------------------------------------------------------------------
830 void SAL_CALL ORowSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
832 updateValue(columnIndex,x);
834 // -------------------------------------------------------------------------
835 void SAL_CALL ORowSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
837 updateValue(columnIndex,x);
839 // -------------------------------------------------------------------------
840 void SAL_CALL ORowSet::updateLong( sal_Int32 columnIndex, sal_Int64 x ) throw(SQLException, RuntimeException)
842 updateValue(columnIndex,x);
844 // -------------------------------------------------------------------------
845 void SAL_CALL ORowSet::updateFloat( sal_Int32 columnIndex, float x ) throw(SQLException, RuntimeException)
847 updateValue(columnIndex,x);
849 // -------------------------------------------------------------------------
850 void SAL_CALL ORowSet::updateDouble( sal_Int32 columnIndex, double x ) throw(SQLException, RuntimeException)
852 updateValue(columnIndex,x);
854 // -------------------------------------------------------------------------
855 void SAL_CALL ORowSet::updateString( sal_Int32 columnIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
857 updateValue(columnIndex,x);
859 // -------------------------------------------------------------------------
860 void SAL_CALL ORowSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
862 updateValue(columnIndex,x);
864 // -------------------------------------------------------------------------
865 void SAL_CALL ORowSet::updateDate( sal_Int32 columnIndex, const ::com::sun::star::util::Date& x ) throw(SQLException, RuntimeException)
867 updateValue(columnIndex,x);
869 // -------------------------------------------------------------------------
870 void SAL_CALL ORowSet::updateTime( sal_Int32 columnIndex, const ::com::sun::star::util::Time& x ) throw(SQLException, RuntimeException)
872 updateValue(columnIndex,x);
874 // -------------------------------------------------------------------------
875 void SAL_CALL ORowSet::updateTimestamp( sal_Int32 columnIndex, const ::com::sun::star::util::DateTime& x ) throw(SQLException, RuntimeException)
877 updateValue(columnIndex,x);
879 // -------------------------------------------------------------------------
880 void SAL_CALL ORowSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
882 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
884 ::osl::MutexGuard aGuard( *m_pMutex );
886 checkUpdateConditions(columnIndex);
888 checkUpdateIterator();
889 ::connectivity::ORowSetValue aOldValue;
890 if(((*m_aCurrentRow)->get())[columnIndex].getTypeKind() == DataType::BLOB)
892 m_pCache->updateBinaryStream(columnIndex,x,length);
893 aOldValue = ((*m_aCurrentRow)->get())[columnIndex];
894 ((*m_aCurrentRow)->get())[columnIndex] = makeAny(x);
896 else
898 Sequence<sal_Int8> aSeq;
899 if(x.is())
900 x->readBytes(aSeq,length);
901 updateValue(columnIndex,aSeq);
902 aOldValue = ((*m_aCurrentRow)->get())[columnIndex];
903 ((*m_aCurrentRow)->get())[columnIndex] = aSeq;
906 firePropertyChange(columnIndex-1 ,aOldValue);
907 fireProperty(PROPERTY_ID_ISMODIFIED,sal_True,sal_False);
909 // -------------------------------------------------------------------------
910 void SAL_CALL ORowSet::updateCharacterStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
912 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
914 ::osl::MutexGuard aGuard( *m_pMutex );
915 checkUpdateConditions(columnIndex);
917 checkUpdateIterator();
918 m_pCache->updateCharacterStream(columnIndex,x,length);
920 ::connectivity::ORowSetValue aOldValue(((*m_aCurrentRow)->get())[columnIndex]);
921 ((*m_aCurrentRow)->get())[columnIndex] = makeAny(x);
922 firePropertyChange(columnIndex-1 ,aOldValue);
923 fireProperty(PROPERTY_ID_ISMODIFIED,sal_True,sal_False);
925 // -------------------------------------------------------------------------
926 void SAL_CALL ORowSet::updateObject( sal_Int32 columnIndex, const Any& x ) throw(SQLException, RuntimeException)
928 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
930 ::osl::MutexGuard aGuard( *m_pMutex );
931 checkUpdateConditions(columnIndex);
933 checkUpdateIterator();
935 Any aNewValue = x;
937 if ( m_pColumns )
939 Reference<XPropertySet> xColumn(m_pColumns->getByIndex(columnIndex-1),UNO_QUERY);
940 sal_Int32 nColType = 0;
941 xColumn->getPropertyValue(PROPERTY_TYPE) >>= nColType;
942 switch( nColType )
944 case DataType::DATE:
945 case DataType::TIME:
946 case DataType::TIMESTAMP:
948 double nValue = 0;
949 if ( x >>= nValue )
951 if ( DataType::TIMESTAMP == nColType )
952 aNewValue <<= dbtools::DBTypeConversion::toDateTime( nValue );
953 else if ( DataType::DATE == nColType )
954 aNewValue <<= dbtools::DBTypeConversion::toDate( nValue );
955 else
956 aNewValue <<= dbtools::DBTypeConversion::toTime( nValue );
958 break;
963 if (!::dbtools::implUpdateObject(this, columnIndex, aNewValue))
964 { // there is no other updateXXX call which can handle the value in x
965 ::connectivity::ORowSetValue aOldValue(((*m_aCurrentRow)->get())[columnIndex]);
966 m_pCache->updateObject(columnIndex,aNewValue);
967 // we have to notify all listeners
968 ((*m_aCurrentRow)->get())[columnIndex] = aNewValue;
969 firePropertyChange(columnIndex-1 ,aOldValue);
970 fireProperty(PROPERTY_ID_ISMODIFIED,sal_True,sal_False);
973 // -------------------------------------------------------------------------
974 void SAL_CALL ORowSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 scale ) throw(SQLException, RuntimeException)
976 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
978 ::osl::MutexGuard aGuard( *m_pMutex );
979 checkUpdateConditions(columnIndex);
981 checkUpdateIterator();
982 ::connectivity::ORowSetValue aOldValue(((*m_aCurrentRow)->get())[columnIndex]);
983 m_pCache->updateNumericObject(columnIndex,x,scale);
984 // we have to notify all listeners
985 ((*m_aCurrentRow)->get())[columnIndex] = x;
986 firePropertyChange(columnIndex-1 ,aOldValue);
987 fireProperty(PROPERTY_ID_ISMODIFIED,sal_True,sal_False);
989 // -------------------------------------------------------------------------
991 // XResultSetUpdate
992 void SAL_CALL ORowSet::insertRow( ) throw(SQLException, RuntimeException)
994 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
995 // insertRow is not allowd when
996 // standing not on the insert row nor
997 // when the row isn't modified
998 // or the concurency is read only
999 ::osl::ResettableMutexGuard aGuard( *m_pMutex );
1001 if(!m_pCache || !m_bNew || !m_bModified || m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY)
1002 throwFunctionSequenceException(*this);
1004 if(m_bModified)
1006 // remember old value for fire
1007 sal_Bool bOld = m_bNew;
1009 ORowSetRow aOldValues;
1010 if ( !m_aCurrentRow.isNull() )
1011 aOldValues = new ORowSetValueVector( m_aCurrentRow->getBody() );
1012 RowChangeEvent aEvt(*this,RowChangeAction::INSERT,1);
1013 notifyAllListenersRowBeforeChange(aGuard,aEvt);
1015 sal_Bool bInserted = m_pCache->insertRow();
1017 // make sure that our row is set to the new inserted row before clearing the insert flags in the cache
1018 m_pCache->resetInsertRow(bInserted);
1020 // notification order
1021 // - column values
1022 setCurrentRow( sal_False, sal_True, aOldValues, aGuard ); // we don't move here
1024 // - rowChanged
1025 notifyAllListenersRowChanged(aGuard,aEvt);
1027 // - IsModified
1028 if(!m_bModified)
1029 fireProperty(PROPERTY_ID_ISMODIFIED,sal_False,sal_True);
1030 OSL_ENSURE( !m_bModified, "ORowSet::insertRow: just updated, but _still_ modified?" );
1032 // - IsNew
1033 if(m_bNew != bOld)
1034 fireProperty(PROPERTY_ID_ISNEW,m_bNew,bOld);
1036 // - RowCount/IsRowCountFinal
1037 fireRowcount();
1040 // -------------------------------------------------------------------------
1041 sal_Int32 SAL_CALL ORowSet::getRow( ) throw(SQLException, RuntimeException)
1043 ::osl::MutexGuard aGuard( *m_pMutex );
1044 checkCache();
1046 // check if we are inserting a row
1047 return (m_pCache && ( m_pCache->m_bNew || m_bModified )) ? 0 : ORowSetBase::getRow();
1049 // -------------------------------------------------------------------------
1050 void SAL_CALL ORowSet::updateRow( ) throw(SQLException, RuntimeException)
1052 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1053 // not allowed when standing on insert row
1054 ::osl::ResettableMutexGuard aGuard( *m_pMutex );
1055 if ( !m_pCache || m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY || m_bNew || ((m_pCache->m_nPrivileges & Privilege::UPDATE ) != Privilege::UPDATE) )
1056 throwFunctionSequenceException(*this);
1059 if(m_bModified)
1061 ORowSetRow aOldValues;
1062 if ( !m_aCurrentRow.isNull() )
1063 aOldValues = new ORowSetValueVector( m_aCurrentRow->getBody() );
1065 RowChangeEvent aEvt(*this,RowChangeAction::UPDATE,1);
1066 notifyAllListenersRowBeforeChange(aGuard,aEvt);
1068 m_pCache->updateRow(m_aCurrentRow.operator ->());
1069 m_aBookmark = m_pCache->getBookmark();
1070 m_aCurrentRow = m_pCache->m_aMatrixIter;
1071 m_aOldRow->setRow(new ORowSetValueVector(m_aCurrentRow->getBody()));
1073 // notification order
1074 // - column values
1075 ORowSetBase::firePropertyChange(aOldValues);
1077 // - rowChanged
1078 notifyAllListenersRowChanged(aGuard,aEvt);
1080 // - IsModified
1081 if(!m_bModified)
1082 fireProperty(PROPERTY_ID_ISMODIFIED,sal_False,sal_True);
1083 OSL_ENSURE( !m_bModified, "ORowSet::updateRow: just updated, but _still_ modified?" );
1086 // -------------------------------------------------------------------------
1087 void SAL_CALL ORowSet::deleteRow( ) throw(SQLException, RuntimeException)
1089 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1091 ::osl::ResettableMutexGuard aGuard( *m_pMutex );
1092 checkCache();
1094 if ( m_bBeforeFirst || m_bAfterLast )
1095 throwSQLException( "Cannot delete the before-first or after-last row.", SQL_INVALID_CURSOR_POSITION, *this );
1096 // TODO: resource
1097 if ( m_bNew )
1098 throwSQLException( "Cannot delete the insert-row.", SQL_INVALID_CURSOR_POSITION, *this );
1099 // TODO: resource
1100 if ( m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY )
1101 throwSQLException( "Result set is read only.", SQL_FUNCTION_SEQUENCE_ERROR, *this );
1102 // TODO: resource
1103 if ( ( m_pCache->m_nPrivileges & Privilege::DELETE ) != Privilege::DELETE )
1104 throwSQLException( "DELETE privilege not available.", SQL_FUNCTION_SEQUENCE_ERROR, *this );
1105 // TODO: resource
1106 if ( rowDeleted() )
1107 throwSQLException( "Current row already deleted.", SQL_FUNCTION_SEQUENCE_ERROR, *this );
1108 // TODO: resource
1110 // this call position the cache indirect
1111 Any aBookmarkToDelete( m_aBookmark );
1112 positionCache( MOVE_NONE_REFRESH_ONLY );
1113 sal_Int32 nDeletePosition = m_pCache->getRow();
1115 notifyRowSetAndClonesRowDelete( aBookmarkToDelete );
1117 ORowSetRow aOldValues;
1118 if ( m_pCache->m_aMatrixIter != m_pCache->getEnd() && m_pCache->m_aMatrixIter->isValid() )
1119 aOldValues = new ORowSetValueVector( m_pCache->m_aMatrixIter->getBody() );
1121 RowChangeEvent aEvt(*this,RowChangeAction::DELETE,1);
1122 notifyAllListenersRowBeforeChange(aGuard,aEvt);
1124 m_pCache->deleteRow();
1125 notifyRowSetAndClonesRowDeleted( aBookmarkToDelete, nDeletePosition );
1127 ORowSetNotifier aNotifier( this );
1128 // this will call cancelRowModification on the cache if necessary
1130 // notification order
1131 // - rowChanged
1132 notifyAllListenersRowChanged(aGuard,aEvt);
1134 // - IsModified
1135 // - IsNew
1136 aNotifier.fire( );
1138 // - RowCount/IsRowCountFinal
1139 fireRowcount();
1142 // -------------------------------------------------------------------------
1143 void ORowSet::implCancelRowUpdates( sal_Bool _bNotifyModified ) SAL_THROW( ( SQLException, RuntimeException ) )
1145 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1147 ::osl::MutexGuard aGuard( *m_pMutex );
1148 if ( m_bBeforeFirst || m_bAfterLast || rowDeleted() )
1149 return; // nothing to do so return
1151 checkCache();
1152 // cancelRowUpdates is not allowed when:
1153 // - standing on the insert row
1154 // - the concurrency is read only
1155 // - the current row is deleted
1156 if ( m_bNew || m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY )
1157 throwFunctionSequenceException(*this);
1159 positionCache( MOVE_NONE_REFRESH_ONLY );
1161 ORowSetRow aOldValues;
1162 if ( !m_aCurrentRow.isNull() )
1163 aOldValues = new ORowSetValueVector( m_aCurrentRow->getBody() );
1165 m_pCache->cancelRowUpdates();
1167 m_aBookmark = m_pCache->getBookmark();
1168 m_aCurrentRow = m_pCache->m_aMatrixIter;
1169 m_aCurrentRow.setBookmark(m_aBookmark);
1171 // notification order
1172 // - column values
1173 ORowSetBase::firePropertyChange(aOldValues);
1174 // IsModified
1175 if( !m_bModified && _bNotifyModified )
1176 fireProperty(PROPERTY_ID_ISMODIFIED,sal_False,sal_True);
1179 // -------------------------------------------------------------------------
1180 void SAL_CALL ORowSet::cancelRowUpdates( ) throw(SQLException, RuntimeException)
1182 implCancelRowUpdates( sal_True );
1185 // -------------------------------------------------------------------------
1186 void SAL_CALL ORowSet::addRowSetListener( const Reference< XRowSetListener >& listener ) throw(RuntimeException)
1188 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1190 ::osl::MutexGuard aGuard( m_aColumnsMutex );
1191 if(listener.is())
1192 m_aRowsetListeners.addInterface(listener);
1194 // -------------------------------------------------------------------------
1195 void SAL_CALL ORowSet::removeRowSetListener( const Reference< XRowSetListener >& listener ) throw(RuntimeException)
1197 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1199 ::osl::MutexGuard aGuard( m_aColumnsMutex );
1200 if(listener.is())
1201 m_aRowsetListeners.removeInterface(listener);
1203 // -----------------------------------------------------------------------------
1204 void ORowSet::notifyAllListeners(::osl::ResettableMutexGuard& _rGuard)
1206 EventObject aEvt(*m_pMySelf);
1207 _rGuard.clear();
1208 m_aRowsetListeners.notifyEach( &XRowSetListener::rowSetChanged, aEvt );
1209 _rGuard.reset();
1211 // -------------------------------------------------------------------------
1212 void ORowSet::notifyAllListenersCursorMoved(::osl::ResettableMutexGuard& _rGuard)
1214 EventObject aEvt(*m_pMySelf);
1215 _rGuard.clear();
1216 m_aRowsetListeners.notifyEach( &XRowSetListener::cursorMoved, aEvt );
1217 _rGuard.reset();
1219 // -------------------------------------------------------------------------
1220 void ORowSet::notifyAllListenersRowChanged(::osl::ResettableMutexGuard& _rGuard, const EventObject& aEvt)
1222 _rGuard.clear();
1223 m_aRowsetListeners.notifyEach( &XRowSetListener::rowChanged, aEvt );
1224 _rGuard.reset();
1226 // -------------------------------------------------------------------------
1227 sal_Bool ORowSet::notifyAllListenersCursorBeforeMove(::osl::ResettableMutexGuard& _rGuard)
1229 EventObject aEvt(*m_pMySelf);
1230 NOTIFY_LISTERNERS_CHECK(m_aApproveListeners,XRowSetApproveListener,approveCursorMove);
1231 return bCheck;
1233 // -------------------------------------------------------------------------
1234 void ORowSet::notifyAllListenersRowBeforeChange(::osl::ResettableMutexGuard& _rGuard,const RowChangeEvent &aEvt)
1236 NOTIFY_LISTERNERS_CHECK(m_aApproveListeners,XRowSetApproveListener,approveRowChange);
1237 if ( !bCheck )
1238 m_aErrors.raiseTypedException( sdb::ErrorCondition::ROW_SET_OPERATION_VETOED, *this, ::cppu::UnoType< RowSetVetoException >::get() );
1240 // -------------------------------------------------------------------------
1241 void ORowSet::fireRowcount()
1243 sal_Int32 nCurrentRowCount( impl_getRowCount() );
1244 sal_Bool bCurrentRowCountFinal( m_pCache->m_bRowCountFinal );
1246 if ( m_nLastKnownRowCount != nCurrentRowCount )
1248 sal_Int32 nHandle = PROPERTY_ID_ROWCOUNT;
1249 Any aNew,aOld;
1250 aNew <<= nCurrentRowCount; aOld <<= m_nLastKnownRowCount;
1251 fire(&nHandle,&aNew,&aOld,1,sal_False);
1252 m_nLastKnownRowCount = nCurrentRowCount;
1254 if ( !m_bLastKnownRowCountFinal && ( m_bLastKnownRowCountFinal != bCurrentRowCountFinal ) )
1256 sal_Int32 nHandle = PROPERTY_ID_ISROWCOUNTFINAL;
1257 Any aNew,aOld;
1258 aNew <<= bool2any( bCurrentRowCountFinal );
1259 aOld <<= bool2any( m_bLastKnownRowCountFinal );
1260 fire(&nHandle,&aNew,&aOld,1,sal_False);
1261 m_bLastKnownRowCountFinal = bCurrentRowCountFinal;
1264 // -------------------------------------------------------------------------
1265 void SAL_CALL ORowSet::moveToInsertRow( ) throw(SQLException, RuntimeException)
1267 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1269 ::osl::ResettableMutexGuard aGuard( *m_pMutex );
1270 checkPositioningAllowed();
1271 if ( ( m_pCache->m_nPrivileges & Privilege::INSERT ) != Privilege::INSERT )
1272 throwSQLException( "No insert privileges", SQL_GENERAL_ERROR, *this );
1273 // TODO: resource
1275 if ( notifyAllListenersCursorBeforeMove( aGuard ) )
1277 // remember old value for fire
1278 ORowSetRow aOldValues;
1279 if ( rowDeleted() )
1281 positionCache( MOVE_FORWARD );
1282 m_pCache->next();
1283 setCurrentRow( sal_True, sal_False, aOldValues, aGuard);
1285 else
1286 positionCache( MOVE_NONE_REFRESH_ONLY );
1288 // check before because the resultset could be empty
1289 if ( !m_bBeforeFirst
1290 && !m_bAfterLast
1291 && m_pCache->m_aMatrixIter != m_pCache->getEnd()
1292 && m_pCache->m_aMatrixIter->isValid()
1294 aOldValues = new ORowSetValueVector( m_pCache->m_aMatrixIter->getBody() );
1296 const sal_Bool bNewState = m_bNew;
1297 const sal_Bool bModState = m_bModified;
1299 m_pCache->moveToInsertRow();
1300 m_aCurrentRow = m_pCache->m_aInsertRow;
1302 // notification order
1303 // - column values
1304 ORowSetBase::firePropertyChange(aOldValues);
1306 // - cursorMoved
1307 notifyAllListenersCursorMoved(aGuard);
1309 // - IsModified
1310 if ( bModState != m_bModified )
1311 fireProperty( PROPERTY_ID_ISMODIFIED, m_bModified, bModState );
1313 // - IsNew
1314 if ( bNewState != m_bNew )
1315 fireProperty( PROPERTY_ID_ISNEW, m_bNew, bNewState );
1317 // - RowCount/IsRowCountFinal
1318 fireRowcount();
1321 // -------------------------------------------------------------------------
1322 void SAL_CALL ORowSet::moveToCurrentRow( ) throw(SQLException, RuntimeException)
1324 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1326 ::osl::ResettableMutexGuard aGuard( *m_pMutex );
1327 checkPositioningAllowed();
1329 if ( !m_pCache->m_bNew && !m_bModified )
1330 // nothing to do if we're not on the insertion row, and not modified otherwise
1331 return;
1333 if ( rowDeleted() )
1334 // this would perhaps even justify a RuntimeException ....
1335 // if the current row is deleted, then no write access to this row should be possible. So,
1336 // m_bModified should be true. Also, as soon as somebody calls moveToInsertRow,
1337 // our current row should not be deleted anymore. So, we should not have survived the above
1338 // check "if ( !m_pCache->m_bNew && !m_bModified )"
1339 throwSQLException( "The current row is deleted.", SQL_FUNCTION_SEQUENCE_ERROR, *this );
1340 // TODO: resource
1342 if ( notifyAllListenersCursorBeforeMove( aGuard ) )
1344 positionCache( MOVE_NONE_REFRESH_ONLY );
1346 ORowSetNotifier aNotifier( this );
1348 // notification order
1349 // - cursorMoved
1350 notifyAllListenersCursorMoved(aGuard);
1352 // - IsModified
1353 // - IsNew
1354 aNotifier.fire();
1357 // -------------------------------------------------------------------------
1358 // XRow
1359 sal_Bool SAL_CALL ORowSet::wasNull( ) throw(SQLException, RuntimeException)
1361 ::osl::MutexGuard aGuard( *m_pMutex );
1362 checkCache();
1364 return ( m_pCache && isInsertRow() ) ? ((*m_pCache->m_aInsertRow)->get())[m_nLastColumnIndex].isNull() : ORowSetBase::wasNull();
1366 // -----------------------------------------------------------------------------
1367 const ORowSetValue& ORowSet::getInsertValue(sal_Int32 columnIndex)
1369 checkCache();
1371 if ( m_pCache && isInsertRow() )
1372 return ((*m_pCache->m_aInsertRow)->get())[m_nLastColumnIndex = columnIndex];
1374 return getValue(columnIndex);
1376 // -------------------------------------------------------------------------
1377 ::rtl::OUString SAL_CALL ORowSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1379 ::osl::MutexGuard aGuard( *m_pMutex );
1380 return getInsertValue(columnIndex);
1382 // -------------------------------------------------------------------------
1383 sal_Bool SAL_CALL ORowSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1385 ::osl::MutexGuard aGuard( *m_pMutex );
1386 return getInsertValue(columnIndex);
1388 // -------------------------------------------------------------------------
1389 sal_Int8 SAL_CALL ORowSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1391 ::osl::MutexGuard aGuard( *m_pMutex );
1392 return getInsertValue(columnIndex);
1394 // -------------------------------------------------------------------------
1395 sal_Int16 SAL_CALL ORowSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1397 ::osl::MutexGuard aGuard( *m_pMutex );
1398 return getInsertValue(columnIndex);
1400 // -------------------------------------------------------------------------
1401 sal_Int32 SAL_CALL ORowSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1403 ::osl::MutexGuard aGuard( *m_pMutex );
1404 return getInsertValue(columnIndex);
1406 // -------------------------------------------------------------------------
1407 sal_Int64 SAL_CALL ORowSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1409 ::osl::MutexGuard aGuard( *m_pMutex );
1410 return getInsertValue(columnIndex);
1412 // -------------------------------------------------------------------------
1413 float SAL_CALL ORowSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1415 ::osl::MutexGuard aGuard( *m_pMutex );
1416 return getInsertValue(columnIndex);
1418 // -------------------------------------------------------------------------
1419 double SAL_CALL ORowSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1421 ::osl::MutexGuard aGuard( *m_pMutex );
1422 return getInsertValue(columnIndex);
1424 // -------------------------------------------------------------------------
1425 Sequence< sal_Int8 > SAL_CALL ORowSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1427 ::osl::MutexGuard aGuard( *m_pMutex );
1428 return getInsertValue(columnIndex);
1430 // -------------------------------------------------------------------------
1431 ::com::sun::star::util::Date SAL_CALL ORowSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1433 ::osl::MutexGuard aGuard( *m_pMutex );
1434 return getInsertValue(columnIndex);
1436 // -------------------------------------------------------------------------
1437 ::com::sun::star::util::Time SAL_CALL ORowSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1439 ::osl::MutexGuard aGuard( *m_pMutex );
1440 return getInsertValue(columnIndex);
1442 // -------------------------------------------------------------------------
1443 ::com::sun::star::util::DateTime SAL_CALL ORowSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1445 ::osl::MutexGuard aGuard( *m_pMutex );
1446 return getInsertValue(columnIndex);
1448 // -------------------------------------------------------------------------
1449 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ORowSet::getBinaryStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1451 ::osl::MutexGuard aGuard( *m_pMutex );
1452 if ( m_pCache && isInsertRow() )
1454 checkCache();
1455 return new ::comphelper::SequenceInputStream(((*m_pCache->m_aInsertRow)->get())[m_nLastColumnIndex = columnIndex].getSequence());
1458 return ORowSetBase::getBinaryStream(columnIndex);
1460 // -------------------------------------------------------------------------
1461 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ORowSet::getCharacterStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1463 ::osl::MutexGuard aGuard( *m_pMutex );
1464 if(m_pCache && isInsertRow() )
1466 checkCache();
1467 return new ::comphelper::SequenceInputStream(((*m_pCache->m_aInsertRow)->get())[m_nLastColumnIndex = columnIndex].getSequence());
1470 return ORowSetBase::getCharacterStream(columnIndex);
1472 // -------------------------------------------------------------------------
1473 Any SAL_CALL ORowSet::getObject( sal_Int32 columnIndex, const Reference< XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
1475 ::osl::MutexGuard aGuard( *m_pMutex );
1476 return getInsertValue(columnIndex).makeAny();
1478 // -------------------------------------------------------------------------
1479 Reference< XRef > SAL_CALL ORowSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
1481 return Reference< XRef >();
1483 // -------------------------------------------------------------------------
1484 Reference< XBlob > SAL_CALL ORowSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
1486 return Reference< XBlob >();
1488 // -------------------------------------------------------------------------
1489 Reference< XClob > SAL_CALL ORowSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
1491 return Reference< XClob >();
1493 // -------------------------------------------------------------------------
1494 Reference< XArray > SAL_CALL ORowSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
1496 return Reference< XArray >();
1498 // -------------------------------------------------------------------------
1499 void SAL_CALL ORowSet::executeWithCompletion( const Reference< XInteractionHandler >& _rxHandler ) throw(SQLException, RuntimeException)
1501 if (!_rxHandler.is())
1502 execute();
1504 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1506 // tell everybody that we will change the result set
1507 approveExecution();
1509 ResettableMutexGuard aGuard( m_aMutex );
1513 freeResources( m_bCommandFacetsDirty );
1515 // calc the connection to be used
1516 if (m_xActiveConnection.is() && m_bRebuildConnOnExecute)
1518 // there was a setProperty(ActiveConnection), but a setProperty(DataSource) _after_ that, too
1519 Reference< XConnection > xXConnection;
1520 setActiveConnection( xXConnection );
1522 calcConnection( _rxHandler );
1523 m_bRebuildConnOnExecute = sal_False;
1525 Reference< XSingleSelectQueryComposer > xComposer = getCurrentSettingsComposer( this, m_aContext.getLegacyServiceFactory() );
1526 Reference<XParametersSupplier> xParameters(xComposer, UNO_QUERY);
1528 Reference<XIndexAccess> xParamsAsIndicies = xParameters.is() ? xParameters->getParameters() : Reference<XIndexAccess>();
1529 const sal_Int32 nParamCount = xParamsAsIndicies.is() ? xParamsAsIndicies->getCount() : 0;
1530 if ( m_aParametersSet.size() < (size_t)nParamCount )
1531 m_aParametersSet.resize( nParamCount ,false);
1533 ::dbtools::askForParameters( xComposer, this, m_xActiveConnection, _rxHandler,m_aParametersSet );
1535 // ensure that only the allowed exceptions leave this block
1536 catch(SQLException&)
1538 throw;
1540 catch(RuntimeException&)
1542 throw;
1544 catch(Exception&)
1546 DBG_ERROR("ORowSet::executeWithCompletion: caught an unexpected exception type while filling in the parameters!");
1549 // we're done with the parameters, now for the real execution
1551 // do the real execute
1552 execute_NoApprove_NoNewConn(aGuard);
1555 // -------------------------------------------------------------------------
1556 Reference< XIndexAccess > SAL_CALL ORowSet::getParameters( ) throw (RuntimeException)
1558 ::osl::MutexGuard aGuard( *m_pMutex );
1559 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1561 if ( m_bCommandFacetsDirty )
1562 // need to rebuild the parameters, since some property which contributes to the
1563 // complete command, and thus the parameters, changed
1564 impl_disposeParametersContainer_nothrow();
1566 if ( !m_pParameters.get() && m_aCommand.getLength() )
1570 ::rtl::OUString sNotInterestedIn;
1571 impl_initComposer_throw( sNotInterestedIn );
1573 catch( const Exception& )
1575 // silence it
1579 return m_pParameters.get();
1582 // -------------------------------------------------------------------------
1583 void ORowSet::approveExecution() throw (RowSetVetoException, RuntimeException)
1585 ::osl::MutexGuard aGuard( m_aColumnsMutex );
1586 EventObject aEvt(*this);
1588 OInterfaceIteratorHelper aApproveIter( m_aApproveListeners );
1589 while ( aApproveIter.hasMoreElements() )
1591 Reference< XRowSetApproveListener > xListener( static_cast< XRowSetApproveListener* >( aApproveIter.next() ) );
1594 if ( xListener.is() && !xListener->approveRowSetChange( aEvt ) )
1595 throw RowSetVetoException();
1597 catch ( const DisposedException& e )
1599 if ( e.Context == xListener )
1600 aApproveIter.remove();
1602 catch ( const RuntimeException& ) { throw; }
1603 catch ( const RowSetVetoException& ) { throw; }
1604 catch ( const Exception& )
1606 DBG_UNHANDLED_EXCEPTION();
1610 // -------------------------------------------------------------------------
1611 // XRowSet
1612 // -------------------------------------------------------------------------
1613 void SAL_CALL ORowSet::execute( ) throw(SQLException, RuntimeException)
1615 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1617 // tell everybody that we will change the result set
1618 approveExecution();
1620 ResettableMutexGuard aGuard( m_aMutex );
1621 freeResources( m_bCommandFacetsDirty );
1623 // calc the connection to be used
1624 if (m_xActiveConnection.is() && m_bRebuildConnOnExecute) {
1625 // there was a setProperty(ActiveConnection), but a setProperty(DataSource) _after_ that, too
1626 Reference< XConnection> xXConnection;
1627 setActiveConnection( xXConnection );
1630 calcConnection(NULL);
1631 m_bRebuildConnOnExecute = sal_False;
1633 // do the real execute
1634 execute_NoApprove_NoNewConn(aGuard);
1637 //------------------------------------------------------------------------------
1638 void ORowSet::setStatementResultSetType( const Reference< XPropertySet >& _rxStatement, sal_Int32 _nDesiredResultSetType, sal_Int32 _nDesiredResultSetConcurrency )
1640 OSL_ENSURE( _rxStatement.is(), "ORowSet::setStatementResultSetType: invalid statement - this will crash!" );
1642 sal_Int32 nResultSetType( _nDesiredResultSetType );
1643 sal_Int32 nResultSetConcurrency( _nDesiredResultSetConcurrency );
1645 // there *might* be a data source setting which tells use to be more defensive with those settings
1646 // #i15113# / 2005-02-10 / frank.schoenheit@sun.com
1647 sal_Bool bRespectDriverRST = sal_False;
1648 Any aSetting;
1649 if ( getDataSourceSetting( ::dbaccess::getDataSource( m_xActiveConnection ), "RespectDriverResultSetType", aSetting ) )
1651 OSL_VERIFY( aSetting >>= bRespectDriverRST );
1654 if ( bRespectDriverRST )
1656 // try type/concurrency settings with decreasing usefullness, and rely on what the connection claims
1657 // to support
1658 Reference< XDatabaseMetaData > xMeta( m_xActiveConnection->getMetaData() );
1660 sal_Int32 nCharacteristics[5][2] =
1661 { { ResultSetType::SCROLL_SENSITIVE, ResultSetConcurrency::UPDATABLE },
1662 { ResultSetType::SCROLL_INSENSITIVE, ResultSetConcurrency::UPDATABLE },
1663 { ResultSetType::SCROLL_SENSITIVE, ResultSetConcurrency::READ_ONLY },
1664 { ResultSetType::SCROLL_INSENSITIVE, ResultSetConcurrency::READ_ONLY },
1665 { ResultSetType::FORWARD_ONLY, ResultSetConcurrency::READ_ONLY }
1667 for ( sal_Int32 i=0; i<5; ++i )
1669 nResultSetType = nCharacteristics[i][0];
1670 nResultSetConcurrency = nCharacteristics[i][1];
1672 // don't try type/concurrency pairs which are more featured than what our caller requested
1673 if ( nResultSetType > _nDesiredResultSetType )
1674 continue;
1675 if ( nResultSetConcurrency > _nDesiredResultSetConcurrency )
1676 continue;
1678 if ( xMeta.is() && xMeta->supportsResultSetConcurrency( nResultSetType, nResultSetConcurrency ) )
1679 break;
1683 _rxStatement->setPropertyValue( PROPERTY_RESULTSETTYPE, makeAny( nResultSetType ) );
1684 _rxStatement->setPropertyValue( PROPERTY_RESULTSETCONCURRENCY, makeAny( nResultSetConcurrency ) );
1687 // -----------------------------------------------------------------------------
1688 Reference< XResultSet > ORowSet::impl_prepareAndExecute_throw()
1690 ::rtl::OUString sCommandToExecute;
1691 sal_Bool bUseEscapeProcessing = impl_initComposer_throw( sCommandToExecute );
1693 Reference< XResultSet> xResultSet;
1696 m_xStatement = m_xActiveConnection->prepareStatement( sCommandToExecute );
1697 if ( !m_xStatement.is() )
1699 SQLException aError;
1700 aError.Context = *this;
1701 aError.SQLState = getStandardSQLState( SQL_GENERAL_ERROR );
1702 aError.Message = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Internal error: no statement object provided by the database driver." ) );
1703 // TODO: resource
1704 throw aError;
1707 Reference< XPropertySet > xStatementProps( m_xStatement, UNO_QUERY_THROW );
1708 // set the result set type and concurrency
1711 xStatementProps->setPropertyValue( PROPERTY_USEBOOKMARKS, makeAny( sal_True ) );
1712 setStatementResultSetType( xStatementProps, m_nResultSetType, m_nResultSetConcurrency );
1714 catch ( const Exception& )
1716 // this exception doesn't matter here because when we catch an exception
1717 // then the driver doesn't support this feature
1719 m_aParameterValueForCache.get().resize(1);
1720 Reference< XParameters > xParam( m_xStatement, UNO_QUERY_THROW );
1721 size_t nParamCount( m_pParameters.is() ? m_pParameters->size() : m_aPrematureParamValues.get().size() );
1722 for ( size_t i=1; i<=nParamCount; ++i )
1724 ORowSetValue& rParamValue( getParameterStorage( (sal_Int32)i ) );
1725 ::dbtools::setObjectWithInfo( xParam, i, rParamValue.makeAny(), rParamValue.getTypeKind() );
1726 m_aParameterValueForCache.get().push_back(rParamValue);
1729 xResultSet = m_xStatement->executeQuery();
1731 catch( const SQLException& )
1733 SQLExceptionInfo aError( ::cppu::getCaughtException() );
1734 OSL_ENSURE( aError.isValid(), "ORowSet::impl_prepareAndExecute_throw: caught an SQLException which we cannot analyze!" );
1736 // append information about what we were actually going to execute
1739 String sQuery = bUseEscapeProcessing && m_xComposer.is() ? m_xComposer->getQuery() : m_aActiveCommand;
1740 String sInfo( DBA_RES_PARAM( RID_STR_COMMAND_LEADING_TO_ERROR, "$command$", sQuery ) );
1741 aError.append( SQLExceptionInfo::SQL_CONTEXT, sInfo );
1743 catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
1745 // propagate
1746 aError.doThrow();
1749 return xResultSet;
1752 // -----------------------------------------------------------------------------
1753 void ORowSet::impl_initializeColumnSettings_nothrow( const Reference< XPropertySet >& _rxTemplateColumn, const Reference< XPropertySet >& _rxRowSetColumn )
1755 OSL_ENSURE( _rxTemplateColumn.is() && _rxRowSetColumn.is(),
1756 "ORowSet::impl_initializeColumnSettings_nothrow: this will crash!" );
1758 bool bHaveAnyColumnSetting = false;
1761 Reference< XPropertySetInfo > xInfo( _rxTemplateColumn->getPropertySetInfo(), UNO_QUERY_THROW );
1763 // a number of properties is plain copied
1764 const ::rtl::OUString aPropertyNames[] = {
1765 PROPERTY_ALIGN, PROPERTY_RELATIVEPOSITION, PROPERTY_WIDTH, PROPERTY_HIDDEN, PROPERTY_CONTROLMODEL,
1766 PROPERTY_HELPTEXT, PROPERTY_CONTROLDEFAULT
1768 for ( size_t i=0; i<sizeof( aPropertyNames ) / sizeof( aPropertyNames[0] ); ++i )
1770 if ( xInfo->hasPropertyByName( aPropertyNames[i] ) )
1772 _rxRowSetColumn->setPropertyValue( aPropertyNames[i], _rxTemplateColumn->getPropertyValue( aPropertyNames[i] ) );
1773 bHaveAnyColumnSetting = true;
1777 // the format key is slightly more complex
1778 sal_Int32 nFormatKey = 0;
1779 if( xInfo->hasPropertyByName( PROPERTY_NUMBERFORMAT ) )
1781 _rxTemplateColumn->getPropertyValue( PROPERTY_NUMBERFORMAT ) >>= nFormatKey;
1782 bHaveAnyColumnSetting = true;
1784 if ( !nFormatKey && m_xNumberFormatTypes.is() )
1785 nFormatKey = ::dbtools::getDefaultNumberFormat( _rxTemplateColumn, m_xNumberFormatTypes, SvtSysLocale().GetLocaleData().getLocale() );
1786 _rxRowSetColumn->setPropertyValue( PROPERTY_NUMBERFORMAT, makeAny( nFormatKey ) );
1788 catch(Exception&)
1790 DBG_UNHANDLED_EXCEPTION();
1791 return;
1794 if ( bHaveAnyColumnSetting )
1795 return;
1797 // the template column could not provide *any* setting. Okay, probably it's a parser column, which
1798 // does not offer those. However, perhaps the template column referes to a table column, which we
1799 // can use as new template column
1802 Reference< XPropertySetInfo > xInfo( _rxTemplateColumn->getPropertySetInfo(), UNO_QUERY_THROW );
1803 if ( !xInfo->hasPropertyByName( PROPERTY_TABLENAME ) )
1804 // no chance
1805 return;
1807 ::rtl::OUString sTableName;
1808 OSL_VERIFY( _rxTemplateColumn->getPropertyValue( PROPERTY_TABLENAME ) >>= sTableName );
1810 Reference< XNameAccess > xTables( impl_getTables_throw(), UNO_QUERY_THROW );
1811 if ( !xTables->hasByName( sTableName ) )
1812 // no chance
1813 return;
1815 Reference< XColumnsSupplier > xTableColSup( xTables->getByName( sTableName ), UNO_QUERY_THROW );
1816 Reference< XNameAccess > xTableCols( xTableColSup->getColumns(), UNO_QUERY_THROW );
1818 ::rtl::OUString sTableColumnName;
1820 // get the "Name" or (preferred) "RealName" property of the column
1821 ::rtl::OUString sNamePropertyName( PROPERTY_NAME );
1822 if ( xInfo->hasPropertyByName( PROPERTY_REALNAME ) )
1823 sNamePropertyName = PROPERTY_REALNAME;
1824 OSL_VERIFY( _rxTemplateColumn->getPropertyValue( sNamePropertyName ) >>= sTableColumnName );
1826 if ( !xTableCols->hasByName( sTableColumnName ) )
1827 return;
1829 Reference< XPropertySet > xTableColumn( xTableCols->getByName( sTableColumnName ), UNO_QUERY_THROW );
1830 impl_initializeColumnSettings_nothrow( xTableColumn, _rxRowSetColumn );
1832 catch( const Exception& )
1834 DBG_UNHANDLED_EXCEPTION();
1838 // -----------------------------------------------------------------------------
1839 void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotification)
1841 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "frank.schoenheit@sun.com", "ORowSet::execute_NoApprove_NoNewConn" );
1843 // now we can dispose our old connection
1844 ::comphelper::disposeComponent(m_xOldConnection);
1845 m_xOldConnection = NULL;
1847 // do we need a new statement
1848 if ( m_bCommandFacetsDirty )
1850 m_xStatement = NULL;
1851 m_xComposer = NULL;
1853 Reference< XResultSet > xResultSet( impl_prepareAndExecute_throw() );
1855 // let our warnings container forget the reference to the (possibly disposed) old result set
1856 m_aWarnings.setExternalWarnings( NULL );
1857 // clear all current warnings
1858 m_aWarnings.clearWarnings();
1859 // let the warnings container know about the new "external warnings"
1860 m_aWarnings.setExternalWarnings( Reference< XWarningsSupplier >( xResultSet, UNO_QUERY ) );
1862 ::rtl::OUString aComposedUpdateTableName;
1863 if ( m_aUpdateTableName.getLength() )
1864 aComposedUpdateTableName = composeTableName( m_xActiveConnection->getMetaData(), m_aUpdateCatalogName, m_aUpdateSchemaName, m_aUpdateTableName, sal_False, ::dbtools::eInDataManipulation );
1867 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "frank.schoenheit@sun.com", "ORowSet::execute_NoApprove_NoNewConn: creating cache" );
1868 m_pCache = new ORowSetCache( xResultSet, m_xComposer.get(), m_aContext, aComposedUpdateTableName, m_bModified, m_bNew,m_aParameterValueForCache );
1869 if ( m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY )
1871 m_nPrivileges = Privilege::SELECT;
1872 m_pCache->m_nPrivileges = Privilege::SELECT;
1874 m_pCache->setMaxRowSize(m_nFetchSize);
1875 m_aCurrentRow = m_pCache->createIterator(this);
1876 m_aOldRow = m_pCache->registerOldRow();
1879 // get the locale
1880 // ConfigManager* pConfigMgr = ConfigManager::GetConfigManager();
1881 Locale aLocale = SvtSysLocale().GetLocaleData().getLocale();
1882 // pConfigMgr->GetDirectConfigProperty(ConfigManager::LOCALE) >>= aLocale;
1884 // get the numberformatTypes
1885 OSL_ENSURE(m_xActiveConnection.is(),"No ActiveConnection");
1886 Reference< XNumberFormatTypes> xNumberFormatTypes;
1887 Reference< XNumberFormatsSupplier> xNumberFormat = ::dbtools::getNumberFormats(m_xActiveConnection);
1888 if ( xNumberFormat.is() )
1889 m_xNumberFormatTypes.set(xNumberFormat->getNumberFormats(),UNO_QUERY);
1891 ::vos::ORef< ::connectivity::OSQLColumns> aColumns = new ::connectivity::OSQLColumns();
1892 ::std::vector< ::rtl::OUString> aNames;
1893 ::rtl::OUString aDescription;
1894 sal_Int32 nFormatKey = 0;
1896 if(!m_xColumns.is())
1898 RTL_LOGFILE_CONTEXT_AUTHOR( aColumnCreateLog, "dbaccess", "frank.schoenheit@sun.com", "ORowSet::execute_NoApprove_NoNewConn::creating columns" );
1899 // use the meta data
1900 Reference<XResultSetMetaDataSupplier> xMetaSup(m_xStatement,UNO_QUERY);
1903 Reference<XResultSetMetaData> xMetaData = xMetaSup->getMetaData();
1904 if ( xMetaData.is() )
1906 sal_Int32 nCount = xMetaData->getColumnCount();
1907 m_aDataColumns.reserve(nCount+1);
1908 aColumns->get().reserve(nCount+1);
1909 DECLARE_STL_USTRINGACCESS_MAP(int,StringMap);
1910 StringMap aColumnMap;
1911 for (sal_Int32 i = 0 ; i < nCount; ++i)
1913 // retrieve the name of the column
1914 ::rtl::OUString sName = xMetaData->getColumnName(i + 1);
1915 // check for duplicate entries
1916 if(aColumnMap.find(sName) != aColumnMap.end())
1918 ::rtl::OUString sAlias(sName);
1919 sal_Int32 searchIndex=1;
1920 while(aColumnMap.find(sAlias) != aColumnMap.end())
1922 (sAlias = sName) += ::rtl::OUString::valueOf(searchIndex++);
1924 sName = sAlias;
1926 ORowSetDataColumn* pColumn = new ORowSetDataColumn( getMetaData(),
1927 this,
1928 this,
1929 i+1,
1930 m_xActiveConnection->getMetaData(),
1931 aDescription,
1932 m_aCurrentRow);
1933 aColumnMap.insert(StringMap::value_type(sName,0));
1934 aColumns->get().push_back(pColumn);
1935 pColumn->setName(sName);
1936 aNames.push_back(sName);
1937 m_aDataColumns.push_back(pColumn);
1941 nFormatKey = 0;
1942 if(m_xNumberFormatTypes.is())
1943 nFormatKey = ::dbtools::getDefaultNumberFormat(pColumn,m_xNumberFormatTypes,aLocale);
1946 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_NUMBERFORMAT,makeAny(nFormatKey));
1947 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_RELATIVEPOSITION,makeAny(sal_Int32(i+1)));
1948 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_WIDTH,makeAny(sal_Int32(227)));
1949 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ALIGN,makeAny((sal_Int32)0));
1950 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_HIDDEN,::cppu::bool2any(sal_False));
1952 catch(Exception&)
1958 catch (SQLException&)
1962 else
1964 // create the rowset columns
1965 Reference< XResultSetMetaData > xMeta( getMetaData(), UNO_QUERY_THROW );
1966 sal_Int32 nCount = xMeta->getColumnCount();
1967 m_aDataColumns.reserve(nCount+1);
1968 aColumns->get().reserve(nCount+1);
1969 ::std::set< Reference< XPropertySet > > aAllColumns;
1971 for(sal_Int32 i=1; i <= nCount ;++i)
1973 ::rtl::OUString sName = xMeta->getColumnName(i);
1975 // retrieve the column number |i|
1976 Reference<XPropertySet> xColumn;
1978 sal_Bool bReFetchName = sal_False;
1979 if (m_xColumns->hasByName(sName))
1980 m_xColumns->getByName(sName) >>= xColumn;
1981 if (!xColumn.is() && m_xColumns->hasByName(xMeta->getColumnLabel(i)))
1982 m_xColumns->getByName(xMeta->getColumnLabel(i)) >>= xColumn;
1983 // check if column already in the list we need another
1984 if ( aAllColumns.find( xColumn ) != aAllColumns.end() )
1986 xColumn = NULL;
1987 bReFetchName = sal_True;
1989 if(!xColumn.is())
1991 // no column found so we could look at the position i
1992 Reference<XIndexAccess> xIndexAccess(m_xColumns,UNO_QUERY);
1993 if(xIndexAccess.is() && i <= xIndexAccess->getCount())
1995 xIndexAccess->getByIndex(i-1) >>= xColumn;
1997 else
1999 Sequence< ::rtl::OUString> aSeq = m_xColumns->getElementNames();
2000 if( i <= aSeq.getLength())
2001 m_xColumns->getByName(aSeq.getConstArray()[i-1]) >>= xColumn;
2004 if(bReFetchName && xColumn.is())
2005 xColumn->getPropertyValue(PROPERTY_NAME) >>= sName;
2006 aAllColumns.insert( xColumn );
2009 // create a RowSetDataColumn
2011 Reference<XPropertySetInfo> xInfo = xColumn.is() ? xColumn->getPropertySetInfo() : Reference<XPropertySetInfo>();
2012 if(xInfo.is() && xInfo->hasPropertyByName(PROPERTY_DESCRIPTION))
2013 aDescription = comphelper::getString(xColumn->getPropertyValue(PROPERTY_DESCRIPTION));
2015 ORowSetDataColumn* pColumn = new ORowSetDataColumn( getMetaData(),
2016 this,
2017 this,
2019 m_xActiveConnection->getMetaData(),
2020 aDescription,
2021 m_aCurrentRow);
2022 aColumns->get().push_back(pColumn);
2023 if(!sName.getLength())
2025 if(xColumn.is())
2026 xColumn->getPropertyValue(PROPERTY_NAME) >>= sName;
2027 else
2028 sName = ::rtl::OUString::createFromAscii("Expression1");
2029 // TODO: resource
2031 pColumn->setName(sName);
2032 aNames.push_back(sName);
2033 m_aDataColumns.push_back(pColumn);
2035 if ( xColumn.is() )
2036 impl_initializeColumnSettings_nothrow( xColumn, pColumn );
2040 // now create the columns we need
2041 if(m_pColumns)
2042 m_pColumns->assign(aColumns,aNames);
2043 else
2045 Reference<XDatabaseMetaData> xMeta = m_xActiveConnection->getMetaData();
2046 m_pColumns = new ORowSetDataColumns(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers(),
2047 aColumns,*this,m_aColumnsMutex,aNames);
2050 checkCache();
2051 // notify the rowset listeners
2052 notifyAllListeners(_rClearForNotification);
2054 // -------------------------------------------------------------------------
2055 // XRowSetApproveBroadcaster
2056 void SAL_CALL ORowSet::addRowSetApproveListener( const Reference< XRowSetApproveListener >& listener ) throw(RuntimeException)
2058 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2060 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2062 m_aApproveListeners.addInterface(listener);
2064 // -------------------------------------------------------------------------
2065 void SAL_CALL ORowSet::removeRowSetApproveListener( const Reference< XRowSetApproveListener >& listener ) throw(RuntimeException)
2067 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2069 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2071 m_aApproveListeners.removeInterface(listener);
2073 // -------------------------------------------------------------------------
2075 // XResultSetAccess
2076 Reference< XResultSet > SAL_CALL ORowSet::createResultSet( ) throw(SQLException, RuntimeException)
2078 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2080 if(m_xStatement.is())
2082 ORowSetClone* pClone = new ORowSetClone( m_aContext, *this, m_pMutex );
2083 Reference< XResultSet > xRet(pClone);
2084 m_aClones.push_back(WeakReferenceHelper(xRet));
2085 return xRet;
2087 return Reference< XResultSet >();
2089 // -------------------------------------------------------------------------
2091 // ::com::sun::star::util::XCancellable
2092 void SAL_CALL ORowSet::cancel( ) throw(RuntimeException)
2094 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2096 // -------------------------------------------------------------------------
2098 // ::com::sun::star::sdbcx::XDeleteRows
2099 Sequence< sal_Int32 > SAL_CALL ORowSet::deleteRows( const Sequence< Any >& rows ) throw(SQLException, RuntimeException)
2101 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2103 if(!m_pCache || m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY)
2104 throwFunctionSequenceException(*this);
2106 ::osl::ResettableMutexGuard aGuard( *m_pMutex );
2108 RowChangeEvent aEvt(*this,RowChangeAction::DELETE,rows.getLength());
2109 // notify the rowset listeners
2110 notifyAllListenersRowBeforeChange(aGuard,aEvt);
2112 Sequence< sal_Int32 > aResults( rows.getLength() );
2113 const Any* row = rows.getConstArray();
2114 const Any* rowEnd = rows.getConstArray() + rows.getLength();
2115 sal_Int32* result = aResults.getArray();
2116 for ( ; row != rowEnd; ++row, ++result )
2118 *result = 0;
2119 if ( !m_pCache->moveToBookmark( *row ) )
2120 continue;
2121 sal_Int32 nDeletePosition = m_pCache->getRow();
2123 // first notify the clones so that they can save their position
2124 notifyRowSetAndClonesRowDelete( *row );
2126 // now delete the row
2127 if ( !m_pCache->deleteRow() )
2128 continue;
2129 *result = 1;
2130 // now notify that we have deleted
2131 notifyRowSetAndClonesRowDeleted( *row, nDeletePosition );
2133 aEvt.Rows = aResults.getLength();
2135 // we have to check if we stand on the insert row and if so we have to reset it
2136 ORowSetNotifier aNotifier( this );
2137 // this will call cancelRowModification on the cache if necessary
2138 // notification order
2139 // - rowChanged
2140 notifyAllListenersRowChanged(aGuard,aEvt);
2142 // - IsModified
2143 // - IsNew
2144 aNotifier.fire();
2146 // - RowCount/IsRowCountFinal
2147 fireRowcount();
2149 return aResults;
2151 // -----------------------------------------------------------------------------
2152 void ORowSet::notifyRowSetAndClonesRowDelete( const Any& _rBookmark )
2154 // notify ourself
2155 onDeleteRow( _rBookmark );
2156 // notify the clones
2157 connectivity::OWeakRefArray::iterator aEnd = m_aClones.end();
2158 for (connectivity::OWeakRefArray::iterator i = m_aClones.begin(); aEnd != i; i++)
2160 Reference< XUnoTunnel > xTunnel(i->get(),UNO_QUERY);
2161 if(xTunnel.is())
2163 ORowSetClone* pClone = reinterpret_cast<ORowSetClone*>(xTunnel->getSomething(ORowSetClone::getUnoTunnelImplementationId()));
2164 if(pClone)
2165 pClone->onDeleteRow( _rBookmark );
2169 //------------------------------------------------------------------------------
2170 void ORowSet::notifyRowSetAndClonesRowDeleted( const Any& _rBookmark, sal_Int32 _nPos )
2172 // notify ourself
2173 onDeletedRow( _rBookmark, _nPos );
2174 // notify the clones
2175 connectivity::OWeakRefArray::iterator aEnd = m_aClones.end();
2176 for (connectivity::OWeakRefArray::iterator i = m_aClones.begin(); aEnd != i; i++)
2178 Reference< XUnoTunnel > xTunnel(i->get(),UNO_QUERY);
2179 if(xTunnel.is())
2181 ORowSetClone* pClone = reinterpret_cast<ORowSetClone*>(xTunnel->getSomething(ORowSetClone::getUnoTunnelImplementationId()));
2182 if(pClone)
2183 pClone->onDeletedRow( _rBookmark, _nPos );
2187 //------------------------------------------------------------------------------
2188 Reference< XConnection > ORowSet::calcConnection(const Reference< XInteractionHandler >& _rxHandler) throw( SQLException, RuntimeException )
2190 MutexGuard aGuard(m_aMutex);
2191 if (!m_xActiveConnection.is())
2193 Reference< XConnection > xNewConn;
2194 if (m_aDataSourceName.getLength())
2196 // is it a file url?
2197 Reference< XNameAccess > xNamingContext;
2198 if ( m_aContext.createComponent( (::rtl::OUString)SERVICE_SDB_DATABASECONTEXT, xNamingContext ) )
2199 if (xNamingContext.is() )
2203 if(_rxHandler.is())
2205 Reference< XCompletedConnection> xComplConn(xNamingContext->getByName(m_aDataSourceName), UNO_QUERY);
2206 if(xComplConn.is())
2207 xNewConn = xComplConn->connectWithCompletion(_rxHandler);
2209 else
2211 Reference< XDataSource > xDataSource(xNamingContext->getByName(m_aDataSourceName), UNO_QUERY);
2212 if (xDataSource.is())
2213 xNewConn = xDataSource->getConnection(m_aUser, m_aPassword);
2216 catch (SQLException &e)
2218 throw e;
2220 catch (Exception&)
2222 throw SQLException();
2226 setActiveConnection(xNewConn);
2227 m_bOwnConnection = sal_True;
2229 return m_xActiveConnection;
2231 //------------------------------------------------------------------------------
2232 Reference< XNameAccess > ORowSet::impl_getTables_throw()
2234 Reference< XNameAccess > xTables;
2236 Reference< XTablesSupplier > xTablesAccess( m_xActiveConnection, UNO_QUERY );
2237 if ( xTablesAccess.is() )
2239 xTables.set( xTablesAccess->getTables(), UNO_QUERY_THROW );
2241 else if ( m_pTables )
2243 xTables = m_pTables;
2245 else
2247 if ( !m_xActiveConnection.is() )
2248 throw SQLException(DBA_RES(RID_STR_CONNECTION_INVALID),*this,SQLSTATE_GENERAL,1000,Any() );
2250 sal_Bool bCase = sal_True;
2253 Reference<XDatabaseMetaData> xMeta = m_xActiveConnection->getMetaData();
2254 bCase = xMeta.is() && xMeta->storesMixedCaseQuotedIdentifiers();
2256 catch(SQLException&)
2258 DBG_UNHANDLED_EXCEPTION();
2261 m_pTables = new OTableContainer(*this,m_aMutex,m_xActiveConnection,bCase,NULL,NULL,NULL,m_nInAppend);
2262 xTables = m_pTables;
2263 Sequence< ::rtl::OUString> aTableFilter(1);
2264 aTableFilter[0] = ::rtl::OUString::createFromAscii("%");
2265 m_pTables->construct(aTableFilter,Sequence< ::rtl::OUString>());
2268 return xTables;
2271 //------------------------------------------------------------------------------
2272 void ORowSet::impl_resetTables_nothrow()
2274 if ( !m_pTables )
2275 return;
2279 m_pTables->dispose();
2281 catch( const Exception& )
2283 DBG_UNHANDLED_EXCEPTION();
2286 DELETEZ( m_pTables );
2289 //------------------------------------------------------------------------------
2290 sal_Bool ORowSet::impl_initComposer_throw( ::rtl::OUString& _out_rCommandToExecute )
2292 sal_Bool bUseEscapeProcessing = impl_buildActiveCommand_throw( );
2293 _out_rCommandToExecute = m_aActiveCommand;
2294 if ( !bUseEscapeProcessing )
2295 return bUseEscapeProcessing;
2297 Reference< XMultiServiceFactory > xFactory( m_xActiveConnection, UNO_QUERY );
2298 if ( xFactory.is() )
2302 ::comphelper::disposeComponent( m_xComposer );
2303 m_xComposer.set( xFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
2305 catch (const Exception& ) { m_xComposer = NULL; }
2307 if ( !m_xComposer.is() )
2308 m_xComposer = new OSingleSelectQueryComposer( impl_getTables_throw(), m_xActiveConnection, m_aContext );
2310 m_xComposer->setElementaryQuery( m_aActiveCommand );
2312 m_xComposer->setFilter( m_bApplyFilter ? m_aFilter : ::rtl::OUString() );
2313 m_xComposer->setHavingClause( m_bApplyFilter ? m_aHavingClause : ::rtl::OUString() );
2315 if ( m_bIgnoreResult )
2316 { // append a "0=1" filter
2317 // don't simply overwrite an existent filter, this would lead to problems if this existent
2318 // filter contains paramters (since a keyset may add parameters itself)
2319 // 2003-12-12 - #23418# - fs@openoffice.org
2320 m_xComposer->setElementaryQuery( m_xComposer->getQuery( ) );
2321 m_xComposer->setFilter( ::rtl::OUString::createFromAscii( "0 = 1" ) );
2324 m_xComposer->setOrder( m_aOrder );
2325 m_xComposer->setGroup( m_aGroupBy );
2327 if ( !m_xColumns.is() )
2329 Reference< XColumnsSupplier > xCols( m_xComposer, UNO_QUERY_THROW );
2330 m_xColumns = xCols->getColumns();
2333 impl_initParametersContainer_nothrow();
2335 _out_rCommandToExecute = m_xComposer->getQueryWithSubstitution();
2336 return bUseEscapeProcessing;
2339 //------------------------------------------------------------------------------
2340 sal_Bool ORowSet::impl_buildActiveCommand_throw()
2342 // create the sql command
2343 // from a table name or get the command out of a query (not a view)
2344 // the last use the command as it is
2345 sal_Bool bDoEscapeProcessing = m_bUseEscapeProcessing;
2347 m_aActiveCommand = ::rtl::OUString();
2348 ::rtl::OUString sCommand;
2350 if ( !m_aCommand.getLength() )
2351 return bDoEscapeProcessing;
2353 switch (m_nCommandType)
2355 case CommandType::TABLE:
2357 impl_resetTables_nothrow();
2359 Reference< XNameAccess > xTables( impl_getTables_throw() );
2360 if ( xTables->hasByName(m_aCommand) )
2362 Reference< XPropertySet > xTable;
2365 xTables->getByName( m_aCommand ) >>= xTable;
2367 catch(const WrappedTargetException& e)
2369 SQLException e2;
2370 if ( e.TargetException >>= e2 )
2371 throw e2;
2373 catch(Exception&)
2375 DBG_UNHANDLED_EXCEPTION();
2378 Reference<XColumnsSupplier> xSup(xTable,UNO_QUERY);
2379 if ( xSup.is() )
2380 m_xColumns = xSup->getColumns();
2382 sCommand = rtl::OUString::createFromAscii("SELECT * FROM ");
2383 ::rtl::OUString sCatalog, sSchema, sTable;
2384 ::dbtools::qualifiedNameComponents( m_xActiveConnection->getMetaData(), m_aCommand, sCatalog, sSchema, sTable, ::dbtools::eInDataManipulation );
2385 sCommand += ::dbtools::composeTableNameForSelect( m_xActiveConnection, sCatalog, sSchema, sTable );
2387 else
2389 String sMessage( DBACORE_RESSTRING( RID_STR_TABLE_DOES_NOT_EXIST ) );
2390 sMessage.SearchAndReplaceAscii( "$table$", m_aCommand );
2391 throwGenericSQLException(sMessage,*this);
2394 break;
2396 case CommandType::QUERY:
2398 Reference< XQueriesSupplier > xQueriesAccess(m_xActiveConnection, UNO_QUERY);
2399 if (xQueriesAccess.is())
2401 Reference< ::com::sun::star::container::XNameAccess > xQueries(xQueriesAccess->getQueries());
2402 if (xQueries->hasByName(m_aCommand))
2404 Reference< XPropertySet > xQuery(xQueries->getByName(m_aCommand),UNO_QUERY);
2405 OSL_ENSURE(xQuery.is(),"ORowSet::impl_buildActiveCommand_throw: Query is NULL!");
2406 if ( xQuery.is() )
2408 xQuery->getPropertyValue(PROPERTY_COMMAND) >>= sCommand;
2409 xQuery->getPropertyValue(PROPERTY_ESCAPE_PROCESSING) >>= bDoEscapeProcessing;
2411 ::rtl::OUString aCatalog,aSchema,aTable;
2412 xQuery->getPropertyValue(PROPERTY_UPDATE_CATALOGNAME) >>= aCatalog;
2413 xQuery->getPropertyValue(PROPERTY_UPDATE_SCHEMANAME) >>= aSchema;
2414 xQuery->getPropertyValue(PROPERTY_UPDATE_TABLENAME) >>= aTable;
2415 if(aTable.getLength())
2416 m_aUpdateTableName = composeTableName( m_xActiveConnection->getMetaData(), aCatalog, aSchema, aTable, sal_False, ::dbtools::eInDataManipulation );
2418 Reference<XColumnsSupplier> xSup(xQuery,UNO_QUERY);
2419 if(xSup.is())
2420 m_xColumns = xSup->getColumns();
2423 else
2425 String sMessage( DBACORE_RESSTRING( RID_STR_QUERY_DOES_NOT_EXIST ) );
2426 sMessage.SearchAndReplaceAscii( "$table$", m_aCommand );
2427 throwGenericSQLException(sMessage,*this);
2430 else
2431 throw SQLException(DBA_RES(RID_STR_NO_XQUERIESSUPPLIER),*this,::rtl::OUString(),0,Any());
2433 break;
2435 default:
2436 sCommand = m_aCommand;
2437 break;
2440 m_aActiveCommand = sCommand;
2442 if ( !m_aActiveCommand.getLength() )
2443 throwSQLException( "No SQL command was provided.", SQL_FUNCTION_SEQUENCE_ERROR, *this );
2444 // TODO: resource
2446 return bDoEscapeProcessing;
2449 //------------------------------------------------------------------------------
2450 void ORowSet::impl_initParametersContainer_nothrow()
2452 OSL_PRECOND( !m_pParameters.is(), "ORowSet::impl_initParametersContainer_nothrow: already initialized the parameters!" );
2454 m_pParameters = new param::ParameterWrapperContainer( m_xComposer.get() );
2455 // copy the premature parameters into the final ones
2456 size_t nParamCount( ::std::min( m_pParameters->size(), m_aPrematureParamValues.get().size() ) );
2457 for ( size_t i=0; i<nParamCount; ++i )
2459 (*m_pParameters)[i] = m_aPrematureParamValues.get()[i];
2463 //------------------------------------------------------------------------------
2464 void ORowSet::impl_disposeParametersContainer_nothrow()
2466 if ( !m_pParameters.is() )
2467 return;
2469 // copy the actual values to our "premature" ones, to preserve them for later use
2470 size_t nParamCount( m_pParameters->size() );
2471 m_aPrematureParamValues.get().resize( nParamCount );
2472 for ( size_t i=0; i<nParamCount; ++i )
2474 m_aPrematureParamValues.get()[i] = (*m_pParameters)[i];
2477 m_pParameters->dispose();
2478 m_pParameters = NULL;
2481 // -----------------------------------------------------------------------------
2482 ORowSetValue& ORowSet::getParameterStorage(sal_Int32 parameterIndex)
2484 ::connectivity::checkDisposed( ORowSet_BASE1::rBHelper.bDisposed );
2485 if ( parameterIndex < 1 )
2486 throwInvalidIndexException( *this );
2488 if ( m_aParametersSet.size() < (size_t)parameterIndex )
2489 m_aParametersSet.resize( parameterIndex ,false);
2490 m_aParametersSet[parameterIndex - 1] = true;
2492 if ( m_aParametersSet.size() < (size_t)parameterIndex )
2493 m_aParametersSet.resize( parameterIndex ,false);
2494 m_aParametersSet[parameterIndex - 1] = true;
2496 if ( m_pParameters.is() )
2498 if ( m_bCommandFacetsDirty )
2499 // need to rebuild the parameters, since some property which contributes to the
2500 // complete command, and thus the parameters, changed
2501 impl_disposeParametersContainer_nothrow();
2502 if ( m_pParameters.is() )
2504 if ( (size_t)parameterIndex > m_pParameters->size() )
2505 throwInvalidIndexException( *this );
2506 return (*m_pParameters)[ parameterIndex - 1 ];
2510 if ( m_aPrematureParamValues.get().size() < (size_t)parameterIndex )
2511 m_aPrematureParamValues.get().resize( parameterIndex );
2512 return m_aPrematureParamValues.get()[ parameterIndex - 1 ];
2514 // -------------------------------------------------------------------------
2515 // XParameters
2516 void SAL_CALL ORowSet::setNull( sal_Int32 parameterIndex, sal_Int32 /*sqlType*/ ) throw(SQLException, RuntimeException)
2518 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2520 getParameterStorage( parameterIndex ).setNull();
2522 // -------------------------------------------------------------------------
2523 void SAL_CALL ORowSet::setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& /*typeName*/ ) throw(SQLException, RuntimeException)
2525 setNull( parameterIndex, sqlType );
2527 // -----------------------------------------------------------------------------
2528 void ORowSet::setParameter(sal_Int32 parameterIndex, const ORowSetValue& x)
2530 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2532 getParameterStorage( parameterIndex ) = x;
2535 // -------------------------------------------------------------------------
2536 void SAL_CALL ORowSet::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(SQLException, RuntimeException)
2538 setParameter(parameterIndex,x);
2540 // -------------------------------------------------------------------------
2541 void SAL_CALL ORowSet::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
2543 setParameter(parameterIndex,x);
2545 // -------------------------------------------------------------------------
2546 void SAL_CALL ORowSet::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
2548 setParameter(parameterIndex,x);
2550 // -------------------------------------------------------------------------
2551 void SAL_CALL ORowSet::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
2553 setParameter(parameterIndex,x);
2555 // -------------------------------------------------------------------------
2556 void SAL_CALL ORowSet::setLong( sal_Int32 parameterIndex, sal_Int64 x ) throw(SQLException, RuntimeException)
2558 setParameter(parameterIndex,x);
2560 // -------------------------------------------------------------------------
2561 void SAL_CALL ORowSet::setFloat( sal_Int32 parameterIndex, float x ) throw(SQLException, RuntimeException)
2563 setParameter(parameterIndex,x);
2565 // -------------------------------------------------------------------------
2566 void SAL_CALL ORowSet::setDouble( sal_Int32 parameterIndex, double x ) throw(SQLException, RuntimeException)
2568 setParameter(parameterIndex,x);
2570 // -------------------------------------------------------------------------
2571 void SAL_CALL ORowSet::setString( sal_Int32 parameterIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
2573 setParameter(parameterIndex,x);
2575 // -------------------------------------------------------------------------
2576 void SAL_CALL ORowSet::setBytes( sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
2578 setParameter(parameterIndex,x);
2580 // -------------------------------------------------------------------------
2581 void SAL_CALL ORowSet::setDate( sal_Int32 parameterIndex, const ::com::sun::star::util::Date& x ) throw(SQLException, RuntimeException)
2583 setParameter(parameterIndex,x);
2585 // -------------------------------------------------------------------------
2586 void SAL_CALL ORowSet::setTime( sal_Int32 parameterIndex, const ::com::sun::star::util::Time& x ) throw(SQLException, RuntimeException)
2588 setParameter(parameterIndex,x);
2590 // -------------------------------------------------------------------------
2591 void SAL_CALL ORowSet::setTimestamp( sal_Int32 parameterIndex, const ::com::sun::star::util::DateTime& x ) throw(SQLException, RuntimeException)
2593 setParameter(parameterIndex,x);
2595 // -------------------------------------------------------------------------
2596 void SAL_CALL ORowSet::setBinaryStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
2598 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2599 ORowSetValue& rParamValue( getParameterStorage( parameterIndex ) );
2603 Sequence <sal_Int8> aData;
2604 x->readBytes(aData, length);
2605 rParamValue = aData;
2606 x->closeInput();
2608 catch( Exception& )
2610 throw SQLException();
2613 // -------------------------------------------------------------------------
2614 void SAL_CALL ORowSet::setCharacterStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
2616 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2617 ORowSetValue& rParamValue( getParameterStorage( parameterIndex ) );
2620 Sequence <sal_Int8> aData;
2621 rtl::OUString aDataStr;
2622 // the data is given as character data and the length defines the character length
2623 sal_Int32 nSize = x->readBytes(aData, length * sizeof(sal_Unicode));
2624 if (nSize / sizeof(sal_Unicode))
2625 aDataStr = rtl::OUString((sal_Unicode*)aData.getConstArray(), nSize / sizeof(sal_Unicode));
2626 rParamValue = aDataStr;
2627 rParamValue.setTypeKind( DataType::LONGVARCHAR );
2628 x->closeInput();
2630 catch( Exception& )
2632 throw SQLException();
2635 // -------------------------------------------------------------------------
2636 void SAL_CALL ORowSet::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException)
2638 if ( !::dbtools::implSetObject( this, parameterIndex, x ) )
2639 { // there is no other setXXX call which can handle the value in x
2640 throw SQLException();
2643 // -------------------------------------------------------------------------
2644 void SAL_CALL ORowSet::setObjectWithInfo( sal_Int32 parameterIndex, const Any& x, sal_Int32 targetSqlType, sal_Int32 /*scale*/ ) throw(SQLException, RuntimeException)
2646 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2647 ORowSetValue& rParamValue( getParameterStorage( parameterIndex ) );
2648 setObject( parameterIndex, x );
2649 rParamValue.setTypeKind( targetSqlType );
2651 // -------------------------------------------------------------------------
2652 void SAL_CALL ORowSet::setRef( sal_Int32 /*parameterIndex*/, const Reference< XRef >& /*x*/ ) throw(SQLException, RuntimeException)
2654 ::dbtools::throwFeatureNotImplementedException( "XParameters::setRef", *this );
2656 // -------------------------------------------------------------------------
2657 void SAL_CALL ORowSet::setBlob( sal_Int32 /*parameterIndex*/, const Reference< XBlob >& /*x*/ ) throw(SQLException, RuntimeException)
2659 ::dbtools::throwFeatureNotImplementedException( "XParameters::setBlob", *this );
2661 // -------------------------------------------------------------------------
2662 void SAL_CALL ORowSet::setClob( sal_Int32 /*parameterIndex*/, const Reference< XClob >& /*x*/ ) throw(SQLException, RuntimeException)
2664 ::dbtools::throwFeatureNotImplementedException( "XParameters::setClob", *this );
2666 // -------------------------------------------------------------------------
2667 void SAL_CALL ORowSet::setArray( sal_Int32 /*parameterIndex*/, const Reference< XArray >& /*x*/ ) throw(SQLException, RuntimeException)
2669 ::dbtools::throwFeatureNotImplementedException( "XParameters::setArray", *this );
2671 // -------------------------------------------------------------------------
2672 void SAL_CALL ORowSet::clearParameters( ) throw(SQLException, RuntimeException)
2674 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2676 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2678 size_t nParamCount( m_pParameters.is() ? m_pParameters->size() : m_aPrematureParamValues.get().size() );
2679 for ( size_t i=1; i<=nParamCount; ++i )
2680 getParameterStorage( (sal_Int32)i ).setNull();
2681 m_aParametersSet.clear();
2684 // -------------------------------------------------------------------------
2685 Any SAL_CALL ORowSet::getWarnings( ) throw (SQLException, RuntimeException)
2687 return m_aWarnings.getWarnings();
2690 // -------------------------------------------------------------------------
2691 void SAL_CALL ORowSet::clearWarnings( ) throw (SQLException, RuntimeException)
2693 m_aWarnings.clearWarnings();
2696 // -------------------------------------------------------------------------
2697 void ORowSet::firePropertyChange(sal_Int32 _nPos,const ::connectivity::ORowSetValue& _rOldValue)
2699 OSL_ENSURE(_nPos < (sal_Int32)m_aDataColumns.size(),"nPos is invalid!");
2700 m_aDataColumns[_nPos]->fireValueChange(_rOldValue);
2703 // -----------------------------------------------------------------------------
2704 void ORowSet::doCancelModification( )
2706 //OSL_ENSURE( isModification(), "ORowSet::doCancelModification: invalid call (no cache!)!" );
2707 if ( isModification() )
2708 m_pCache->cancelRowModification();
2709 m_bModified = sal_False;
2712 // -----------------------------------------------------------------------------
2713 sal_Bool ORowSet::isModification( )
2715 return isNew();
2718 // -----------------------------------------------------------------------------
2719 sal_Bool ORowSet::isModified( )
2721 return m_bModified;
2724 // -----------------------------------------------------------------------------
2725 sal_Bool ORowSet::isNew( )
2727 return m_bNew;
2730 // -----------------------------------------------------------------------------
2731 void ORowSet::checkUpdateIterator()
2733 if(!m_bModified && !m_bNew)
2735 m_pCache->setUpdateIterator(m_aCurrentRow);
2736 m_aCurrentRow = m_pCache->m_aInsertRow;
2737 m_bModified = sal_True;
2738 } // if(!m_bModified && !m_bNew)
2739 else if ( m_bNew ) // here we are modifing a value
2740 m_bModified = sal_True;
2742 // -----------------------------------------------------------------------------
2743 void ORowSet::checkUpdateConditions(sal_Int32 columnIndex)
2745 checkCache();
2746 if ( columnIndex <= 0 )
2747 throwSQLException( "Invalid column index", SQL_INVALID_DESCRIPTOR_INDEX, *this );
2748 // TODO: resource
2749 if ( rowDeleted() )
2750 throwSQLException( "Current row is deleted", SQL_INVALID_CURSOR_POSITION, *this );
2751 // TODO: resource
2752 if ( m_aCurrentRow.isNull() )
2753 throwSQLException( "Invalid cursor state", SQL_INVALID_CURSOR_STATE, *this );
2755 if ( sal_Int32((*m_aCurrentRow)->get().size()) <= columnIndex )
2756 throwSQLException( "Invalid column index", SQL_INVALID_DESCRIPTOR_INDEX, *this );
2757 // TODO: resource
2758 if ( m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY)
2759 throwSQLException( "Result set is not writeable", SQL_GENERAL_ERROR, *this );
2760 // TODO: resource
2762 // -----------------------------------------------------------------------------
2763 void SAL_CALL ORowSet::refreshRow( ) throw(SQLException, RuntimeException)
2766 ORowSetNotifier aNotifier( this );
2767 // this will call cancelRowModification on the cache if necessary
2769 // notification order:
2770 if ( m_bModified && m_pCache )
2771 // - column values
2772 implCancelRowUpdates( sal_False ); // do _not_ notify the IsModify - will do this ourself below
2774 ORowSetBase::refreshRow();
2776 // - IsModified
2777 // - IsNew
2778 aNotifier.fire( );
2780 // ***********************************************************
2781 // ORowSetClone
2782 // ***********************************************************
2783 DBG_NAME(ORowSetClone);
2784 //--------------------------------------------------------------------------
2785 ORowSetClone::ORowSetClone( const ::comphelper::ComponentContext& _rContext, ORowSet& rParent, ::osl::Mutex* _pMutex )
2786 :OSubComponent(m_aMutex, rParent)
2787 ,ORowSetBase( _rContext, OComponentHelper::rBHelper, _pMutex )
2788 ,m_pParent(&rParent)
2789 ,m_nFetchDirection(rParent.m_nFetchDirection)
2790 ,m_nFetchSize(rParent.m_nFetchSize)
2791 ,m_bIsBookmarable(sal_True)
2793 DBG_CTOR(ORowSetClone, NULL);
2795 m_nResultSetType = rParent.m_nResultSetType;
2796 m_nResultSetConcurrency = ResultSetConcurrency::READ_ONLY;
2797 m_pMySelf = this;
2798 m_bClone = sal_True;
2799 m_bBeforeFirst = rParent.m_bBeforeFirst;
2800 m_bAfterLast = rParent.m_bAfterLast;
2801 m_pCache = rParent.m_pCache;
2802 m_aBookmark = rParent.m_aBookmark;
2803 m_aCurrentRow = m_pCache->createIterator(this);
2804 m_xNumberFormatTypes = rParent.m_xNumberFormatTypes;
2806 m_aOldRow = m_pCache->registerOldRow();
2808 ::vos::ORef< ::connectivity::OSQLColumns> aColumns = new ::connectivity::OSQLColumns();
2809 ::std::vector< ::rtl::OUString> aNames;
2811 ::rtl::OUString aDescription;
2812 // ConfigManager* pConfigMgr = ConfigManager::GetConfigManager();
2813 // Locale aLocale;
2814 // pConfigMgr->GetDirectConfigProperty(ConfigManager::LOCALE) >>= aLocale;
2815 Locale aLocale = SvtSysLocale().GetLocaleData().getLocale();
2817 if ( rParent.m_pColumns )
2819 Sequence< ::rtl::OUString> aSeq = rParent.m_pColumns->getElementNames();
2820 const ::rtl::OUString* pIter = aSeq.getConstArray();
2821 const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
2822 aColumns->get().reserve(aSeq.getLength()+1);
2823 for(sal_Int32 i=1;pIter != pEnd ;++pIter,++i)
2825 Reference<XPropertySet> xColumn;
2826 rParent.m_pColumns->getByName(*pIter) >>= xColumn;
2827 if(xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_DESCRIPTION))
2828 aDescription = comphelper::getString(xColumn->getPropertyValue(PROPERTY_DESCRIPTION));
2829 ORowSetColumn* pColumn = new ORowSetColumn( rParent.getMetaData(),
2830 this,
2832 rParent.m_xActiveConnection->getMetaData(),
2833 aDescription,
2834 m_aCurrentRow);
2835 aColumns->get().push_back(pColumn);
2836 pColumn->setName(*pIter);
2837 aNames.push_back(*pIter);
2838 m_aDataColumns.push_back(pColumn);
2840 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ALIGN,xColumn->getPropertyValue(PROPERTY_ALIGN));
2841 sal_Int32 nFormatKey = comphelper::getINT32(xColumn->getPropertyValue(PROPERTY_NUMBERFORMAT));
2842 if(!nFormatKey && xColumn.is() && m_xNumberFormatTypes.is())
2843 nFormatKey = ::dbtools::getDefaultNumberFormat(xColumn,m_xNumberFormatTypes,aLocale);
2844 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_NUMBERFORMAT,makeAny(nFormatKey));
2845 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_RELATIVEPOSITION,xColumn->getPropertyValue(PROPERTY_RELATIVEPOSITION));
2846 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_WIDTH,xColumn->getPropertyValue(PROPERTY_WIDTH));
2847 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_HIDDEN,xColumn->getPropertyValue(PROPERTY_HIDDEN));
2848 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_CONTROLMODEL,xColumn->getPropertyValue(PROPERTY_CONTROLMODEL));
2849 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_HELPTEXT,xColumn->getPropertyValue(PROPERTY_HELPTEXT));
2850 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_CONTROLDEFAULT,xColumn->getPropertyValue(PROPERTY_CONTROLDEFAULT));
2852 } // for(sal_Int32 i=1;pIter != pEnd ;++pIter,++i)
2854 Reference<XDatabaseMetaData> xMeta = rParent.m_xActiveConnection->getMetaData();
2855 m_pColumns = new ORowSetDataColumns(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers(),
2856 aColumns,*this,m_aMutex,aNames);
2858 sal_Int32 nRT = PropertyAttribute::READONLY | PropertyAttribute::TRANSIENT;
2860 // sdb.RowSet Properties
2861 // registerProperty(PROPERTY_CURSORNAME, PROPERTY_ID_CURSORNAME, PropertyAttribute::READONLY, &m_aDataSourceName, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
2862 registerMayBeVoidProperty(PROPERTY_ACTIVE_CONNECTION,PROPERTY_ID_ACTIVE_CONNECTION, PropertyAttribute::MAYBEVOID|PropertyAttribute::READONLY, &rParent.m_aActiveConnection, ::getCppuType(reinterpret_cast< Reference< XConnection >* >(NULL)));
2863 registerProperty(PROPERTY_RESULTSETCONCURRENCY, PROPERTY_ID_RESULTSETCONCURRENCY, PropertyAttribute::READONLY, &m_nResultSetConcurrency,::getCppuType(reinterpret_cast< sal_Int32*>(NULL)));
2864 registerProperty(PROPERTY_RESULTSETTYPE, PROPERTY_ID_RESULTSETTYPE, PropertyAttribute::READONLY, &m_nResultSetType, ::getCppuType(reinterpret_cast< sal_Int32*>(NULL)));
2865 registerProperty(PROPERTY_FETCHDIRECTION, PROPERTY_ID_FETCHDIRECTION, PropertyAttribute::TRANSIENT, &m_nFetchDirection, ::getCppuType(reinterpret_cast< sal_Int32*>(NULL)));
2866 registerProperty(PROPERTY_FETCHSIZE, PROPERTY_ID_FETCHSIZE, PropertyAttribute::TRANSIENT, &m_nFetchSize, ::getCppuType(reinterpret_cast< sal_Int32*>(NULL)));
2867 registerProperty(PROPERTY_ISBOOKMARKABLE, PROPERTY_ID_ISBOOKMARKABLE, nRT, &m_bIsBookmarable, ::getBooleanCppuType());
2870 //--------------------------------------------------------------------------
2871 ORowSetClone::~ORowSetClone()
2873 DBG_DTOR(ORowSetClone, NULL);
2875 // com::sun::star::XTypeProvider
2876 //--------------------------------------------------------------------------
2877 Sequence< Type > ORowSetClone::getTypes() throw (RuntimeException)
2879 return ::comphelper::concatSequences(OSubComponent::getTypes(),ORowSetBase::getTypes());
2881 // com::sun::star::XInterface
2882 //--------------------------------------------------------------------------
2883 Any ORowSetClone::queryInterface( const Type & rType ) throw (RuntimeException)
2885 Any aRet = ORowSetBase::queryInterface(rType);
2886 if(!aRet.hasValue())
2887 aRet = OSubComponent::queryInterface(rType);
2888 return aRet;
2890 //------------------------------------------------------------------------------
2891 void ORowSetClone::acquire() throw()
2893 OSubComponent::acquire();
2896 //------------------------------------------------------------------------------
2897 void ORowSetClone::release() throw()
2899 OSubComponent::release();
2902 // XServiceInfo
2903 //------------------------------------------------------------------------------
2904 rtl::OUString ORowSetClone::getImplementationName( ) throw(RuntimeException)
2906 return rtl::OUString::createFromAscii("com.sun.star.sdb.ORowSetClone");
2909 //------------------------------------------------------------------------------
2910 sal_Bool ORowSetClone::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
2912 return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
2915 //------------------------------------------------------------------------------
2916 Sequence< ::rtl::OUString > ORowSetClone::getSupportedServiceNames( ) throw (RuntimeException)
2918 Sequence< ::rtl::OUString > aSNS( 2 );
2919 aSNS[0] = SERVICE_SDBC_RESULTSET;
2920 aSNS[1] = SERVICE_SDB_RESULTSET;
2921 return aSNS;
2924 // OComponentHelper
2925 //------------------------------------------------------------------------------
2926 void ORowSetClone::disposing()
2928 MutexGuard aGuard( m_aMutex );
2929 ORowSetBase::disposing();
2931 m_pParent = NULL;
2932 m_pMutex = &m_aMutex; // this must be done here because someone could hold a ref to us and try to do something
2933 OSubComponent::disposing();
2936 // XCloseable
2937 //------------------------------------------------------------------------------
2938 void ORowSetClone::close(void) throw( SQLException, RuntimeException )
2941 MutexGuard aGuard( m_aMutex );
2942 if (OComponentHelper::rBHelper.bDisposed)
2943 throw DisposedException();
2945 dispose();
2947 // -------------------------------------------------------------------------
2949 // comphelper::OPropertyArrayUsageHelper
2950 ::cppu::IPropertyArrayHelper* ORowSetClone::createArrayHelper( ) const
2952 Sequence< Property > aProps;
2953 describeProperties(aProps);
2954 return new ::cppu::OPropertyArrayHelper(aProps);
2956 // -------------------------------------------------------------------------
2958 // cppu::OPropertySetHelper
2959 ::cppu::IPropertyArrayHelper& SAL_CALL ORowSetClone::getInfoHelper()
2961 typedef ::comphelper::OPropertyArrayUsageHelper<ORowSetClone> ORowSetClone_PROP;
2962 return *ORowSetClone_PROP::getArrayHelper();
2964 // -------------------------------------------------------------------------
2965 //--------------------------------------------------------------------------
2966 Sequence< sal_Int8 > ORowSetClone::getUnoTunnelImplementationId()
2968 static ::cppu::OImplementationId * pId = 0;
2969 if (! pId)
2971 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
2972 if (! pId)
2974 static ::cppu::OImplementationId aId;
2975 pId = &aId;
2978 return pId->getImplementationId();
2980 // -----------------------------------------------------------------------------
2981 // com::sun::star::XUnoTunnel
2982 sal_Int64 SAL_CALL ORowSetClone::getSomething( const Sequence< sal_Int8 >& rId ) throw(RuntimeException)
2984 if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
2985 return reinterpret_cast<sal_Int64>(this);
2987 return 0;
2989 // -----------------------------------------------------------------------------
2990 void SAL_CALL ORowSetClone::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception)
2992 if ( nHandle == PROPERTY_ID_FETCHSIZE )
2994 if ( m_pParent )
2995 m_pParent->setFastPropertyValue_NoBroadcast( nHandle, rValue );
2998 OPropertyStateContainer::setFastPropertyValue_NoBroadcast(nHandle,rValue);
3001 // -----------------------------------------------------------------------------
3002 void ORowSetClone::doCancelModification( )
3004 //OSL_ENSURE( sal_False, "ORowSetClone::doCancelModification: invalid call!" );
3007 // -----------------------------------------------------------------------------
3008 sal_Bool ORowSetClone::isModification( )
3010 return sal_False;
3013 // -----------------------------------------------------------------------------
3014 sal_Bool ORowSetClone::isModified( )
3016 return sal_False;
3019 // -----------------------------------------------------------------------------
3020 sal_Bool ORowSetClone::isNew( )
3022 return sal_False;
3025 // -------------------------------------------------------------------------
3026 void SAL_CALL ORowSetClone::execute( ) throw(SQLException, RuntimeException)
3028 throwFunctionNotSupportedException( "RowSetClone::XRowSet::execute", *this );
3031 // -------------------------------------------------------------------------
3032 void SAL_CALL ORowSetClone::addRowSetListener( const Reference< XRowSetListener >& ) throw(RuntimeException)
3034 throwFunctionNotSupportedException( "RowSetClone::XRowSet", *this );
3037 // -------------------------------------------------------------------------
3038 void SAL_CALL ORowSetClone::removeRowSetListener( const Reference< XRowSetListener >& ) throw(RuntimeException)
3040 throwFunctionNotSupportedException( "RowSetClone::XRowSet", *this );
3043 } // dbaccess