LCOV - code coverage report
Current view: top level - dbaccess/source/core/api - RowSetCache.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 5 5 100.0 %
Date: 2014-11-03 Functions: 5 5 100.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             : #ifndef INCLUDED_DBACCESS_SOURCE_CORE_API_ROWSETCACHE_HXX
      20             : #define INCLUDED_DBACCESS_SOURCE_CORE_API_ROWSETCACHE_HXX
      21             : 
      22             : #include <connectivity/CommonTools.hxx>
      23             : #include <com/sun/star/lang/XServiceInfo.hpp>
      24             : #include <com/sun/star/sdbc/XPreparedStatement.hpp>
      25             : #include <com/sun/star/sdbc/XConnection.hpp>
      26             : #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
      27             : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
      28             : #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
      29             : #include <com/sun/star/sdb/XResultSetAccess.hpp>
      30             : #include <com/sun/star/sdbc/XRow.hpp>
      31             : #include <com/sun/star/sdbc/XColumnLocate.hpp>
      32             : #include <com/sun/star/sdbcx/XRowLocate.hpp>
      33             : #include <com/sun/star/sdbc/XRowUpdate.hpp>
      34             : #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
      35             : #include <com/sun/star/sdb/XRowSetApproveBroadcaster.hpp>
      36             : #include <com/sun/star/sdbc/ResultSetType.hpp>
      37             : #include <com/sun/star/sdbcx/XDeleteRows.hpp>
      38             : #include <cppuhelper/compbase11.hxx>
      39             : #include <comphelper/propertycontainer.hxx>
      40             : #include <cppuhelper/implbase5.hxx>
      41             : #include <comphelper/proparrhlp.hxx>
      42             : #include "RowSetRow.hxx"
      43             : #include "RowSetCacheIterator.hxx"
      44             : 
      45             : namespace connectivity
      46             : {
      47             :     class OSQLParseNode;
      48             : }
      49             : namespace dbaccess
      50             : {
      51             :     class OCacheSet;
      52             : 
      53             :     class ORowSetCache
      54             :     {
      55             :         friend class ORowSetBase;
      56             :         friend class ORowSet;
      57             :         friend class ORowSetClone;
      58             :         friend class ORowSetCacheIterator;
      59             : 
      60             :         typedef ::std::vector< TORowSetOldRowHelperRef >    TOldRowSetRows;
      61             : 
      62             :         ::std::map<sal_Int32,sal_Int32> m_aKeyColumns;
      63             :         //the set can be static, bookmarkable or keyset
      64             :         ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet>       m_xSet;
      65             :         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData >  m_xMetaData; // must be before m_aInsertRow
      66             :         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>     m_aContext;
      67             : 
      68             :         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow>                 m_xCacheSet;
      69             : 
      70             :         OCacheSet*                      m_pCacheSet;            // is a bookmarkable, keyset or static resultset
      71             :         ORowSetMatrix*                  m_pMatrix;              // represent the table struct
      72             :         ORowSetMatrix::iterator         m_aMatrixIter;          // represent a row of the table
      73             :         ORowSetMatrix::iterator         m_aMatrixEnd;           // present the row behind the last row of the table
      74             :         ORowSetCacheMap                 m_aCacheIterators;
      75             :         TOldRowSetRows                  m_aOldRows;
      76             : 
      77             :         ORowSetMatrix*                  m_pInsertMatrix;        // represent the rows which should be inserted normally this is only one
      78             :         ORowSetMatrix::iterator         m_aInsertRow;           // represent a insert row
      79             : 
      80             :         sal_Int32                       m_nLastColumnIndex;     // the last column ask for, used for wasNull()
      81             : 
      82             :         connectivity::OSQLTable         m_aUpdateTable;         // used for updates/deletes and inserts
      83             : 
      84             :         sal_Int32                   m_nFetchSize;
      85             :         sal_Int32                   m_nRowCount;
      86             :         sal_Int32                   m_nPrivileges;
      87             :         sal_Int32                   m_nPosition;                // 0 means before first (i.e. 1-based)
      88             : 
      89             :         sal_Int32                   m_nStartPos;                // start pos of the window zero based (inclusive)
      90             :         sal_Int32                   m_nEndPos;                  // end   pos of the window zero based (exclusive)
      91             : 
      92             :         bool                    m_bRowCountFinal ;
      93             :         bool                    m_bBeforeFirst ;
      94             :         bool                    m_bAfterLast ;
      95             :         bool                    m_bUpdated ;
      96             :         bool&                   m_bModified ;           // points to the rowset member m_bModified
      97             :         bool&                   m_bNew ;                // points to the rowset member m_bNew
      98             : 
      99             :         bool fill(ORowSetMatrix::iterator& _aIter, const ORowSetMatrix::const_iterator& _aEnd, sal_Int32& _nPos, bool _bCheck);
     100             :         bool reFillMatrix(sal_Int32 _nNewStartPos,sal_Int32 nNewEndPos);
     101             :         bool fillMatrix(sal_Int32 &_nNewStartPos,sal_Int32 &_nNewEndPos);
     102             :         bool moveWindow();
     103             :         // returns true when a keyset needs to be created.
     104             :         bool impl_createBookmarkSet_nothrow(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet >& _xRs);
     105             : 
     106             :         void firePropertyChange(sal_Int32 _nColumnIndex,const ::connectivity::ORowSetValue& _rOldValue);
     107             : 
     108             :         void rotateCacheIterator(ORowSetMatrix::difference_type _nDist);
     109             :         void updateValue(sal_Int32 columnIndex
     110             :                         ,const connectivity::ORowSetValue& x
     111             :                         ,ORowSetValueVector::Vector& io_aRow
     112             :                         ,::std::vector<sal_Int32>& o_ChangedColumns
     113             :                         );
     114             : 
     115             :         void impl_updateRowFromCache_throw(ORowSetValueVector::Vector& io_aRow
     116             :                                    ,::std::vector<sal_Int32>& o_ChangedColumns
     117             :                                    );
     118             :         // checks and set the flags isAfterLast isLast and position when afterlast is true
     119             :         void checkPositionFlags();
     120             :         void checkUpdateConditions(sal_Int32 columnIndex);
     121             :         bool checkJoin( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,
     122             :                             const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer >& _xComposer,
     123             :                             const OUString& _sUpdateTableName);
     124             :         bool checkInnerJoin(const ::connectivity::OSQLParseNode *pNode
     125             :                             ,const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection
     126             :                             ,const OUString& _sUpdateTableName);
     127             : 
     128             :         // clears the insert row
     129             :         void                    clearInsertRow();
     130             :         ORowSetMatrix::iterator calcPosition() const;
     131             : 
     132             :     protected:
     133        5830 :         const ORowSetMatrix::iterator& getEnd() const { return m_aMatrixEnd;}
     134             :         // is called when after a moveToInsertRow a movement (next, etc) was called
     135             :         void cancelRowModification();
     136             :     public:
     137             :         ORowSetCache(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet >& _xRs,
     138             :                      const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer >& _xAnalyzer,
     139             :                      const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rContext,
     140             :                      const OUString& _rUpdateTableName,
     141             :                      bool&  _bModified,
     142             :                      bool&  _bNew,
     143             :                      const ORowSetValueVector& _aParameterValueForCache,
     144             :                      const OUString& i_sRowSetFilter,
     145             :                      sal_Int32 i_nMaxRows);
     146             :         ~ORowSetCache();
     147             : 
     148             : 
     149             :         // called from the rowset when a updateXXX was called for the first time
     150             :         void setUpdateIterator(const ORowSetMatrix::iterator& _rOriginalRow);
     151             :         ORowSetCacheIterator createIterator(ORowSetBase* _pRowSet);
     152             :         void deleteIterator(const ORowSetBase* _pRowSet);
     153             :         // sets the size of the matrix
     154             :         void setFetchSize(sal_Int32 _nSize);
     155             : 
     156             :         TORowSetOldRowHelperRef registerOldRow();
     157             :         void deregisterOldRow(const TORowSetOldRowHelperRef& _rRow);
     158             : 
     159             :     // ::com::sun::star::sdbc::XResultSetMetaDataSupplier
     160         632 :         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > getMetaData(  ) { return m_xMetaData;}
     161             : 
     162             :     // ::com::sun::star::sdbcx::XRowLocate
     163             :         ::com::sun::star::uno::Any getBookmark(  );
     164             :         bool moveToBookmark( const ::com::sun::star::uno::Any& bookmark );
     165             :         bool moveRelativeToBookmark( const ::com::sun::star::uno::Any& bookmark, sal_Int32 rows );
     166             :         sal_Int32 compareBookmarks( const ::com::sun::star::uno::Any& first, const ::com::sun::star::uno::Any& second );
     167             :         bool hasOrderedBookmarks(  );
     168             :         sal_Int32 hashBookmark( const ::com::sun::star::uno::Any& bookmark );
     169             : 
     170             :     // ::com::sun::star::sdbc::XRowUpdate
     171             :         void updateCharacterStream( sal_Int32 columnIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length,ORowSetValueVector::Vector& io_aRow,::std::vector<sal_Int32>& o_ChangedColumns
     172             :              );
     173             :         void updateObject( sal_Int32 columnIndex, const ::com::sun::star::uno::Any& x,ORowSetValueVector::Vector& io_aRow ,::std::vector<sal_Int32>& o_ChangedColumns);
     174             :         void updateNumericObject( sal_Int32 columnIndex, const ::com::sun::star::uno::Any& x, sal_Int32 scale,ORowSetValueVector::Vector& io_aRow ,::std::vector<sal_Int32>& o_ChangedColumns);
     175             :         void updateNull(sal_Int32 columnIndex
     176             :                         ,ORowSetValueVector::Vector& io_aRow
     177             :                         ,::std::vector<sal_Int32>& o_ChangedColumns
     178             :                         );
     179             : 
     180             :     // ::com::sun::star::sdbc::XResultSet
     181             :         bool next(  );
     182         504 :         bool isBeforeFirst(  ) { return m_bBeforeFirst;}
     183         880 :         bool isAfterLast(  ) { return m_bAfterLast;}
     184             :         bool isFirst(  );
     185             :         bool isLast(  );
     186             :         bool beforeFirst(  );
     187             :         bool afterLast(  );
     188             :         bool first(  );
     189             :         bool last(  );
     190             :         sal_Int32 getRow(  );
     191             :         bool absolute( sal_Int32 row );
     192             :         bool relative( sal_Int32 rows );
     193             :         bool previous(  );
     194             :         void refreshRow(  );
     195             :         bool rowUpdated(  );
     196             :         bool rowInserted(  );
     197             : 
     198             :     // ::com::sun::star::sdbc::XResultSetUpdate
     199             :         bool insertRow(::std::vector< ::com::sun::star::uno::Any >& o_aBookmarks);
     200             :         void resetInsertRow(bool _bClearInsertRow);
     201             : 
     202             :         void updateRow( ORowSetMatrix::iterator& _rUpdateRow,::std::vector< ::com::sun::star::uno::Any >& o_aBookmarks );
     203             :         bool deleteRow();
     204             :         void cancelRowUpdates(  );
     205             :         void moveToInsertRow(  );
     206             : 
     207          40 :         const ::std::map<sal_Int32,sal_Int32>& getKeyColumns() const { return m_aKeyColumns; }
     208             :         bool isResultSetChanged() const;
     209             :         void reset(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet);
     210             :     };
     211             : }
     212             : #endif
     213             : 
     214             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10