LCOV - code coverage report
Current view: top level - dbaccess/source/core/api - RowSetCache.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 2 100.0 %
Date: 2012-08-25 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

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

Generated by: LCOV version 1.10