office-gobmx/connectivity/source/commontools/TSkipDeletedSet.cxx
Rüdiger Timm 5a0228bf90 CWS-TOOLING: integrate CWS dba31d
2008-12-08 16:22:07 +0100 rt  r265005 : Remove DOS lineends
2008-12-05 13:56:24 +0100 fs  r264906 : #i10000# removed unreachable statement
2008-11-20 11:41:26 +0100 fs  r264037 : merged in the fix for #i95865# (it was wrongly committed to CWS dba32a, should have been here)
2008-11-20 11:34:24 +0100 fs  r264036 : line ends
2008-11-14 08:44:50 +0100 lla  r263665 : #i10000# comparsion between int and uint fixed
2008-11-13 13:31:12 +0100 lla  r263641 : #i10000# build problem fixed
2008-11-13 11:20:01 +0100 lla  r263625 : #i96130# hard code name of extension
2008-11-12 11:13:41 +0100 fs  r263582 : #i96096# when opening a SRB-report fails due to the missing SRB extension, log this as warning only, and proceed with the migration
2008-11-12 11:11:35 +0100 fs  r263581 : #i96096# ContentType handling. Now all contents deliver proper results in XContent::getContentType
2008-11-12 11:10:11 +0100 fs  r263580 : #i96096# new ctors taking UNO_QUERY_THROW
2008-11-11 10:10:13 +0100 lla  r263546 : CWS-TOOLING: rebase CWS dba31d to trunk@263288 (milestone: DEV300:m35)
2008-11-06 15:55:39 +0100 oj  r263393 : #i93452# get field from model fallbackis the name
2008-11-06 15:31:47 +0100 oj  r263392 : #i93465# remeber location of floating windows
2008-11-06 13:36:24 +0100 oj  r263381 : #i93450# check typemap for null
2008-11-06 13:28:49 +0100 oj  r263379 : #i93020# empty column list boxes when new relation should be created
2008-11-06 12:33:53 +0100 oj  r263377 : #i93012# set border to default : flat
2008-11-06 12:26:54 +0100 oj  r263375 : #i74927# do some less calls for odbc
2008-11-06 09:34:01 +0100 oj  r263362 : #i93383# grabFocus in suspend to get allmodified cells
2008-11-03 21:01:39 +0100 oj  r263308 : #i86739# check if slash can be valid for tables
2008-11-03 14:40:21 +0100 oj  r263287 : #i86739# check if slash can be valid for tables
2008-11-03 14:32:17 +0100 oj  r263286 : #i95227# column width 
2008-11-03 14:27:26 +0100 oj  r263285 : link fwe
2008-11-03 14:24:54 +0100 oj  r263284 : #i95235# changed to hold no ref only weak
2008-10-31 11:21:48 +0100 oj  r262859 : #i93459# set images add menu entry
2008-10-31 09:06:37 +0100 oj  r262851 : #i88629# correct fileopen filter for database odb files
2008-10-30 15:01:04 +0100 oj  r262828 : #i95229# set filter at the composer
2008-10-29 15:57:41 +0100 oj  r262817 : #i95235# changed to hold no ref only weak
2008-10-29 15:57:19 +0100 oj  r262816 : #i95235# changed to hold no ref only weak
2008-10-29 15:57:03 +0100 oj  r262815 : #i95235# changed to hold no ref only weak
2008-10-29 15:56:15 +0100 oj  r262814 : #i95235# filtermanger changed to hold no ref only weak
2008-10-29 10:32:39 +0100 oj  r262773 : #i93474# use correct table name
2008-10-28 13:49:33 +0100 lla  r262744 : #i95524# make an Invalidate and refresh on Tables
2008-10-28 10:45:02 +0100 fs  r262707 : line ends
2008-10-28 10:34:42 +0100 fs  r262706 : #i95522# don't expect the component to live in a TopWindow
2008-10-28 08:30:40 +0100 lla  r262696 : #i93176# set preview mode on view
2008-10-28 07:56:57 +0100 oj  r262694 : merge cvs svn
2008-10-27 14:13:51 +0100 oj  r262673 : #i94129# use dummy data
2008-10-27 12:38:45 +0100 fs  r262669 : #i94125# rework ScrollColumns
2008-10-23 15:53:57 +0200 oj  r262624 : #i94568# do not load the embeddedobj just copy the storage
2008-10-23 14:39:14 +0200 oj  r262622 : #i94129# handle chart correctly
2008-10-22 10:51:19 +0200 lla  r262582 : #i94115# problem with left walk chart shape fixed
2008-10-22 07:47:48 +0200 oj  r262576 : #i94455# rename now do not use remove insert
2008-10-22 07:47:27 +0200 oj  r262575 : #i94455# rename now do not use remove insert
2008-10-21 12:46:26 +0200 lla  r262567 : #i93845# extra check if default schema doesn't exists, fix assertion
2008-12-09 07:25:38 +00:00

281 lines
13 KiB
C++

/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: TSkipDeletedSet.cxx,v $
* $Revision: 1.10 $
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_connectivity.hxx"
#include "TSkipDeletedSet.hxx"
#include <osl/diagnose.h>
#include <rtl/logfile.hxx>
using namespace connectivity;
// -----------------------------------------------------------------------------
OSkipDeletedSet::OSkipDeletedSet(IResultSetHelper* _pHelper)
: m_pHelper(_pHelper)
{
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "commontools", "Ocke.Janssen@sun.com", "OSkipDeletedSet::OSkipDeletedSet" );
m_bDeletedVisible = m_pHelper->deletedVisible();
m_aBookmarksPositions.reserve(256);
}
// -----------------------------------------------------------------------------
OSkipDeletedSet::~OSkipDeletedSet()
{
m_aBookmarksPositions.clear();
//m_aBookmarks.clear();
}
// -----------------------------------------------------------------------------
sal_Bool OSkipDeletedSet::skipDeleted(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, sal_Bool _bRetrieveData)
{
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "commontools", "Ocke.Janssen@sun.com", "OSkipDeletedSet::skipDeleted" );
OSL_ENSURE(_eCursorPosition != IResultSetHelper::BOOKMARK,"OSkipDeletedSet::SkipDeleted can't be called for BOOKMARK");
IResultSetHelper::Movement eDelPosition = _eCursorPosition;
sal_Int32 nDelOffset = abs(_nOffset);
switch (_eCursorPosition)
{
case IResultSetHelper::ABSOLUTE:
return moveAbsolute(_nOffset,_bRetrieveData);
case IResultSetHelper::FIRST: // set the movement when positioning failed
eDelPosition = IResultSetHelper::NEXT;
nDelOffset = 1;
break;
case IResultSetHelper::LAST:
eDelPosition = IResultSetHelper::PRIOR; // lsat row is invalid so position before
nDelOffset = 1;
break;
case IResultSetHelper::RELATIVE:
eDelPosition = (_nOffset >= 0) ? IResultSetHelper::NEXT : IResultSetHelper::PRIOR;
break;
default:
break;
}
sal_Bool bDone = sal_True;
sal_Bool bDataFound = sal_False;
if (_eCursorPosition == IResultSetHelper::LAST)
{
RTL_LOGFILE_CONTEXT_TRACE( aLogger, "OSkipDeletedSet::skipDeleted: last" );
sal_Int32 nBookmark = 0;
// first position on the last known row
if ( m_aBookmarksPositions.empty() )
{
bDataFound = m_pHelper->move(IResultSetHelper::FIRST, 0, _bRetrieveData);
if(bDataFound && (m_bDeletedVisible || !m_pHelper->isRowDeleted()))
//m_aBookmarksPositions.push_back(m_aBookmarks.insert(TInt2IntMap::value_type(m_pHelper->getDriverPos(),m_aBookmarksPositions.size()+1)).first);
m_aBookmarksPositions.push_back(m_pHelper->getDriverPos());
}
else
{
// I already have a bookmark so we can positioned on that and look if it is the last one
nBookmark = (*m_aBookmarksPositions.rbegin())/*->first*/;
bDataFound = m_pHelper->move(IResultSetHelper::BOOKMARK, nBookmark, _bRetrieveData);
OSL_ENSURE((m_bDeletedVisible || !m_pHelper->isRowDeleted()),"A bookmark should not be deleted!");
}
// and than move forward until we are after the last row
while(bDataFound)
{
bDataFound = m_pHelper->move(IResultSetHelper::NEXT, 1, sal_False); // we don't need the data here
if( bDataFound && ( m_bDeletedVisible || !m_pHelper->isRowDeleted()) )
{ // we weren't on the last row we remember it and move on
m_aBookmarksPositions.push_back(m_pHelper->getDriverPos());
//m_aBookmarksPositions.push_back(m_aBookmarks.insert(TInt2IntMap::value_type(m_pHelper->getDriverPos(),m_aBookmarksPositions.size()+1)).first);
}
else if(!bDataFound && !m_aBookmarksPositions.empty() )
{
// i already know the last bookmark :-)
// now we only have to repositioning us to the last row
nBookmark = (*m_aBookmarksPositions.rbegin())/*->first*/;
bDataFound = m_pHelper->move(IResultSetHelper::BOOKMARK, nBookmark, _bRetrieveData);
break;
}
}
return bDataFound;
}
else if (_eCursorPosition != IResultSetHelper::RELATIVE)
{
bDataFound = m_pHelper->move(_eCursorPosition, _nOffset, _bRetrieveData);
bDone = bDataFound && (m_bDeletedVisible || !m_pHelper->isRowDeleted());
}
else
{
bDataFound = m_pHelper->move(eDelPosition, 1, _bRetrieveData);
if (bDataFound && (m_bDeletedVisible || !m_pHelper->isRowDeleted()))
{
bDone = (--nDelOffset) == 0;
if ( !bDone )
m_aBookmarksPositions.push_back(m_pHelper->getDriverPos());
//m_aBookmarksPositions.push_back(m_aBookmarks.insert(TInt2IntMap::value_type(m_pHelper->getDriverPos(),m_aBookmarksPositions.size()+1)).first);
}
else
bDone = sal_False;
}
while (bDataFound && !bDone) // solange iterieren bis man auf einem gueltigen Satz ist
{
bDataFound = m_pHelper->move(eDelPosition, 1, _bRetrieveData);
if (_eCursorPosition != IResultSetHelper::RELATIVE)
bDone = bDataFound && (m_bDeletedVisible || !m_pHelper->isRowDeleted());
else if (bDataFound && (m_bDeletedVisible || !m_pHelper->isRowDeleted()))
{
bDone = (--nDelOffset) == 0;
if ( !bDone )
m_aBookmarksPositions.push_back(m_pHelper->getDriverPos());
//m_aBookmarksPositions.push_back(m_aBookmarks.insert(TInt2IntMap::value_type(m_pHelper->getDriverPos(),m_aBookmarksPositions.size()+1)).first);
}
else
bDone = sal_False;
}
if(bDataFound && bDone )
{
const sal_Int32 nDriverPos = m_pHelper->getDriverPos();
if ( ::std::find(m_aBookmarksPositions.begin(),m_aBookmarksPositions.end(),nDriverPos) == m_aBookmarksPositions.end() )
m_aBookmarksPositions.push_back(nDriverPos);
/*sal_Int32 nDriverPos = m_pHelper->getDriverPos();
if(m_aBookmarks.find(nDriverPos) == m_aBookmarks.end())
m_aBookmarksPositions.push_back(m_aBookmarks.insert(TInt2IntMap::value_type(nDriverPos,m_aBookmarksPositions.size()+1)).first);*/
}
return bDataFound;
}
// -------------------------------------------------------------------------
sal_Bool OSkipDeletedSet::moveAbsolute(sal_Int32 _nPos,sal_Bool _bRetrieveData)
{
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "commontools", "Ocke.Janssen@sun.com", "OSkipDeletedSet::moveAbsolute" );
sal_Bool bDataFound = sal_False;
sal_Int32 nNewPos = _nPos;
if(nNewPos > 0)
{
if((sal_Int32)m_aBookmarksPositions.size() < nNewPos)
{
// bookmark isn't known yet
// start at the last known position
sal_Int32 nCurPos = 0,nLastBookmark = 1;
if ( m_aBookmarksPositions.empty() )
{
bDataFound = m_pHelper->move(IResultSetHelper::FIRST, 0, _bRetrieveData );
if(bDataFound && (m_bDeletedVisible || !m_pHelper->isRowDeleted()))
{
++nCurPos;
m_aBookmarksPositions.push_back(m_pHelper->getDriverPos());
//m_aBookmarksPositions.push_back(m_aBookmarks.insert(TInt2IntMap::value_type(m_pHelper->getDriverPos(),m_aBookmarksPositions.size()+1)).first);
--nNewPos;
}
} // if ( m_aBookmarksPositions.empty() )
else
{
nLastBookmark = (*m_aBookmarksPositions.rbegin())/*->first*/;
nCurPos = /*(**/m_aBookmarksPositions.size()/*->second*/;
nNewPos = nNewPos - nCurPos;
bDataFound = m_pHelper->move(IResultSetHelper::BOOKMARK, nLastBookmark, _bRetrieveData);
}
// now move to that row we need and don't count deleted rows
while (bDataFound && nNewPos)
{
bDataFound = m_pHelper->move(IResultSetHelper::NEXT, 1, _bRetrieveData);
if(bDataFound && (m_bDeletedVisible || !m_pHelper->isRowDeleted()))
{
++nCurPos;
m_aBookmarksPositions.push_back(m_pHelper->getDriverPos());
//m_aBookmarksPositions.push_back(m_aBookmarks.insert(TInt2IntMap::value_type(m_pHelper->getDriverPos(),m_aBookmarksPositions.size()+1)).first);
--nNewPos;
}
}
}
else
{
const sal_Int32 nBookmark = m_aBookmarksPositions[nNewPos-1]/*->first*/;
bDataFound = m_pHelper->move(IResultSetHelper::BOOKMARK,nBookmark, _bRetrieveData);
OSL_ENSURE((m_bDeletedVisible || !m_pHelper->isRowDeleted()),"moveAbsolute: row can't be deleted!");
}
}
else
{
++nNewPos;
bDataFound = skipDeleted(IResultSetHelper::LAST,0,nNewPos == 0);
for(sal_Int32 i=nNewPos+1;bDataFound && i <= 0;++i)
bDataFound = skipDeleted(IResultSetHelper::PRIOR,1,i == 0);
}
return bDataFound;
}
// -----------------------------------------------------------------------------
void OSkipDeletedSet::clear()
{
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "commontools", "Ocke.Janssen@sun.com", "OSkipDeletedSet::clear" );
::std::vector<sal_Int32>().swap(m_aBookmarksPositions);
//TInt2IntMap().swap(m_aBookmarks);
}
// -----------------------------------------------------------------------------
sal_Int32 OSkipDeletedSet::getMappedPosition(sal_Int32 _nPos) const
{
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "commontools", "Ocke.Janssen@sun.com", "OSkipDeletedSet::getMappedPosition" );
::std::vector<sal_Int32>::const_iterator aFind = ::std::find(m_aBookmarksPositions.begin(),m_aBookmarksPositions.end(),_nPos);
if ( aFind != m_aBookmarksPositions.end() )
return (aFind - m_aBookmarksPositions.begin()) + 1;
/*TInt2IntMap::const_iterator aFind = m_aBookmarks.find(_nPos);
OSL_ENSURE(aFind != m_aBookmarks.end(),"OSkipDeletedSet::getMappedPosition() invalid bookmark!");
return aFind->second;*/
OSL_ENSURE(0,"Why!");
return -1;
}
// -----------------------------------------------------------------------------
void OSkipDeletedSet::insertNewPosition(sal_Int32 _nPos)
{
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "commontools", "Ocke.Janssen@sun.com", "OSkipDeletedSet::insertNewPosition" );
//OSL_ENSURE(m_aBookmarks.find(_nPos) == m_aBookmarks.end(),"OSkipDeletedSet::insertNewPosition: Invalid position");
//m_aBookmarksPositions.push_back(m_aBookmarks.insert(TInt2IntMap::value_type(_nPos,m_aBookmarksPositions.size()+1)).first);
//OSL_ENSURE(::std::find(m_aBookmarksPositions.begin(),m_aBookmarksPositions.end(),_nPos) == m_aBookmarksPositions.end(),"Invalid driver pos");
m_aBookmarksPositions.push_back(_nPos);
}
// -----------------------------------------------------------------------------
void OSkipDeletedSet::deletePosition(sal_Int32 _nBookmark)
{
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "commontools", "Ocke.Janssen@sun.com", "OSkipDeletedSet::deletePosition" );
::std::vector<sal_Int32>::iterator aFind = ::std::find(m_aBookmarksPositions.begin(),m_aBookmarksPositions.end(),_nBookmark);
if ( aFind != m_aBookmarksPositions.end() )
{
//TInt2IntMap::iterator aFind = m_aBookmarks.find(_nPos);
//OSL_ENSURE(aFind != m_aBookmarks.end(),"OSkipDeletedSet::deletePosition() bookmark not found!");
//TInt2IntMap::iterator aIter = aFind;
m_aBookmarksPositions.erase(aFind);
//for (; aFind != m_aBookmarksPositions.end() ; ++aIter)
// --(aFind->second);
} // if ( aFind != m_aBookmarksPositions.end() )
//m_aBookmarksPositions.erase(m_aBookmarksPositions.begin() + aFind->second-1);
//m_aBookmarks.erase(_nPos);
}
// -----------------------------------------------------------------------------