Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "RowSetBase.hxx"
22 : #include "CRowSetDataColumn.hxx"
23 : #include <connectivity/sdbcx/VCollection.hxx>
24 : #include "RowSetCache.hxx"
25 : #include "dbastrings.hrc"
26 : #include "core_resource.hrc"
27 : #include <com/sun/star/lang/DisposedException.hpp>
28 : #include <com/sun/star/beans/PropertyAttribute.hpp>
29 : #include <com/sun/star/sdbcx/CompareBookmark.hpp>
30 : #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
31 : #include <com/sun/star/lang/Locale.hpp>
32 : #include <com/sun/star/util/NumberFormat.hpp>
33 : #include <comphelper/sequence.hxx>
34 : #include <comphelper/extract.hxx>
35 : #include <comphelper/seqstream.hxx>
36 : #include <connectivity/dbexception.hxx>
37 : #include <osl/thread.h>
38 : #include <tools/debug.hxx>
39 : #include <rtl/logfile.hxx>
40 :
41 : using namespace dbaccess;
42 : using namespace connectivity;
43 : using namespace connectivity::sdbcx;
44 : using namespace comphelper;
45 : using namespace dbtools;
46 : using namespace ::com::sun::star::uno;
47 : using namespace ::com::sun::star::beans;
48 : using namespace ::com::sun::star::sdbc;
49 : using namespace ::com::sun::star::sdb;
50 : using namespace ::com::sun::star::sdbcx;
51 : using namespace ::com::sun::star::container;
52 : using namespace ::com::sun::star::lang;
53 : using namespace ::com::sun::star::util;
54 : using namespace ::cppu;
55 : using namespace ::osl;
56 :
57 : namespace dbaccess
58 : {
59 :
60 : // =========================================================================
61 : // = OEmptyCollection
62 : // =========================================================================
63 0 : class OEmptyCollection : public sdbcx::OCollection
64 : {
65 : protected:
66 : virtual void impl_refresh() throw(RuntimeException);
67 : virtual connectivity::sdbcx::ObjectType createObject(const ::rtl::OUString& _rName);
68 : public:
69 0 : OEmptyCollection(::cppu::OWeakObject& _rParent,::osl::Mutex& _rMutex) : OCollection(_rParent,sal_True,_rMutex,::std::vector< ::rtl::OUString>()){}
70 : };
71 :
72 0 : void OEmptyCollection::impl_refresh() throw(RuntimeException)
73 : {
74 0 : }
75 :
76 0 : connectivity::sdbcx::ObjectType OEmptyCollection::createObject(const ::rtl::OUString& /*_rName*/)
77 : {
78 0 : return connectivity::sdbcx::ObjectType();
79 : }
80 :
81 : // =========================================================================
82 : // = ORowSetBase
83 : // =========================================================================
84 : DBG_NAME(ORowSetBase)
85 :
86 4 : ORowSetBase::ORowSetBase( const ::comphelper::ComponentContext& _rContext, ::cppu::OBroadcastHelper& _rBHelper, ::osl::Mutex* _pMutex )
87 : :OPropertyStateContainer(_rBHelper)
88 : ,m_pMutex(_pMutex)
89 : ,m_pCache(NULL)
90 : ,m_pColumns(NULL)
91 : ,m_rBHelper(_rBHelper)
92 : ,m_pEmptyCollection( NULL )
93 : ,m_aContext( _rContext )
94 : ,m_aErrors( _rContext.getUNOContext() )
95 : ,m_nLastColumnIndex(-1)
96 : ,m_nDeletedPosition(-1)
97 : ,m_nResultSetType( ResultSetType::FORWARD_ONLY )
98 : ,m_nResultSetConcurrency( ResultSetConcurrency::READ_ONLY )
99 : ,m_bClone(sal_False)
100 : ,m_bIgnoreResult(sal_False)
101 : ,m_bBeforeFirst(sal_True) // changed from sal_False
102 : ,m_bAfterLast(sal_False)
103 4 : ,m_bIsInsertRow(sal_False)
104 : {
105 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::ORowSetBase" );
106 : DBG_CTOR(ORowSetBase,NULL);
107 :
108 4 : sal_Int32 nRBT = PropertyAttribute::READONLY | PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT;
109 :
110 4 : sal_Int32 nInitialRowCountValue = 0;
111 4 : sal_Bool bInitialRowCountFinalValue( sal_False );
112 4 : registerPropertyNoMember( PROPERTY_ROWCOUNT, PROPERTY_ID_ROWCOUNT, nRBT, ::getCppuType( &nInitialRowCountValue ), &nInitialRowCountValue );
113 4 : registerPropertyNoMember( PROPERTY_ISROWCOUNTFINAL, PROPERTY_ID_ISROWCOUNTFINAL, nRBT, ::getBooleanCppuType(), &bInitialRowCountFinalValue );
114 4 : }
115 :
116 4 : ORowSetBase::~ORowSetBase()
117 : {
118 2 : if(m_pColumns)
119 : {
120 0 : TDataColumns().swap(m_aDataColumns);
121 0 : m_pColumns->acquire();
122 0 : m_pColumns->disposing();
123 0 : delete m_pColumns;
124 0 : m_pColumns = NULL;
125 : }
126 :
127 2 : if ( m_pEmptyCollection )
128 0 : delete m_pEmptyCollection;
129 :
130 : DBG_DTOR(ORowSetBase,NULL);
131 2 : }
132 :
133 : // com::sun::star::lang::XTypeProvider
134 0 : Sequence< Type > ORowSetBase::getTypes() throw (RuntimeException)
135 : {
136 : //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getTypes" );
137 0 : return ::comphelper::concatSequences(ORowSetBase_BASE::getTypes(),OPropertyStateContainer::getTypes());
138 : }
139 :
140 : // com::sun::star::uno::XInterface
141 52 : Any ORowSetBase::queryInterface( const Type & rType ) throw (RuntimeException)
142 : {
143 : //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::queryInterface" );
144 52 : Any aRet = ORowSetBase_BASE::queryInterface(rType);
145 52 : if(!aRet.hasValue())
146 44 : aRet = OPropertyStateContainer::queryInterface(rType);
147 52 : return aRet;
148 : }
149 :
150 2 : void SAL_CALL ORowSetBase::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const
151 : {
152 : //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getFastPropertyValue" );
153 2 : if(m_pCache)
154 : {
155 0 : switch(nHandle)
156 : {
157 : case PROPERTY_ID_ROWCOUNT:
158 0 : rValue <<= impl_getRowCount();
159 0 : break;
160 : case PROPERTY_ID_ISROWCOUNTFINAL:
161 0 : rValue.setValue(&m_pCache->m_bRowCountFinal,::getCppuBooleanType());
162 0 : break;
163 : default:
164 0 : OPropertyStateContainer::getFastPropertyValue(rValue,nHandle);
165 : };
166 : }
167 : else
168 2 : OPropertyStateContainer::getFastPropertyValue(rValue,nHandle);
169 2 : }
170 :
171 : // OComponentHelper
172 3 : void SAL_CALL ORowSetBase::disposing(void)
173 : {
174 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::disposing" );
175 3 : MutexGuard aGuard(*m_pMutex);
176 :
177 3 : if ( m_pColumns )
178 : {
179 0 : TDataColumns().swap(m_aDataColumns);
180 0 : m_pColumns->disposing();
181 : }
182 3 : if ( m_pCache )
183 : {
184 0 : m_pCache->deregisterOldRow(m_aOldRow);
185 0 : m_pCache->deleteIterator(this);
186 : }
187 3 : m_pCache = NULL;
188 3 : }
189 :
190 : // comphelper::OPropertyArrayUsageHelper
191 0 : ::cppu::IPropertyArrayHelper* ORowSetBase::createArrayHelper( ) const
192 : {
193 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::createArrayHelper" );
194 0 : Sequence< Property > aProps;
195 0 : describeProperties(aProps);
196 0 : return new ::cppu::OPropertyArrayHelper(aProps);
197 : }
198 :
199 : // cppu::OPropertySetHelper
200 0 : ::cppu::IPropertyArrayHelper& SAL_CALL ORowSetBase::getInfoHelper()
201 : {
202 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getInfoHelper" );
203 0 : return *const_cast<ORowSetBase*>(this)->getArrayHelper();
204 : }
205 :
206 : // XRow
207 0 : sal_Bool SAL_CALL ORowSetBase::wasNull( ) throw(SQLException, RuntimeException)
208 : {
209 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::wasNull" );
210 0 : ::osl::MutexGuard aGuard( *m_pMutex );
211 0 : checkCache();
212 0 : return impl_wasNull();
213 : }
214 :
215 0 : sal_Bool ORowSetBase::impl_wasNull()
216 : {
217 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::impl_wasNull" );
218 0 : return ((m_nLastColumnIndex != -1) && !m_aCurrentRow.isNull() && m_aCurrentRow != m_pCache->getEnd() && m_aCurrentRow->is()) ? ((*m_aCurrentRow)->get())[m_nLastColumnIndex].isNull() : sal_True;
219 : }
220 :
221 0 : const ORowSetValue& ORowSetBase::getValue(sal_Int32 columnIndex)
222 : {
223 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getValue" );
224 0 : checkCache();
225 0 : return impl_getValue(columnIndex);
226 : }
227 :
228 0 : const ORowSetValue& ORowSetBase::impl_getValue(sal_Int32 columnIndex)
229 : {
230 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::impl_getValue" );
231 0 : if ( m_bBeforeFirst || m_bAfterLast )
232 : {
233 : OSL_FAIL("ORowSetBase::getValue: Illegal call here (we're before first or after last)!");
234 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_CURSOR_BEFORE_OR_AFTER ), SQL_INVALID_CURSOR_POSITION, *m_pMySelf );
235 : }
236 :
237 0 : if ( impl_rowDeleted() )
238 : {
239 0 : return m_aEmptyValue;
240 : }
241 :
242 0 : bool bValidCurrentRow = ( !m_aCurrentRow.isNull() && m_aCurrentRow != m_pCache->getEnd() && m_aCurrentRow->is() );
243 0 : if ( !bValidCurrentRow )
244 : {
245 : // currentrow is null when the clone moves the window
246 0 : positionCache( MOVE_NONE_REFRESH_ONLY );
247 0 : m_aCurrentRow = m_pCache->m_aMatrixIter;
248 0 : m_bIsInsertRow = sal_False;
249 : OSL_ENSURE(!m_aCurrentRow.isNull(),"ORowSetBase::getValue: we don't stand on a valid row! Row is null.");
250 :
251 0 : bValidCurrentRow = ( !m_aCurrentRow.isNull() && m_aCurrentRow != m_pCache->getEnd() && m_aCurrentRow->is() );
252 : }
253 :
254 0 : if ( bValidCurrentRow )
255 : {
256 : #if OSL_DEBUG_LEVEL > 0
257 : ORowSetMatrix::iterator aCacheEnd;
258 : ORowSetMatrix::iterator aCurrentRow;
259 : aCacheEnd = m_pCache->getEnd();
260 : aCurrentRow = m_aCurrentRow;
261 : ORowSetCacheMap::iterator aCacheIter = m_aCurrentRow.getIter();
262 : ORowSetCacheIterator_Helper aHelper = aCacheIter->second;
263 : ORowSetMatrix::iterator k = aHelper.aIterator;
264 : for (; k != m_pCache->getEnd(); ++k)
265 : {
266 : ORowSetValueVector* pTemp = k->get();
267 : OSL_ENSURE( pTemp != (void*)0xfeeefeee,"HALT!" );
268 : }
269 : #endif
270 : OSL_ENSURE(!m_aCurrentRow.isNull() && m_aCurrentRow < m_pCache->getEnd() && aCacheIter != m_pCache->m_aCacheIterators.end(),"Invalid iterator set for currentrow!");
271 : #if OSL_DEBUG_LEVEL > 0
272 : ORowSetRow rRow = (*m_aCurrentRow);
273 : OSL_ENSURE(rRow.is() && static_cast<sal_uInt16>(columnIndex) < (rRow->get()).size(),"Invalid size of vector!");
274 : #endif
275 0 : return ((*m_aCurrentRow)->get())[m_nLastColumnIndex = columnIndex];
276 : }
277 :
278 : // we should normally never reach this
279 0 : return m_aEmptyValue;
280 : }
281 :
282 0 : ::rtl::OUString SAL_CALL ORowSetBase::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
283 : {
284 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getString" );
285 0 : ::osl::MutexGuard aGuard( *m_pMutex );
286 0 : return getValue(columnIndex);
287 : }
288 :
289 0 : sal_Bool SAL_CALL ORowSetBase::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
290 : {
291 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getBoolean" );
292 0 : ::osl::MutexGuard aGuard( *m_pMutex );
293 0 : return getValue(columnIndex);
294 : }
295 :
296 0 : sal_Int8 SAL_CALL ORowSetBase::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
297 : {
298 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getByte" );
299 0 : ::osl::MutexGuard aGuard( *m_pMutex );
300 0 : return getValue(columnIndex);
301 : }
302 :
303 0 : sal_Int16 SAL_CALL ORowSetBase::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
304 : {
305 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getShort" );
306 0 : ::osl::MutexGuard aGuard( *m_pMutex );
307 0 : return getValue(columnIndex);
308 : }
309 :
310 0 : sal_Int32 SAL_CALL ORowSetBase::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
311 : {
312 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getInt" );
313 0 : ::osl::MutexGuard aGuard( *m_pMutex );
314 0 : return getValue(columnIndex);
315 : }
316 :
317 0 : sal_Int64 SAL_CALL ORowSetBase::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
318 : {
319 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getLong" );
320 0 : ::osl::MutexGuard aGuard( *m_pMutex );
321 0 : return getValue(columnIndex);
322 : }
323 :
324 0 : float SAL_CALL ORowSetBase::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
325 : {
326 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getFloat" );
327 0 : ::osl::MutexGuard aGuard( *m_pMutex );
328 0 : return getValue(columnIndex);
329 : }
330 :
331 0 : double SAL_CALL ORowSetBase::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
332 : {
333 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getDouble" );
334 0 : ::osl::MutexGuard aGuard( *m_pMutex );
335 0 : return getValue(columnIndex);
336 : }
337 :
338 0 : Sequence< sal_Int8 > SAL_CALL ORowSetBase::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
339 : {
340 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getBytes" );
341 0 : ::osl::MutexGuard aGuard( *m_pMutex );
342 0 : return getValue(columnIndex);
343 : }
344 :
345 0 : ::com::sun::star::util::Date SAL_CALL ORowSetBase::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
346 : {
347 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getDate" );
348 0 : ::osl::MutexGuard aGuard( *m_pMutex );
349 0 : return getValue(columnIndex);
350 : }
351 :
352 0 : ::com::sun::star::util::Time SAL_CALL ORowSetBase::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
353 : {
354 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getTime" );
355 0 : ::osl::MutexGuard aGuard( *m_pMutex );
356 0 : return getValue(columnIndex);
357 : }
358 :
359 0 : ::com::sun::star::util::DateTime SAL_CALL ORowSetBase::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
360 : {
361 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getTimestamp" );
362 0 : ::osl::MutexGuard aGuard( *m_pMutex );
363 0 : return getValue(columnIndex);
364 : }
365 :
366 0 : Reference< ::com::sun::star::io::XInputStream > SAL_CALL ORowSetBase::getBinaryStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
367 : {
368 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getBinaryStream" );
369 0 : ::osl::MutexGuard aGuard( *m_pMutex );
370 0 : checkCache();
371 :
372 0 : if ( m_bBeforeFirst || m_bAfterLast )
373 : {
374 : OSL_FAIL("ORowSetBase::getBinaryStream: Illegal call here (we're before first or after last)!");
375 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_CURSOR_BEFORE_OR_AFTER ), SQL_INVALID_CURSOR_POSITION, *m_pMySelf );
376 : }
377 :
378 0 : if ( impl_rowDeleted() )
379 : {
380 0 : return NULL;
381 : }
382 :
383 0 : bool bValidCurrentRow = ( !m_aCurrentRow.isNull() && m_aCurrentRow != m_pCache->getEnd() && m_aCurrentRow->is() );
384 0 : if ( !bValidCurrentRow )
385 : {
386 0 : positionCache( MOVE_NONE_REFRESH_ONLY );
387 0 : m_aCurrentRow = m_pCache->m_aMatrixIter;
388 0 : m_bIsInsertRow = sal_False;
389 : OSL_ENSURE(!m_aCurrentRow.isNull(),"ORowSetBase::getBinaryStream: we don't stand on a valid row! Row is null.");
390 :
391 0 : bValidCurrentRow = ( !m_aCurrentRow.isNull() && m_aCurrentRow != m_pCache->getEnd() && m_aCurrentRow->is() );
392 : }
393 :
394 0 : if ( bValidCurrentRow )
395 0 : return new ::comphelper::SequenceInputStream(((*m_aCurrentRow)->get())[m_nLastColumnIndex = columnIndex].getSequence());
396 :
397 : // we should normally never reach this
398 0 : return Reference< ::com::sun::star::io::XInputStream >();
399 : }
400 :
401 0 : Reference< ::com::sun::star::io::XInputStream > SAL_CALL ORowSetBase::getCharacterStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
402 : {
403 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getCharacterStream" );
404 0 : return getBinaryStream(columnIndex);
405 : }
406 :
407 0 : Any SAL_CALL ORowSetBase::getObject( sal_Int32 columnIndex, const Reference< XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
408 : {
409 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getObject" );
410 0 : ::osl::MutexGuard aGuard( *m_pMutex );
411 0 : checkCache();
412 :
413 0 : return getValue(columnIndex).makeAny();
414 : }
415 :
416 0 : Reference< XRef > SAL_CALL ORowSetBase::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
417 : {
418 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getRef" );
419 0 : ::dbtools::throwFeatureNotImplementedException( "XRow::getRef", *m_pMySelf );
420 0 : return NULL;
421 : }
422 :
423 0 : Reference< XBlob > SAL_CALL ORowSetBase::getBlob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
424 : {
425 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getBlob" );
426 0 : return Reference< XBlob >(getValue(columnIndex).makeAny(),UNO_QUERY);
427 : }
428 :
429 0 : Reference< XClob > SAL_CALL ORowSetBase::getClob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
430 : {
431 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getClob" );
432 0 : return Reference< XClob >(getValue(columnIndex).makeAny(),UNO_QUERY);
433 : }
434 :
435 0 : Reference< XArray > SAL_CALL ORowSetBase::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
436 : {
437 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getArray" );
438 0 : ::dbtools::throwFeatureNotImplementedException( "XRow::getArray", *m_pMySelf );
439 0 : return NULL;
440 : }
441 :
442 : // ::com::sun::star::sdbcx::XRowLocate
443 0 : Any SAL_CALL ORowSetBase::getBookmark( ) throw(SQLException, RuntimeException)
444 : {
445 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getBookmark" );
446 : OSL_TRACE("DBACCESS ORowSetBase::getBookmark() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
447 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
448 0 : ::osl::MutexGuard aGuard( *m_pMutex );
449 0 : checkCache();
450 :
451 0 : if ( m_bBeforeFirst || m_bAfterLast )
452 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_BOOKMARK_BEFORE_OR_AFTER ), SQL_INVALID_CURSOR_POSITION, *m_pMySelf );
453 :
454 0 : if ( impl_rowDeleted() )
455 0 : ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_BOOKMARK_DELETED ), SQL_INVALID_CURSOR_POSITION, *m_pMySelf );
456 :
457 : OSL_ENSURE( m_aBookmark.hasValue(), "ORowSetBase::getBookmark: bookmark has no value!" );
458 0 : return m_aBookmark;
459 : }
460 :
461 0 : sal_Bool SAL_CALL ORowSetBase::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
462 : {
463 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::moveToBookmark" );
464 : OSL_TRACE("DBACCESS ORowSetBase::moveToBookmark(Any) Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
465 : OSL_ENSURE(bookmark.hasValue(),"ORowSetBase::moveToBookmark bookmark has no value!");
466 0 : ::osl::ResettableMutexGuard aGuard( *m_pMutex );
467 :
468 0 : if(!bookmark.hasValue() || m_nResultSetType == ResultSetType::FORWARD_ONLY)
469 : {
470 0 : if(bookmark.hasValue())
471 : OSL_FAIL("MoveToBookmark is not possible when we are only forward");
472 : else
473 : OSL_FAIL("Bookmark is not valid");
474 0 : throwFunctionSequenceException(*m_pMySelf);
475 : }
476 :
477 :
478 0 : checkCache();
479 :
480 0 : sal_Bool bRet( notifyAllListenersCursorBeforeMove( aGuard ) );
481 0 : if ( bRet )
482 : {
483 : // check if we are inserting a row
484 0 : sal_Bool bWasNew = m_pCache->m_bNew || impl_rowDeleted();
485 :
486 0 : ORowSetNotifier aNotifier( this );
487 : // this will call cancelRowModification on the cache if necessary
488 :
489 0 : ORowSetRow aOldValues = getOldRow(bWasNew);
490 :
491 0 : bRet = m_pCache->moveToBookmark(bookmark);
492 0 : doCancelModification( );
493 0 : if(bRet)
494 : {
495 : // notification order
496 : // - column values
497 : // - cursorMoved
498 0 : setCurrentRow( sal_True, sal_True, aOldValues, aGuard );
499 : }
500 : else
501 : {
502 0 : movementFailed();
503 : }
504 :
505 : // - IsModified
506 : // - IsNew
507 0 : aNotifier.fire( );
508 : }
509 : OSL_TRACE("DBACCESS ORowSetBase::moveToBookmark(Any) = %i Clone = %i",bRet,m_bClone);
510 0 : return bRet;
511 : }
512 :
513 0 : sal_Bool SAL_CALL ORowSetBase::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException)
514 : {
515 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::moveRelativeToBookmark" );
516 : OSL_TRACE("DBACCESS ORowSetBase::moveRelativeToBookmark(Any,%i) Clone = %i",rows,m_bClone);
517 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
518 :
519 0 : ::osl::ResettableMutexGuard aGuard( *m_pMutex );
520 :
521 0 : checkPositioningAllowed();
522 :
523 0 : sal_Bool bRet( notifyAllListenersCursorBeforeMove( aGuard ) );
524 0 : if ( bRet )
525 : {
526 : // check if we are inserting a row
527 0 : sal_Bool bWasNew = m_pCache->m_bNew || rowDeleted();
528 :
529 0 : ORowSetNotifier aNotifier( this );
530 : // this will call cancelRowModification on the cache if necessary
531 :
532 0 : ORowSetRow aOldValues = getOldRow(bWasNew);
533 :
534 0 : bRet = m_pCache->moveRelativeToBookmark(bookmark,rows);
535 0 : doCancelModification( );
536 0 : if(bRet)
537 : {
538 : // notification order
539 : // - column values
540 : // - cursorMoved
541 0 : setCurrentRow( sal_True, sal_True, aOldValues, aGuard );
542 : }
543 : else
544 0 : movementFailed();
545 :
546 : // - IsModified
547 : // - IsNew
548 0 : aNotifier.fire( );
549 :
550 : // RowCount/IsRowCountFinal
551 0 : fireRowcount();
552 : }
553 : OSL_TRACE("DBACCESS ORowSetBase::moveRelativeToBookmark(Any,%i) = %i Clone = %i",rows,bRet,m_bClone);
554 0 : return bRet;
555 : }
556 :
557 0 : sal_Int32 SAL_CALL ORowSetBase::compareBookmarks( const Any& _first, const Any& _second ) throw(SQLException, RuntimeException)
558 : {
559 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::compareBookmarks" );
560 0 : ::osl::MutexGuard aGuard( *m_pMutex );
561 0 : checkCache();
562 0 : return m_pCache->compareBookmarks(_first,_second);
563 : }
564 :
565 0 : sal_Bool SAL_CALL ORowSetBase::hasOrderedBookmarks( ) throw(SQLException, RuntimeException)
566 : {
567 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::hasOrderedBookmarks" );
568 0 : ::osl::MutexGuard aGuard( *m_pMutex );
569 0 : checkCache();
570 0 : return m_pCache->hasOrderedBookmarks();
571 : }
572 :
573 0 : sal_Int32 SAL_CALL ORowSetBase::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
574 : {
575 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::hashBookmark" );
576 0 : ::osl::MutexGuard aGuard( *m_pMutex );
577 0 : checkCache();
578 0 : return m_pCache->hashBookmark(bookmark);
579 : }
580 :
581 : // XResultSetMetaDataSupplier
582 0 : Reference< XResultSetMetaData > SAL_CALL ORowSetBase::getMetaData( ) throw(SQLException, RuntimeException)
583 : {
584 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getMetaData" );
585 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
586 :
587 0 : Reference< XResultSetMetaData > xMeta;
588 0 : if(m_pCache)
589 0 : xMeta = m_pCache->getMetaData();
590 :
591 0 : return xMeta;
592 : }
593 :
594 : // XColumnLocate
595 0 : sal_Int32 SAL_CALL ORowSetBase::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException)
596 : {
597 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::findColumn" );
598 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
599 :
600 0 : ::osl::MutexGuard aGuard( m_aColumnsMutex );
601 : // it is possible to save some time here when we remember the names - position relation in a map
602 0 : return m_pColumns ? m_pColumns->findColumn(columnName) : sal_Int32(0);
603 : }
604 :
605 : // ::com::sun::star::sdbcx::XColumnsSupplier
606 0 : Reference< XNameAccess > SAL_CALL ORowSetBase::getColumns( ) throw(RuntimeException)
607 : {
608 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getColumns" );
609 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
610 :
611 0 : ::osl::MutexGuard aGuard( m_aColumnsMutex );
612 0 : if(!m_pColumns)
613 : {
614 0 : if (!m_pEmptyCollection)
615 0 : m_pEmptyCollection = new OEmptyCollection(*m_pMySelf,m_aColumnsMutex);
616 0 : return m_pEmptyCollection;
617 : }
618 :
619 0 : return m_pColumns;
620 : }
621 :
622 : // XResultSet
623 0 : sal_Bool SAL_CALL ORowSetBase::next( ) throw(SQLException, RuntimeException)
624 : {
625 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::next" );
626 : OSL_TRACE("DBACCESS ORowSetBase::next() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
627 0 : ::osl::ResettableMutexGuard aGuard( *m_pMutex );
628 0 : checkCache();
629 :
630 0 : sal_Bool bRet( notifyAllListenersCursorBeforeMove( aGuard ) );
631 0 : if ( bRet )
632 : {
633 : // check if we are inserting a row
634 0 : sal_Bool bWasNew = m_pCache->m_bNew || impl_rowDeleted();
635 :
636 0 : ORowSetNotifier aNotifier( this );
637 : // this will call cancelRowModification on the cache if necessary
638 :
639 0 : ORowSetRow aOldValues = getOldRow(bWasNew);
640 :
641 0 : positionCache( MOVE_FORWARD );
642 0 : sal_Bool bAfterLast = m_pCache->isAfterLast();
643 0 : bRet = m_pCache->next();
644 0 : doCancelModification( );
645 :
646 0 : if ( bRet || bAfterLast != m_pCache->isAfterLast() )
647 : {
648 : // notification order
649 : // - column values
650 : // - cursorMoved
651 0 : setCurrentRow( bRet, sal_True, aOldValues, aGuard );
652 : OSL_ENSURE(!m_bBeforeFirst,"BeforeFirst is true. I don't know why?");
653 : }
654 : else
655 : {
656 : // moved after the last row
657 0 : movementFailed();
658 : OSL_ENSURE(m_bAfterLast,"AfterLast is false. I don't know why?");
659 : }
660 :
661 : // - IsModified
662 : // - IsNew
663 0 : aNotifier.fire();
664 :
665 : // - RowCount/IsRowCountFinal
666 0 : fireRowcount();
667 : }
668 : OSL_TRACE("DBACCESS ORowSetBase::next() = %i Clone = %i ID = %i",bRet,m_bClone,osl_getThreadIdentifier(NULL));
669 0 : return bRet;
670 : }
671 :
672 0 : sal_Bool SAL_CALL ORowSetBase::isBeforeFirst( ) throw(SQLException, RuntimeException)
673 : {
674 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::isBeforeFirst" );
675 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
676 0 : ::osl::MutexGuard aGuard( *m_pMutex );
677 0 : checkCache();
678 :
679 : OSL_TRACE("DBACCESS ORowSetBase::isBeforeFirst() = %i Clone = %i",m_bBeforeFirst,m_bClone);
680 :
681 0 : return m_bBeforeFirst;
682 : }
683 :
684 0 : sal_Bool SAL_CALL ORowSetBase::isAfterLast( ) throw(SQLException, RuntimeException)
685 : {
686 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::isAfterLast" );
687 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
688 0 : ::osl::MutexGuard aGuard( *m_pMutex );
689 0 : checkCache();
690 : OSL_TRACE("DBACCESS ORowSetBase::isAfterLast() = %i Clone = %i",m_bAfterLast,m_bClone);
691 :
692 0 : return m_bAfterLast;
693 : }
694 :
695 0 : sal_Bool ORowSetBase::isOnFirst()
696 : {
697 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::isOnFirst" );
698 0 : return isFirst();
699 : }
700 :
701 0 : sal_Bool SAL_CALL ORowSetBase::isFirst( ) throw(SQLException, RuntimeException)
702 : {
703 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::isFirst" );
704 : OSL_TRACE("DBACCESS ORowSetBase::isFirst() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
705 :
706 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
707 0 : ::osl::MutexGuard aGuard( *m_pMutex );
708 0 : checkCache();
709 :
710 0 : if ( m_bBeforeFirst || m_bAfterLast )
711 0 : return sal_False;
712 :
713 0 : if ( impl_rowDeleted() )
714 0 : return ( m_nDeletedPosition == 1 );
715 :
716 0 : sal_Bool bIsFirst = m_pCache->isFirst();
717 :
718 : OSL_TRACE("DBACCESS ORowSetBase::isFirst() = %i Clone = %i",bIsFirst,m_bClone);
719 0 : return bIsFirst;
720 : }
721 :
722 0 : sal_Bool ORowSetBase::isOnLast()
723 : {
724 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::isOnLast" );
725 0 : return isLast();
726 : }
727 :
728 0 : sal_Bool SAL_CALL ORowSetBase::isLast( ) throw(SQLException, RuntimeException)
729 : {
730 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::isLast" );
731 : OSL_TRACE("DBACCESS ORowSetBase::isLast() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
732 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
733 0 : ::osl::MutexGuard aGuard( *m_pMutex );
734 0 : checkCache();
735 :
736 0 : if ( m_bBeforeFirst || m_bAfterLast )
737 0 : return sal_False;
738 :
739 0 : if ( impl_rowDeleted() )
740 : {
741 0 : if ( !m_pCache->m_bRowCountFinal )
742 0 : return sal_False;
743 : else
744 0 : return ( m_nDeletedPosition == impl_getRowCount() );
745 : }
746 :
747 0 : sal_Bool bIsLast = m_pCache->isLast();
748 :
749 : OSL_TRACE("DBACCESS ORowSetBase::isLast() = %i Clone = %i",bIsLast,m_bClone);
750 0 : return bIsLast;
751 : }
752 :
753 0 : void SAL_CALL ORowSetBase::beforeFirst( ) throw(SQLException, RuntimeException)
754 : {
755 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::beforeFirst" );
756 : OSL_TRACE("DBACCESS ORowSetBase::beforeFirst() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
757 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
758 0 : ::osl::ResettableMutexGuard aGuard( *m_pMutex );
759 :
760 0 : checkPositioningAllowed();
761 :
762 : // check if we are inserting a row
763 0 : sal_Bool bWasNew = m_pCache->m_bNew || impl_rowDeleted();
764 :
765 0 : if((bWasNew || !m_bBeforeFirst) && notifyAllListenersCursorBeforeMove(aGuard) )
766 : {
767 0 : ORowSetNotifier aNotifier( this );
768 : // this will call cancelRowModification on the cache if necessary
769 :
770 0 : if ( !m_bBeforeFirst )
771 : {
772 0 : ORowSetRow aOldValues = getOldRow(bWasNew);
773 0 : m_pCache->beforeFirst();
774 0 : doCancelModification( );
775 :
776 : // notification order
777 : // - column values
778 : // - cursorMoved
779 0 : setCurrentRow( sal_True, sal_True, aOldValues, aGuard );
780 :
781 : // - IsModified
782 : // - Isnew
783 0 : aNotifier.fire();
784 :
785 : // - RowCount/IsRowCountFinal
786 0 : fireRowcount();
787 : }
788 :
789 : // to be done _after_ the notifications!
790 0 : m_aOldRow->clearRow();
791 : }
792 0 : OSL_TRACE("DBACCESS ORowSetBase::beforeFirst() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
793 0 : }
794 :
795 0 : void SAL_CALL ORowSetBase::afterLast( ) throw(SQLException, RuntimeException)
796 : {
797 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::afterLast" );
798 : OSL_TRACE("DBACCESS ORowSetBase::afterLast() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
799 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
800 :
801 0 : ::osl::ResettableMutexGuard aGuard( *m_pMutex );
802 0 : checkPositioningAllowed();
803 :
804 0 : sal_Bool bWasNew = m_pCache->m_bNew || impl_rowDeleted();
805 :
806 0 : if((bWasNew || !m_bAfterLast) && notifyAllListenersCursorBeforeMove(aGuard) )
807 : {
808 : // check if we are inserting a row
809 0 : ORowSetNotifier aNotifier( this );
810 : // this will call cancelRowModification on the cache if necessary
811 :
812 0 : if(!m_bAfterLast)
813 : {
814 0 : ORowSetRow aOldValues = getOldRow(bWasNew);
815 :
816 0 : m_pCache->afterLast();
817 0 : doCancelModification( );
818 :
819 : // notification order
820 : // - column values
821 : // - cursorMoved
822 0 : setCurrentRow( sal_True, sal_True, aOldValues, aGuard );
823 :
824 : // - IsModified
825 : // - Isnew
826 0 : aNotifier.fire();
827 :
828 : // - RowCount/IsRowCountFinal
829 0 : fireRowcount();
830 0 : }
831 : }
832 0 : OSL_TRACE("DBACCESS ORowSetBase::afterLast() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
833 0 : }
834 :
835 0 : sal_Bool SAL_CALL ORowSetBase::move( ::std::mem_fun_t<sal_Bool,ORowSetBase>& _aCheckFunctor,
836 : ::std::mem_fun_t<sal_Bool,ORowSetCache>& _aMovementFunctor)
837 : {
838 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::move" );
839 : OSL_TRACE("DBACCESS ORowSetBase::move() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
840 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
841 0 : ::osl::ResettableMutexGuard aGuard( *m_pMutex );
842 0 : checkPositioningAllowed();
843 :
844 0 : sal_Bool bRet( notifyAllListenersCursorBeforeMove( aGuard ) );
845 0 : if( bRet )
846 : {
847 : // check if we are inserting a row
848 0 : sal_Bool bWasNew = m_pCache->m_bNew || rowDeleted();
849 :
850 0 : ORowSetNotifier aNotifier( this );
851 : // this will call cancelRowModification on the cache if necessary
852 :
853 0 : ORowSetRow aOldValues = getOldRow(bWasNew);
854 :
855 0 : sal_Bool bMoved = ( bWasNew || !_aCheckFunctor(this) );
856 :
857 0 : bRet = _aMovementFunctor(m_pCache);
858 0 : doCancelModification( );
859 :
860 0 : if ( bRet )
861 : {
862 : // notification order
863 : // - column values
864 : // - cursorMoved
865 0 : setCurrentRow( bMoved, sal_True, aOldValues, aGuard );
866 : }
867 : else
868 : { // first goes wrong so there is no row
869 0 : movementFailed();
870 : }
871 :
872 : // - IsModified
873 : // - IsNew
874 0 : aNotifier.fire();
875 :
876 : // - RowCount/IsRowCountFinal
877 0 : fireRowcount();
878 : }
879 : OSL_TRACE("DBACCESS ORowSetBase::move() = %i Clone = %i",bRet,m_bClone);
880 0 : return bRet;
881 : }
882 :
883 0 : sal_Bool SAL_CALL ORowSetBase::first( ) throw(SQLException, RuntimeException)
884 : {
885 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::first" );
886 : OSL_TRACE("DBACCESS ORowSetBase::first() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
887 0 : ::std::mem_fun_t<sal_Bool,ORowSetBase> ioF_tmp(&ORowSetBase::isOnFirst);
888 0 : ::std::mem_fun_t<sal_Bool,ORowSetCache> F_tmp(&ORowSetCache::first);
889 0 : return move(ioF_tmp,F_tmp);
890 : }
891 :
892 0 : sal_Bool SAL_CALL ORowSetBase::last( ) throw(SQLException, RuntimeException)
893 : {
894 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::last" );
895 : OSL_TRACE("DBACCESS ORowSetBase::last() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
896 0 : ::std::mem_fun_t<sal_Bool,ORowSetBase> ioL_tmp(&ORowSetBase::isOnLast);
897 0 : ::std::mem_fun_t<sal_Bool,ORowSetCache> L_tmp(&ORowSetCache::last);
898 0 : return move(ioL_tmp,L_tmp);
899 : }
900 :
901 0 : sal_Int32 SAL_CALL ORowSetBase::getRow( ) throw(SQLException, RuntimeException)
902 : {
903 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getRow" );
904 : OSL_TRACE("DBACCESS ORowSetBase::getRow() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
905 0 : ::osl::MutexGuard aGuard( *m_pMutex );
906 :
907 0 : checkCache();
908 0 : return impl_getRow();
909 : }
910 :
911 0 : sal_Int32 ORowSetBase::impl_getRow()
912 : {
913 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::impl_getRow" );
914 0 : sal_Int32 nPos = 0;
915 0 : if ( m_bBeforeFirst )
916 0 : nPos = 0;
917 0 : else if ( m_bAfterLast )
918 0 : nPos = impl_getRowCount() + 1;
919 0 : else if ( impl_rowDeleted() )
920 0 : nPos = m_nDeletedPosition;
921 0 : else if ( !m_bClone && m_pCache->m_bNew )
922 0 : nPos = 0;
923 : else
924 : {
925 0 : if ( m_pCache->isAfterLast()
926 0 : || m_pCache->isBeforeFirst()
927 0 : || ( m_pCache->compareBookmarks( m_aBookmark, m_pCache->getBookmark() ) != CompareBookmark::EQUAL )
928 : )
929 : {
930 0 : positionCache( MOVE_NONE_REFRESH_ONLY );
931 : }
932 0 : nPos = m_pCache->getRow();
933 : }
934 : OSL_TRACE("DBACCESS ORowSetBase::impl_getRow() = %i Clone = %i ID = %i",nPos,m_bClone,osl_getThreadIdentifier(NULL));
935 0 : return nPos;
936 : }
937 :
938 0 : sal_Bool SAL_CALL ORowSetBase::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
939 : {
940 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::absolute" );
941 : OSL_TRACE("DBACCESS ORowSetBase::absolute(%i) Clone = %i",row,m_bClone);
942 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
943 0 : ::osl::ResettableMutexGuard aGuard( *m_pMutex );
944 0 : checkPositioningAllowed();
945 :
946 : sal_Bool bRet = ( row > 0 )
947 0 : && notifyAllListenersCursorBeforeMove( aGuard );
948 0 : if ( bRet )
949 : {
950 : // check if we are inserting a row
951 0 : sal_Bool bWasNew = m_pCache->m_bNew || rowDeleted();
952 :
953 0 : ORowSetNotifier aNotifier( this );
954 : // this will call cancelRowModification on the cache if necessary
955 :
956 0 : ORowSetRow aOldValues = getOldRow(bWasNew);
957 :
958 0 : bRet = m_pCache->absolute(row);
959 0 : doCancelModification( );
960 :
961 0 : if(bRet)
962 : {
963 : // notification order
964 : // - column values
965 : // - cursorMoved
966 0 : setCurrentRow( sal_True, sal_True, aOldValues, aGuard );
967 : }
968 : else
969 : { // absolute movement goes wrong we stand left or right side of the rows
970 0 : movementFailed();
971 : }
972 :
973 : // - IsModified
974 : // - IsNew
975 0 : aNotifier.fire();
976 :
977 : // - RowCount/IsRowCountFinal
978 0 : fireRowcount();
979 : }
980 : OSL_TRACE("DBACCESS ORowSetBase::absolute(%i) = %i Clone = %i",row,bRet,m_bClone);
981 0 : return bRet;
982 : }
983 :
984 0 : sal_Bool SAL_CALL ORowSetBase::relative( sal_Int32 rows ) throw(SQLException, RuntimeException)
985 : {
986 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::relative" );
987 : OSL_TRACE("DBACCESS ORowSetBase::relative(%i) Clone = %i",rows,m_bClone);
988 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
989 :
990 0 : ::osl::ResettableMutexGuard aGuard( *m_pMutex );
991 :
992 0 : if(!rows)
993 0 : return sal_True; // in this case do nothing
994 :
995 0 : checkPositioningAllowed();
996 :
997 : sal_Bool bRet =
998 0 : ( ( !m_bAfterLast || rows <= 0 )
999 0 : && ( !m_bBeforeFirst || rows >= 0 )
1000 0 : && notifyAllListenersCursorBeforeMove( aGuard )
1001 0 : );
1002 :
1003 0 : if ( bRet )
1004 : {
1005 : // check if we are inserting a row
1006 0 : sal_Bool bWasNew = m_pCache->m_bNew || rowDeleted();
1007 :
1008 0 : ORowSetNotifier aNotifier( this );
1009 : // this will call cancelRowModification on the cache if necessary
1010 :
1011 0 : ORowSetRow aOldValues = getOldRow(bWasNew);
1012 :
1013 0 : positionCache( rows > 0 ? MOVE_FORWARD : MOVE_BACKWARD );
1014 0 : bRet = m_pCache->relative(rows);
1015 0 : doCancelModification( );
1016 :
1017 0 : if(bRet)
1018 : {
1019 : // notification order
1020 : // - column values
1021 : // - cursorMoved
1022 0 : setCurrentRow( sal_True, sal_True, aOldValues, aGuard );
1023 : }
1024 : else
1025 : {
1026 0 : movementFailed();
1027 : }
1028 :
1029 : // - IsModified
1030 : // - IsNew
1031 0 : aNotifier.fire();
1032 :
1033 : // - RowCount/IsRowCountFinal
1034 0 : fireRowcount();
1035 : }
1036 : OSL_TRACE("DBACCESS ORowSetBase::relative(%i) = %i Clone = %i",rows,bRet,m_bClone);
1037 0 : return bRet;
1038 : }
1039 :
1040 0 : sal_Bool SAL_CALL ORowSetBase::previous( ) throw(SQLException, RuntimeException)
1041 : {
1042 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::previous" );
1043 : OSL_TRACE("DBACCESS ORowSetBase::previous() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
1044 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
1045 0 : ::osl::ResettableMutexGuard aGuard( *m_pMutex );
1046 :
1047 0 : checkPositioningAllowed();
1048 :
1049 0 : sal_Bool bRet = !m_bBeforeFirst
1050 0 : && notifyAllListenersCursorBeforeMove(aGuard);
1051 :
1052 0 : if ( bRet )
1053 : {
1054 : // check if we are inserting a row
1055 0 : sal_Bool bWasNew = m_pCache->m_bNew || rowDeleted();
1056 :
1057 0 : ORowSetNotifier aNotifier( this );
1058 : // this will call cancelRowModification on the cache if necessary
1059 :
1060 0 : ORowSetRow aOldValues = getOldRow(bWasNew);
1061 :
1062 0 : positionCache( MOVE_BACKWARD );
1063 0 : bRet = m_pCache->previous();
1064 0 : doCancelModification( );
1065 :
1066 : // if m_bBeforeFirst is false and bRet is false than we stood on the first row
1067 0 : if(!m_bBeforeFirst || bRet)
1068 : {
1069 : // notification order
1070 : // - column values
1071 : // - cursorMoved
1072 0 : setCurrentRow( sal_True, sal_True, aOldValues, aGuard );
1073 : }
1074 : else
1075 : {
1076 : OSL_FAIL( "ORowSetBase::previous: inconsistency!" );
1077 : // we should never reach this place, as we should not get into this whole branch if m_bBeforeFirst
1078 : // was |true| from the beginning
1079 0 : movementFailed();
1080 : }
1081 :
1082 : // - IsModified
1083 : // - IsNew
1084 0 : aNotifier.fire();
1085 :
1086 : // - RowCount/IsRowCountFinal
1087 0 : fireRowcount();
1088 : }
1089 : OSL_TRACE("DBACCESS ORowSetBase::previous() = %i Clone = %i",bRet,m_bClone);
1090 0 : return bRet;
1091 : }
1092 :
1093 0 : void ORowSetBase::setCurrentRow( sal_Bool _bMoved, sal_Bool _bDoNotify, const ORowSetRow& _rOldValues, ::osl::ResettableMutexGuard& _rGuard )
1094 : {
1095 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::setCurrentRow" );
1096 : OSL_TRACE("DBACCESS ORowSetBase::setCurrentRow() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
1097 0 : m_bBeforeFirst = m_pCache->isBeforeFirst();
1098 0 : m_bAfterLast = m_pCache->isAfterLast();
1099 :
1100 0 : if(!(m_bBeforeFirst || m_bAfterLast))
1101 : {
1102 0 : m_aBookmark = m_pCache->getBookmark();
1103 : OSL_ENSURE(m_aBookmark.hasValue(),"Bookmark has no value!");
1104 0 : m_aCurrentRow = m_pCache->m_aMatrixIter;
1105 0 : m_bIsInsertRow = sal_False;
1106 : OSL_ENSURE(!m_aCurrentRow.isNull(),"CurrentRow is null!");
1107 0 : m_aCurrentRow.setBookmark(m_aBookmark);
1108 : OSL_ENSURE(!m_aCurrentRow.isNull() && m_aCurrentRow != m_pCache->getEnd(),"Position of matrix iterator isn't valid!");
1109 : OSL_ENSURE(m_aCurrentRow->is(),"Currentrow isn't valid");
1110 : OSL_ENSURE(m_aBookmark.hasValue(),"Bookmark has no value!");
1111 :
1112 0 : m_aCurrentRow = m_pCache->m_aMatrixIter;
1113 0 : m_bIsInsertRow = sal_False;
1114 : OSL_ENSURE(!m_aCurrentRow.isNull(),"CurrentRow is nul after positionCache!");
1115 : #if OSL_DEBUG_LEVEL > 0
1116 : ORowSetRow rRow = (*m_aCurrentRow);
1117 : OSL_ENSURE(rRow.is() ,"Invalid size of vector!");
1118 : #endif
1119 : // the cache could repositioned so we need to adjust the cache
1120 0 : if ( _bMoved && m_aCurrentRow.isNull() )
1121 : {
1122 0 : positionCache( MOVE_NONE_REFRESH_ONLY );
1123 0 : m_aCurrentRow = m_pCache->m_aMatrixIter;
1124 0 : m_bIsInsertRow = sal_False;
1125 : OSL_ENSURE(!m_aCurrentRow.isNull(),"CurrentRow is nul after positionCache!");
1126 : }
1127 : }
1128 : else
1129 : {
1130 0 : m_aOldRow->clearRow();
1131 0 : m_aCurrentRow = m_pCache->getEnd();
1132 0 : m_aBookmark = Any();
1133 0 : m_aCurrentRow.setBookmark(m_aBookmark);
1134 : }
1135 :
1136 : // notification order
1137 : // - column values
1138 0 : if ( _bDoNotify )
1139 0 : firePropertyChange(_rOldValues);
1140 :
1141 : // TODO: can this be done before the notifications?
1142 0 : if(!(m_bBeforeFirst || m_bAfterLast) && !m_aCurrentRow.isNull() && m_aCurrentRow->is() && m_aCurrentRow != m_pCache->getEnd())
1143 0 : m_aOldRow->setRow(new ORowSetValueVector( *(*m_aCurrentRow) ));
1144 :
1145 0 : if ( _bMoved && _bDoNotify )
1146 : // - cursorMoved
1147 0 : notifyAllListenersCursorMoved( _rGuard );
1148 :
1149 : OSL_TRACE("DBACCESS ORowSetBase::setCurrentRow() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
1150 0 : }
1151 :
1152 0 : void ORowSetBase::checkPositioningAllowed() throw( SQLException, RuntimeException )
1153 : {
1154 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::checkPositioningAllowed" );
1155 0 : if(!m_pCache || m_nResultSetType == ResultSetType::FORWARD_ONLY)
1156 0 : throwFunctionSequenceException(*m_pMySelf);
1157 0 : }
1158 :
1159 0 : Reference< XInterface > ORowSetBase::getStatement(void) throw( SQLException, RuntimeException )
1160 : {
1161 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getStatement" );
1162 0 : return NULL;
1163 : }
1164 :
1165 0 : void SAL_CALL ORowSetBase::refreshRow( ) throw(SQLException, RuntimeException)
1166 : {
1167 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::refreshRow" );
1168 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
1169 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1170 0 : checkCache();
1171 0 : if ( impl_rowDeleted() )
1172 0 : throwSQLException( "The current row is deleted", SQL_INVALID_CURSOR_STATE, Reference< XRowSet >( this ) );
1173 :
1174 0 : if(!(m_bBeforeFirst || m_bAfterLast))
1175 : {
1176 0 : sal_Bool bWasNew = m_pCache->m_bNew || impl_rowDeleted();
1177 0 : ORowSetRow aOldValues = getOldRow(bWasNew);
1178 0 : positionCache( MOVE_NONE_REFRESH_ONLY );
1179 0 : m_pCache->refreshRow();
1180 0 : firePropertyChange(aOldValues);
1181 0 : }
1182 0 : }
1183 :
1184 0 : sal_Bool SAL_CALL ORowSetBase::rowUpdated( ) throw(SQLException, RuntimeException)
1185 : {
1186 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::rowUpdated" );
1187 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1188 0 : checkCache();
1189 :
1190 0 : if ( impl_rowDeleted() )
1191 0 : return sal_False;
1192 :
1193 0 : return m_pCache->rowUpdated();
1194 : }
1195 :
1196 0 : sal_Bool SAL_CALL ORowSetBase::rowInserted( ) throw(SQLException, RuntimeException)
1197 : {
1198 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::rowInserted" );
1199 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1200 :
1201 0 : checkCache();
1202 :
1203 0 : if ( impl_rowDeleted() )
1204 0 : return sal_False;
1205 :
1206 0 : return m_pCache->rowInserted();
1207 : }
1208 :
1209 0 : sal_Bool SAL_CALL ORowSetBase::rowDeleted( ) throw(SQLException, RuntimeException)
1210 : {
1211 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::rowDeleted" );
1212 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1213 0 : checkCache();
1214 0 : return impl_rowDeleted();
1215 : }
1216 :
1217 0 : sal_Bool ORowSetBase::impl_rowDeleted( )
1218 : {
1219 0 : return !m_aBookmark.hasValue() && !m_bBeforeFirst && !m_bAfterLast;
1220 : }
1221 :
1222 : // XWarningsSupplier
1223 0 : Any SAL_CALL ORowSetBase::getWarnings( ) throw(SQLException, RuntimeException)
1224 : {
1225 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getWarnings" );
1226 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1227 :
1228 0 : if ( m_pCache )
1229 : {
1230 0 : Reference< XWarningsSupplier > xWarnings( m_pCache->m_xSet.get(), UNO_QUERY );
1231 0 : if ( xWarnings.is() )
1232 0 : return xWarnings->getWarnings();
1233 : }
1234 :
1235 0 : return Any();
1236 : }
1237 :
1238 0 : void SAL_CALL ORowSetBase::clearWarnings( ) throw(SQLException, RuntimeException)
1239 : {
1240 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::clearWarnings" );
1241 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1242 :
1243 0 : if ( m_pCache )
1244 : {
1245 0 : Reference< XWarningsSupplier > xWarnings( m_pCache->m_xSet.get(), UNO_QUERY );
1246 0 : if ( xWarnings.is() )
1247 0 : xWarnings->clearWarnings();
1248 0 : }
1249 0 : }
1250 :
1251 0 : void ORowSetBase::firePropertyChange(const ORowSetRow& _rOldRow)
1252 : {
1253 0 : if (!isPropertyChangeNotificationEnabled())
1254 0 : return;
1255 :
1256 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::firePropertyChange" );
1257 : OSL_TRACE("DBACCESS ORowSetBase::firePropertyChange() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
1258 : OSL_ENSURE(m_pColumns,"Columns can not be NULL here!");
1259 0 : sal_Int32 i=0;
1260 : try
1261 : {
1262 0 : TDataColumns::iterator aEnd = m_aDataColumns.end();
1263 0 : for(TDataColumns::iterator aIter = m_aDataColumns.begin();aIter != aEnd;++aIter,++i)
1264 0 : (*aIter)->fireValueChange(_rOldRow.is() ? (_rOldRow->get())[i+1] : ::connectivity::ORowSetValue());
1265 : }
1266 0 : catch (const Exception&)
1267 : {
1268 : OSL_FAIL("firePropertyChange: Exception");
1269 : }
1270 : OSL_TRACE("DBACCESS ORowSetBase::firePropertyChange() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
1271 : }
1272 :
1273 0 : void ORowSetBase::firePropertyChange(sal_Int32 _nPos,const ::connectivity::ORowSetValue& _rOldValue)
1274 : {
1275 : OSL_ENSURE(_nPos < (sal_Int32)m_aDataColumns.size(),"nPos is invalid!");
1276 0 : m_aDataColumns[_nPos]->fireValueChange(_rOldValue);
1277 0 : }
1278 :
1279 0 : void ORowSetBase::fireRowcount()
1280 : {
1281 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::fireRowcount" );
1282 0 : }
1283 :
1284 0 : sal_Bool ORowSetBase::notifyAllListenersCursorBeforeMove(::osl::ResettableMutexGuard& /*_rGuard*/)
1285 : {
1286 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::notifyAllListenersCursorBeforeMove" );
1287 0 : return sal_True;
1288 : }
1289 :
1290 0 : void ORowSetBase::notifyAllListenersCursorMoved(::osl::ResettableMutexGuard& /*_rGuard*/)
1291 : {
1292 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::notifyAllListenersCursorMoved" );
1293 0 : }
1294 :
1295 0 : void ORowSetBase::notifyAllListeners(::osl::ResettableMutexGuard& /*_rGuard*/)
1296 : {
1297 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::notifyAllListeners" );
1298 0 : }
1299 :
1300 0 : sal_Bool ORowSetBase::isPropertyChangeNotificationEnabled() const
1301 : {
1302 0 : return sal_True;
1303 : }
1304 :
1305 0 : void ORowSetBase::fireProperty( sal_Int32 _nProperty, sal_Bool _bNew, sal_Bool _bOld )
1306 : {
1307 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::fireProperty" );
1308 0 : Any aNew = bool2any( _bNew );
1309 0 : Any aOld = bool2any( _bOld );
1310 0 : fire( &_nProperty, &aNew, &aOld, 1, sal_False );
1311 0 : }
1312 :
1313 0 : void ORowSetBase::positionCache( CursorMoveDirection _ePrepareForDirection )
1314 : {
1315 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::positionCache" );
1316 : OSL_TRACE("DBACCESS ORowSetBase::positionCache() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
1317 :
1318 0 : sal_Bool bSuccess = sal_False;
1319 0 : if ( m_aBookmark.hasValue() )
1320 : {
1321 0 : if ( _ePrepareForDirection == MOVE_NONE_REFRESH_ONLY ||
1322 0 : m_pCache->compareBookmarks( m_aBookmark, m_pCache->getBookmark() ) != CompareBookmark::EQUAL )
1323 0 : bSuccess = m_pCache->moveToBookmark( m_aBookmark );
1324 : else
1325 0 : bSuccess = sal_True;
1326 : }
1327 : else
1328 : {
1329 0 : if ( m_bBeforeFirst )
1330 : {
1331 0 : bSuccess = m_pCache->beforeFirst();
1332 : }
1333 0 : else if ( m_bAfterLast )
1334 : {
1335 0 : bSuccess = m_pCache->afterLast();
1336 : }
1337 : else
1338 : {
1339 : OSL_ENSURE( m_nDeletedPosition >= 1, "ORowSetBase::positionCache: no bookmark, and no valid 'deleted position'!" );
1340 0 : switch ( _ePrepareForDirection )
1341 : {
1342 : case MOVE_FORWARD:
1343 0 : if ( m_nDeletedPosition > 1 )
1344 0 : bSuccess = m_pCache->absolute( m_nDeletedPosition - 1 );
1345 : else
1346 : {
1347 0 : m_pCache->beforeFirst();
1348 0 : bSuccess = sal_True;
1349 : }
1350 0 : break;
1351 :
1352 : case MOVE_BACKWARD:
1353 0 : if ( m_pCache->m_bRowCountFinal && ( m_nDeletedPosition == impl_getRowCount() ) )
1354 : {
1355 0 : m_pCache->afterLast();
1356 0 : bSuccess = sal_True;
1357 : }
1358 : else
1359 0 : bSuccess = m_pCache->absolute( m_nDeletedPosition );
1360 0 : break;
1361 :
1362 : case MOVE_NONE_REFRESH_ONLY:
1363 0 : bSuccess = sal_False; // will be asserted below
1364 0 : break;
1365 : }
1366 : }
1367 : }
1368 : OSL_ENSURE( bSuccess, "ORowSetBase::positionCache: failed!" );
1369 : (void)bSuccess;
1370 :
1371 : OSL_TRACE("DBACCESS ORowSetBase::positionCache() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
1372 0 : }
1373 :
1374 0 : void ORowSetBase::checkCache()
1375 : {
1376 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::checkCache" );
1377 0 : ::connectivity::checkDisposed(m_rBHelper.bDisposed);
1378 0 : if(!m_pCache)
1379 0 : throwFunctionSequenceException(*m_pMySelf);
1380 0 : }
1381 :
1382 0 : void ORowSetBase::movementFailed()
1383 : {
1384 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::movementFailed" );
1385 : OSL_TRACE("DBACCESS ORowSetBase::movementFailed() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
1386 0 : m_aOldRow->clearRow();
1387 0 : m_aCurrentRow = m_pCache->getEnd();
1388 0 : m_bBeforeFirst = m_pCache->isBeforeFirst();
1389 0 : m_bAfterLast = m_pCache->isAfterLast();
1390 0 : m_aBookmark = Any();
1391 0 : m_aCurrentRow.setBookmark(m_aBookmark);
1392 : OSL_ENSURE(m_bBeforeFirst || m_bAfterLast,"BeforeFirst or AfterLast is wrong!");
1393 : OSL_TRACE("DBACCESS ORowSetBase::movementFailed() Clone = %i ID = %i",m_bClone,osl_getThreadIdentifier(NULL));
1394 0 : }
1395 :
1396 0 : ORowSetRow ORowSetBase::getOldRow(sal_Bool _bWasNew)
1397 : {
1398 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getOldRow" );
1399 : OSL_ENSURE(m_aOldRow.is(),"RowSetRowHElper isn't valid!");
1400 0 : ORowSetRow aOldValues;
1401 0 : if ( !_bWasNew && m_aOldRow->getRow().is() )
1402 0 : aOldValues = new ORowSetValueVector( *(m_aOldRow->getRow())); // remember the old values
1403 0 : return aOldValues;
1404 : }
1405 :
1406 0 : void ORowSetBase::getPropertyDefaultByHandle( sal_Int32 /*_nHandle*/, Any& _rDefault ) const
1407 : {
1408 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::getPropertyDefaultByHandle" );
1409 0 : _rDefault.clear();
1410 0 : }
1411 :
1412 0 : void ORowSetBase::onDeleteRow( const Any& _rBookmark )
1413 : {
1414 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::onDeleteRow" );
1415 0 : if ( rowDeleted() )
1416 : // not interested in
1417 0 : return;
1418 :
1419 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1420 : //OSL_ENSURE( m_aBookmark.hasValue(), "ORowSetBase::onDeleteRow: Bookmark isn't valid!" );
1421 0 : if ( compareBookmarks( _rBookmark, m_aBookmark ) == 0 )
1422 : {
1423 0 : positionCache( MOVE_NONE_REFRESH_ONLY );
1424 0 : m_nDeletedPosition = m_pCache->getRow();
1425 0 : }
1426 : }
1427 :
1428 0 : void ORowSetBase::onDeletedRow( const Any& _rBookmark, sal_Int32 _nPos )
1429 : {
1430 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::onDeletedRow" );
1431 0 : if ( rowDeleted() )
1432 : {
1433 : // if we're a clone, and on a deleted row, and the main RowSet deleted another
1434 : // row (only the main RowSet can, clones can't), which is *before* our
1435 : // deleted position, then we have to adjust this position
1436 0 : if ( m_bClone && ( _nPos < m_nDeletedPosition ) )
1437 0 : --m_nDeletedPosition;
1438 0 : return;
1439 : }
1440 :
1441 0 : ::osl::MutexGuard aGuard( *m_pMutex );
1442 0 : if ( compareBookmarks( _rBookmark, m_aBookmark ) == 0 )
1443 : {
1444 0 : m_aOldRow->clearRow();
1445 0 : m_aCurrentRow = m_pCache->getEnd();
1446 0 : m_aBookmark = Any();
1447 0 : m_aCurrentRow.setBookmark( m_aBookmark );
1448 0 : }
1449 : }
1450 :
1451 0 : sal_Int32 ORowSetBase::impl_getRowCount() const
1452 : {
1453 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetBase::impl_getRowCount" );
1454 0 : sal_Int32 nRowCount( m_pCache->m_nRowCount );
1455 0 : if ( const_cast< ORowSetBase* >( this )->rowDeleted() && !m_pCache->m_bNew )
1456 0 : ++nRowCount;
1457 0 : return nRowCount;
1458 : }
1459 : // =============================================================================
1460 0 : struct ORowSetNotifierImpl
1461 : {
1462 : ::std::vector<sal_Int32> aChangedColumns;
1463 : ::std::vector<Any> aChangedBookmarks;
1464 : ORowSetValueVector::Vector aRow;
1465 :
1466 : };
1467 : DBG_NAME(ORowSetNotifier)
1468 :
1469 0 : ORowSetNotifier::ORowSetNotifier( ORowSetBase* _pRowSet )
1470 : :m_pRowSet( _pRowSet )
1471 : ,m_bWasNew( sal_False )
1472 0 : ,m_bWasModified( sal_False )
1473 : #ifdef DBG_UTIL
1474 : ,m_bNotifyCalled( sal_False )
1475 : #endif
1476 : {
1477 : DBG_CTOR(ORowSetNotifier,NULL);
1478 :
1479 : OSL_ENSURE( m_pRowSet, "ORowSetNotifier::ORowSetNotifier: invalid row set. This wil crash." );
1480 :
1481 : // remember the "inserted" and "modified" state for later firing
1482 0 : m_bWasNew = m_pRowSet->isNew( ORowSetBase::GrantNotifierAccess() );
1483 0 : m_bWasModified = m_pRowSet->isModified( ORowSetBase::GrantNotifierAccess() );
1484 :
1485 : // if the row set is on the insert row, then we need to cancel this
1486 0 : if ( m_pRowSet->isModification( ORowSetBase::GrantNotifierAccess() ) )
1487 0 : m_pRowSet->doCancelModification( ORowSetBase::GrantNotifierAccess() );
1488 0 : }
1489 :
1490 0 : ORowSetNotifier::ORowSetNotifier( ORowSetBase* _pRowSet,const ORowSetValueVector::Vector& i_aRow )
1491 0 : :m_pImpl(new ORowSetNotifierImpl)
1492 : ,m_pRowSet( _pRowSet )
1493 : ,m_bWasNew( sal_False )
1494 0 : ,m_bWasModified( sal_False )
1495 : #ifdef DBG_UTIL
1496 : ,m_bNotifyCalled( sal_False )
1497 : #endif
1498 : {
1499 : DBG_CTOR(ORowSetNotifier,NULL);
1500 :
1501 : OSL_ENSURE( m_pRowSet, "ORowSetNotifier::ORowSetNotifier: invalid row set. This wil crash." );
1502 0 : m_pImpl->aRow = i_aRow; // yes, create a copy to store the old values
1503 0 : }
1504 :
1505 0 : ORowSetNotifier::~ORowSetNotifier( )
1506 : {
1507 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetNotifier::~ORowSetNotifier" );
1508 : DBG_DTOR(ORowSetNotifier,NULL);
1509 0 : }
1510 :
1511 0 : void ORowSetNotifier::fire()
1512 : {
1513 : // we're not interested in firing changes FALSE->TRUE, only TRUE->FALSE.
1514 : // (the former would be quite pathological, e.g. after a failed movement)
1515 :
1516 0 : if ( m_bWasModified
1517 0 : && ( m_bWasModified != m_pRowSet->isModified( ORowSetBase::GrantNotifierAccess() ) )
1518 : )
1519 0 : m_pRowSet->fireProperty( PROPERTY_ID_ISMODIFIED, sal_False, sal_True, ORowSetBase::GrantNotifierAccess() );
1520 :
1521 0 : if ( m_bWasNew
1522 0 : && ( m_bWasNew != m_pRowSet->isNew( ORowSetBase::GrantNotifierAccess() ) )
1523 : )
1524 0 : m_pRowSet->fireProperty( PROPERTY_ID_ISNEW, sal_False, sal_True, ORowSetBase::GrantNotifierAccess() );
1525 :
1526 : #ifdef DBG_UTIL
1527 : m_bNotifyCalled = sal_True;
1528 : #endif
1529 0 : }
1530 :
1531 0 : ::std::vector<sal_Int32>& ORowSetNotifier::getChangedColumns() const
1532 : {
1533 : OSL_ENSURE(m_pImpl.get(),"Illegal CTor call, use the other one!");
1534 0 : return m_pImpl->aChangedColumns;
1535 : }
1536 :
1537 0 : void ORowSetNotifier::firePropertyChange()
1538 : {
1539 : OSL_ENSURE(m_pImpl.get(),"Illegal CTor call, use the other one!");
1540 0 : if( m_pImpl.get() )
1541 : {
1542 0 : ::std::vector<sal_Int32>::iterator aIter = m_pImpl->aChangedColumns.begin();
1543 0 : for(;aIter != m_pImpl->aChangedColumns.end();++aIter)
1544 : {
1545 0 : m_pRowSet->firePropertyChange((*aIter)-1 ,m_pImpl->aRow[(*aIter)-1], ORowSetBase::GrantNotifierAccess());
1546 : }
1547 0 : if ( !m_pImpl->aChangedColumns.empty() )
1548 0 : m_pRowSet->fireProperty(PROPERTY_ID_ISMODIFIED,sal_True,sal_False, ORowSetBase::GrantNotifierAccess());
1549 : }
1550 0 : }
1551 : } // namespace dbaccess
1552 :
1553 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|