LCOV - code coverage report
Current view: top level - libreoffice/connectivity/source/commontools - TSkipDeletedSet.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 111 0.0 %
Date: 2012-12-27 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          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             : #include "TSkipDeletedSet.hxx"
      21             : #include <osl/diagnose.h>
      22             : #include <rtl/logfile.hxx>
      23             : 
      24             : using namespace connectivity;
      25             : // -----------------------------------------------------------------------------
      26           0 : OSkipDeletedSet::OSkipDeletedSet(IResultSetHelper* _pHelper)
      27             :     : m_pHelper(_pHelper)
      28           0 :     ,m_bDeletedVisible(false)
      29             : {
      30             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "commontools", "Ocke.Janssen@sun.com", "OSkipDeletedSet::OSkipDeletedSet" );
      31           0 :     m_aBookmarksPositions.reserve(256);
      32           0 : }
      33             : // -----------------------------------------------------------------------------
      34           0 : OSkipDeletedSet::~OSkipDeletedSet()
      35             : {
      36           0 :     m_aBookmarksPositions.clear();
      37             :     //m_aBookmarks.clear();
      38           0 : }
      39             : // -----------------------------------------------------------------------------
      40           0 : sal_Bool OSkipDeletedSet::skipDeleted(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, sal_Bool _bRetrieveData)
      41             : {
      42             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "commontools", "Ocke.Janssen@sun.com", "OSkipDeletedSet::skipDeleted" );
      43             :     OSL_ENSURE(_eCursorPosition != IResultSetHelper::BOOKMARK,"OSkipDeletedSet::SkipDeleted can't be called for BOOKMARK");
      44             : 
      45           0 :     IResultSetHelper::Movement eDelPosition = _eCursorPosition;
      46           0 :     sal_Int32 nDelOffset = abs(_nOffset);
      47             : 
      48           0 :     switch (_eCursorPosition)
      49             :     {
      50             :         case IResultSetHelper::ABSOLUTE:
      51           0 :             return moveAbsolute(_nOffset,_bRetrieveData);
      52             :         case IResultSetHelper::FIRST:                   // set the movement when positioning failed
      53           0 :             eDelPosition = IResultSetHelper::NEXT;
      54           0 :             nDelOffset = 1;
      55           0 :             break;
      56             :         case IResultSetHelper::LAST:
      57           0 :             eDelPosition = IResultSetHelper::PRIOR; // lsat row is invalid so position before
      58           0 :             nDelOffset = 1;
      59           0 :             break;
      60             :         case IResultSetHelper::RELATIVE:
      61           0 :             eDelPosition = (_nOffset >= 0) ? IResultSetHelper::NEXT : IResultSetHelper::PRIOR;
      62           0 :             break;
      63             :         default:
      64           0 :             break;
      65             :     }
      66             : 
      67           0 :     sal_Bool bDone          = sal_True;
      68           0 :     sal_Bool bDataFound     = sal_False;
      69             : 
      70           0 :     if (_eCursorPosition == IResultSetHelper::LAST)
      71             :     {
      72             :         RTL_LOGFILE_CONTEXT_TRACE( aLogger, "OSkipDeletedSet::skipDeleted: last" );
      73           0 :         sal_Int32 nBookmark = 0;
      74             :         // first position on the last known row
      75           0 :         if ( m_aBookmarksPositions.empty() )
      76             :         {
      77           0 :             bDataFound = m_pHelper->move(IResultSetHelper::FIRST, 0, _bRetrieveData);
      78           0 :             if(bDataFound && (m_bDeletedVisible || !m_pHelper->isRowDeleted()))
      79             :                 //m_aBookmarksPositions.push_back(m_aBookmarks.insert(TInt2IntMap::value_type(m_pHelper->getDriverPos(),m_aBookmarksPositions.size()+1)).first);
      80           0 :                 m_aBookmarksPositions.push_back(m_pHelper->getDriverPos());
      81             :         }
      82             :         else
      83             :         {
      84             :             // I already have a bookmark so we can positioned on that and look if it is the last one
      85           0 :             nBookmark = (*m_aBookmarksPositions.rbegin())/*->first*/;
      86             : 
      87           0 :             bDataFound = m_pHelper->move(IResultSetHelper::BOOKMARK, nBookmark, _bRetrieveData);
      88             :             OSL_ENSURE((m_bDeletedVisible || !m_pHelper->isRowDeleted()),"A bookmark should not be deleted!");
      89             :         }
      90             : 
      91             : 
      92             :         // and than move forward until we are after the last row
      93           0 :         while(bDataFound)
      94             :         {
      95           0 :             bDataFound = m_pHelper->move(IResultSetHelper::NEXT, 1, sal_False); // we don't need the data here
      96           0 :             if( bDataFound && ( m_bDeletedVisible || !m_pHelper->isRowDeleted()) )
      97             :             {   // we weren't on the last row we remember it and move on
      98           0 :                 m_aBookmarksPositions.push_back(m_pHelper->getDriverPos());
      99             :                 //m_aBookmarksPositions.push_back(m_aBookmarks.insert(TInt2IntMap::value_type(m_pHelper->getDriverPos(),m_aBookmarksPositions.size()+1)).first);
     100             :             }
     101           0 :             else if(!bDataFound && !m_aBookmarksPositions.empty() )
     102             :             {
     103             :                 // i already know the last bookmark :-)
     104             :                 // now we only have to repositioning us to the last row
     105           0 :                 nBookmark = (*m_aBookmarksPositions.rbegin())/*->first*/;
     106           0 :                 bDataFound = m_pHelper->move(IResultSetHelper::BOOKMARK, nBookmark, _bRetrieveData);
     107           0 :                 break;
     108             :             }
     109             :         }
     110           0 :         return bDataFound;
     111             :     }
     112           0 :     else if (_eCursorPosition != IResultSetHelper::RELATIVE)
     113             :     {
     114           0 :         bDataFound = m_pHelper->move(_eCursorPosition, _nOffset, _bRetrieveData);
     115           0 :         bDone = bDataFound && (m_bDeletedVisible || !m_pHelper->isRowDeleted());
     116             :     }
     117             :     else
     118             :     {
     119           0 :         bDataFound = m_pHelper->move(eDelPosition, 1, _bRetrieveData);
     120           0 :         if (bDataFound && (m_bDeletedVisible || !m_pHelper->isRowDeleted()))
     121             :         {
     122           0 :             bDone = (--nDelOffset) == 0;
     123           0 :             if ( !bDone )
     124           0 :                 m_aBookmarksPositions.push_back(m_pHelper->getDriverPos());
     125             :             //m_aBookmarksPositions.push_back(m_aBookmarks.insert(TInt2IntMap::value_type(m_pHelper->getDriverPos(),m_aBookmarksPositions.size()+1)).first);
     126             :         }
     127             :         else
     128           0 :             bDone = sal_False;
     129             :     }
     130             : 
     131           0 :     while (bDataFound && !bDone)            // Iterate until we are at the valid set
     132             :     {
     133           0 :         bDataFound = m_pHelper->move(eDelPosition, 1, _bRetrieveData);
     134           0 :         if (_eCursorPosition != IResultSetHelper::RELATIVE)
     135           0 :             bDone = bDataFound && (m_bDeletedVisible || !m_pHelper->isRowDeleted());
     136           0 :         else if (bDataFound && (m_bDeletedVisible || !m_pHelper->isRowDeleted()))
     137             :         {
     138           0 :             bDone = (--nDelOffset) == 0;
     139           0 :             if ( !bDone )
     140           0 :                 m_aBookmarksPositions.push_back(m_pHelper->getDriverPos());
     141             :             //m_aBookmarksPositions.push_back(m_aBookmarks.insert(TInt2IntMap::value_type(m_pHelper->getDriverPos(),m_aBookmarksPositions.size()+1)).first);
     142             :         }
     143             :         else
     144           0 :             bDone = sal_False;
     145             :     }
     146             : 
     147           0 :     if(bDataFound && bDone)
     148             :     {
     149           0 :         const sal_Int32 nDriverPos = m_pHelper->getDriverPos();
     150           0 :         if ( m_bDeletedVisible )
     151             :         {
     152           0 :             if ( nDriverPos > (sal_Int32)m_aBookmarksPositions.size() )
     153           0 :                 m_aBookmarksPositions.push_back(nDriverPos);
     154             :         }
     155           0 :         else if ( ::std::find(m_aBookmarksPositions.begin(),m_aBookmarksPositions.end(),nDriverPos) == m_aBookmarksPositions.end() )
     156           0 :             m_aBookmarksPositions.push_back(nDriverPos);
     157             :         /*sal_Int32 nDriverPos = m_pHelper->getDriverPos();
     158             :         if(m_aBookmarks.find(nDriverPos) == m_aBookmarks.end())
     159             :             m_aBookmarksPositions.push_back(m_aBookmarks.insert(TInt2IntMap::value_type(nDriverPos,m_aBookmarksPositions.size()+1)).first);*/
     160             :     }
     161             : 
     162           0 :     return bDataFound;
     163             : }
     164             : // -------------------------------------------------------------------------
     165           0 : sal_Bool OSkipDeletedSet::moveAbsolute(sal_Int32 _nPos,sal_Bool _bRetrieveData)
     166             : {
     167             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "commontools", "Ocke.Janssen@sun.com", "OSkipDeletedSet::moveAbsolute" );
     168           0 :     sal_Bool bDataFound = sal_False;
     169           0 :     sal_Int32 nNewPos = _nPos;
     170           0 :     if(nNewPos > 0)
     171             :     {
     172           0 :         if((sal_Int32)m_aBookmarksPositions.size() < nNewPos)
     173             :         {
     174             :             // bookmark isn't known yet
     175             :             // start at the last known position
     176           0 :             sal_Int32 nCurPos = 0,nLastBookmark = 1;
     177           0 :             if ( m_aBookmarksPositions.empty() )
     178             :             {
     179           0 :                 bDataFound = m_pHelper->move(IResultSetHelper::FIRST, 0, _bRetrieveData );
     180           0 :                 if(bDataFound && (m_bDeletedVisible || !m_pHelper->isRowDeleted()))
     181             :                 {
     182           0 :                     ++nCurPos;
     183           0 :                     m_aBookmarksPositions.push_back(m_pHelper->getDriverPos());
     184             :                     //m_aBookmarksPositions.push_back(m_aBookmarks.insert(TInt2IntMap::value_type(m_pHelper->getDriverPos(),m_aBookmarksPositions.size()+1)).first);
     185           0 :                     --nNewPos;
     186             :                 }
     187             :             } // if ( m_aBookmarksPositions.empty() )
     188             :             else
     189             :             {
     190           0 :                 nLastBookmark   = (*m_aBookmarksPositions.rbegin())/*->first*/;
     191           0 :                 nCurPos         = /*(**/m_aBookmarksPositions.size()/*->second*/;
     192           0 :                 nNewPos         = nNewPos - nCurPos;
     193           0 :                 bDataFound      = m_pHelper->move(IResultSetHelper::BOOKMARK, nLastBookmark, _bRetrieveData);
     194             :             }
     195             : 
     196             :             // now move to that row we need and don't count deleted rows
     197           0 :             while (bDataFound && nNewPos)
     198             :             {
     199           0 :                 bDataFound = m_pHelper->move(IResultSetHelper::NEXT, 1, _bRetrieveData);
     200           0 :                 if(bDataFound && (m_bDeletedVisible || !m_pHelper->isRowDeleted()))
     201             :                 {
     202           0 :                     ++nCurPos;
     203           0 :                     m_aBookmarksPositions.push_back(m_pHelper->getDriverPos());
     204             :                     //m_aBookmarksPositions.push_back(m_aBookmarks.insert(TInt2IntMap::value_type(m_pHelper->getDriverPos(),m_aBookmarksPositions.size()+1)).first);
     205           0 :                     --nNewPos;
     206             :                 }
     207             :             }
     208             :         }
     209             :         else
     210             :         {
     211           0 :             const sal_Int32 nBookmark = m_aBookmarksPositions[nNewPos-1]/*->first*/;
     212           0 :             bDataFound = m_pHelper->move(IResultSetHelper::BOOKMARK,nBookmark, _bRetrieveData);
     213             :             OSL_ENSURE((m_bDeletedVisible || !m_pHelper->isRowDeleted()),"moveAbsolute: row can't be deleted!");
     214             :         }
     215             :     }
     216             :     else
     217             :     {
     218           0 :         ++nNewPos;
     219           0 :         bDataFound = skipDeleted(IResultSetHelper::LAST,0,nNewPos == 0);
     220             : 
     221           0 :         for(sal_Int32 i=nNewPos+1;bDataFound && i <= 0;++i)
     222           0 :             bDataFound = skipDeleted(IResultSetHelper::PRIOR,1,i == 0);
     223             : 
     224             :     }
     225           0 :     return bDataFound;
     226             : }
     227             : // -----------------------------------------------------------------------------
     228           0 : void OSkipDeletedSet::clear()
     229             : {
     230             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "commontools", "Ocke.Janssen@sun.com", "OSkipDeletedSet::clear" );
     231           0 :     ::std::vector<sal_Int32>().swap(m_aBookmarksPositions);
     232             :     //TInt2IntMap().swap(m_aBookmarks);
     233           0 : }
     234             : // -----------------------------------------------------------------------------
     235           0 : sal_Int32 OSkipDeletedSet::getMappedPosition(sal_Int32 _nPos) const
     236             : {
     237             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "commontools", "Ocke.Janssen@sun.com", "OSkipDeletedSet::getMappedPosition" );
     238           0 :     ::std::vector<sal_Int32>::const_iterator aFind = ::std::find(m_aBookmarksPositions.begin(),m_aBookmarksPositions.end(),_nPos);
     239           0 :     if ( aFind !=  m_aBookmarksPositions.end() )
     240           0 :         return (aFind - m_aBookmarksPositions.begin()) + 1;
     241             :     /*TInt2IntMap::const_iterator aFind = m_aBookmarks.find(_nPos);
     242             :     OSL_ENSURE(aFind != m_aBookmarks.end(),"OSkipDeletedSet::getMappedPosition() invalid bookmark!");
     243             :     return aFind->second;*/
     244             :     OSL_FAIL("Why!");
     245           0 :     return -1;
     246             : }
     247             : // -----------------------------------------------------------------------------
     248           0 : void OSkipDeletedSet::insertNewPosition(sal_Int32 _nPos)
     249             : {
     250             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "commontools", "Ocke.Janssen@sun.com", "OSkipDeletedSet::insertNewPosition" );
     251             :     //OSL_ENSURE(m_aBookmarks.find(_nPos) == m_aBookmarks.end(),"OSkipDeletedSet::insertNewPosition: Invalid position");
     252             :     //m_aBookmarksPositions.push_back(m_aBookmarks.insert(TInt2IntMap::value_type(_nPos,m_aBookmarksPositions.size()+1)).first);
     253             :     //OSL_ENSURE(::std::find(m_aBookmarksPositions.begin(),m_aBookmarksPositions.end(),_nPos) == m_aBookmarksPositions.end(),"Invalid driver pos");
     254           0 :     m_aBookmarksPositions.push_back(_nPos);
     255           0 : }
     256             : // -----------------------------------------------------------------------------
     257           0 : void OSkipDeletedSet::deletePosition(sal_Int32 _nBookmark)
     258             : {
     259             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "commontools", "Ocke.Janssen@sun.com", "OSkipDeletedSet::deletePosition" );
     260           0 :     ::std::vector<sal_Int32>::iterator aFind = ::std::find(m_aBookmarksPositions.begin(),m_aBookmarksPositions.end(),_nBookmark);
     261           0 :     if ( aFind !=  m_aBookmarksPositions.end() )
     262             :     {
     263             :     //TInt2IntMap::iterator aFind = m_aBookmarks.find(_nPos);
     264             :     //OSL_ENSURE(aFind != m_aBookmarks.end(),"OSkipDeletedSet::deletePosition() bookmark not found!");
     265             :     //TInt2IntMap::iterator aIter = aFind;
     266           0 :         m_aBookmarksPositions.erase(aFind);
     267             :         //for (; aFind != m_aBookmarksPositions.end() ; ++aIter)
     268             :            // --(aFind->second);
     269             :     } // if ( aFind !=  m_aBookmarksPositions.end() )
     270             :     //m_aBookmarksPositions.erase(m_aBookmarksPositions.begin() + aFind->second-1);
     271             :     //m_aBookmarks.erase(_nPos);
     272           0 : }
     273             : // -----------------------------------------------------------------------------
     274             : 
     275             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10