LCOV - code coverage report
Current view: top level - dbaccess/source/core/api - StaticSet.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 165 0.0 %
Date: 2014-04-14 Functions: 0 34 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             : 
      21             : #include "StaticSet.hxx"
      22             : #include <com/sun/star/sdbcx/CompareBookmark.hpp>
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
      25             : #include <com/sun/star/sdbc/XPreparedStatement.hpp>
      26             : #include "dbastrings.hrc"
      27             : #include "apitools.hxx"
      28             : #include <connectivity/CommonTools.hxx>
      29             : #include <comphelper/types.hxx>
      30             : 
      31             : using namespace dbaccess;
      32             : using namespace connectivity;
      33             : using namespace ::com::sun::star::uno;
      34             : using namespace ::com::sun::star::beans;
      35             : using namespace ::com::sun::star::sdbc;
      36             : using namespace ::com::sun::star::sdbcx;
      37             : using namespace ::com::sun::star::container;
      38             : using namespace ::com::sun::star::lang;
      39             : using namespace ::osl;
      40             : 
      41           0 : void OStaticSet::fillValueRow(ORowSetRow& _rRow,sal_Int32 /*_nPosition*/)
      42             : {
      43             :     SAL_INFO("dbaccess", "OStaticSet::fillValueRow" );
      44           0 :     _rRow = *m_aSetIter;
      45           0 : }
      46             : 
      47             : // ::com::sun::star::sdbcx::XRowLocate
      48           0 : Any SAL_CALL OStaticSet::getBookmark() throw(SQLException, RuntimeException)
      49             : {
      50             :     SAL_INFO("dbaccess", "OStaticSet::getBookmark" );
      51           0 :     return makeAny(getRow());
      52             : }
      53             : 
      54           0 : sal_Bool SAL_CALL OStaticSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
      55             : {
      56             :     SAL_INFO("dbaccess", "OStaticSet::moveToBookmark" );
      57           0 :     m_bInserted = m_bUpdated = m_bDeleted = sal_False;
      58           0 :     return absolute(::comphelper::getINT32(bookmark));
      59             : }
      60             : 
      61           0 : sal_Bool SAL_CALL OStaticSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException)
      62             : {
      63             :     SAL_INFO("dbaccess", "OStaticSet::moveRelativeToBookmark" );
      64           0 :     m_bInserted = m_bUpdated = m_bDeleted = sal_False;
      65           0 :     return absolute(::comphelper::getINT32(bookmark)+rows);
      66             : }
      67             : 
      68           0 : sal_Int32 SAL_CALL OStaticSet::compareBookmarks( const Any& _first, const Any& _second ) throw(SQLException, RuntimeException)
      69             : {
      70             :     SAL_INFO("dbaccess", "OStaticSet::compareBookmarks" );
      71           0 :     sal_Int32 nFirst = 0, nSecond = 0;
      72           0 :     _first >>= nFirst;
      73           0 :     _second >>= nSecond;
      74           0 :     return (nFirst < nSecond) ? CompareBookmark::LESS : ((nFirst > nSecond) ? CompareBookmark::GREATER : CompareBookmark::EQUAL);
      75             : }
      76             : 
      77           0 : sal_Bool SAL_CALL OStaticSet::hasOrderedBookmarks(  ) throw(SQLException, RuntimeException)
      78             : {
      79             :     SAL_INFO("dbaccess", "OStaticSet::hasOrderedBookmarks" );
      80           0 :     return sal_True;
      81             : }
      82             : 
      83           0 : sal_Int32 SAL_CALL OStaticSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
      84             : {
      85             :     SAL_INFO("dbaccess", "OStaticSet::hashBookmark" );
      86           0 :     return ::comphelper::getINT32(bookmark);
      87             : }
      88             : 
      89           0 : sal_Bool OStaticSet::fetchRow()
      90             : {
      91             :     SAL_INFO("dbaccess", "OStaticSet::fetchRow" );
      92           0 :     sal_Bool bRet = sal_False;
      93           0 :     if ( !m_bEnd && (!m_nMaxRows || sal_Int32(m_aSet.size()) < m_nMaxRows) )
      94           0 :         bRet = m_xDriverSet->next();
      95           0 :     if ( bRet )
      96             :     {
      97           0 :         m_aSet.push_back(new connectivity::ORowVector< connectivity::ORowSetValue >(m_xSetMetaData->getColumnCount()));
      98           0 :         m_aSetIter = m_aSet.end() - 1;
      99           0 :         ((*m_aSetIter)->get())[0] = getRow();
     100           0 :         OCacheSet::fillValueRow(*m_aSetIter,((*m_aSetIter)->get())[0]);
     101             :     }
     102             :     else
     103           0 :         m_bEnd = sal_True;
     104           0 :     return bRet;
     105             : }
     106             : 
     107           0 : void OStaticSet::fillAllRows()
     108             : {
     109             :     SAL_INFO("dbaccess", "OStaticSet::fillAllRows" );
     110           0 :     if(!m_bEnd)
     111             :     {
     112           0 :         sal_Int32 nColumnCount = m_xSetMetaData->getColumnCount();
     113           0 :         while(m_xDriverSet->next())
     114             :         {
     115           0 :             ORowSetRow pRow = new connectivity::ORowVector< connectivity::ORowSetValue >(nColumnCount);
     116           0 :             m_aSet.push_back(pRow);
     117           0 :             m_aSetIter = m_aSet.end() - 1;
     118           0 :             (pRow->get())[0] = getRow();
     119           0 :             OCacheSet::fillValueRow(pRow,(pRow->get())[0]);
     120           0 :         }
     121           0 :         m_bEnd = sal_True;
     122             :     }
     123           0 : }
     124             : 
     125             : // XResultSet
     126           0 : sal_Bool SAL_CALL OStaticSet::next(  ) throw(SQLException, RuntimeException)
     127             : {
     128             :     SAL_INFO("dbaccess", "OStaticSet::next" );
     129           0 :     m_bInserted = m_bUpdated = m_bDeleted = sal_False;
     130             : 
     131           0 :     if(isAfterLast())
     132           0 :         return sal_False;
     133           0 :     if(!m_bEnd) // not yet all records fetched
     134             :     {
     135           0 :         ++m_aSetIter;
     136           0 :         if(m_aSetIter == m_aSet.end() && !fetchRow())
     137           0 :             m_aSetIter = m_aSet.end();
     138             :     }
     139           0 :     else if(!isAfterLast())
     140           0 :         ++m_aSetIter;
     141           0 :     return !isAfterLast();
     142             : }
     143             : 
     144           0 : sal_Bool SAL_CALL OStaticSet::isBeforeFirst(  ) throw(SQLException, RuntimeException)
     145             : {
     146             :     SAL_INFO("dbaccess", "OStaticSet::isBeforeFirst" );
     147           0 :     return m_aSetIter == m_aSet.begin();
     148             : }
     149             : 
     150           0 : sal_Bool SAL_CALL OStaticSet::isAfterLast(  ) throw(SQLException, RuntimeException)
     151             : {
     152             :     SAL_INFO("dbaccess", "OStaticSet::isAfterLast" );
     153           0 :     return m_aSetIter == m_aSet.end() && m_bEnd;
     154             : }
     155             : 
     156           0 : sal_Bool SAL_CALL OStaticSet::isFirst(  ) throw(SQLException, RuntimeException)
     157             : {
     158             :     SAL_INFO("dbaccess", "OStaticSet::isFirst" );
     159           0 :     return m_aSetIter == m_aSet.begin()+1;
     160             : }
     161             : 
     162           0 : sal_Bool SAL_CALL OStaticSet::isLast(  ) throw(SQLException, RuntimeException)
     163             : {
     164             :     SAL_INFO("dbaccess", "OStaticSet::isLast" );
     165           0 :     return m_aSetIter == m_aSet.end()-1 && m_bEnd;
     166             : }
     167             : 
     168           0 : void SAL_CALL OStaticSet::beforeFirst(  ) throw(SQLException, RuntimeException)
     169             : {
     170             :     SAL_INFO("dbaccess", "OStaticSet::beforeFirst" );
     171           0 :     m_bInserted = m_bUpdated = m_bDeleted = sal_False;
     172           0 :     m_aSetIter = m_aSet.begin();
     173           0 : }
     174             : 
     175           0 : void SAL_CALL OStaticSet::afterLast(  ) throw(SQLException, RuntimeException)
     176             : {
     177             :     SAL_INFO("dbaccess", "OStaticSet::afterLast" );
     178           0 :     m_bInserted = m_bUpdated = m_bDeleted = sal_False;
     179           0 :     fillAllRows();
     180           0 :     m_aSetIter = m_aSet.end();
     181           0 : }
     182             : 
     183           0 : sal_Bool SAL_CALL OStaticSet::first(  ) throw(SQLException, RuntimeException)
     184             : {
     185             :     SAL_INFO("dbaccess", "OStaticSet::first" );
     186           0 :     m_bInserted = m_bUpdated = m_bDeleted = sal_False;
     187           0 :     m_aSetIter = m_aSet.begin()+1;
     188           0 :     if(m_aSetIter == m_aSet.end() && !fetchRow())
     189           0 :         m_aSetIter = m_aSet.end();
     190             : 
     191           0 :     return m_aSetIter != m_aSet.end();
     192             : }
     193             : 
     194           0 : sal_Bool SAL_CALL OStaticSet::last(  ) throw(SQLException, RuntimeException)
     195             : {
     196             :     SAL_INFO("dbaccess", "OStaticSet::last" );
     197           0 :     m_bInserted = m_bUpdated = m_bDeleted = sal_False;
     198           0 :     fillAllRows();
     199           0 :     m_aSetIter = m_aSet.end()-1;
     200             : 
     201           0 :     return !isBeforeFirst() && !isAfterLast();
     202             : }
     203             : 
     204           0 : sal_Int32 SAL_CALL OStaticSet::getRow(  ) throw(SQLException, RuntimeException)
     205             : {
     206             :     SAL_INFO("dbaccess", "OStaticSet::getRow" );
     207             :     OSL_ENSURE(!isAfterLast(),"getRow is not allowed when afterlast record!");
     208             :     OSL_ENSURE(!isBeforeFirst(),"getRow is not allowed when beforefirst record!");
     209             : 
     210           0 :     sal_Int32 nPos = m_aSet.size() - (m_aSet.end() - m_aSetIter);
     211             :     OSL_ENSURE(nPos > 0,"RowPos is < 0");
     212           0 :     return nPos;
     213             : }
     214             : 
     215           0 : sal_Bool SAL_CALL OStaticSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
     216             : {
     217             :     SAL_INFO("dbaccess", "OStaticSet::absolute" );
     218           0 :     m_bInserted = m_bUpdated = m_bDeleted = sal_False;
     219             :     OSL_ENSURE(row,"OStaticSet::absolute: INVALID row number!");
     220             :     // if row greater 0 than count from end - row means last
     221           0 :     if(row < 0)
     222             :     {
     223           0 :         if(!m_bEnd)
     224           0 :             fillAllRows();
     225             : 
     226           0 :         sal_Int32 nRow = getRow();
     227           0 :         nRow += row;
     228           0 :         if(nRow <= (sal_Int32)m_aSet.size())
     229           0 :             m_aSetIter = m_aSet.begin() + nRow;
     230             :         else
     231           0 :             m_aSetIter = m_aSet.begin();
     232             :     }
     233           0 :     else if(row > 0)
     234             :     {
     235           0 :         if(row >= (sal_Int32)m_aSet.size())
     236             :         {
     237           0 :             if(!m_bEnd)
     238             :             {
     239           0 :                 sal_Bool bNext = sal_True;
     240           0 :                 for(sal_Int32 i=m_aSet.size()-1;i < row && bNext;++i)
     241           0 :                     bNext = fetchRow();
     242             :             }
     243             : 
     244           0 :             if(row > (sal_Int32)m_aSet.size())
     245           0 :                 m_aSetIter = m_aSet.end();  // check again
     246             :             else
     247           0 :                 m_aSetIter = m_aSet.begin() + row;
     248             :         }
     249             :         else
     250           0 :             m_aSetIter = m_aSet.begin() + row;
     251             :     }
     252             : 
     253           0 :     return m_aSetIter != m_aSet.end() && m_aSetIter != m_aSet.begin();
     254             : }
     255             : 
     256           0 : sal_Bool SAL_CALL OStaticSet::relative( sal_Int32 rows ) throw(SQLException, RuntimeException)
     257             : {
     258             :     SAL_INFO("dbaccess", "OStaticSet::relative" );
     259           0 :     if(!rows)
     260           0 :         return sal_True;
     261             : 
     262           0 :     sal_Int32 nCurPos = getRow();
     263           0 :     return absolute(nCurPos+rows);
     264             : }
     265             : 
     266           0 : sal_Bool SAL_CALL OStaticSet::previous(  ) throw(SQLException, RuntimeException)
     267             : {
     268             :     SAL_INFO("dbaccess", "OStaticSet::previous" );
     269           0 :     m_bInserted = m_bUpdated = m_bDeleted = sal_False;
     270             : 
     271           0 :     if(m_aSetIter != m_aSet.begin())
     272           0 :         --m_aSetIter;
     273             : 
     274           0 :     return m_aSetIter != m_aSet.begin();
     275             : }
     276             : 
     277           0 : void SAL_CALL OStaticSet::refreshRow(  ) throw(SQLException, RuntimeException)
     278             : {
     279             :     SAL_INFO("dbaccess", "OStaticSet::refreshRow" );
     280           0 : }
     281             : 
     282           0 : sal_Bool SAL_CALL OStaticSet::rowUpdated(  ) throw(SQLException, RuntimeException)
     283             : {
     284             :     SAL_INFO("dbaccess", "OStaticSet::rowUpdated" );
     285           0 :     return m_bUpdated;
     286             : }
     287             : 
     288           0 : sal_Bool SAL_CALL OStaticSet::rowInserted(  ) throw(SQLException, RuntimeException)
     289             : {
     290             :     SAL_INFO("dbaccess", "OStaticSet::rowInserted" );
     291           0 :     return m_bInserted;
     292             : }
     293             : 
     294           0 : sal_Bool SAL_CALL OStaticSet::rowDeleted(  ) throw(SQLException, RuntimeException)
     295             : {
     296             :     SAL_INFO("dbaccess", "OStaticSet::rowDeleted" );
     297           0 :     return m_bDeleted;
     298             : }
     299             : 
     300           0 : Sequence< sal_Int32 > SAL_CALL OStaticSet::deleteRows( const Sequence< Any >& rows,const connectivity::OSQLTable& _xTable ) throw(SQLException, RuntimeException)
     301             : {
     302             :     SAL_INFO("dbaccess", "OStaticSet::deleteRows" );
     303           0 :     Sequence< sal_Int32 > aRet(rows.getLength());
     304           0 :     const Any* pBegin   = rows.getConstArray();
     305           0 :     const Any* pEnd     = pBegin + rows.getLength();
     306           0 :     for(sal_Int32 i=0;pBegin != pEnd; ++pBegin,++i)
     307             :     {
     308           0 :         deleteRow(*(m_aSet.begin() + comphelper::getINT32(*pBegin)),_xTable);
     309           0 :         aRet.getArray()[i] = m_bDeleted;
     310             :     }
     311           0 :     return aRet;
     312             : }
     313             : 
     314           0 : void SAL_CALL OStaticSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
     315             : {
     316             :     SAL_INFO("dbaccess", "OStaticSet::insertRow" );
     317           0 :     OCacheSet::insertRow( _rInsertRow,_xTable);
     318           0 :     if(m_bInserted)
     319             :     {
     320           0 :         m_aSet.push_back(new ORowVector< ORowSetValue >(*_rInsertRow)); // we don't know where the new row is so we append it to the current rows
     321           0 :         m_aSetIter = m_aSet.end() - 1;
     322           0 :         ((*m_aSetIter)->get())[0] = (_rInsertRow->get())[0] = getBookmark();
     323           0 :         m_bEnd = sal_False;
     324             :     }
     325           0 : }
     326             : 
     327           0 : void SAL_CALL OStaticSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOriginalRow,const connectivity::OSQLTable& _xTable  ) throw(SQLException, RuntimeException)
     328             : {
     329             :     SAL_INFO("dbaccess", "OStaticSet::updateRow" );
     330           0 :     OCacheSet::updateRow( _rInsertRow,_rOriginalRow,_xTable);
     331           0 : }
     332             : 
     333           0 : void SAL_CALL OStaticSet::deleteRow(const ORowSetRow& _rDeleteRow ,const connectivity::OSQLTable& _xTable  ) throw(SQLException, RuntimeException)
     334             : {
     335             :     SAL_INFO("dbaccess", "OStaticSet::deleteRow" );
     336           0 :     OCacheSet::deleteRow(_rDeleteRow,_xTable);
     337           0 :     if(m_bDeleted)
     338             :     {
     339           0 :         ORowSetMatrix::iterator aPos = m_aSet.begin()+(_rDeleteRow->get())[0].getInt32();
     340           0 :         if(aPos == (m_aSet.end()-1))
     341           0 :             m_aSetIter = m_aSet.end();
     342           0 :         m_aSet.erase(aPos);
     343             :     }
     344           0 : }
     345             : 
     346           0 : void SAL_CALL OStaticSet::cancelRowUpdates(  ) throw(SQLException, RuntimeException)
     347             : {
     348             :     SAL_INFO("dbaccess", "OStaticSet::cancelRowUpdates" );
     349           0 : }
     350             : 
     351           0 : void SAL_CALL OStaticSet::moveToInsertRow(  ) throw(SQLException, RuntimeException)
     352             : {
     353             :     SAL_INFO("dbaccess", "OStaticSet::moveToInsertRow" );
     354           0 : }
     355             : 
     356           0 : void SAL_CALL OStaticSet::moveToCurrentRow(  ) throw(SQLException, RuntimeException)
     357             : {
     358             :     SAL_INFO("dbaccess", "OStaticSet::moveToCurrentRow" );
     359           0 : }
     360             : 
     361           0 : void OStaticSet::reset(const Reference< XResultSet> &_xDriverSet)
     362             : {
     363           0 :     OCacheSet::construct(_xDriverSet, m_sRowSetFilter);
     364             :     {
     365           0 :         ORowSetMatrix t;
     366           0 :         m_aSet.swap(t);
     367             :     }
     368           0 :     m_aSetIter = m_aSet.end();
     369           0 :     m_bEnd = sal_False;
     370           0 :     m_aSet.push_back(NULL); // this is the beforefirst record
     371           0 : }
     372             : 
     373             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10