Tag: cws_src680_dba30 User: fs Date: 06/03/21 10:20:41 Modified: /dba/dbaccess/source/core/api/ RowSetBase.cxx
Log: RESYNC: (1.79-1.84); FILE MERGED File Changes: Directory: /dba/dbaccess/source/core/api/ ========================================= File [changed]: RowSetBase.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/api/RowSetBase.cxx?r1=1.75.6.4&r2=1.75.6.5 Delta lines: +301 -154 ----------------------- --- RowSetBase.cxx 23 Nov 2005 10:14:16 -0000 1.75.6.4 +++ RowSetBase.cxx 21 Mar 2006 18:20:38 -0000 1.75.6.5 @@ -80,7 +80,9 @@ #ifndef _CONNECTIVITY_EMPTYMETADATA_HXX_ #include <connectivity/emptymetadata.hxx> #endif - +#ifndef _OSL_THREAD_H_ +#include <osl/thread.h> +#endif #ifndef _TOOLS_DEBUG_HXX #include <tools/debug.hxx> #endif @@ -138,12 +140,10 @@ , m_rBHelper(_rBHelper) , m_pCache(NULL) , m_pColumns(NULL) - , m_nRowCount(0) , m_bBeforeFirst(sal_True) // changed from sal_False , m_bAfterLast(sal_False) - , m_bRowCountFinal(sal_False) , m_bClone(sal_False) - , m_nPosition(-1) + , m_nDeletedPosition(-1) , m_bIgnoreResult(sal_False) , m_nLastColumnIndex(-1) , m_pEmptyCollection( NULL ) @@ -152,8 +152,10 @@ sal_Int32 nRBT = PropertyAttribute::READONLY | PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT; - registerProperty(PROPERTY_ROWCOUNT, PROPERTY_ID_ROWCOUNT, nRBT, &m_nRowCount, ::getCppuType(reinterpret_cast< sal_Int32*>(NULL))); - registerProperty(PROPERTY_ISROWCOUNTFINAL, PROPERTY_ID_ISROWCOUNTFINAL, nRBT, &m_bRowCountFinal, ::getBooleanCppuType()); + sal_Int32 nInitialRowCountValue = 0; + sal_Bool bInitialRowCountFinalValue( sal_False ); + registerPropertyNoMember( PROPERTY_ROWCOUNT, PROPERTY_ID_ROWCOUNT, nRBT, ::getCppuType( &nInitialRowCountValue ), &nInitialRowCountValue ); + registerPropertyNoMember( PROPERTY_ISROWCOUNTFINAL, PROPERTY_ID_ISROWCOUNTFINAL, nRBT, ::getBooleanCppuType(), &bInitialRowCountFinalValue ); } // ----------------------------------------------------------------------------- ORowSetBase::~ORowSetBase() @@ -195,7 +197,7 @@ switch(nHandle) { case PROPERTY_ID_ROWCOUNT: - rValue <<= m_pCache->m_nRowCount; + rValue <<= impl_getRowCount(); break; case PROPERTY_ID_ISROWCOUNTFINAL: rValue.setValue(&m_pCache->m_bRowCountFinal,::getCppuBooleanType()); @@ -243,20 +245,42 @@ ::osl::MutexGuard aGuard( *m_pMutex ); checkCache(); + return ((m_nLastColumnIndex != -1) && !m_aCurrentRow.isNull() && m_aCurrentRow != m_pCache->getEnd() && m_aCurrentRow->isValid()) ? (*(*m_aCurrentRow))[m_nLastColumnIndex].isNull() : sal_True; } // ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- const ORowSetValue& ORowSetBase::getValue(sal_Int32 columnIndex) { - ::osl::MutexGuard aGuard( *m_pMutex ); + DBG_TRACE2("DBACCESS ORowSetBase::getValue() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); + checkCache(); + if ( m_bBeforeFirst || m_bAfterLast ) { OSL_ENSURE(0,"ORowSetBase::getValue: Illegal call here (we're before first or after last)!"); - throwFunctionSequenceException(*m_pMySelf); + throwSQLException( "The cursor points to before the first or after the last row.", SQL_INVALID_CURSOR_POSITION, *m_pMySelf ); } - if ( !m_aCurrentRow.isNull() && m_aCurrentRow != m_pCache->getEnd() && m_aCurrentRow->isValid() ) + if ( rowDeleted() ) + { + DBG_TRACE2("DBACCESS ORowSetBase::getValue() Clone = %i rowDeleted() ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); + return m_aEmptyValue; + } + + bool bValidCurrentRow = ( !m_aCurrentRow.isNull() && m_aCurrentRow != m_pCache->getEnd() && m_aCurrentRow->isValid() ); + if ( !bValidCurrentRow ) + { + // currentrow is null when the clone moves the window + positionCache( MOVE_NONE_REFRESH_ONLY ); + m_aCurrentRow = m_pCache->m_aMatrixIter; + OSL_ENSURE(!m_aCurrentRow.isNull(),"ORowSetBase::getValue: we don't stand on a valid row! Row is null."); + + bValidCurrentRow = ( !m_aCurrentRow.isNull() && m_aCurrentRow != m_pCache->getEnd() && m_aCurrentRow->isValid() ); + } + + if ( bValidCurrentRow ) { #if OSL_DEBUG_LEVEL > 0 ORowSetMatrix::iterator aCacheEnd = m_pCache->getEnd(); @@ -265,79 +289,81 @@ OSL_ENSURE(!m_aCurrentRow.isNull() && m_aCurrentRow <= m_pCache->getEnd(),"Invalid iterator set for currentrow!"); return (*(*m_aCurrentRow))[m_nLastColumnIndex = columnIndex]; } - else - { // currentrow is null when the clone move the window - if ( m_aCurrentRow.isNull() ) - { - positionCache(); - m_aCurrentRow = m_pCache->m_aMatrixIter; - OSL_ENSURE(!m_aCurrentRow.isNull(),"ORowSetBase::getValue: we don't stand on a valid row! Row is null."); - return getValue(columnIndex); - } - OSL_ENSURE(!m_aCurrentRow.isNull() && (m_bBeforeFirst || m_bAfterLast),"ORowSetBase::getValue: we don't stand on a valid row! Row is equal to end of matrix"); - } - // we should normally never reach this here + DBG_TRACE2("DBACCESS ORowSetBase::getValue() Clone = %i EmptyValue ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); + // we should normally never reach this return m_aEmptyValue; } // ------------------------------------------------------------------------- ::rtl::OUString SAL_CALL ORowSetBase::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ::osl::MutexGuard aGuard( *m_pMutex ); return getValue(columnIndex); } // ------------------------------------------------------------------------- sal_Bool SAL_CALL ORowSetBase::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ::osl::MutexGuard aGuard( *m_pMutex ); return getValue(columnIndex); } // ------------------------------------------------------------------------- sal_Int8 SAL_CALL ORowSetBase::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ::osl::MutexGuard aGuard( *m_pMutex ); return getValue(columnIndex); } // ------------------------------------------------------------------------- sal_Int16 SAL_CALL ORowSetBase::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ::osl::MutexGuard aGuard( *m_pMutex ); return getValue(columnIndex); } // ------------------------------------------------------------------------- sal_Int32 SAL_CALL ORowSetBase::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ::osl::MutexGuard aGuard( *m_pMutex ); return getValue(columnIndex); } // ------------------------------------------------------------------------- sal_Int64 SAL_CALL ORowSetBase::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ::osl::MutexGuard aGuard( *m_pMutex ); return getValue(columnIndex); } // ------------------------------------------------------------------------- float SAL_CALL ORowSetBase::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ::osl::MutexGuard aGuard( *m_pMutex ); return getValue(columnIndex); } // ------------------------------------------------------------------------- double SAL_CALL ORowSetBase::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ::osl::MutexGuard aGuard( *m_pMutex ); return getValue(columnIndex); } // ------------------------------------------------------------------------- Sequence< sal_Int8 > SAL_CALL ORowSetBase::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ::osl::MutexGuard aGuard( *m_pMutex ); return getValue(columnIndex); } // ------------------------------------------------------------------------- ::com::sun::star::util::Date SAL_CALL ORowSetBase::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ::osl::MutexGuard aGuard( *m_pMutex ); return getValue(columnIndex); } // ------------------------------------------------------------------------- ::com::sun::star::util::Time SAL_CALL ORowSetBase::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ::osl::MutexGuard aGuard( *m_pMutex ); return getValue(columnIndex); } // ------------------------------------------------------------------------- ::com::sun::star::util::DateTime SAL_CALL ORowSetBase::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ::osl::MutexGuard aGuard( *m_pMutex ); return getValue(columnIndex); } // ------------------------------------------------------------------------- @@ -346,18 +372,22 @@ ::osl::MutexGuard aGuard( *m_pMutex ); checkCache(); + if( !m_aCurrentRow.isNull() && m_aCurrentRow != m_pCache->getEnd()) return new ::comphelper::SequenceInputStream((*(*m_aCurrentRow))[m_nLastColumnIndex = columnIndex].getSequence()); else { if(!m_aCurrentRow.isNull()) - OSL_ENSURE((m_bBeforeFirst || m_bAfterLast),"ORowSetBase::getValue: we don't stand on a valid row! Row is equal to end of matrix"); + OSL_ENSURE((m_bBeforeFirst || m_bAfterLast),"ORowSetBase::getBinaryStream: we don't stand on a valid row! Row is equal to end of matrix"); else { - positionCache(); + if ( rowDeleted() ) + return NULL; + + positionCache( MOVE_NONE_REFRESH_ONLY ); m_aCurrentRow = m_pCache->m_aMatrixIter; - OSL_ENSURE(!m_aCurrentRow.isNull(),"ORowSetBase::getValue: we don't stand on a valid row! Row is null."); + OSL_ENSURE(!m_aCurrentRow.isNull(),"ORowSetBase::getBinaryStream: we don't stand on a valid row! Row is null."); return getBinaryStream(columnIndex); } } @@ -414,23 +444,24 @@ // ::com::sun::star::sdbcx::XRowLocate Any SAL_CALL ORowSetBase::getBookmark( ) throw(SQLException, RuntimeException) { - DBG_TRACE1("DBACCESS ORowSetBase::getBookmark() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::getBookmark() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); ::connectivity::checkDisposed(m_rBHelper.bDisposed); ::osl::MutexGuard aGuard( *m_pMutex ); + checkCache(); - if(!m_pCache || m_bBeforeFirst || m_bAfterLast) - { - OSL_ENSURE(0,"Ask for bookmark but we stand on invalid row."); - throwFunctionSequenceException(*m_pMySelf); - } + if ( m_bBeforeFirst || m_bAfterLast ) + throwSQLException( "The rows before the first and after the last row don't have a bookmark.", SQL_INVALID_CURSOR_POSITION, *m_pMySelf ); - OSL_ENSURE(m_aBookmark.hasValue(),"Bookmark has no value!"); + if ( rowDeleted() ) + throwSQLException( "The current row is deleted, and this doesn't have a bookmark.", SQL_INVALID_CURSOR_POSITION, *m_pMySelf ); + + OSL_ENSURE( m_aBookmark.hasValue(), "ORowSetBase::getBookmark: bookmark has no value!" ); return m_aBookmark; } // ------------------------------------------------------------------------- sal_Bool SAL_CALL ORowSetBase::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException) { - DBG_TRACE1("DBACCESS ORowSetBase::moveToBookmark(Any) Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::moveToBookmark(Any) Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); OSL_ENSURE(bookmark.hasValue(),"ORowSetBase::moveToBookmark bookmark has no value!"); ::osl::ResettableMutexGuard aGuard( *m_pMutex ); @@ -450,7 +481,7 @@ if(bRet = notifyAllListenersCursorBeforeMove(aGuard)) { // check if we are inserting a row - sal_Bool bWasNew = m_pCache->m_bInserted || m_pCache->m_bDeleted; + sal_Bool bWasNew = m_pCache->m_bNew || rowDeleted(); ORowSetNotifier aNotifier( this ); // this will call cancelRowModification on the cache if necessary @@ -458,12 +489,13 @@ ORowSetRow aOldValues = getOldRow(bWasNew); bRet = m_pCache->moveToBookmark(bookmark); + m_pCache->clearModified(); if(bRet) { // notification order // - column values // - cursorMoved - setCurrentRow(sal_True,aOldValues,aGuard); + setCurrentRow( sal_True, sal_True, aOldValues, aGuard ); } else { @@ -487,12 +519,11 @@ checkPositioningAllowed(); - sal_Bool bRet; if(bRet = notifyAllListenersCursorBeforeMove(aGuard)) { // check if we are inserting a row - sal_Bool bWasNew = m_pCache->m_bInserted || m_pCache->m_bDeleted; + sal_Bool bWasNew = m_pCache->m_bNew || rowDeleted(); ORowSetNotifier aNotifier( this ); // this will call cancelRowModification on the cache if necessary @@ -500,12 +531,13 @@ ORowSetRow aOldValues = getOldRow(bWasNew); bRet = m_pCache->moveRelativeToBookmark(bookmark,rows); + m_pCache->clearModified(); if(bRet) { // notification order // - column values // - cursorMoved - setCurrentRow(sal_True,aOldValues,aGuard); + setCurrentRow( sal_True, sal_True, aOldValues, aGuard ); } else movementFailed(); @@ -588,7 +620,7 @@ // XResultSet sal_Bool SAL_CALL ORowSetBase::next( ) throw(SQLException, RuntimeException) { - DBG_TRACE1("DBACCESS ORowSetBase::next() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::next() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); ::osl::ResettableMutexGuard aGuard( *m_pMutex ); checkCache(); @@ -596,17 +628,17 @@ if(bRet = notifyAllListenersCursorBeforeMove(aGuard)) { // check if we are inserting a row - sal_Bool bWasNew = m_pCache->m_bInserted || m_pCache->m_bDeleted; + sal_Bool bWasNew = m_pCache->m_bNew || rowDeleted(); ORowSetNotifier aNotifier( this ); // this will call cancelRowModification on the cache if necessary ORowSetRow aOldValues = getOldRow(bWasNew); - if ( m_aBookmark.hasValue() ) // #104474# OJ - positionCache(); + positionCache( MOVE_FORWARD ); sal_Bool bAfterLast = m_pCache->isAfterLast(); bRet = m_pCache->next(); + m_pCache->clearModified(); if ( bRet || bAfterLast != m_pCache->isAfterLast() ) @@ -614,7 +646,7 @@ // notification order // - column values // - cursorMoved - setCurrentRow(sal_True,aOldValues,aGuard); + setCurrentRow( bRet, sal_True, aOldValues, aGuard ); OSL_ENSURE(!m_bBeforeFirst,"BeforeFirst is true. I don't know why?"); } else @@ -631,16 +663,16 @@ // - RowCount/IsRowCountFinal fireRowcount(); } - DBG_TRACE2("DBACCESS ORowSetBase::next() = %i Clone = %i\n",bRet,m_bClone); + DBG_TRACE3("DBACCESS ORowSetBase::next() = %i Clone = %i ID = %i\n",bRet,m_bClone,osl_getThreadIdentifier(NULL)); return bRet; } // ------------------------------------------------------------------------- sal_Bool SAL_CALL ORowSetBase::isBeforeFirst( ) throw(SQLException, RuntimeException) { - DBG_TRACE1("DBACCESS ORowSetBase::isBeforeFirst() Clone = %i\n",m_bClone); ::connectivity::checkDisposed(m_rBHelper.bDisposed); ::osl::MutexGuard aGuard( *m_pMutex ); - checkPositioningAllowed(); + checkCache(); + DBG_TRACE2("DBACCESS ORowSetBase::isBeforeFirst() = %i Clone = %i\n",m_bBeforeFirst,m_bClone); return m_bBeforeFirst; @@ -648,10 +680,9 @@ // ------------------------------------------------------------------------- sal_Bool SAL_CALL ORowSetBase::isAfterLast( ) throw(SQLException, RuntimeException) { - DBG_TRACE1("DBACCESS ORowSetBase::isAfterLast() Clone = %i\n",m_bClone); ::connectivity::checkDisposed(m_rBHelper.bDisposed); ::osl::MutexGuard aGuard( *m_pMutex ); - checkPositioningAllowed(); + checkCache(); DBG_TRACE2("DBACCESS ORowSetBase::isAfterLast() = %i Clone = %i\n",m_bAfterLast,m_bClone); return m_bAfterLast; @@ -664,18 +695,20 @@ // ------------------------------------------------------------------------- sal_Bool SAL_CALL ORowSetBase::isFirst( ) throw(SQLException, RuntimeException) { - DBG_TRACE1("DBACCESS ORowSetBase::isFirst() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::isFirst() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); ::connectivity::checkDisposed(m_rBHelper.bDisposed); ::osl::MutexGuard aGuard( *m_pMutex ); - checkPositioningAllowed(); + checkCache(); - sal_Bool bIsFirst = !(m_bBeforeFirst || m_bAfterLast); - if(bIsFirst) - { - positionCache(); - bIsFirst = m_pCache->isFirst(); - } + if ( m_bBeforeFirst || m_bAfterLast ) + return sal_False; + + if ( rowDeleted() ) + return ( m_nDeletedPosition == 1 ); + + positionCache( MOVE_NONE_REFRESH_ONLY ); + sal_Bool bIsFirst = m_pCache->isFirst(); DBG_TRACE2("DBACCESS ORowSetBase::isFirst() = %i Clone = %i\n",bIsFirst,m_bClone); return bIsFirst; @@ -688,31 +721,37 @@ // ----------------------------------------------------------------------------- sal_Bool SAL_CALL ORowSetBase::isLast( ) throw(SQLException, RuntimeException) { - DBG_TRACE1("DBACCESS ORowSetBase::isLast() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::isLast() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); ::connectivity::checkDisposed(m_rBHelper.bDisposed); ::osl::MutexGuard aGuard( *m_pMutex ); - checkPositioningAllowed(); + checkCache(); + + if ( m_bBeforeFirst || m_bAfterLast ) + return sal_False; + + if ( rowDeleted() ) + if ( !m_pCache->m_bRowCountFinal ) + return sal_False; + else + return ( m_nDeletedPosition == impl_getRowCount() ); + + positionCache( MOVE_NONE_REFRESH_ONLY ); + sal_Bool bIsLast = m_pCache->isLast(); - sal_Bool bIsLast = !(m_bBeforeFirst || m_bAfterLast); - if(bIsLast) // so we can't be on the last - { - positionCache(); - bIsLast = m_pCache->isLast(); - } DBG_TRACE2("DBACCESS ORowSetBase::isLast() = %i Clone = %i\n",bIsLast,m_bClone); return bIsLast; } // ------------------------------------------------------------------------- void SAL_CALL ORowSetBase::beforeFirst( ) throw(SQLException, RuntimeException) { - DBG_TRACE1("DBACCESS ORowSetBase::beforeFirst() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::beforeFirst() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); ::connectivity::checkDisposed(m_rBHelper.bDisposed); ::osl::ResettableMutexGuard aGuard( *m_pMutex ); checkPositioningAllowed(); // check if we are inserting a row - sal_Bool bWasNew = m_pCache->m_bInserted || m_pCache->m_bDeleted; + sal_Bool bWasNew = m_pCache->m_bNew || rowDeleted(); if((bWasNew || !m_bBeforeFirst) && notifyAllListenersCursorBeforeMove(aGuard) ) { @@ -723,11 +762,12 @@ { ORowSetRow aOldValues = getOldRow(bWasNew); m_pCache->beforeFirst(); + m_pCache->clearModified(); // notification order // - column values // - cursorMoved - setCurrentRow(sal_True,aOldValues,aGuard); + setCurrentRow( sal_True, sal_True, aOldValues, aGuard ); // - IsModified // - Isnew @@ -740,18 +780,18 @@ // to be done _after_ the notifications! m_aOldRow->clearRow(); } - DBG_TRACE1("DBACCESS ORowSetBase::beforeFirst() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::beforeFirst() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); } // ------------------------------------------------------------------------- void SAL_CALL ORowSetBase::afterLast( ) throw(SQLException, RuntimeException) { - DBG_TRACE1("DBACCESS ORowSetBase::afterLast() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::afterLast() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); ::connectivity::checkDisposed(m_rBHelper.bDisposed); ::osl::ResettableMutexGuard aGuard( *m_pMutex ); checkPositioningAllowed(); - sal_Bool bWasNew = m_pCache->m_bInserted || m_pCache->m_bDeleted; + sal_Bool bWasNew = m_pCache->m_bNew || rowDeleted(); if((bWasNew || !m_bAfterLast) && notifyAllListenersCursorBeforeMove(aGuard) ) { @@ -764,11 +804,12 @@ ORowSetRow aOldValues = getOldRow(bWasNew); m_pCache->afterLast(); + m_pCache->clearModified(); // notification order // - column values // - cursorMoved - setCurrentRow(sal_True,aOldValues,aGuard); + setCurrentRow( sal_True, sal_True, aOldValues, aGuard ); // - IsModified // - Isnew @@ -778,13 +819,13 @@ fireRowcount(); } } - DBG_TRACE1("DBACCESS ORowSetBase::afterLast() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::afterLast() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); } // ----------------------------------------------------------------------------- sal_Bool SAL_CALL ORowSetBase::move( ::std::mem_fun_t<sal_Bool,ORowSetBase>& _aCheckFunctor, ::std::mem_fun_t<sal_Bool,ORowSetCache>& _aMovementFunctor) { - DBG_TRACE1("DBACCESS ORowSetBase::move() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::move() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); ::connectivity::checkDisposed(m_rBHelper.bDisposed); ::osl::ResettableMutexGuard aGuard( *m_pMutex ); checkPositioningAllowed(); @@ -793,7 +834,7 @@ if(bRet = notifyAllListenersCursorBeforeMove(aGuard) ) { // check if we are inserting a row - sal_Bool bWasNew = m_pCache->m_bInserted || m_pCache->m_bDeleted; + sal_Bool bWasNew = m_pCache->m_bNew || rowDeleted(); ORowSetNotifier aNotifier( this ); // this will call cancelRowModification on the cache if necessary @@ -803,13 +844,14 @@ sal_Bool bMoved = ( bWasNew || !_aCheckFunctor(this) ); bRet = _aMovementFunctor(m_pCache); + m_pCache->clearModified(); if ( bRet ) { // notification order // - column values // - cursorMoved - setCurrentRow(bMoved,aOldValues,aGuard); + setCurrentRow( bMoved, sal_True, aOldValues, aGuard ); } else { // first goes wrong so there is no row @@ -829,7 +871,7 @@ // ------------------------------------------------------------------------- sal_Bool SAL_CALL ORowSetBase::first( ) throw(SQLException, RuntimeException) { - DBG_TRACE1("DBACCESS ORowSetBase::first() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::first() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); ::std::mem_fun_t<sal_Bool,ORowSetBase> ioF_tmp(&ORowSetBase::isOnFirst); ::std::mem_fun_t<sal_Bool,ORowSetCache> F_tmp(&ORowSetCache::first); return move(ioF_tmp,F_tmp); @@ -837,7 +879,7 @@ // ------------------------------------------------------------------------- sal_Bool SAL_CALL ORowSetBase::last( ) throw(SQLException, RuntimeException) { - DBG_TRACE1("DBACCESS ORowSetBase::last() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::last() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); ::std::mem_fun_t<sal_Bool,ORowSetBase> ioL_tmp(&ORowSetBase::isOnLast); ::std::mem_fun_t<sal_Bool,ORowSetCache> L_tmp(&ORowSetCache::last); return move(ioL_tmp,L_tmp); @@ -845,35 +887,33 @@ // ------------------------------------------------------------------------- sal_Int32 SAL_CALL ORowSetBase::getRow( ) throw(SQLException, RuntimeException) { - DBG_TRACE1("DBACCESS ORowSetBase::getRow() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::getRow() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); ::osl::MutexGuard aGuard( *m_pMutex ); + checkCache(); + sal_Int32 nPos = 0; - if(!(m_bAfterLast || m_bBeforeFirst)) // we are on no valid row - { - // check if we are inserting a row - if(!(!m_bClone && m_pCache->m_bInserted)) - { - if(!m_aBookmark.hasValue()) // check if we are standing on a deleted row - nPos = m_nPosition; + if ( m_bBeforeFirst ) + nPos = 0; + else if ( m_bAfterLast ) + nPos = impl_getRowCount() + 1; + else if ( rowDeleted() ) + nPos = m_nDeletedPosition; + else if ( !m_bClone && m_pCache->m_bNew ) + nPos = 0; else { - if(m_pCache->m_bAfterLast || m_pCache->m_bBeforeFirst || m_pCache->compareBookmarks(m_aBookmark,m_pCache->getBookmark()) != CompareBookmark::EQUAL) + if ( m_pCache->isAfterLast() + || m_pCache->isBeforeFirst() + || ( m_pCache->compareBookmarks( m_aBookmark, m_pCache->getBookmark() ) != CompareBookmark::EQUAL ) + ) { -#ifdef DBG_UTIL - sal_Bool bRet = m_pCache->moveToBookmark(m_aBookmark); - OSL_ENSURE(bRet,"moveToBookamrk failed so the position isn't valid!"); -#else - m_pCache->moveToBookmark(m_aBookmark); - -#endif + positionCache( MOVE_NONE_REFRESH_ONLY ); } nPos = m_pCache->getRow(); } - } - } - DBG_TRACE2("DBACCESS ORowSetBase::getRow() = %i Clone = %i\n",nPos,m_bClone); + DBG_TRACE3("DBACCESS ORowSetBase::getRow() = %i Clone = %i ID = %i\n",nPos,m_bClone,osl_getThreadIdentifier(NULL)); return nPos; } // ------------------------------------------------------------------------- @@ -884,12 +924,11 @@ ::osl::ResettableMutexGuard aGuard( *m_pMutex ); checkPositioningAllowed(); - sal_Bool bRet = !(m_bAfterLast && row > 1); // m_bAfterLast && row > 1 we are already behind the last row - + sal_Bool bRet = row > 0; if ( bRet && (bRet = notifyAllListenersCursorBeforeMove(aGuard)) ) { // check if we are inserting a row - sal_Bool bWasNew = m_pCache->m_bInserted || m_pCache->m_bDeleted; + sal_Bool bWasNew = m_pCache->m_bNew || rowDeleted(); ORowSetNotifier aNotifier( this ); // this will call cancelRowModification on the cache if necessary @@ -897,13 +936,14 @@ ORowSetRow aOldValues = getOldRow(bWasNew); bRet = m_pCache->absolute(row); + m_pCache->clearModified(); if(bRet) { // notification order // - column values // - cursorMoved - setCurrentRow(sal_True,aOldValues,aGuard); + setCurrentRow( sal_True, sal_True, aOldValues, aGuard ); } else { // absolute movement goes wrong we stand left or right side of the rows @@ -933,29 +973,29 @@ checkPositioningAllowed(); - sal_Bool bRet =!((m_bAfterLast && rows > 1) || (m_bBeforeFirst && rows < 0)); // we are already behind the last row or before the first + sal_Bool bRet =!((m_bAfterLast && rows > 0) || (m_bBeforeFirst && rows < 0)); // we are already behind the last row or before the first if(bRet && (bRet = notifyAllListenersCursorBeforeMove(aGuard))) { // check if we are inserting a row - sal_Bool bWasNew = m_pCache->m_bInserted || m_pCache->m_bDeleted; + sal_Bool bWasNew = m_pCache->m_bNew || rowDeleted(); ORowSetNotifier aNotifier( this ); // this will call cancelRowModification on the cache if necessary ORowSetRow aOldValues = getOldRow(bWasNew); - if ( m_aBookmark.hasValue() ) // #104474# OJ - positionCache(); + positionCache( rows > 0 ? MOVE_FORWARD : MOVE_BACKWARD ); bRet = m_pCache->relative(rows); + m_pCache->clearModified(); if(bRet) { // notification order // - column values // - cursorMoved - setCurrentRow(sal_True,aOldValues,aGuard); + setCurrentRow( sal_True, sal_True, aOldValues, aGuard ); } else { @@ -975,7 +1015,7 @@ // ------------------------------------------------------------------------- sal_Bool SAL_CALL ORowSetBase::previous( ) throw(SQLException, RuntimeException) { - DBG_TRACE1("DBACCESS ORowSetBase::previous() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::previous() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); ::connectivity::checkDisposed(m_rBHelper.bDisposed); ::osl::ResettableMutexGuard aGuard( *m_pMutex ); @@ -986,16 +1026,16 @@ if(bRet && (bRet = notifyAllListenersCursorBeforeMove(aGuard))) { // check if we are inserting a row - sal_Bool bWasNew = m_pCache->m_bInserted || m_pCache->m_bDeleted; + sal_Bool bWasNew = m_pCache->m_bNew || rowDeleted(); ORowSetNotifier aNotifier( this ); // this will call cancelRowModification on the cache if necessary ORowSetRow aOldValues = getOldRow(bWasNew); - if ( m_aBookmark.hasValue() ) // #104474# OJ - positionCache(); + positionCache( MOVE_BACKWARD ); bRet = m_pCache->previous(); + m_pCache->clearModified(); // if m_bBeforeFirst is false and bRet is false than we stood on the first row if(!m_bBeforeFirst || bRet) @@ -1003,26 +1043,33 @@ // notification order // - column values // - cursorMoved - setCurrentRow(sal_True,aOldValues,aGuard); + setCurrentRow( sal_True, sal_True, aOldValues, aGuard ); } else { + DBG_ERROR( "ORowSetBase::previous: inconsistency!" ); + // we should never reach this place, as we should not get into this whole branch if m_bBeforeFirst + // was |true| from the beginning movementFailed(); } // - IsModified // - IsNew aNotifier.fire(); + + // - RowCount/IsRowCountFinal + fireRowcount(); } DBG_TRACE2("DBACCESS ORowSetBase::previous() = %i Clone = %i\n",bRet,m_bClone); return bRet; } // ----------------------------------------------------------------------------- -void ORowSetBase::setCurrentRow(sal_Bool _bMoved,const ORowSetRow& _rOldValues,::osl::ResettableMutexGuard& _rGuard) +void ORowSetBase::setCurrentRow( sal_Bool _bMoved, sal_Bool _bDoNotify, const ORowSetRow& _rOldValues, ::osl::ResettableMutexGuard& _rGuard ) { - DBG_TRACE1("DBACCESS ORowSetBase::setCurrentRow() Clone = %i",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::setCurrentRow() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); m_bBeforeFirst = m_pCache->isBeforeFirst(); m_bAfterLast = m_pCache->isAfterLast(); + //m_pCache->resetInsertRow(sal_True); if(!(m_bBeforeFirst || m_bAfterLast)) { @@ -1036,45 +1083,43 @@ OSL_ENSURE(m_aBookmark.hasValue(),"Bookmark has no value!"); sal_Int32 nOldRow = m_pCache->getRow(); - positionCache(); + positionCache( MOVE_NONE_REFRESH_ONLY ); sal_Int32 nNewRow = m_pCache->getRow(); OSL_ENSURE(nOldRow == nNewRow,"Old position is not equal to new postion"); m_aCurrentRow = m_pCache->m_aMatrixIter; OSL_ENSURE(!m_aCurrentRow.isNull(),"CurrentRow is nul after positionCache!"); - } - else - { - m_aOldRow->clearRow(); - m_aCurrentRow = m_pCache->getEnd(); - m_aBookmark = Any(); - m_aCurrentRow.setBookmark(m_aBookmark); - } - if ( _bMoved ) - { // the cache could repositioned so we need to adjust the cache // #104144# OJ - if ( m_aCurrentRow.isNull() ) + if ( _bMoved && m_aCurrentRow.isNull() ) { - positionCache(); + positionCache( MOVE_NONE_REFRESH_ONLY ); m_aCurrentRow = m_pCache->m_aMatrixIter; OSL_ENSURE(!m_aCurrentRow.isNull(),"CurrentRow is nul after positionCache!"); } } + else + { + m_aOldRow->clearRow(); + m_aCurrentRow = m_pCache->getEnd(); + m_aBookmark = Any(); + m_aCurrentRow.setBookmark(m_aBookmark); + } // notification order // - column values + if ( _bDoNotify ) firePropertyChange(_rOldValues); // TODO: can this be done before the notifications? if(!(m_bBeforeFirst || m_bAfterLast) && !m_aCurrentRow.isNull() && m_aCurrentRow->isValid() && m_aCurrentRow != m_pCache->getEnd()) m_aOldRow->setRow(new ORowSetValueVector(m_aCurrentRow->getBody())); - if ( _bMoved ) + if ( _bMoved && _bDoNotify ) // - cursorMoved notifyAllListenersCursorMoved( _rGuard ); - DBG_TRACE1("DBACCESS ORowSetBase::setCurrentRow() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::setCurrentRow() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); } // ----------------------------------------------------------------------------- void ORowSetBase::checkPositioningAllowed() throw( SQLException, RuntimeException ) @@ -1092,11 +1137,13 @@ { ::connectivity::checkDisposed(m_rBHelper.bDisposed); ::osl::MutexGuard aGuard( *m_pMutex ); - checkPositioningAllowed(); + checkCache(); + if ( rowDeleted() ) + throwSQLException( "The current row is deleted", SQL_INVALID_CURSOR_STATE, Reference< XRowSet >( this ) ); if(!(m_bBeforeFirst || m_bAfterLast)) { - positionCache(); + positionCache( MOVE_NONE_REFRESH_ONLY ); m_pCache->refreshRow(); } } @@ -1106,14 +1153,29 @@ ::osl::MutexGuard aGuard( *m_pMutex ); checkCache(); + + if ( rowDeleted() ) + return sal_False; + + if ( rowDeleted() ) + return sal_False; + return m_pCache->rowUpdated(); } // ------------------------------------------------------------------------- sal_Bool SAL_CALL ORowSetBase::rowInserted( ) throw(SQLException, RuntimeException) { ::osl::MutexGuard aGuard( *m_pMutex ); + checkCache(); + + if ( rowDeleted() ) + return sal_False; + + if ( rowDeleted() ) + return sal_False; + return m_pCache->rowInserted(); } // ------------------------------------------------------------------------- @@ -1122,7 +1184,7 @@ ::osl::MutexGuard aGuard( *m_pMutex ); checkCache(); - return m_pCache->rowDeleted(); + return !m_aBookmark.hasValue() && !m_bBeforeFirst && !m_bAfterLast; } // ------------------------------------------------------------------------- // XWarningsSupplier @@ -1143,6 +1205,7 @@ ::osl::MutexGuard aGuard( *m_pMutex ); checkCache(); + Reference< XWarningsSupplier > xWarnings( m_pCache->m_xSet.get(), UNO_QUERY ); if ( xWarnings.is() ) xWarnings->clearWarnings(); @@ -1150,14 +1213,12 @@ // ------------------------------------------------------------------------- void ORowSetBase::firePropertyChange(const ORowSetRow& _rOldRow) { - DBG_TRACE1("DBACCESS ORowSetBase::firePropertyChange() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::firePropertyChange() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); OSL_ENSURE(m_pColumns,"Columns can not be NULL here!"); #if OSL_DEBUG_LEVEL > 1 sal_Bool bNull = m_aCurrentRow.isNull(); ORowSetMatrix::iterator atest = m_aCurrentRow; #endif - // OSL_ENSURE(!m_aCurrentRow.isNull() && m_aCurrentRow != m_pCache->getEnd(),"Position of matrix iterator isn't valid!"); - OSL_ENSURE(m_aCurrentRow->isValid(),"Currentrow isn't valid"); sal_Int32 i=0; try { @@ -1168,13 +1229,13 @@ { OSL_ENSURE(0,"firePropertyChange: Exception"); } - DBG_TRACE1("DBACCESS ORowSetBase::firePropertyChange() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::firePropertyChange() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); } // ----------------------------------------------------------------------------- sal_Bool ORowSetBase::isModification( ) { - return m_pCache && m_pCache->m_bInserted; + return m_pCache && m_pCache->m_bNew; } // ----------------------------------------------------------------------------- @@ -1186,17 +1247,59 @@ } // ----------------------------------------------------------------------------- -void ORowSetBase::positionCache() +void ORowSetBase::positionCache( CursorMoveDirection _ePrepareForDirection ) { - DBG_TRACE1("DBACCESS ORowSetBase::positionCache() Clone = %i\n",m_bClone); - if(m_aBookmark.hasValue()) + DBG_TRACE2("DBACCESS ORowSetBase::positionCache() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); + + sal_Bool bSuccess = sal_False; + if ( m_aBookmark.hasValue() ) + { + bSuccess = m_pCache->moveToBookmark( m_aBookmark ); + } + else + { + if ( m_bBeforeFirst ) + { + bSuccess = m_pCache->beforeFirst(); + } + else if ( m_bAfterLast ) + { + bSuccess = m_pCache->afterLast(); + } + else + { + OSL_ENSURE( m_nDeletedPosition >= 1, "ORowSetBase::positionCache: no bookmark, and no valid 'deleted position'!" ); + switch ( _ePrepareForDirection ) + { + case MOVE_FORWARD: + if ( m_nDeletedPosition > 1 ) + bSuccess = m_pCache->absolute( m_nDeletedPosition - 1 ); + else + { + m_pCache->beforeFirst(); + bSuccess = sal_True; + } + break; + + case MOVE_BACKWARD: + if ( m_pCache->m_bRowCountFinal && ( m_nDeletedPosition == impl_getRowCount() ) ) { - sal_Bool bOK = m_pCache->moveToBookmark(m_aBookmark); - OSL_ENSURE(bOK ,"ORowSetBase::positionCache: positioning cache fails!"); + m_pCache->afterLast(); + bSuccess = sal_True; } else - OSL_ENSURE(0,"ORowSetBase::positionCache: no bookmark set!"); - DBG_TRACE1("DBACCESS ORowSetBase::positionCache() Clone = %i\n",m_bClone); + bSuccess = m_pCache->absolute( m_nDeletedPosition ); + break; + + case MOVE_NONE_REFRESH_ONLY: + bSuccess = sal_False; // will be asserted below + break; + } + } + } + OSL_ENSURE( bSuccess, "ORowSetBase::positionCache: failed!" ); + + DBG_TRACE2("DBACCESS ORowSetBase::positionCache() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); } // ----------------------------------------------------------------------------- void ORowSetBase::checkCache() @@ -1208,7 +1311,7 @@ // ----------------------------------------------------------------------------- void ORowSetBase::movementFailed() { - DBG_TRACE1("DBACCESS ORowSetBase::movementFailed() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::movementFailed() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); m_aOldRow->clearRow(); m_aCurrentRow = m_pCache->getEnd(); m_bBeforeFirst = m_pCache->isBeforeFirst(); @@ -1216,7 +1319,7 @@ m_aBookmark = Any(); m_aCurrentRow.setBookmark(m_aBookmark); OSL_ENSURE(m_bBeforeFirst || m_bAfterLast,"BeforeFirst or AfterLast is wrong!"); - DBG_TRACE1("DBACCESS ORowSetBase::movementFailed() Clone = %i\n",m_bClone); + DBG_TRACE2("DBACCESS ORowSetBase::movementFailed() Clone = %i ID = %i\n",m_bClone,osl_getThreadIdentifier(NULL)); } // ----------------------------------------------------------------------------- ORowSetRow ORowSetBase::getOldRow(sal_Bool _bWasNew) @@ -1232,6 +1335,51 @@ { _rDefault.clear(); } +// ----------------------------------------------------------------------------- +void ORowSetBase::onDeleteRow( const Any& _rBookmark ) +{ + if ( rowDeleted() ) + // not interested in + return; + + ::osl::MutexGuard aGuard( *m_pMutex ); + OSL_ENSURE( m_aBookmark.hasValue(), "ORowSetBase::onDeleteRow: Bookmark isn't valid!" ); + if ( compareBookmarks( _rBookmark, m_aBookmark ) == 0 ) + { + positionCache( MOVE_NONE_REFRESH_ONLY ); + m_nDeletedPosition = m_pCache->getRow(); + } +} +// ----------------------------------------------------------------------------- +void ORowSetBase::onDeletedRow( const Any& _rBookmark, sal_Int32 _nPos ) +{ + if ( rowDeleted() ) + { + // if we're a clone, and on a deleted row, and the main RowSet deleted another + // row (only the main RowSet can, clones can't), which is *before* our + // deleted position, then we have to adjust this position + if ( m_bClone && ( _nPos < m_nDeletedPosition ) ) + --m_nDeletedPosition; + return; + } + + ::osl::MutexGuard aGuard( *m_pMutex ); + if ( compareBookmarks( _rBookmark, m_aBookmark ) == 0 ) + { + m_aOldRow->clearRow(); + m_aCurrentRow = m_pCache->getEnd(); + m_aBookmark = Any(); + m_aCurrentRow.setBookmark( m_aBookmark ); + } +} +// ----------------------------------------------------------------------------- +sal_Int32 ORowSetBase::impl_getRowCount() const +{ + sal_Int32 nRowCount( m_pCache->m_nRowCount ); + if ( const_cast< ORowSetBase* >( this )->rowDeleted() && !m_pCache->m_bNew ) + ++nRowCount; + return nRowCount; +} // ============================================================================= DBG_NAME(ORowSetNotifier) // ----------------------------------------------------------------------------- @@ -1248,7 +1396,7 @@ OSL_ENSURE( m_pRowSet, "ORowSetNotifier::ORowSetNotifier: invalid row set. This wil crash." ); // remember the "inserted" and "modified" state for later firing - m_bWasNew = m_pRowSet->isNew( ORowSetBase::GrantNotifierAccess() );; + m_bWasNew = m_pRowSet->isNew( ORowSetBase::GrantNotifierAccess() ); m_bWasModified = m_pRowSet->isModified( ORowSetBase::GrantNotifierAccess() ); // if the row set is on the insert row, then we need to cancel this @@ -1259,7 +1407,6 @@ // ----------------------------------------------------------------------------- ORowSetNotifier::~ORowSetNotifier( ) { - DBG_DTOR(ORowSetNotifier,NULL); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
