1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RowSet.cxx,v $
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"
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>
43 #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
44 #include <com/sun/star/lang/DisposedException.hpp>
46 #ifndef _CPPUHELPER_INTERFACECONTAINER_H_
47 #include <cppuhelper/interfacecontainer.h>
49 #ifndef _CPPUHELPER_EXC_HLP_HXX_
50 #include <cppuhelper/exc_hlp.hxx>
52 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
53 #include <cppuhelper/typeprovider.hxx>
55 #ifndef _COMPHELPER_SEQUENCE_HXX_
56 #include <comphelper/sequence.hxx>
58 #ifndef COMPHELPER_COMPONENTCONTEXT_HXX
59 #include <comphelper/componentcontext.hxx>
61 #ifndef _COM_SUN_STAR_SDB_XCOMPLETEDCONNECTION_HPP_
62 #include <com/sun/star/sdb/XCompletedConnection.hpp>
64 #ifndef _COM_SUN_STAR_SDB_ROWSETVETOEXCEPTION_HPP_
65 #include <com/sun/star/sdb/RowSetVetoException.hpp>
67 #ifndef _COM_SUN_STAR_SDBC_FETCHDIRECTION_HPP_
68 #include <com/sun/star/sdbc/FetchDirection.hpp>
70 #ifndef _COM_SUN_STAR_SDBC_RESULTSETCONCURRENCY_HPP_
71 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
73 #ifndef _COM_SUN_STAR_SDBCX_PRIVILEGE_HPP_
74 #include <com/sun/star/sdbcx/Privilege.hpp>
76 #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
77 #include <com/sun/star/sdb/CommandType.hpp>
79 #ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
80 #include <com/sun/star/sdbc/XDataSource.hpp>
82 #ifndef _COM_SUN_STAR_SDB_XQUERIESSUPPLIER_HPP_
83 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
85 #ifndef _COM_SUN_STAR_SDB_ROWCHANGEACTION_HPP_
86 #include <com/sun/star/sdb/RowChangeAction.hpp>
88 #ifndef _COM_SUN_STAR_SDB_ERRORCONDITION_HPP_
89 #include <com/sun/star/sdb/ErrorCondition.hpp>
91 #ifndef _COM_SUN_STAR_SDBC_XDRIVERACCESS_HPP_
92 #include <com/sun/star/sdbc/XDriverAccess.hpp>
94 #ifndef _COM_SUN_STAR_SDBCX_XDATADEFINITIONSUPPLIER_HPP_
95 #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
97 #ifndef _COM_SUN_STAR_SDBCX_COMPAREBOOKMARK_HPP_
98 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
100 #ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_
101 #include <com/sun/star/uno/XNamingService.hpp>
103 #ifndef _COM_SUN_STAR_SDBCX_PRIVILEGE_HPP_
104 #include <com/sun/star/sdbcx/Privilege.hpp>
106 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
107 #include <connectivity/dbtools.hxx>
109 #ifndef _COMPHELPER_EXTRACT_HXX_
110 #include <comphelper/extract.hxx>
112 #ifndef DBACCESS_CORE_API_ROWSETCACHE_HXX
113 #include "RowSetCache.hxx"
115 #if OSL_DEBUG_LEVEL > 1
116 #ifndef _COM_SUN_STAR_SDBC_XDRIVERMANAGER_HPP_
117 #include <com/sun/star/sdbc/XDriverManager.hpp>
120 #ifndef _DBACORE_DATACOLUMN_HXX_
121 #include "CRowSetDataColumn.hxx"
123 #ifndef DBACCESS_CORE_API_CROWSETCOLUMN_HXX
124 #include "CRowSetColumn.hxx"
126 #ifndef _COMPHELPER_TYPES_HXX_
127 #include <comphelper/types.hxx>
129 #ifndef _COMPHELPER_SEQSTREAM_HXX
130 #include <comphelper/seqstream.hxx>
132 #ifndef _TOOLS_DEBUG_HXX
133 #include <tools/debug.hxx>
135 #ifndef TOOLS_DIAGNOSE_EX_H
136 #include <tools/diagnose_ex.h>
138 #ifndef _DBHELPER_DBEXCEPTION_HXX_
139 #include <connectivity/dbexception.hxx>
141 #ifndef _DBA_CORE_TABLECONTAINER_HXX_
142 #include "tablecontainer.hxx"
144 #ifndef _COM_SUN_STAR_SDB_PARAMETERSREQUEST_HPP_
145 #include <com/sun/star/sdb/ParametersRequest.hpp>
147 #ifndef _COM_SUN_STAR_SDB_PARAMETERSREQUEST_HPP_
148 #include <com/sun/star/sdb/ParametersRequest.hpp>
150 #ifndef _COM_SUN_STAR_SDB_XPARAMETERSSUPPLIER_HPP_
151 #include <com/sun/star/sdb/XParametersSupplier.hpp>
153 #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
154 #include <com/sun/star/container/XChild.hpp>
156 #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATSSUPPLIER_HPP_
157 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
159 #ifndef _COMPHELPER_INTERACTION_HXX_
160 #include <comphelper/interaction.hxx>
162 #ifndef _COMPHELPER_PROPERTY_HXX_
163 #include <comphelper/property.hxx>
165 #ifndef _UTL_CONFIGMGR_HXX_
166 #include <unotools/configmgr.hxx>
168 #ifndef _COMPHELPER_UNO3_HXX_
169 #include <comphelper/uno3.hxx>
171 #ifndef _COM_SUN_STAR_SDBCX_COMPAREBOOKMARK_HPP_
172 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
174 #ifndef _DBA_CORE_RESOURCE_HXX_
175 #include "core_resource.hxx"
177 #ifndef _DBA_CORE_RESOURCE_HRC_
178 #include "core_resource.hrc"
180 #ifndef _DBHELPER_DBCONVERSION_HXX_
181 #include <connectivity/dbconversion.hxx>
183 #ifndef INCLUDED_SVTOOLS_SYSLOCALE_HXX
184 #include <svtools/syslocale.hxx>
186 #ifndef _RTL_LOGFILE_HXX_
187 #include <rtl/logfile.hxx>
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(); \
222 sal_Bool bCheck = sal_True; \
223 while( pxInt > pxIntBegin && bCheck ) \
227 while( pxInt > pxIntBegin && bCheck ) \
230 bCheck = static_cast< T* >( pxInt->get() )->method(aEvt); \
233 catch( RuntimeException& ) \
240 //..................................................................
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
)
259 ,m_nFetchDirection(FetchDirection::FORWARD
)
264 ,m_nCommandType(CommandType::COMMAND
)
265 ,m_nTransactionIsolation(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
)
275 ,m_bCanUpdateInsertedRows(sal_True
)
276 ,m_bOwnConnection(sal_False
)
278 m_nResultSetType
= ResultSetType::SCROLL_SENSITIVE
;
279 m_nResultSetConcurrency
= ResultSetConcurrency::UPDATABLE
;
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
)));
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
);
340 // -----------------------------------------------------------------------------
341 void ORowSet::getPropertyDefaultByHandle( sal_Int32 _nHandle
, Any
& _rDefault
) const
345 case PROPERTY_ID_COMMAND_TYPE
:
346 _rDefault
<<= static_cast<sal_Int32
>(CommandType::COMMAND
);
348 case PROPERTY_ID_IGNORERESULT
:
349 _rDefault
<<= sal_False
;
351 case PROPERTY_ID_APPLYFILTER
:
352 _rDefault
<<= sal_False
;
354 case PROPERTY_ID_ISMODIFIED
:
355 _rDefault
<<= sal_False
;
357 case PROPERTY_ID_ISBOOKMARKABLE
:
358 _rDefault
<<= sal_True
;
360 case PROPERTY_ID_CANUPDATEINSERTEDROWS
:
361 _rDefault
<<= sal_True
;
363 case PROPERTY_ID_RESULTSETTYPE
:
364 _rDefault
<<= ResultSetType::SCROLL_INSENSITIVE
;
366 case PROPERTY_ID_RESULTSETCONCURRENCY
:
367 _rDefault
<<= ResultSetConcurrency::UPDATABLE
;
369 case PROPERTY_ID_FETCHDIRECTION
:
370 _rDefault
<<= FetchDirection::FORWARD
;
372 case PROPERTY_ID_FETCHSIZE
:
373 _rDefault
<<= static_cast<sal_Int32
>(1);
375 case PROPERTY_ID_ESCAPE_PROCESSING
:
376 _rDefault
<<= sal_True
;
378 case PROPERTY_ID_MAXROWS
:
379 _rDefault
<<= sal_Int32( 0 );
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();
392 // -------------------------------------------------------------------------
393 // typedef ::comphelper::OPropertyArrayUsageHelper<ORowSet> ORowSet_Prop;
395 void SAL_CALL
ORowSet::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
) throw (Exception
)
399 case PROPERTY_ID_ISMODIFIED
:
400 m_bModified
= cppu::any2bool(rValue
);
402 case PROPERTY_ID_FETCHDIRECTION
:
403 if( m_nResultSetType
== ResultSetType::FORWARD_ONLY
)
404 throw Exception(); // else run through
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
;
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
;
440 case PROPERTY_ID_DATASOURCENAME
:
441 if(!m_xStatement
.is())
443 Reference
< XConnection
> xNewConn
;
445 aNewConn
<<= xNewConn
;
446 setFastPropertyValue(PROPERTY_ID_ACTIVE_CONNECTION
, aNewConn
);
449 m_bRebuildConnOnExecute
= sal_True
;
451 case PROPERTY_ID_FETCHSIZE
:
454 m_pCache
->setMaxRowSize(m_nFetchSize
);
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
;
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
;
470 aNewConn
<<= xNewConn
;
471 setFastPropertyValue(PROPERTY_ID_ACTIVE_CONNECTION
, aNewConn
);
474 m_bOwnConnection
= sal_True
;
476 case PROPERTY_ID_TYPEMAP
:
477 ::cppu::extractInterface(m_xTypeMap
,m_aTypeMap
);
483 // -------------------------------------------------------------------------
484 void SAL_CALL
ORowSet::getFastPropertyValue(Any
& rValue
,sal_Int32 nHandle
) const
490 case PROPERTY_ID_ISMODIFIED
:
491 rValue
.setValue(&m_bModified
,::getCppuBooleanType());
493 case PROPERTY_ID_ISNEW
:
494 rValue
.setValue(&m_bNew
,::getCppuBooleanType());
496 case PROPERTY_ID_PRIVILEGES
:
497 rValue
<<= m_pCache
->m_nPrivileges
;
499 case PROPERTY_ID_ACTIVE_CONNECTION
:
500 rValue
<<= m_xActiveConnection
;
502 case PROPERTY_ID_TYPEMAP
:
503 rValue
<<= m_xTypeMap
;
506 ORowSetBase::getFastPropertyValue(rValue
,nHandle
);
513 case PROPERTY_ID_ACTIVE_CONNECTION
:
514 rValue
<<= m_xActiveConnection
;
516 case PROPERTY_ID_TYPEMAP
:
517 rValue
<<= m_xTypeMap
;
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;
540 MutexGuard
aGuard( Mutex::getGlobalMutex() );
543 static OImplementationId 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);
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
);
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
;
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 // -------------------------------------------------------------------------
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
);
641 Reference
<XEventListener
> xEvt
;
642 query_aggregation(this,xEvt
);
643 xComponent
->removeEventListener(xEvt
);
646 m_aActiveConnection
= Any(); // the any conatains a reference too
648 ::comphelper::disposeComponent(m_xActiveConnection
);
649 m_xActiveConnection
= NULL
;
652 ORowSetBase::disposing();
654 // -------------------------------------------------------------------------
655 void ORowSet::freeResources( bool _bComplete
)
657 MutexGuard
aGuard(m_aMutex
);
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
);
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
676 m_pColumns
->disposing();
677 // dispose the composer to avoid that everbody knows that the querycomposer is eol
678 try { ::comphelper::disposeComponent( m_xComposer
); }
681 DBG_UNHANDLED_EXCEPTION();
687 impl_resetTables_nothrow();
693 m_bBeforeFirst
= sal_True
;
694 m_bAfterLast
= 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())
715 // remove the event listener for the old connection
716 Reference
< XComponent
> xComponent(m_xActiveConnection
, UNO_QUERY
);
719 Reference
<XEventListener
> xListener
;
720 query_aggregation(this, xListener
);
721 xComponent
->removeEventListener(xListener
);
724 // if we owned the connection, remember it for later disposing
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
;
738 m_aActiveConnection
.clear();
742 fire(&nHandle
, &aNewConnection
, &aOldConnection
, 1, sal_False
);
744 // register as event listener for the new connection
745 xComponent
.set(m_xActiveConnection
,UNO_QUERY
);
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
)
764 MutexGuard
aGuard( m_aMutex
);
765 Reference
< XConnection
> xXConnection
;
766 setActiveConnection( xXConnection
);
770 // -------------------------------------------------------------------------
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 // -------------------------------------------------------------------------
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
);
898 Sequence
<sal_Int8
> aSeq
;
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();
939 Reference
<XPropertySet
> xColumn(m_pColumns
->getByIndex(columnIndex
-1),UNO_QUERY
);
940 sal_Int32 nColType
= 0;
941 xColumn
->getPropertyValue(PROPERTY_TYPE
) >>= nColType
;
946 case DataType::TIMESTAMP
:
951 if ( DataType::TIMESTAMP
== nColType
)
952 aNewValue
<<= dbtools::DBTypeConversion::toDateTime( nValue
);
953 else if ( DataType::DATE
== nColType
)
954 aNewValue
<<= dbtools::DBTypeConversion::toDate( nValue
);
956 aNewValue
<<= dbtools::DBTypeConversion::toTime( nValue
);
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 // -------------------------------------------------------------------------
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);
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
1022 setCurrentRow( sal_False
, sal_True
, aOldValues
, aGuard
); // we don't move here
1025 notifyAllListenersRowChanged(aGuard
,aEvt
);
1029 fireProperty(PROPERTY_ID_ISMODIFIED
,sal_False
,sal_True
);
1030 OSL_ENSURE( !m_bModified
, "ORowSet::insertRow: just updated, but _still_ modified?" );
1034 fireProperty(PROPERTY_ID_ISNEW
,m_bNew
,bOld
);
1036 // - RowCount/IsRowCountFinal
1040 // -------------------------------------------------------------------------
1041 sal_Int32 SAL_CALL
ORowSet::getRow( ) throw(SQLException
, RuntimeException
)
1043 ::osl::MutexGuard
aGuard( *m_pMutex
);
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);
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
1075 ORowSetBase::firePropertyChange(aOldValues
);
1078 notifyAllListenersRowChanged(aGuard
,aEvt
);
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
);
1094 if ( m_bBeforeFirst
|| m_bAfterLast
)
1095 throwSQLException( "Cannot delete the before-first or after-last row.", SQL_INVALID_CURSOR_POSITION
, *this );
1098 throwSQLException( "Cannot delete the insert-row.", SQL_INVALID_CURSOR_POSITION
, *this );
1100 if ( m_nResultSetConcurrency
== ResultSetConcurrency::READ_ONLY
)
1101 throwSQLException( "Result set is read only.", SQL_FUNCTION_SEQUENCE_ERROR
, *this );
1103 if ( ( m_pCache
->m_nPrivileges
& Privilege::DELETE
) != Privilege::DELETE
)
1104 throwSQLException( "DELETE privilege not available.", SQL_FUNCTION_SEQUENCE_ERROR
, *this );
1107 throwSQLException( "Current row already deleted.", SQL_FUNCTION_SEQUENCE_ERROR
, *this );
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
1132 notifyAllListenersRowChanged(aGuard
,aEvt
);
1138 // - RowCount/IsRowCountFinal
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
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
1173 ORowSetBase::firePropertyChange(aOldValues
);
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
);
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
);
1201 m_aRowsetListeners
.removeInterface(listener
);
1203 // -----------------------------------------------------------------------------
1204 void ORowSet::notifyAllListeners(::osl::ResettableMutexGuard
& _rGuard
)
1206 EventObject
aEvt(*m_pMySelf
);
1208 m_aRowsetListeners
.notifyEach( &XRowSetListener::rowSetChanged
, aEvt
);
1211 // -------------------------------------------------------------------------
1212 void ORowSet::notifyAllListenersCursorMoved(::osl::ResettableMutexGuard
& _rGuard
)
1214 EventObject
aEvt(*m_pMySelf
);
1216 m_aRowsetListeners
.notifyEach( &XRowSetListener::cursorMoved
, aEvt
);
1219 // -------------------------------------------------------------------------
1220 void ORowSet::notifyAllListenersRowChanged(::osl::ResettableMutexGuard
& _rGuard
, const EventObject
& aEvt
)
1223 m_aRowsetListeners
.notifyEach( &XRowSetListener::rowChanged
, aEvt
);
1226 // -------------------------------------------------------------------------
1227 sal_Bool
ORowSet::notifyAllListenersCursorBeforeMove(::osl::ResettableMutexGuard
& _rGuard
)
1229 EventObject
aEvt(*m_pMySelf
);
1230 NOTIFY_LISTERNERS_CHECK(m_aApproveListeners
,XRowSetApproveListener
,approveCursorMove
);
1233 // -------------------------------------------------------------------------
1234 void ORowSet::notifyAllListenersRowBeforeChange(::osl::ResettableMutexGuard
& _rGuard
,const RowChangeEvent
&aEvt
)
1236 NOTIFY_LISTERNERS_CHECK(m_aApproveListeners
,XRowSetApproveListener
,approveRowChange
);
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
;
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
;
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 );
1275 if ( notifyAllListenersCursorBeforeMove( aGuard
) )
1277 // remember old value for fire
1278 ORowSetRow aOldValues
;
1281 positionCache( MOVE_FORWARD
);
1283 setCurrentRow( sal_True
, sal_False
, aOldValues
, aGuard
);
1286 positionCache( MOVE_NONE_REFRESH_ONLY
);
1288 // check before because the resultset could be empty
1289 if ( !m_bBeforeFirst
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
1304 ORowSetBase::firePropertyChange(aOldValues
);
1307 notifyAllListenersCursorMoved(aGuard
);
1310 if ( bModState
!= m_bModified
)
1311 fireProperty( PROPERTY_ID_ISMODIFIED
, m_bModified
, bModState
);
1314 if ( bNewState
!= m_bNew
)
1315 fireProperty( PROPERTY_ID_ISNEW
, m_bNew
, bNewState
);
1317 // - RowCount/IsRowCountFinal
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
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 );
1342 if ( notifyAllListenersCursorBeforeMove( aGuard
) )
1344 positionCache( MOVE_NONE_REFRESH_ONLY
);
1346 ORowSetNotifier
aNotifier( this );
1348 // notification order
1350 notifyAllListenersCursorMoved(aGuard
);
1357 // -------------------------------------------------------------------------
1359 sal_Bool SAL_CALL
ORowSet::wasNull( ) throw(SQLException
, RuntimeException
)
1361 ::osl::MutexGuard
aGuard( *m_pMutex
);
1364 return ( m_pCache
&& isInsertRow() ) ? ((*m_pCache
->m_aInsertRow
)->get())[m_nLastColumnIndex
].isNull() : ORowSetBase::wasNull();
1366 // -----------------------------------------------------------------------------
1367 const ORowSetValue
& ORowSet::getInsertValue(sal_Int32 columnIndex
)
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() )
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() )
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())
1504 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper
.bDisposed
);
1506 // tell everybody that we will change the result set
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
&)
1540 catch(RuntimeException
&)
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
& )
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 // -------------------------------------------------------------------------
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
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
;
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
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
)
1675 if ( nResultSetConcurrency
> _nDesiredResultSetConcurrency
)
1678 if ( xMeta
.is() && xMeta
->supportsResultSetConcurrency( nResultSetType
, nResultSetConcurrency
) )
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." ) );
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(); }
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
) );
1790 DBG_UNHANDLED_EXCEPTION();
1794 if ( bHaveAnyColumnSetting
)
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
) )
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
) )
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
) )
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
;
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();
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
++);
1926 ORowSetDataColumn
* pColumn
= new ORowSetDataColumn( getMetaData(),
1930 m_xActiveConnection
->getMetaData(),
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
);
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
));
1958 catch (SQLException
&)
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() )
1987 bReFetchName
= sal_True
;
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
;
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(),
2019 m_xActiveConnection
->getMetaData(),
2022 aColumns
->get().push_back(pColumn
);
2023 if(!sName
.getLength())
2026 xColumn
->getPropertyValue(PROPERTY_NAME
) >>= sName
;
2028 sName
= ::rtl::OUString::createFromAscii("Expression1");
2031 pColumn
->setName(sName
);
2032 aNames
.push_back(sName
);
2033 m_aDataColumns
.push_back(pColumn
);
2036 impl_initializeColumnSettings_nothrow( xColumn
, pColumn
);
2040 // now create the columns we need
2042 m_pColumns
->assign(aColumns
,aNames
);
2045 Reference
<XDatabaseMetaData
> xMeta
= m_xActiveConnection
->getMetaData();
2046 m_pColumns
= new ORowSetDataColumns(xMeta
.is() && xMeta
->supportsMixedCaseQuotedIdentifiers(),
2047 aColumns
,*this,m_aColumnsMutex
,aNames
);
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 // -------------------------------------------------------------------------
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
));
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
)
2119 if ( !m_pCache
->moveToBookmark( *row
) )
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() )
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
2140 notifyAllListenersRowChanged(aGuard
,aEvt
);
2146 // - RowCount/IsRowCountFinal
2151 // -----------------------------------------------------------------------------
2152 void ORowSet::notifyRowSetAndClonesRowDelete( const Any
& _rBookmark
)
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
);
2163 ORowSetClone
* pClone
= reinterpret_cast<ORowSetClone
*>(xTunnel
->getSomething(ORowSetClone::getUnoTunnelImplementationId()));
2165 pClone
->onDeleteRow( _rBookmark
);
2169 //------------------------------------------------------------------------------
2170 void ORowSet::notifyRowSetAndClonesRowDeleted( const Any
& _rBookmark
, sal_Int32 _nPos
)
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
);
2181 ORowSetClone
* pClone
= reinterpret_cast<ORowSetClone
*>(xTunnel
->getSomething(ORowSetClone::getUnoTunnelImplementationId()));
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() )
2205 Reference
< XCompletedConnection
> xComplConn(xNamingContext
->getByName(m_aDataSourceName
), UNO_QUERY
);
2207 xNewConn
= xComplConn
->connectWithCompletion(_rxHandler
);
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
)
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
;
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
>());
2271 //------------------------------------------------------------------------------
2272 void ORowSet::impl_resetTables_nothrow()
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
)
2370 if ( e
.TargetException
>>= e2
)
2375 DBG_UNHANDLED_EXCEPTION();
2378 Reference
<XColumnsSupplier
> xSup(xTable
,UNO_QUERY
);
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
);
2389 String
sMessage( DBACORE_RESSTRING( RID_STR_TABLE_DOES_NOT_EXIST
) );
2390 sMessage
.SearchAndReplaceAscii( "$table$", m_aCommand
);
2391 throwGenericSQLException(sMessage
,*this);
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!");
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
);
2420 m_xColumns
= xSup
->getColumns();
2425 String
sMessage( DBACORE_RESSTRING( RID_STR_QUERY_DOES_NOT_EXIST
) );
2426 sMessage
.SearchAndReplaceAscii( "$table$", m_aCommand
);
2427 throwGenericSQLException(sMessage
,*this);
2431 throw SQLException(DBA_RES(RID_STR_NO_XQUERIESSUPPLIER
),*this,::rtl::OUString(),0,Any());
2436 sCommand
= m_aCommand
;
2440 m_aActiveCommand
= sCommand
;
2442 if ( !m_aActiveCommand
.getLength() )
2443 throwSQLException( "No SQL command was provided.", SQL_FUNCTION_SEQUENCE_ERROR
, *this );
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() )
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 // -------------------------------------------------------------------------
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
;
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
);
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( )
2718 // -----------------------------------------------------------------------------
2719 sal_Bool
ORowSet::isModified( )
2724 // -----------------------------------------------------------------------------
2725 sal_Bool
ORowSet::isNew( )
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
)
2746 if ( columnIndex
<= 0 )
2747 throwSQLException( "Invalid column index", SQL_INVALID_DESCRIPTOR_INDEX
, *this );
2750 throwSQLException( "Current row is deleted", SQL_INVALID_CURSOR_POSITION
, *this );
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 );
2758 if ( m_nResultSetConcurrency
== ResultSetConcurrency::READ_ONLY
)
2759 throwSQLException( "Result set is not writeable", SQL_GENERAL_ERROR
, *this );
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
)
2772 implCancelRowUpdates( sal_False
); // do _not_ notify the IsModify - will do this ourself below
2774 ORowSetBase::refreshRow();
2780 // ***********************************************************
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
;
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();
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(),
2832 rParent
.m_xActiveConnection
->getMetaData(),
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
);
2890 //------------------------------------------------------------------------------
2891 void ORowSetClone::acquire() throw()
2893 OSubComponent::acquire();
2896 //------------------------------------------------------------------------------
2897 void ORowSetClone::release() throw()
2899 OSubComponent::release();
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
;
2925 //------------------------------------------------------------------------------
2926 void ORowSetClone::disposing()
2928 MutexGuard
aGuard( m_aMutex
);
2929 ORowSetBase::disposing();
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();
2937 //------------------------------------------------------------------------------
2938 void ORowSetClone::close(void) throw( SQLException
, RuntimeException
)
2941 MutexGuard
aGuard( m_aMutex
);
2942 if (OComponentHelper::rBHelper
.bDisposed
)
2943 throw DisposedException();
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;
2971 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
2974 static ::cppu::OImplementationId 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);
2989 // -----------------------------------------------------------------------------
2990 void SAL_CALL
ORowSetClone::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
) throw (Exception
)
2992 if ( nHandle
== PROPERTY_ID_FETCHSIZE
)
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( )
3013 // -----------------------------------------------------------------------------
3014 sal_Bool
ORowSetClone::isModified( )
3019 // -----------------------------------------------------------------------------
3020 sal_Bool
ORowSetClone::isNew( )
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 );