Tag: cws_src680_dba202f User: fs Date: 06/01/26 22:53:45 Modified: /dba/dbaccess/source/core/api/ RowSetBase.cxx
Log: RESYNC: (1.80-1.83); 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.80.8.1&r2=1.80.8.2 Delta lines: +234 -127 ----------------------- --- RowSetBase.cxx 20 Jan 2006 14:51:44 -0000 1.80.8.1 +++ RowSetBase.cxx 27 Jan 2006 06:53:42 -0000 1.80.8.2 @@ -138,12 +138,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 +150,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 +195,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()); @@ -246,6 +246,8 @@ 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 ); @@ -253,10 +255,24 @@ 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() ) + 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,19 +281,8 @@ 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 + // we should normally never reach this return m_aEmptyValue; } // ------------------------------------------------------------------------- @@ -351,13 +356,16 @@ 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); } } @@ -417,14 +425,15 @@ DBG_TRACE1("DBACCESS ORowSetBase::getBookmark() Clone = %i\n",m_bClone); ::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; } // ------------------------------------------------------------------------- @@ -450,7 +459,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_bInserted || rowDeleted(); ORowSetNotifier aNotifier( this ); // this will call cancelRowModification on the cache if necessary @@ -464,7 +473,7 @@ // notification order // - column values // - cursorMoved - setCurrentRow(sal_True,aOldValues,aGuard); + setCurrentRow( sal_True, sal_True, aOldValues, aGuard ); } else { @@ -488,12 +497,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_bInserted || rowDeleted(); ORowSetNotifier aNotifier( this ); // this will call cancelRowModification on the cache if necessary @@ -507,7 +515,7 @@ // notification order // - column values // - cursorMoved - setCurrentRow(sal_True,aOldValues,aGuard); + setCurrentRow( sal_True, sal_True, aOldValues, aGuard ); } else movementFailed(); @@ -598,15 +606,14 @@ 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_bInserted || 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(); @@ -617,7 +624,7 @@ // notification order // - column values // - cursorMoved - setCurrentRow(bRet,aOldValues,aGuard); + setCurrentRow( bRet, sal_True, aOldValues, aGuard ); OSL_ENSURE(!m_bBeforeFirst,"BeforeFirst is true. I don't know why?"); } else @@ -640,10 +647,10 @@ // ------------------------------------------------------------------------- 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; @@ -651,10 +658,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; @@ -671,14 +677,16 @@ ::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; @@ -694,14 +702,20 @@ DBG_TRACE1("DBACCESS ORowSetBase::isLast() Clone = %i\n",m_bClone); ::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; } @@ -715,7 +729,7 @@ 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_bInserted || rowDeleted(); if((bWasNew || !m_bBeforeFirst) && notifyAllListenersCursorBeforeMove(aGuard) ) { @@ -731,7 +745,7 @@ // notification order // - column values // - cursorMoved - setCurrentRow(sal_True,aOldValues,aGuard); + setCurrentRow( sal_True, sal_True, aOldValues, aGuard ); // - IsModified // - Isnew @@ -755,7 +769,7 @@ ::osl::ResettableMutexGuard aGuard( *m_pMutex ); checkPositioningAllowed(); - sal_Bool bWasNew = m_pCache->m_bInserted || m_pCache->m_bDeleted; + sal_Bool bWasNew = m_pCache->m_bInserted || rowDeleted(); if((bWasNew || !m_bAfterLast) && notifyAllListenersCursorBeforeMove(aGuard) ) { @@ -773,7 +787,7 @@ // notification order // - column values // - cursorMoved - setCurrentRow(sal_True,aOldValues,aGuard); + setCurrentRow( sal_True, sal_True, aOldValues, aGuard ); // - IsModified // - Isnew @@ -798,7 +812,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_bInserted || rowDeleted(); ORowSetNotifier aNotifier( this ); // this will call cancelRowModification on the cache if necessary @@ -815,7 +829,7 @@ // notification order // - column values // - cursorMoved - setCurrentRow(bMoved,aOldValues,aGuard); + setCurrentRow( bMoved, sal_True, aOldValues, aGuard ); } else { // first goes wrong so there is no row @@ -856,29 +870,25 @@ 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_bInserted ) + 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); return nPos; } @@ -890,12 +900,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_bInserted || rowDeleted(); ORowSetNotifier aNotifier( this ); // this will call cancelRowModification on the cache if necessary @@ -910,7 +919,7 @@ // 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 @@ -940,21 +949,20 @@ 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_bInserted || 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(); @@ -963,7 +971,7 @@ // notification order // - column values // - cursorMoved - setCurrentRow(sal_True,aOldValues,aGuard); + setCurrentRow( sal_True, sal_True, aOldValues, aGuard ); } else { @@ -994,15 +1002,14 @@ 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_bInserted || 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(); @@ -1012,22 +1019,28 @@ // 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); m_bBeforeFirst = m_pCache->isBeforeFirst(); @@ -1046,41 +1059,39 @@ 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 ); @@ -1102,11 +1113,14 @@ { ::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(); } } @@ -1116,6 +1130,9 @@ ::osl::MutexGuard aGuard( *m_pMutex ); checkCache(); + if ( rowDeleted() ) + return sal_False; + return m_pCache->rowUpdated(); } // ------------------------------------------------------------------------- @@ -1124,6 +1141,9 @@ ::osl::MutexGuard aGuard( *m_pMutex ); checkCache(); + if ( rowDeleted() ) + return sal_False; + return m_pCache->rowInserted(); } // ------------------------------------------------------------------------- @@ -1132,7 +1152,7 @@ ::osl::MutexGuard aGuard( *m_pMutex ); checkCache(); - return m_pCache->rowDeleted(); + return !m_aBookmark.hasValue() && !m_bBeforeFirst && !m_bAfterLast; } // ------------------------------------------------------------------------- // XWarningsSupplier @@ -1194,16 +1214,58 @@ } // ----------------------------------------------------------------------------- -void ORowSetBase::positionCache() +void ORowSetBase::positionCache( CursorMoveDirection _ePrepareForDirection ) { DBG_TRACE1("DBACCESS ORowSetBase::positionCache() Clone = %i\n",m_bClone); - if(m_aBookmark.hasValue()) + + 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!"); + 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_TRACE1("DBACCESS ORowSetBase::positionCache() Clone = %i\n",m_bClone); } // ----------------------------------------------------------------------------- @@ -1240,6 +1302,52 @@ { return Any(); } +// ----------------------------------------------------------------------------- +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_bInserted ) + ++nRowCount; + return nRowCount; +} + // ============================================================================= DBG_NAME(ORowSetNotifier) // ----------------------------------------------------------------------------- @@ -1267,7 +1375,6 @@ // ----------------------------------------------------------------------------- ORowSetNotifier::~ORowSetNotifier( ) { - DBG_DTOR(ORowSetNotifier,NULL); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
