2000-09-18 23:16:46 +00:00
/*************************************************************************
*
2005-09-08 09:01:42 +00:00
* OpenOffice . org - a multi - platform office productivity suite
2000-09-18 23:16:46 +00:00
*
2005-09-08 09:01:42 +00:00
* $ RCSfile : RowSetCache . cxx , v $
2000-09-18 23:16:46 +00:00
*
2006-09-17 05:32:31 +00:00
* $ Revision : 1.90 $
2000-09-18 23:16:46 +00:00
*
2006-09-17 05:32:31 +00:00
* last change : $ Author : obo $ $ Date : 2006 - 09 - 17 06 : 32 : 31 $
2000-09-18 23:16:46 +00:00
*
2005-09-08 09:01:42 +00:00
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1 .
2000-09-18 23:16:46 +00:00
*
*
2005-09-08 09:01:42 +00:00
* GNU Lesser General Public License Version 2.1
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* Copyright 2005 by Sun Microsystems , Inc .
* 901 San Antonio Road , Palo Alto , CA 94303 , USA
2000-09-18 23:16:46 +00:00
*
2005-09-08 09:01:42 +00:00
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 , as published by the Free Software Foundation .
2000-09-18 23:16:46 +00:00
*
2005-09-08 09:01:42 +00:00
* This library 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 for more details .
2000-09-18 23:16:46 +00:00
*
2005-09-08 09:01:42 +00:00
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston ,
* MA 02111 - 1307 USA
2000-09-18 23:16:46 +00:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-09-17 05:32:31 +00:00
// MARKER(update_precomp.py): autogen include statement, do not remove
# include "precompiled_dbaccess.hxx"
2000-09-18 23:16:46 +00:00
# ifndef _CONNECTIVITY_COMMONTOOLS_HXX_
# include "RowSetCache.hxx"
# endif
2004-06-01 09:09:25 +00:00
# ifndef _DBA_CORE_RESOURCE_HXX_
# include "core_resource.hxx"
# endif
# ifndef _DBA_CORE_RESOURCE_HRC_
# include "core_resource.hrc"
# endif
2000-10-11 10:21:40 +00:00
# ifndef _COMPHELPER_SEQSTREAM_HXX
# include <comphelper/seqstream.hxx>
2000-09-18 23:16:46 +00:00
# endif
2000-11-14 12:28:20 +00:00
# ifndef _COMPHELPER_UNO3_HXX_
# include <comphelper/uno3.hxx>
# endif
2000-09-18 23:16:46 +00:00
# ifndef DBACCESS_CORE_API_BOOKMARKSET_HXX
# include "BookmarkSet.hxx"
# endif
# ifndef DBACCESS_CORE_API_STATICSET_HXX
# include "StaticSet.hxx"
# endif
# ifndef DBACCESS_CORE_API_KEYSET_HXX
# include "KeySet.hxx"
# endif
2000-10-25 06:32:52 +00:00
# ifndef DBACCESS_SHARED_DBASTRINGS_HRC
# include "dbastrings.hrc"
2000-09-18 23:16:46 +00:00
# endif
2001-03-15 07:29:16 +00:00
# ifndef _COMPHELPER_EXTRACT_HXX_
# include <comphelper/extract.hxx>
2000-09-18 23:16:46 +00:00
# endif
# ifndef _COM_SUN_STAR_SDBCX_XKEYSSUPPLIER_HPP_
# include <com/sun/star/sdbcx/XKeysSupplier.hpp>
# endif
2000-10-17 09:19:03 +00:00
# ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
# include <com/sun/star/sdbcx/XTablesSupplier.hpp>
# endif
2000-11-10 13:17:54 +00:00
# ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_
# include <com/sun/star/sdbcx/KeyType.hpp>
# endif
2001-01-09 14:38:59 +00:00
# ifndef _COM_SUN_STAR_SDBC_RESULTSETCONCURRENCY_HPP_
# include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
# endif
2001-02-01 13:23:57 +00:00
# ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_
# include <com/sun/star/sdbc/ColumnValue.hpp>
# endif
2003-04-28 14:59:21 +00:00
# ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
# include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
# endif
2000-09-18 23:16:46 +00:00
# ifndef _COM_SUN_STAR_SDBCX_PRIVILEGE_HPP_
# include <com/sun/star/sdbcx/Privilege.hpp>
# endif
# ifndef _DBACORE_DATACOLUMN_HXX_
# include "CRowSetDataColumn.hxx"
# endif
# ifndef DBACCESS_CORE_API_CROWSETCOLUMN_HXX
# include "CRowSetColumn.hxx"
# endif
2006-01-25 12:43:29 +00:00
# ifndef DBACCESS_CORE_API_ROWSETBASE_HXX
# include "RowSetBase.hxx"
# endif
2000-10-25 06:32:52 +00:00
# ifndef _DBHELPER_DBEXCEPTION_HXX_
# include <connectivity/dbexception.hxx>
# endif
2001-07-19 08:29:22 +00:00
# ifndef _CONNECTIVITY_SQLPARSE_HXX
# include <connectivity/sqlparse.hxx>
# endif
# ifndef _CONNECTIVITY_SQLNODE_HXX
# include <connectivity/sqlnode.hxx>
# endif
2006-08-15 09:42:22 +00:00
# ifndef _CONNECTIVITY_PARSE_SQLITERATOR_HXX_
# include <connectivity/sqliterator.hxx>
# endif
2000-11-15 14:57:40 +00:00
# ifndef _COMPHELPER_PROPERTY_HXX_
# include <comphelper/property.hxx>
# endif
2001-01-22 06:38:24 +00:00
# ifndef _COM_SUN_STAR_SDBCX_COMPAREBOOKMARK_HPP_
# include <com/sun/star/sdbcx/CompareBookmark.hpp>
# endif
2005-09-23 11:03:25 +00:00
# ifndef _TOOLS_DEBUG_HXX
# include <tools/debug.hxx>
# endif
2000-09-18 23:16:46 +00:00
2001-10-12 14:36:42 +00:00
# include <algorithm>
2000-09-18 23:16:46 +00:00
using namespace dbaccess ;
2000-10-25 06:32:52 +00:00
using namespace dbtools ;
2000-09-18 23:16:46 +00:00
using namespace connectivity ;
using namespace : : com : : sun : : star : : uno ;
using namespace : : com : : sun : : star : : beans ;
using namespace : : com : : sun : : star : : sdbc ;
using namespace : : com : : sun : : star : : sdb ;
using namespace : : com : : sun : : star : : sdbcx ;
using namespace : : com : : sun : : star : : container ;
using namespace : : com : : sun : : star : : lang ;
using namespace : : cppu ;
using namespace : : osl ;
2006-07-26 06:46:13 +00:00
# define CHECK_MATRIX_POS(M) OSL_ENSURE(((M) >= static_cast<ORowSetMatrix::difference_type>(0)) && ((M) < static_cast<sal_Int32>(m_pMatrix->size())),"Position is invalid!")
2005-09-23 11:03:25 +00:00
DBG_NAME ( ORowSetCache )
2000-09-18 23:16:46 +00:00
// -------------------------------------------------------------------------
ORowSetCache : : ORowSetCache ( const Reference < XResultSet > & _xRs ,
2004-11-17 13:42:39 +00:00
const Reference < XSingleSelectQueryAnalyzer > & _xAnalyzer ,
2001-07-19 08:29:22 +00:00
const Reference < XMultiServiceFactory > & _xServiceFactory ,
2000-10-17 09:19:03 +00:00
const : : rtl : : OUString & _rUpdateTableName ,
sal_Bool & _bModified ,
sal_Bool & _bNew )
2006-06-20 01:36:29 +00:00
: m_xSet ( _xRs )
, m_xMetaData ( Reference < XResultSetMetaDataSupplier > ( _xRs , UNO_QUERY ) - > getMetaData ( ) )
, m_xServiceFactory ( _xServiceFactory )
, m_pCacheSet ( NULL )
, m_pMatrix ( NULL )
, m_pInsertMatrix ( NULL )
, m_nLastColumnIndex ( 0 )
, m_nFetchSize ( 0 )
, m_nRowCount ( 0 )
, m_nPrivileges ( Privilege : : SELECT )
, m_nPosition ( 0 )
2000-09-18 23:16:46 +00:00
, m_nStartPos ( 0 )
, m_nEndPos ( 0 )
2006-06-20 01:36:29 +00:00
, m_bRowCountFinal ( sal_False )
2000-09-18 23:16:46 +00:00
, m_bBeforeFirst ( sal_True )
2006-01-03 15:13:57 +00:00
, m_bAfterLast ( sal_False )
2000-09-18 23:16:46 +00:00
, m_bUpdated ( sal_False )
2000-10-17 09:19:03 +00:00
, m_bModified ( _bModified )
2006-06-20 01:36:29 +00:00
, m_bNew ( _bNew )
2000-09-18 23:16:46 +00:00
{
2005-09-23 11:03:25 +00:00
DBG_CTOR ( ORowSetCache , NULL ) ;
2000-09-18 23:16:46 +00:00
// check if all keys of the updateable table are fetched
sal_Bool bAllKeysFound = sal_False ;
2001-07-19 08:29:22 +00:00
sal_Int32 nTablesCount = 0 ;
2000-09-18 23:16:46 +00:00
2001-02-01 13:23:57 +00:00
: : rtl : : OUString aUpdateTableName = _rUpdateTableName ;
Reference < XConnection > xConnection ;
2004-11-17 13:42:39 +00:00
if ( _xAnalyzer . is ( ) )
2001-01-04 13:30:37 +00:00
{
2001-11-29 15:35:26 +00:00
try
{
2004-11-17 13:42:39 +00:00
Reference < XTablesSupplier > xTabSup ( _xAnalyzer , UNO_QUERY ) ;
2001-11-29 15:35:26 +00:00
OSL_ENSURE ( xTabSup . is ( ) , " ORowSet::execute composer isn't a tablesupplier! " ) ;
Reference < XNameAccess > xTables = xTabSup - > getTables ( ) ;
2000-10-17 09:19:03 +00:00
2001-02-01 13:23:57 +00:00
2001-11-29 15:35:26 +00:00
if ( _rUpdateTableName . getLength ( ) & & xTables - > hasByName ( _rUpdateTableName ) )
xTables - > getByName ( _rUpdateTableName ) > > = m_aUpdateTable ;
else if ( xTables - > getElementNames ( ) . getLength ( ) )
{
aUpdateTableName = xTables - > getElementNames ( ) [ 0 ] ;
xTables - > getByName ( aUpdateTableName ) > > = m_aUpdateTable ;
}
Reference < XIndexAccess > xIndexAccess ( xTables , UNO_QUERY ) ;
if ( xIndexAccess . is ( ) )
nTablesCount = xIndexAccess - > getCount ( ) ;
else
nTablesCount = xTables - > getElementNames ( ) . getLength ( ) ;
2000-09-18 23:16:46 +00:00
2001-11-29 15:35:26 +00:00
if ( m_aUpdateTable . is ( ) & & nTablesCount < 3 ) // for we can't handle more than 2 tables in our keyset
2000-11-10 13:17:54 +00:00
{
2001-11-29 15:35:26 +00:00
Reference < XKeysSupplier > xKeys ( m_aUpdateTable , UNO_QUERY ) ;
if ( xKeys . is ( ) )
2000-11-10 13:17:54 +00:00
{
2001-11-29 15:35:26 +00:00
Reference < XIndexAccess > xKeyIndex = xKeys - > getKeys ( ) ;
2003-07-21 11:27:44 +00:00
if ( xKeyIndex . is ( ) )
2001-01-04 13:30:37 +00:00
{
2003-07-21 11:27:44 +00:00
Reference < XColumnsSupplier > xColumnsSupplier ;
// search the one and only primary key
for ( sal_Int32 i = 0 ; i < xKeyIndex - > getCount ( ) ; + + i )
2001-11-29 15:35:26 +00:00
{
2003-07-21 11:27:44 +00:00
Reference < XPropertySet > xProp ;
: : cppu : : extractInterface ( xProp , xKeyIndex - > getByIndex ( i ) ) ;
sal_Int32 nKeyType = 0 ;
xProp - > getPropertyValue ( PROPERTY_TYPE ) > > = nKeyType ;
if ( KeyType : : PRIMARY = = nKeyType )
{
2004-08-02 14:01:13 +00:00
xColumnsSupplier . set ( xProp , UNO_QUERY ) ;
2003-07-21 11:27:44 +00:00
break ;
}
2001-11-29 15:35:26 +00:00
}
2000-11-10 13:17:54 +00:00
2003-07-21 11:27:44 +00:00
if ( xColumnsSupplier . is ( ) )
2001-11-29 15:35:26 +00:00
{
2003-07-21 11:27:44 +00:00
// first we need a connection
Reference < XStatement > xStmt ( _xRs - > getStatement ( ) , UNO_QUERY ) ;
if ( xStmt . is ( ) )
xConnection = xStmt - > getConnection ( ) ;
else
{
Reference < XPreparedStatement > xPrepStmt ( _xRs - > getStatement ( ) , UNO_QUERY ) ;
xConnection = xPrepStmt - > getConnection ( ) ;
}
OSL_ENSURE ( xConnection . is ( ) , " No connection! " ) ;
2000-09-18 23:16:46 +00:00
2003-07-21 11:27:44 +00:00
Reference < XNameAccess > xColumns = xColumnsSupplier - > getColumns ( ) ;
2004-11-17 13:42:39 +00:00
Reference < XColumnsSupplier > xColSup ( _xAnalyzer , UNO_QUERY ) ;
2004-03-02 11:41:52 +00:00
if ( xColSup . is ( ) )
{
Reference < XNameAccess > xSelColumns = xColSup - > getColumns ( ) ;
Reference < XDatabaseMetaData > xMeta = xConnection - > getMetaData ( ) ;
2006-08-15 09:42:22 +00:00
SelectColumnsMetaData aColumnNames ( xMeta . is ( ) & & xMeta - > supportsMixedCaseQuotedIdentifiers ( ) ? true : false ) ;
2004-03-02 11:41:52 +00:00
: : dbaccess : : getColumnPositions ( xSelColumns , xColumns , aUpdateTableName , aColumnNames ) ;
2005-09-23 11:03:25 +00:00
bAllKeysFound = ! aColumnNames . empty ( ) & & sal_Int32 ( aColumnNames . size ( ) ) = = xColumns - > getElementNames ( ) . getLength ( ) ;
2004-03-02 11:41:52 +00:00
}
2003-07-21 11:27:44 +00:00
}
2001-11-29 15:35:26 +00:00
}
2000-09-18 23:16:46 +00:00
}
}
}
2001-11-29 15:35:26 +00:00
catch ( Exception & )
{
}
2000-09-18 23:16:46 +00:00
}
Reference < XPropertySet > xProp ( _xRs , UNO_QUERY ) ;
2001-11-29 15:35:26 +00:00
sal_Bool bNeedKeySet = ! ( xProp - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_ISBOOKMARKABLE ) & &
any2bool ( xProp - > getPropertyValue ( PROPERTY_ISBOOKMARKABLE ) ) ) ;
bNeedKeySet = bNeedKeySet | | ( xProp - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_RESULTSETCONCURRENCY ) & &
: : comphelper : : getINT32 ( xProp - > getPropertyValue ( PROPERTY_RESULTSETCONCURRENCY ) ) = = ResultSetConcurrency : : READ_ONLY ) ;
2000-09-18 23:16:46 +00:00
// first check if resultset is bookmarkable
2001-11-29 15:35:26 +00:00
if ( ! bNeedKeySet )
2000-09-18 23:16:46 +00:00
{
2001-11-29 15:35:26 +00:00
try
2000-12-06 08:55:44 +00:00
{
2001-11-29 15:35:26 +00:00
m_pCacheSet = new OBookmarkSet ( ) ;
2004-03-02 11:41:52 +00:00
m_xCacheSet = m_pCacheSet ;
2001-11-29 15:35:26 +00:00
m_pCacheSet - > construct ( _xRs ) ;
// check privileges
m_nPrivileges = Privilege : : SELECT ;
if ( Reference < XResultSetUpdate > ( _xRs , UNO_QUERY ) . is ( ) ) // this interface is optional so we have to check it
2000-12-06 08:55:44 +00:00
{
2001-11-29 15:35:26 +00:00
Reference < XPropertySet > xTable ( m_aUpdateTable , UNO_QUERY ) ;
if ( xTable . is ( ) & & xTable - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_PRIVILEGES ) )
{
m_nPrivileges = 0 ;
xTable - > getPropertyValue ( PROPERTY_PRIVILEGES ) > > = m_nPrivileges ;
if ( ! m_nPrivileges )
m_nPrivileges = Privilege : : SELECT ;
}
2000-12-06 08:55:44 +00:00
}
}
2001-11-29 15:35:26 +00:00
catch ( const SQLException & )
{
bNeedKeySet = sal_True ;
}
2000-09-18 23:16:46 +00:00
}
2001-11-29 15:35:26 +00:00
if ( bNeedKeySet )
2000-09-18 23:16:46 +00:00
{
2001-07-19 08:29:22 +00:00
// need to check if we could handle this select clause
2004-11-17 13:42:39 +00:00
bAllKeysFound = bAllKeysFound & & ( nTablesCount = = 1 | | checkJoin ( xConnection , _xAnalyzer , aUpdateTableName ) ) ;
2001-07-19 08:29:22 +00:00
2001-01-22 06:38:24 +00:00
// || !(comphelper::hasProperty(PROPERTY_CANUPDATEINSERTEDROWS,xProp) && any2bool(xProp->getPropertyValue(PROPERTY_CANUPDATEINSERTEDROWS)))
2001-10-26 06:50:50 +00:00
// oj removed because keyset uses only the next// || (xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_RESULTSETTYPE) && comphelper::getINT32(xProp->getPropertyValue(PROPERTY_RESULTSETTYPE)) == ResultSetType::FORWARD_ONLY)
if ( ! bAllKeysFound )
2000-09-18 23:16:46 +00:00
{
2001-10-30 13:22:10 +00:00
m_pCacheSet = new OStaticSet ( ) ;
2004-03-02 11:41:52 +00:00
m_xCacheSet = m_pCacheSet ;
2001-10-30 13:22:10 +00:00
m_pCacheSet - > construct ( _xRs ) ;
2001-07-19 08:29:22 +00:00
m_nPrivileges = Privilege : : SELECT ;
2000-09-18 23:16:46 +00:00
}
else
{
2003-12-01 09:18:56 +00:00
Reference < XDatabaseMetaData > xMeta = xConnection - > getMetaData ( ) ;
2006-08-15 09:42:22 +00:00
SelectColumnsMetaData aColumnNames ( xMeta . is ( ) & & xMeta - > supportsMixedCaseQuotedIdentifiers ( ) ? true : false ) ;
2004-11-17 13:42:39 +00:00
Reference < XColumnsSupplier > xColSup ( _xAnalyzer , UNO_QUERY ) ;
2001-02-01 13:23:57 +00:00
Reference < XNameAccess > xSelColumns = xColSup - > getColumns ( ) ;
Reference < XNameAccess > xColumns = m_aUpdateTable - > getColumns ( ) ;
: : dbaccess : : getColumnPositions ( xSelColumns , xColumns , aUpdateTableName , aColumnNames ) ;
2000-10-05 13:52:16 +00:00
// check privileges
m_nPrivileges = Privilege : : SELECT ;
2001-02-01 13:23:57 +00:00
sal_Bool bNoInsert = sal_False ;
Sequence < : : rtl : : OUString > aNames ( xColumns - > getElementNames ( ) ) ;
2006-01-16 14:27:42 +00:00
const : : rtl : : OUString * pIter = aNames . getConstArray ( ) ;
const : : rtl : : OUString * pEnd = pIter + aNames . getLength ( ) ;
for ( ; pIter ! = pEnd ; + + pIter )
2001-02-01 13:23:57 +00:00
{
Reference < XPropertySet > xColumn ;
2006-01-16 14:27:42 +00:00
: : cppu : : extractInterface ( xColumn , xColumns - > getByName ( * pIter ) ) ;
2001-02-01 13:23:57 +00:00
OSL_ENSURE ( xColumn . is ( ) , " Column in table is null! " ) ;
if ( xColumn . is ( ) )
{
sal_Int32 nNullable = 0 ;
xColumn - > getPropertyValue ( PROPERTY_ISNULLABLE ) > > = nNullable ;
2006-01-16 14:27:42 +00:00
if ( nNullable = = ColumnValue : : NO_NULLS & & aColumnNames . find ( * pIter ) = = aColumnNames . end ( ) )
2001-02-01 13:23:57 +00:00
{ // we found a column where null is not allowed so we can't insert new values
bNoInsert = sal_True ;
break ; // one column is enough
}
}
}
2004-11-17 13:42:39 +00:00
OKeySet * pKeySet = new OKeySet ( m_aUpdateTable , aUpdateTableName , _xAnalyzer ) ;
2001-07-19 08:29:22 +00:00
try
2000-12-06 08:55:44 +00:00
{
2004-03-02 11:41:52 +00:00
m_pCacheSet = pKeySet ;
m_xCacheSet = m_pCacheSet ;
2001-10-30 13:22:10 +00:00
pKeySet - > construct ( _xRs ) ;
2001-07-19 08:29:22 +00:00
if ( Reference < XResultSetUpdate > ( _xRs , UNO_QUERY ) . is ( ) ) // this interface is optional so we have to check it
2000-12-06 08:55:44 +00:00
{
2001-07-19 08:29:22 +00:00
Reference < XPropertySet > xTable ( m_aUpdateTable , UNO_QUERY ) ;
if ( xTable . is ( ) & & xTable - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_PRIVILEGES ) )
{
m_nPrivileges = 0 ;
xTable - > getPropertyValue ( PROPERTY_PRIVILEGES ) > > = m_nPrivileges ;
if ( ! m_nPrivileges )
m_nPrivileges = Privilege : : SELECT ;
}
2000-12-06 08:55:44 +00:00
}
2001-07-19 08:29:22 +00:00
if ( bNoInsert )
m_nPrivileges | = ~ Privilege : : INSERT ; // remove the insert privilege
}
catch ( const SQLException & )
{
// we couldn't create a keyset here so we have to create a static cache
2003-03-19 16:57:12 +00:00
if ( m_pCacheSet )
2004-03-02 11:41:52 +00:00
m_pCacheSet = NULL ;
m_xCacheSet = NULL ;
2001-10-30 13:22:10 +00:00
m_pCacheSet = new OStaticSet ( ) ;
2004-03-02 11:41:52 +00:00
m_xCacheSet = m_pCacheSet ;
2001-10-30 13:22:10 +00:00
m_pCacheSet - > construct ( _xRs ) ;
2001-07-19 08:29:22 +00:00
m_nPrivileges = Privilege : : SELECT ;
2000-12-06 08:55:44 +00:00
}
2000-09-18 23:16:46 +00:00
}
}
2001-01-09 14:38:59 +00:00
// last check
2001-10-26 06:50:50 +00:00
if ( ! bAllKeysFound & & xProp - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_RESULTSETCONCURRENCY ) & &
2001-01-09 14:38:59 +00:00
: : comphelper : : getINT32 ( xProp - > getPropertyValue ( PROPERTY_RESULTSETCONCURRENCY ) ) = = ResultSetConcurrency : : READ_ONLY )
m_nPrivileges = Privilege : : SELECT ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
ORowSetCache : : ~ ORowSetCache ( )
{
2000-12-12 11:20:31 +00:00
m_pCacheSet = NULL ;
2004-03-02 11:41:52 +00:00
m_xCacheSet = NULL ;
2000-09-18 23:16:46 +00:00
if ( m_pMatrix )
{
m_pMatrix - > clear ( ) ;
delete m_pMatrix ;
}
2000-09-29 14:23:36 +00:00
if ( m_pInsertMatrix )
{
m_pInsertMatrix - > clear ( ) ;
delete m_pInsertMatrix ;
}
2001-02-01 13:23:57 +00:00
m_xSet = WeakReference < XResultSet > ( ) ;
2000-11-03 13:42:50 +00:00
m_xMetaData = NULL ;
m_aUpdateTable = NULL ;
2005-09-23 11:03:25 +00:00
DBG_DTOR ( ORowSetCache , NULL ) ;
2000-09-18 23:16:46 +00:00
}
2002-04-16 06:48:57 +00:00
2000-09-18 23:16:46 +00:00
// -------------------------------------------------------------------------
void ORowSetCache : : setMaxRowSize ( sal_Int32 _nSize )
{
2006-02-06 15:54:31 +00:00
2001-01-24 08:52:19 +00:00
if ( _nSize = = m_nFetchSize )
return ;
2000-09-18 23:16:46 +00:00
m_nFetchSize = _nSize ;
if ( ! m_pMatrix )
2001-01-24 08:52:19 +00:00
{
2000-09-18 23:16:46 +00:00
m_pMatrix = new ORowSetMatrix ( _nSize ) ;
2001-01-24 08:52:19 +00:00
m_aMatrixIter = m_pMatrix - > end ( ) ;
m_aMatrixEnd = m_pMatrix - > end ( ) ;
m_pInsertMatrix = new ORowSetMatrix ( 1 ) ; // a little bit overkill but ??? :-)
m_aInsertRow = m_pInsertMatrix - > end ( ) ;
}
2000-09-18 23:16:46 +00:00
else
{
2001-01-24 08:52:19 +00:00
// now correct the iterator in our iterator vector
: : std : : vector < sal_Int32 > aPositions ;
2001-04-05 13:14:41 +00:00
: : std : : map < sal_Int32 , sal_Bool > aCacheIterToChange ;
// first get the positions where they stand now
2001-01-24 08:52:19 +00:00
ORowSetCacheMap : : iterator aCacheIter = m_aCacheIterators . begin ( ) ;
for ( ; aCacheIter ! = m_aCacheIterators . end ( ) ; + + aCacheIter )
{
2001-04-05 13:14:41 +00:00
aCacheIterToChange [ aCacheIter - > first ] = sal_False ;
2006-01-25 14:10:43 +00:00
if ( ! aCacheIter - > second . pRowSet - > isInsertRow ( )
2006-07-26 06:46:13 +00:00
/*&& aCacheIter->second.aIterator != m_pMatrix->end()*/ & & ! m_bModified )
2001-01-24 08:52:19 +00:00
{
2006-07-10 14:03:49 +00:00
ptrdiff_t nDist = ( aCacheIter - > second . aIterator - m_pMatrix - > begin ( ) ) ;
2001-01-24 08:52:19 +00:00
aPositions . push_back ( nDist ) ;
2001-04-05 13:14:41 +00:00
aCacheIterToChange [ aCacheIter - > first ] = sal_True ;
2001-01-24 08:52:19 +00:00
}
}
sal_Int32 nKeyPos = ( m_aMatrixIter - m_pMatrix - > begin ( ) ) ;
2000-09-18 23:16:46 +00:00
m_pMatrix - > resize ( _nSize ) ;
2006-07-26 06:46:13 +00:00
CHECK_MATRIX_POS ( nKeyPos ) ;
2001-01-24 08:52:19 +00:00
m_aMatrixIter = m_pMatrix - > begin ( ) + nKeyPos ;
m_aMatrixEnd = m_pMatrix - > end ( ) ;
2001-04-05 13:14:41 +00:00
// now adjust their positions because a resize invalid all iterators
: : std : : vector < sal_Int32 > : : const_iterator aIter = aPositions . begin ( ) ;
: : std : : map < sal_Int32 , sal_Bool > : : const_iterator aPosChangeIter = aCacheIterToChange . begin ( ) ;
for ( aCacheIter = m_aCacheIterators . begin ( ) ;
aPosChangeIter ! = aCacheIterToChange . end ( ) ;
+ + aPosChangeIter , + + aCacheIter )
2001-01-24 08:52:19 +00:00
{
2006-07-26 06:46:13 +00:00
if ( aPosChangeIter - > second )
{
CHECK_MATRIX_POS ( * aIter ) ;
2001-01-24 08:52:19 +00:00
aCacheIter - > second . aIterator = m_pMatrix - > begin ( ) + * aIter + + ;
2006-07-26 06:46:13 +00:00
}
2001-01-24 08:52:19 +00:00
}
}
if ( ! m_nPosition )
{
sal_Int32 nNewSt = 1 ;
fillMatrix ( nNewSt , _nSize + 1 ) ;
m_nStartPos = 0 ;
m_nEndPos = _nSize ;
2000-09-18 23:16:46 +00:00
}
}
// -------------------------------------------------------------------------
// XResultSetMetaDataSupplier
2002-12-05 13:10:11 +00:00
Reference < XResultSetMetaData > ORowSetCache : : getMetaData ( )
2000-09-18 23:16:46 +00:00
{
return m_xMetaData ;
}
// -------------------------------------------------------------------------
// ::com::sun::star::sdbcx::XRowLocate
2002-12-05 13:10:11 +00:00
Any ORowSetCache : : getBookmark ( )
2000-09-18 23:16:46 +00:00
{
2006-02-06 15:54:31 +00:00
2000-09-18 23:16:46 +00:00
if ( m_bAfterLast )
2001-04-19 06:14:49 +00:00
throwFunctionSequenceException ( m_xSet . get ( ) ) ;
2000-09-18 23:16:46 +00:00
2003-12-01 09:18:56 +00:00
if ( m_aMatrixIter > = m_pMatrix - > end ( ) | | m_aMatrixIter < m_pMatrix - > begin ( ) | | ! ( * m_aMatrixIter ) . isValid ( ) )
2001-01-24 08:52:19 +00:00
{
return Any ( ) ; // this is allowed here because the rowset knowns what it is doing
}
2001-01-22 06:38:24 +00:00
2000-09-18 23:16:46 +00:00
switch ( ( * ( * m_aMatrixIter ) ) [ 0 ] . getTypeKind ( ) )
{
case DataType : : TINYINT :
case DataType : : SMALLINT :
case DataType : : INTEGER :
return makeAny ( ( sal_Int32 ) ( * ( * m_aMatrixIter ) ) [ 0 ] ) ;
default :
if ( ( * ( * m_aMatrixIter ) ) [ 0 ] . isNull ( ) )
2006-06-20 01:36:29 +00:00
( * ( * m_aMatrixIter ) ) [ 0 ] = m_pCacheSet - > getBookmark ( ) ;
2000-09-18 23:16:46 +00:00
return ( * ( * m_aMatrixIter ) ) [ 0 ] . getAny ( ) ;
}
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
sal_Bool ORowSetCache : : moveToBookmark ( const Any & bookmark )
2000-09-18 23:16:46 +00:00
{
2002-08-08 06:07:42 +00:00
if ( m_pCacheSet - > moveToBookmark ( bookmark ) )
2000-09-18 23:16:46 +00:00
{
2006-01-25 14:10:43 +00:00
m_bBeforeFirst = sal_False ;
2000-09-18 23:16:46 +00:00
m_nPosition = m_pCacheSet - > getRow ( ) ;
2001-06-26 09:30:55 +00:00
checkPositionFlags ( ) ;
2000-12-06 08:55:44 +00:00
if ( ! m_bAfterLast )
{
moveWindow ( ) ;
2001-06-26 09:30:55 +00:00
checkPositionFlags ( ) ;
2002-12-10 11:50:04 +00:00
if ( ! m_bAfterLast )
{
2001-11-29 15:35:26 +00:00
m_aMatrixIter = calcPosition ( ) ;
2004-10-22 07:55:06 +00:00
OSL_ENSURE ( m_aMatrixIter - > isValid ( ) , " Iterator after moveToBookmark not valid " ) ;
2002-12-10 11:50:04 +00:00
}
2000-12-06 08:55:44 +00:00
else
m_aMatrixIter = m_pMatrix - > end ( ) ;
}
else
m_aMatrixIter = m_pMatrix - > end ( ) ;
2000-09-18 23:16:46 +00:00
}
2001-06-22 12:08:06 +00:00
else
return sal_False ;
2000-09-29 14:23:36 +00:00
2000-09-18 23:16:46 +00:00
return m_aMatrixIter ! = m_pMatrix - > end ( ) & & ( * m_aMatrixIter ) . isValid ( ) ;
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
sal_Bool ORowSetCache : : moveRelativeToBookmark ( const Any & bookmark , sal_Int32 rows )
2000-09-18 23:16:46 +00:00
{
2006-07-10 14:03:49 +00:00
sal_Bool bRet ( moveToBookmark ( bookmark ) ) ;
if ( bRet )
2000-09-18 23:16:46 +00:00
{
m_nPosition = m_pCacheSet - > getRow ( ) + rows ;
absolute ( m_nPosition ) ;
// for(sal_Int32 i=0;i<rows && m_aMatrixIter != m_pMatrix->end();++i,++m_aMatrixIter) ;
bRet = m_aMatrixIter ! = m_pMatrix - > end ( ) & & ( * m_aMatrixIter ) . isValid ( ) ;
}
2000-09-29 14:23:36 +00:00
2000-09-18 23:16:46 +00:00
return bRet ;
}
// -------------------------------------------------------------------------
2006-06-20 01:36:29 +00:00
sal_Int32 ORowSetCache : : compareBookmarks ( const Any & _first , const Any & _second )
2000-09-18 23:16:46 +00:00
{
2006-06-20 01:36:29 +00:00
return ( ! _first . hasValue ( ) | | ! _second . hasValue ( ) ) ? CompareBookmark : : NOT_COMPARABLE : m_pCacheSet - > compareBookmarks ( _first , _second ) ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
sal_Bool ORowSetCache : : hasOrderedBookmarks ( )
2000-09-18 23:16:46 +00:00
{
2006-02-06 15:54:31 +00:00
2000-09-18 23:16:46 +00:00
return m_pCacheSet - > hasOrderedBookmarks ( ) ;
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
sal_Int32 ORowSetCache : : hashBookmark ( const Any & bookmark )
2000-09-18 23:16:46 +00:00
{
2006-02-06 15:54:31 +00:00
2001-02-14 12:18:24 +00:00
return m_pCacheSet - > hashBookmark ( bookmark ) ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
// XRowUpdate
2001-06-26 09:30:55 +00:00
// -----------------------------------------------------------------------------
void ORowSetCache : : updateValue ( sal_Int32 columnIndex , const ORowSetValue & x )
2000-09-18 23:16:46 +00:00
{
2001-06-26 09:30:55 +00:00
checkUpdateConditions ( columnIndex ) ;
2000-09-18 23:16:46 +00:00
2006-02-06 15:54:31 +00:00
2000-09-29 14:23:36 +00:00
( * ( * m_aInsertRow ) ) [ columnIndex ] . setBound ( sal_True ) ;
( * ( * m_aInsertRow ) ) [ columnIndex ] = x ;
( * ( * m_aInsertRow ) ) [ columnIndex ] . setModified ( ) ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
void ORowSetCache : : updateBinaryStream ( sal_Int32 columnIndex , const Reference < : : com : : sun : : star : : io : : XInputStream > & x , sal_Int32 length )
2000-09-18 23:16:46 +00:00
{
2001-06-26 09:30:55 +00:00
checkUpdateConditions ( columnIndex ) ;
2001-04-02 10:14:53 +00:00
2006-02-06 15:54:31 +00:00
2001-04-02 10:14:53 +00:00
Sequence < sal_Int8 > aSeq ;
if ( x . is ( ) )
x - > readSomeBytes ( aSeq , length ) ;
2001-06-26 09:30:55 +00:00
updateValue ( columnIndex , aSeq ) ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
void ORowSetCache : : updateCharacterStream ( sal_Int32 columnIndex , const Reference < : : com : : sun : : star : : io : : XInputStream > & x , sal_Int32 length )
2000-09-18 23:16:46 +00:00
{
2001-06-26 09:30:55 +00:00
checkUpdateConditions ( columnIndex ) ;
2001-04-02 10:14:53 +00:00
2006-02-06 15:54:31 +00:00
2001-04-02 10:14:53 +00:00
Sequence < sal_Int8 > aSeq ;
if ( x . is ( ) )
x - > readSomeBytes ( aSeq , length ) ;
2001-06-26 09:30:55 +00:00
updateValue ( columnIndex , aSeq ) ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
void ORowSetCache : : updateObject ( sal_Int32 columnIndex , const Any & x )
2000-09-18 23:16:46 +00:00
{
2001-06-26 09:30:55 +00:00
checkUpdateConditions ( columnIndex ) ;
2001-04-02 10:14:53 +00:00
2006-02-06 15:54:31 +00:00
2001-04-02 10:14:53 +00:00
( * ( * m_aInsertRow ) ) [ columnIndex ] . setBound ( sal_True ) ;
( * ( * m_aInsertRow ) ) [ columnIndex ] = x ;
( * ( * m_aInsertRow ) ) [ columnIndex ] . setModified ( ) ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2006-06-20 01:36:29 +00:00
void ORowSetCache : : updateNumericObject ( sal_Int32 columnIndex , const Any & x , sal_Int32 /*scale*/ )
2000-09-18 23:16:46 +00:00
{
2001-06-26 09:30:55 +00:00
checkUpdateConditions ( columnIndex ) ;
2001-04-02 10:14:53 +00:00
2006-02-06 15:54:31 +00:00
2001-04-02 10:14:53 +00:00
( * ( * m_aInsertRow ) ) [ columnIndex ] . setBound ( sal_True ) ;
( * ( * m_aInsertRow ) ) [ columnIndex ] = x ;
( * ( * m_aInsertRow ) ) [ columnIndex ] . setModified ( ) ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
// XResultSet
2002-12-05 13:10:11 +00:00
sal_Bool ORowSetCache : : next ( )
2000-09-18 23:16:46 +00:00
{
2006-02-06 15:54:31 +00:00
2000-09-18 23:16:46 +00:00
2001-06-26 09:30:55 +00:00
if ( ! isAfterLast ( ) )
2000-09-18 23:16:46 +00:00
{
2001-06-26 09:30:55 +00:00
m_bBeforeFirst = sal_False ;
+ + m_nPosition ;
2006-01-25 14:10:43 +00:00
2001-06-26 09:30:55 +00:00
// after we increment the position we have to check if we are already after the last row
checkPositionFlags ( ) ;
if ( ! m_bAfterLast )
2001-01-26 14:18:17 +00:00
{
2001-06-26 09:30:55 +00:00
moveWindow ( ) ;
OSL_ENSURE ( ( ( m_nPosition - m_nStartPos ) - 1 ) < ( sal_Int32 ) m_pMatrix - > size ( ) , " Position is behind end()! " ) ;
2001-11-29 15:35:26 +00:00
m_aMatrixIter = calcPosition ( ) ;
2001-06-26 09:30:55 +00:00
checkPositionFlags ( ) ;
2001-01-26 14:18:17 +00:00
}
}
2000-09-18 23:16:46 +00:00
return ! m_bAfterLast ;
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
sal_Bool ORowSetCache : : isBeforeFirst ( )
2000-09-18 23:16:46 +00:00
{
// return !m_nPosition;
2006-02-06 15:54:31 +00:00
2000-09-18 23:16:46 +00:00
return m_bBeforeFirst ;
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
sal_Bool ORowSetCache : : isAfterLast ( )
2000-09-18 23:16:46 +00:00
{
2006-02-06 15:54:31 +00:00
2001-01-22 06:38:24 +00:00
return m_bAfterLast ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
sal_Bool ORowSetCache : : isFirst ( )
2000-09-18 23:16:46 +00:00
{
2006-02-06 15:54:31 +00:00
2000-09-18 23:16:46 +00:00
return m_nPosition = = 1 ; // ask resultset for
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
sal_Bool ORowSetCache : : isLast ( )
2000-09-18 23:16:46 +00:00
{
2001-01-22 06:38:24 +00:00
// return m_bRowCountFinal ? (m_nPosition==m_nRowCount) : m_pCacheSet->isLast();
2006-02-06 15:54:31 +00:00
2001-06-26 09:30:55 +00:00
return m_nPosition = = m_nRowCount ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2006-01-25 14:10:43 +00:00
sal_Bool ORowSetCache : : beforeFirst ( )
2000-09-18 23:16:46 +00:00
{
2006-02-06 15:54:31 +00:00
2000-09-18 23:16:46 +00:00
2001-06-26 09:30:55 +00:00
if ( ! m_bBeforeFirst )
{
2001-07-12 06:56:32 +00:00
m_bAfterLast = sal_False ;
2001-06-26 09:30:55 +00:00
m_nPosition = 0 ;
m_bBeforeFirst = sal_True ;
m_pCacheSet - > beforeFirst ( ) ;
moveWindow ( ) ;
m_aMatrixIter = m_pMatrix - > end ( ) ;
}
2006-01-25 14:10:43 +00:00
return sal_True ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2006-01-25 14:10:43 +00:00
sal_Bool ORowSetCache : : afterLast ( )
2000-09-18 23:16:46 +00:00
{
2006-02-06 15:54:31 +00:00
2000-09-18 23:16:46 +00:00
2001-06-26 09:30:55 +00:00
if ( ! m_bAfterLast )
{
2001-07-12 06:56:32 +00:00
m_bBeforeFirst = sal_False ;
2001-06-26 09:30:55 +00:00
m_bAfterLast = sal_True ;
2000-09-18 23:16:46 +00:00
2001-06-26 09:30:55 +00:00
if ( ! m_bRowCountFinal )
{
m_pCacheSet - > last ( ) ;
m_bRowCountFinal = sal_True ;
m_nRowCount = m_pCacheSet - > getRow ( ) ; // + 1 removed
}
m_pCacheSet - > afterLast ( ) ;
2000-09-18 23:16:46 +00:00
2001-06-26 09:30:55 +00:00
m_nPosition = 0 ;
m_aMatrixIter = m_pMatrix - > end ( ) ;
2000-09-18 23:16:46 +00:00
}
2006-01-25 14:10:43 +00:00
return sal_True ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2001-01-22 06:38:24 +00:00
sal_Bool ORowSetCache : : fillMatrix ( sal_Int32 & _nNewStartPos , sal_Int32 _nNewEndPos )
2000-09-18 23:16:46 +00:00
{
2001-06-26 09:30:55 +00:00
OSL_ENSURE ( _nNewStartPos ! = _nNewEndPos , " ORowSetCache::fillMatrix: StartPos and EndPos can not be equal! " ) ;
2000-11-07 12:19:27 +00:00
// fill the whole window with new data
2000-09-18 23:16:46 +00:00
ORowSetMatrix : : iterator aIter = m_pMatrix - > begin ( ) ;
2000-11-07 12:19:27 +00:00
sal_Bool bCheck = m_pCacheSet - > absolute ( _nNewStartPos ) ; // -1 no need to
2001-01-24 08:52:19 +00:00
sal_Int32 i = _nNewStartPos ;
for ( ; i < _nNewEndPos ; + + i , + + aIter )
2000-09-18 23:16:46 +00:00
{
if ( bCheck )
{
if ( ! aIter - > isValid ( ) )
2003-03-19 16:57:12 +00:00
* aIter = new ORowSetValueVector ( m_xMetaData - > getColumnCount ( ) ) ;
2000-12-14 10:41:19 +00:00
m_pCacheSet - > fillValueRow ( * aIter , i ) ;
2000-09-18 23:16:46 +00:00
}
else
{ // there are no more rows found so we can fetch some before start
if ( ! m_bRowCountFinal )
{
2001-01-24 08:52:19 +00:00
if ( m_pCacheSet - > previous ( ) ) // because we stand after the last row
m_nRowCount = m_pCacheSet - > getRow ( ) ; // here we have the row count
if ( ! m_nRowCount )
m_nRowCount = i - 1 ; // it can be that getRow return zero
2000-09-18 23:16:46 +00:00
m_bRowCountFinal = sal_True ;
}
2001-01-24 08:52:19 +00:00
if ( m_nRowCount > m_nFetchSize )
2000-09-18 23:16:46 +00:00
{
2001-01-24 08:52:19 +00:00
ORowSetMatrix : : iterator aEnd = aIter ;
sal_Int32 nPos = m_nRowCount - m_nFetchSize + 1 ;
_nNewStartPos = nPos ;
bCheck = m_pCacheSet - > absolute ( _nNewStartPos ) ;
for ( ; bCheck & & aIter ! = m_pMatrix - > end ( ) ; + + aIter )
2000-09-18 23:16:46 +00:00
{
2001-01-24 08:52:19 +00:00
if ( bCheck )
{
if ( ! aIter - > isValid ( ) )
2003-03-19 16:57:12 +00:00
* aIter = new ORowSetValueVector ( m_xMetaData - > getColumnCount ( ) ) ;
2001-01-24 08:52:19 +00:00
m_pCacheSet - > fillValueRow ( * aIter , nPos + + ) ;
}
bCheck = m_pCacheSet - > next ( ) ;
2000-09-18 23:16:46 +00:00
}
2001-01-24 08:52:19 +00:00
if ( aIter ! = aEnd )
: : std : : rotate ( m_pMatrix - > begin ( ) , aEnd , m_pMatrix - > end ( ) ) ;
2000-09-18 23:16:46 +00:00
}
break ;
}
bCheck = m_pCacheSet - > next ( ) ;
}
2001-01-22 06:38:24 +00:00
// m_nStartPos = _nNewStartPos;
2000-11-07 12:19:27 +00:00
// we have to read one row forward to enshure that we know when we are on last row
// but only when we don't know it already
if ( ! m_bRowCountFinal )
{
if ( ! m_pCacheSet - > next ( ) )
{
if ( m_pCacheSet - > previous ( ) ) // because we stand after the last row
m_nRowCount = m_pCacheSet - > getRow ( ) ; // here we have the row count
m_bRowCountFinal = sal_True ;
}
2001-01-24 08:52:19 +00:00
else
2001-10-12 14:36:42 +00:00
m_nRowCount = std : : max ( i , m_nRowCount ) ;
2001-01-24 08:52:19 +00:00
2000-11-07 12:19:27 +00:00
}
2000-09-18 23:16:46 +00:00
return bCheck ;
}
// -------------------------------------------------------------------------
sal_Bool ORowSetCache : : moveWindow ( )
{
2006-02-06 15:54:31 +00:00
2000-09-18 23:16:46 +00:00
sal_Bool bRet = sal_True ;
2001-04-02 10:14:53 +00:00
sal_Int32 nDiff = ( sal_Int32 ) ( m_nFetchSize * 0.5 - 0.5 ) ;
2001-01-24 08:52:19 +00:00
sal_Int32 nNewStartPos = ( m_nPosition - nDiff ) ;
2000-09-18 23:16:46 +00:00
// sal_Int32 nNewEndPos = (m_nPosition+m_nFetchSize*0.5);
sal_Int32 nNewEndPos = nNewStartPos + m_nFetchSize ;
2003-03-19 16:57:12 +00:00
if ( m_nPosition < = m_nStartPos )
2000-09-18 23:16:46 +00:00
{ // the window is behind the new start pos
if ( ! m_nStartPos )
return sal_False ;
// the new position should be the nPos - nFetchSize/2
2003-03-19 16:57:12 +00:00
if ( nNewEndPos > m_nStartPos )
2000-09-18 23:16:46 +00:00
{ // but the two regions are overlapping
// fill the rows behind the new end
ORowSetMatrix : : iterator aEnd ; // the iterator we need for rotate
ORowSetMatrix : : iterator aIter ; // the iterator we fill with new values
sal_Bool bCheck = sal_True ;
2003-03-19 16:57:12 +00:00
if ( nNewStartPos < 1 )
2000-09-18 23:16:46 +00:00
{
bCheck = m_pCacheSet - > first ( ) ;
2000-12-14 10:41:19 +00:00
// aEnd = m_pMatrix->begin() + (sal_Int32)(m_nFetchSize*0.5);
2001-04-02 10:14:53 +00:00
OSL_ENSURE ( ( nNewEndPos - m_nStartPos - nNewStartPos ) < ( sal_Int32 ) m_pMatrix - > size ( ) , " Position is behind end()! " ) ;
2006-01-25 12:43:29 +00:00
aEnd = m_pMatrix - > begin ( ) + ( nNewEndPos - m_nStartPos - nNewStartPos ) ;
2000-09-18 23:16:46 +00:00
aIter = aEnd ;
2000-12-14 10:41:19 +00:00
m_nStartPos = 0 ;
2000-09-18 23:16:46 +00:00
}
else
{
2001-04-02 10:14:53 +00:00
OSL_ENSURE ( ( nNewEndPos - m_nStartPos - 1 ) < ( sal_Int32 ) m_pMatrix - > size ( ) , " Position is behind end()! " ) ;
2006-01-25 12:43:29 +00:00
aEnd = m_pMatrix - > begin ( ) + ( ( nNewEndPos - m_nStartPos ) - 1 ) ;
aIter = m_pMatrix - > begin ( ) + ( ( nNewEndPos - m_nStartPos ) - 1 ) ;
2001-01-24 08:52:19 +00:00
bCheck = m_pCacheSet - > absolute ( nNewStartPos ) ;
m_nStartPos = nNewStartPos - 1 ;
2000-09-18 23:16:46 +00:00
}
2003-03-19 16:57:12 +00:00
if ( bCheck )
2000-09-18 23:16:46 +00:00
{
2003-03-19 16:57:12 +00:00
sal_Int32 nPos = m_nStartPos ;
bCheck = fill ( aIter , m_pMatrix - > end ( ) , nPos , bCheck ) ;
2000-09-18 23:16:46 +00:00
: : std : : rotate ( m_pMatrix - > begin ( ) , aEnd , m_pMatrix - > end ( ) ) ;
2001-01-22 06:38:24 +00:00
// now correct the iterator in our iterator vector
2001-06-26 09:30:55 +00:00
// rotateCacheIterator(aEnd-m_pMatrix->begin()); //can't be used because they decrement and here we need to increment
2006-07-10 14:03:49 +00:00
ptrdiff_t nNewDist = aEnd - m_pMatrix - > begin ( ) ;
ptrdiff_t nOffSet = m_pMatrix - > end ( ) - aEnd ;
2001-01-24 08:52:19 +00:00
ORowSetCacheMap : : iterator aCacheIter = m_aCacheIterators . begin ( ) ;
for ( ; aCacheIter ! = m_aCacheIterators . end ( ) ; + + aCacheIter )
{
2006-01-25 14:10:43 +00:00
if ( ! aCacheIter - > second . pRowSet - > isInsertRow ( )
2006-02-06 15:54:31 +00:00
& & aCacheIter - > second . aIterator ! = m_pMatrix - > end ( ) & & ! m_bModified )
2001-01-24 08:52:19 +00:00
{
2006-07-10 14:03:49 +00:00
ptrdiff_t nDist = ( aCacheIter - > second . aIterator - m_pMatrix - > begin ( ) ) ;
2002-12-11 13:14:13 +00:00
if ( nDist > = nNewDist )
2001-01-24 08:52:19 +00:00
{
2005-09-05 07:57:54 +00:00
aCacheIter - > second . aIterator = m_pMatrix - > end ( ) ;
2001-01-24 08:52:19 +00:00
}
else
2002-11-13 05:56:59 +00:00
{
2003-04-15 15:02:45 +00:00
# if OSL_DEBUG_LEVEL > 0
2006-08-24 09:37:29 +00:00
ORowSetMatrix : : iterator aOldPos ;
aOldPos = aCacheIter - > second . aIterator ;
2002-12-11 13:14:13 +00:00
# endif
2006-07-26 06:46:13 +00:00
CHECK_MATRIX_POS ( ( ( aOldPos - m_pMatrix - > begin ( ) ) + nOffSet ) ) ;
2002-11-13 05:56:59 +00:00
aCacheIter - > second . aIterator + = nOffSet ;
2003-04-15 15:02:45 +00:00
# if OSL_DEBUG_LEVEL > 0
2006-08-24 09:37:29 +00:00
ORowSetMatrix : : iterator aCurrentPos ;
aCurrentPos = aCacheIter - > second . aIterator ;
2002-12-11 13:14:13 +00:00
# endif
2002-11-13 05:56:59 +00:00
OSL_ENSURE ( aCacheIter - > second . aIterator > = m_pMatrix - > begin ( )
2002-12-05 08:54:54 +00:00
& & aCacheIter - > second . aIterator < m_pMatrix - > end ( ) , " Iterator out of area! " ) ;
2002-11-13 05:56:59 +00:00
}
2001-01-24 08:52:19 +00:00
}
}
2000-09-18 23:16:46 +00:00
}
else
{ // normaly this should never happen
2001-01-24 08:52:19 +00:00
OSL_ENSURE ( 0 , " What the hell is happen here! " ) ;
2000-09-18 23:16:46 +00:00
return sal_False ;
}
}
else
{ // no rows can be reused so fill again
if ( nNewStartPos < 1 ) // special case
{
m_nStartPos = 0 ;
2006-02-06 15:54:31 +00:00
rotateCacheIterator ( static_cast < sal_Int16 > ( m_nFetchSize + 1 ) ) ; // static_cast<sal_Int16>(m_nFetchSize+1)
2000-12-14 10:41:19 +00:00
m_pCacheSet - > beforeFirst ( ) ;
2000-09-18 23:16:46 +00:00
sal_Bool bCheck ;
ORowSetMatrix : : iterator aIter = m_pMatrix - > begin ( ) ;
for ( sal_Int32 i = 0 ; i < m_nFetchSize ; + + i , + + aIter )
{
2006-07-10 14:03:49 +00:00
bCheck = m_pCacheSet - > next ( ) ;
if ( bCheck )
2000-09-18 23:16:46 +00:00
{
if ( ! aIter - > isValid ( ) )
2003-03-19 16:57:12 +00:00
* aIter = new ORowSetValueVector ( m_xMetaData - > getColumnCount ( ) ) ;
2000-12-14 10:41:19 +00:00
m_pCacheSet - > fillValueRow ( * aIter , i + 1 ) ;
2000-09-18 23:16:46 +00:00
}
else
* aIter = NULL ;
}
}
else
2003-03-19 16:57:12 +00:00
bRet = reFillMatrix ( nNewStartPos , nNewEndPos ) ;
2000-09-18 23:16:46 +00:00
}
}
else if ( m_nPosition > m_nStartPos )
2000-11-07 12:19:27 +00:00
{ // the new start pos is above the startpos of the window
2000-09-18 23:16:46 +00:00
if ( m_nPosition < = ( m_nStartPos + m_nFetchSize ) )
{ // position in window
2001-04-02 10:14:53 +00:00
OSL_ENSURE ( ( m_nPosition - m_nStartPos - 1 ) < ( sal_Int32 ) m_pMatrix - > size ( ) , " Position is behind end()! " ) ;
2001-11-29 15:35:26 +00:00
m_aMatrixIter = calcPosition ( ) ;
2000-09-18 23:16:46 +00:00
if ( ! m_aMatrixIter - > isValid ( ) )
{
2006-07-10 14:03:49 +00:00
sal_Bool bOk ( m_pCacheSet - > absolute ( m_nPosition ) ) ;
if ( bOk )
2000-09-18 23:16:46 +00:00
{
2003-03-19 16:57:12 +00:00
* m_aMatrixIter = new ORowSetValueVector ( m_xMetaData - > getColumnCount ( ) ) ;
2000-11-14 12:28:20 +00:00
m_pCacheSet - > fillValueRow ( * m_aMatrixIter , m_nPosition ) ;
2000-11-07 12:19:27 +00:00
// we have to read one row forward to enshure that we know when we are on last row
// but only when we don't know it already
2006-07-10 14:03:49 +00:00
if ( ! m_bRowCountFinal )
{
bOk = m_pCacheSet - > absolute ( m_nPosition + 1 ) ;
if ( bOk )
m_nRowCount = std : : max ( sal_Int32 ( m_nPosition + 1 ) , m_nRowCount ) ;
}
2000-09-18 23:16:46 +00:00
}
2000-11-07 12:19:27 +00:00
if ( ! bOk )
2000-09-18 23:16:46 +00:00
{
if ( ! m_bRowCountFinal )
{
2001-06-26 09:30:55 +00:00
// because we stand after the last row
m_nRowCount = m_pCacheSet - > previous ( ) ? m_pCacheSet - > getRow ( ) : 0 ; // + 1 removed
2000-09-18 23:16:46 +00:00
m_bRowCountFinal = sal_True ;
}
}
}
}
else if ( nNewStartPos < ( m_nStartPos + m_nFetchSize ) )
{ // position behind window but the region is overlapping
// the rows from begin() to (begin + nNewStartPos - m_nStartPos) can be refilled with the new rows
// the rows behind this can be reused
ORowSetMatrix : : iterator aIter = m_pMatrix - > begin ( ) ;
2006-07-26 06:46:13 +00:00
CHECK_MATRIX_POS ( nNewStartPos - m_nStartPos - 1 ) ;
2006-01-25 12:43:29 +00:00
ORowSetMatrix : : iterator aEnd = m_pMatrix - > begin ( ) + ( nNewStartPos - m_nStartPos - 1 ) ;
2003-03-19 16:57:12 +00:00
sal_Int32 nPos = m_nStartPos + m_nFetchSize + 1 ;
sal_Bool bCheck = m_pCacheSet - > absolute ( nPos ) ;
2003-04-28 14:59:21 +00:00
bCheck = fill ( aIter , aEnd , nPos , bCheck ) ; // refill the region wew don't need anymore
2003-03-19 16:57:12 +00:00
2003-04-01 13:00:38 +00:00
// // we know that this is the current maximal rowcount here
// if ( !m_bRowCountFinal && bCheck )
// m_nRowCount = std::max(nPos,m_nRowCount);
2000-11-07 12:19:27 +00:00
// we have to read one row forward to enshure that we know when we are on last row
// but only when we don't know it already
sal_Bool bOk = sal_True ;
if ( bCheck & & ! m_bRowCountFinal )
bOk = m_pCacheSet - > next ( ) ;
2000-09-18 23:16:46 +00:00
// bind end to front
if ( bCheck )
{ // rotate the end to the front
: : std : : rotate ( m_pMatrix - > begin ( ) , aIter , m_pMatrix - > end ( ) ) ;
2001-01-22 06:38:24 +00:00
// now correct the iterator in our iterator vector
2006-07-10 14:03:49 +00:00
rotateCacheIterator ( ( sal_Int16 ) ( aIter - m_pMatrix - > begin ( ) ) ) ;
2000-09-18 23:16:46 +00:00
m_nStartPos = nNewStartPos - 1 ; // must be -1
2000-11-07 12:19:27 +00:00
// now I can say how many rows we have
if ( ! bOk )
{
m_pCacheSet - > previous ( ) ; // because we stand after the last row
2000-11-14 12:28:20 +00:00
m_nRowCount = nPos ; // here we have the row count
2000-11-07 12:19:27 +00:00
m_bRowCountFinal = sal_True ;
}
2001-07-24 13:20:28 +00:00
else if ( ! m_bRowCountFinal )
2001-10-12 14:36:42 +00:00
m_nRowCount = std : : max ( + + nPos , m_nRowCount ) ;
2000-09-18 23:16:46 +00:00
}
else
{ // the end was reached before end() so we can set the start before nNewStartPos
2000-10-25 06:32:52 +00:00
m_nStartPos + = ( aIter - m_pMatrix - > begin ( ) ) ;
2003-04-01 13:00:38 +00:00
// m_nStartPos = (aIter - m_pMatrix->begin());
2000-09-18 23:16:46 +00:00
: : std : : rotate ( m_pMatrix - > begin ( ) , aIter , m_pMatrix - > end ( ) ) ;
2001-01-22 06:38:24 +00:00
// now correct the iterator in our iterator vector
2006-07-10 14:03:49 +00:00
rotateCacheIterator ( ( sal_Int16 ) ( aIter - m_pMatrix - > begin ( ) ) ) ;
2001-01-22 06:38:24 +00:00
2003-04-01 13:00:38 +00:00
if ( ! m_bRowCountFinal )
2000-09-18 23:16:46 +00:00
{
2003-04-01 13:00:38 +00:00
m_pCacheSet - > previous ( ) ; // because we stand after the last row
m_nRowCount = std : : max ( m_nRowCount , - - nPos ) ; // here we have the row count
OSL_ENSURE ( nPos = = m_pCacheSet - > getRow ( ) , " nPos isn't valid! " ) ;
2000-09-18 23:16:46 +00:00
m_bRowCountFinal = sal_True ;
}
// TODO check
2000-10-25 06:32:52 +00:00
// m_nStartPos = (nNewStartPos+m_nRowCount) - m_nFetchSize ;
if ( m_nStartPos < 0 )
m_nStartPos = 0 ;
2000-09-18 23:16:46 +00:00
}
2000-10-25 06:32:52 +00:00
// here we need only to check if the begining row is valid. If not we have to fetch it.
2000-09-18 23:16:46 +00:00
if ( ! m_pMatrix - > begin ( ) - > isValid ( ) )
{
aIter = m_pMatrix - > begin ( ) ;
2000-11-14 12:28:20 +00:00
nPos = m_nStartPos ;
bCheck = m_pCacheSet - > absolute ( m_nStartPos ) ;
2000-09-18 23:16:46 +00:00
for ( ; ! aIter - > isValid ( ) & & bCheck ; + + aIter )
{
2006-07-26 06:46:13 +00:00
OSL_ENSURE ( aIter ! = m_pMatrix - > end ( ) , " Invalid iterator " ) ;
2006-07-10 14:03:49 +00:00
bCheck = m_pCacheSet - > next ( ) ;
if ( bCheck ) // resultset stands on right position
2000-09-18 23:16:46 +00:00
{
2003-03-19 16:57:12 +00:00
* aIter = new ORowSetValueVector ( m_xMetaData - > getColumnCount ( ) ) ;
2000-11-14 12:28:20 +00:00
m_pCacheSet - > fillValueRow ( * aIter , + + nPos ) ;
2000-09-18 23:16:46 +00:00
}
}
}
}
else // no rows can be reused so fill again
2003-03-19 16:57:12 +00:00
bRet = reFillMatrix ( nNewStartPos , nNewEndPos ) ;
2000-09-18 23:16:46 +00:00
}
if ( ! m_bRowCountFinal )
2001-10-12 14:36:42 +00:00
m_nRowCount = std : : max ( m_nPosition , m_nRowCount ) ;
2001-01-22 06:38:24 +00:00
OSL_ENSURE ( m_nStartPos > = 0 , " ORowSetCache::moveWindow: m_nStartPos is less than 0! " ) ;
2000-09-18 23:16:46 +00:00
return bRet ;
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
sal_Bool ORowSetCache : : first ( )
2000-09-18 23:16:46 +00:00
{
// first move to the first row
// then check if the cache window is at the begining
// when not postionize the window and fill it with data
// smart moving of the window -> clear only the rows whom are out of range
sal_Bool bRet = m_pCacheSet - > first ( ) ;
if ( bRet )
{
2001-07-12 06:56:32 +00:00
m_bBeforeFirst = m_bAfterLast = sal_False ;
2000-11-14 12:28:20 +00:00
m_nPosition = 1 ;
2000-09-18 23:16:46 +00:00
moveWindow ( ) ;
2000-11-14 12:28:20 +00:00
m_aMatrixIter = m_pMatrix - > begin ( ) ;
2000-09-18 23:16:46 +00:00
}
2000-11-14 12:28:20 +00:00
else
2001-06-26 09:30:55 +00:00
{
2003-06-25 10:02:47 +00:00
m_bRowCountFinal = m_bBeforeFirst = m_bAfterLast = sal_True ;
m_nRowCount = m_nPosition = 0 ;
2006-02-06 15:54:31 +00:00
OSL_ENSURE ( m_bBeforeFirst | | m_bNew , " ORowSetCache::first return false and BeforeFirst isn't true " ) ;
2000-11-14 12:28:20 +00:00
m_aMatrixIter = m_pMatrix - > end ( ) ;
2001-06-26 09:30:55 +00:00
}
2000-09-18 23:16:46 +00:00
return bRet ;
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
sal_Bool ORowSetCache : : last ( )
2000-09-18 23:16:46 +00:00
{
sal_Bool bRet = m_pCacheSet - > last ( ) ;
if ( bRet )
{
m_bBeforeFirst = m_bAfterLast = sal_False ;
if ( ! m_bRowCountFinal )
{
m_bRowCountFinal = sal_True ;
m_nRowCount = m_nPosition = m_pCacheSet - > getRow ( ) ; // not + 1
}
2000-10-05 13:52:16 +00:00
m_nPosition = m_pCacheSet - > getRow ( ) ;
2000-09-18 23:16:46 +00:00
moveWindow ( ) ;
// we have to repositioning because moveWindow can modify the cache
m_pCacheSet - > last ( ) ;
2001-08-24 05:40:35 +00:00
// if(m_nPosition > m_nFetchSize)
// m_aMatrixIter = m_pMatrix->end() -1;
// else
// m_aMatrixIter = m_pMatrix->begin() + m_nPosition - 1;
OSL_ENSURE ( ( ( m_nPosition - m_nStartPos ) - 1 ) < ( sal_Int32 ) m_pMatrix - > size ( ) , " Position is behind end()! " ) ;
2001-11-29 15:35:26 +00:00
m_aMatrixIter = calcPosition ( ) ;
2000-09-18 23:16:46 +00:00
}
2000-11-14 12:28:20 +00:00
else
2001-06-26 09:30:55 +00:00
{
2003-06-25 10:02:47 +00:00
m_bRowCountFinal = m_bBeforeFirst = m_bAfterLast = sal_True ;
m_nRowCount = m_nPosition = 0 ;
2001-06-26 09:30:55 +00:00
OSL_ENSURE ( m_bBeforeFirst , " ORowSetCache::last return false and BeforeFirst isn't true " ) ;
2000-11-14 12:28:20 +00:00
m_aMatrixIter = m_pMatrix - > end ( ) ;
2001-06-26 09:30:55 +00:00
}
2003-04-15 15:02:45 +00:00
# if OSL_DEBUG_LEVEL > 1
2000-09-18 23:16:46 +00:00
if ( bRet )
{
2001-01-22 06:38:24 +00:00
OSL_ENSURE ( ( * m_aMatrixIter ) . isValid ( ) , " ORowSetCache::last: Row not valid! " ) ;
2000-09-18 23:16:46 +00:00
}
# endif
2000-09-29 14:23:36 +00:00
2000-09-18 23:16:46 +00:00
return bRet ;
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
sal_Int32 ORowSetCache : : getRow ( )
2000-09-18 23:16:46 +00:00
{
2001-06-26 09:30:55 +00:00
return ( isBeforeFirst ( ) | | isAfterLast ( ) ) ? 0 : m_nPosition ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
sal_Bool ORowSetCache : : absolute ( sal_Int32 row )
2000-09-18 23:16:46 +00:00
{
if ( ! row )
2004-06-01 09:09:25 +00:00
throw SQLException ( DBACORE_RESSTRING ( RID_STR_NO_ABS_ZERO ) , NULL , SQLSTATE_GENERAL , 1000 , Any ( ) ) ;
2000-09-18 23:16:46 +00:00
if ( row < 0 )
{
2001-06-26 09:30:55 +00:00
// here we have to scroll from the last row to backward so we have to go to last row and
// and two the previous
2000-09-18 23:16:46 +00:00
if ( m_bRowCountFinal | | last ( ) )
{
2001-04-05 13:14:41 +00:00
m_nPosition = m_nRowCount + row + 1 ; // + row because row is negative and +1 because row==-1 means last row
2000-09-18 23:16:46 +00:00
if ( m_nPosition < 1 )
{
m_bBeforeFirst = sal_True ;
2001-07-12 06:56:32 +00:00
m_bAfterLast = sal_False ;
2000-09-18 23:16:46 +00:00
m_aMatrixIter = m_pMatrix - > end ( ) ;
}
else
{
m_bBeforeFirst = sal_False ;
m_bAfterLast = m_nPosition > m_nRowCount ;
moveWindow ( ) ;
2001-04-02 10:14:53 +00:00
OSL_ENSURE ( ( ( m_nPosition - m_nStartPos ) - 1 ) < ( sal_Int32 ) m_pMatrix - > size ( ) , " Position is behind end()! " ) ;
2001-11-29 15:35:26 +00:00
m_aMatrixIter = calcPosition ( ) ;
2000-09-18 23:16:46 +00:00
}
}
else
m_aMatrixIter = m_pMatrix - > end ( ) ;
}
else
{
m_nPosition = row ;
// the position flags
m_bBeforeFirst = sal_False ;
2001-06-26 09:30:55 +00:00
checkPositionFlags ( ) ;
2000-09-18 23:16:46 +00:00
if ( ! m_bAfterLast )
{
moveWindow ( ) ;
2001-06-26 09:30:55 +00:00
checkPositionFlags ( ) ;
2000-10-25 06:32:52 +00:00
if ( ! m_bAfterLast )
2001-11-29 15:35:26 +00:00
m_aMatrixIter = calcPosition ( ) ;
2000-10-25 06:32:52 +00:00
else
m_aMatrixIter = m_pMatrix - > end ( ) ;
2000-09-18 23:16:46 +00:00
}
else
m_aMatrixIter = m_pMatrix - > end ( ) ;
}
2000-09-29 14:23:36 +00:00
2000-09-18 23:16:46 +00:00
return ! ( m_bAfterLast | | m_bBeforeFirst ) ;
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
sal_Bool ORowSetCache : : relative ( sal_Int32 rows )
2000-09-18 23:16:46 +00:00
{
2001-06-26 09:30:55 +00:00
sal_Bool bErg = sal_True ;
if ( rows )
{
2006-01-25 14:10:43 +00:00
sal_Int32 nNewPosition = m_nPosition + rows ;
2000-09-18 23:16:46 +00:00
2006-01-25 14:10:43 +00:00
if ( m_bBeforeFirst & & rows > 0 )
nNewPosition = rows ;
else if ( m_bRowCountFinal & & m_bAfterLast & & rows < 0 )
nNewPosition = m_nRowCount + 1 + rows ;
else
if ( m_bBeforeFirst | | ( m_bRowCountFinal & & m_bAfterLast ) )
throw SQLException ( DBACORE_RESSTRING ( RID_STR_NO_RELATIVE ) , NULL , SQLSTATE_GENERAL , 1000 , Any ( ) ) ;
if ( nNewPosition )
{
bErg = absolute ( nNewPosition ) ;
2001-06-26 09:30:55 +00:00
bErg = bErg & & ! isAfterLast ( ) & & ! isBeforeFirst ( ) ;
}
else
2006-01-25 14:10:43 +00:00
{
m_bBeforeFirst = sal_True ;
bErg = sal_False ;
}
2001-06-26 09:30:55 +00:00
}
return bErg ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
sal_Bool ORowSetCache : : previous ( )
2000-09-18 23:16:46 +00:00
{
2001-06-26 09:30:55 +00:00
sal_Bool bRet = sal_False ;
if ( ! isBeforeFirst ( ) )
2000-09-18 23:16:46 +00:00
{
2001-06-26 09:30:55 +00:00
if ( m_bAfterLast ) // we stand after the last row so one before is the last row
bRet = last ( ) ;
else
{
m_bAfterLast = sal_False ;
- - m_nPosition ;
moveWindow ( ) ;
OSL_ENSURE ( ( ( m_nPosition - m_nStartPos ) - 1 ) < ( sal_Int32 ) m_pMatrix - > size ( ) , " Position is behind end()! " ) ;
2000-09-18 23:16:46 +00:00
2001-06-26 09:30:55 +00:00
checkPositionFlags ( ) ;
2000-09-18 23:16:46 +00:00
2001-06-26 09:30:55 +00:00
if ( ! m_nPosition )
{
m_bBeforeFirst = sal_True ;
m_aMatrixIter = m_pMatrix - > end ( ) ;
}
else
2001-12-19 14:16:17 +00:00
{
m_aMatrixIter = calcPosition ( ) ;
2001-06-26 09:30:55 +00:00
bRet = ( * m_aMatrixIter ) . isValid ( ) ;
2001-12-19 14:16:17 +00:00
}
2001-06-26 09:30:55 +00:00
}
}
return bRet ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
void ORowSetCache : : refreshRow ( )
2000-09-18 23:16:46 +00:00
{
if ( isAfterLast ( ) )
2004-06-01 09:09:25 +00:00
throw SQLException ( DBACORE_RESSTRING ( RID_STR_NO_REFESH_AFTERLAST ) , NULL , SQLSTATE_GENERAL , 1000 , Any ( ) ) ;
2001-01-22 06:38:24 +00:00
OSL_ENSURE ( m_aMatrixIter ! = m_pMatrix - > end ( ) , " refreshRow() called for invalid row! " ) ;
m_pCacheSet - > refreshRow ( ) ;
2000-11-14 12:28:20 +00:00
m_pCacheSet - > fillValueRow ( * m_aMatrixIter , m_nPosition ) ;
2006-02-06 15:54:31 +00:00
if ( m_bNew )
2002-07-11 06:02:27 +00:00
{
2002-12-05 08:54:54 +00:00
cancelRowModification ( ) ;
2002-07-11 06:02:27 +00:00
}
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
sal_Bool ORowSetCache : : rowUpdated ( )
2000-09-18 23:16:46 +00:00
{
return m_pCacheSet - > rowUpdated ( ) ;
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
sal_Bool ORowSetCache : : rowInserted ( )
2000-09-18 23:16:46 +00:00
{
return m_pCacheSet - > rowInserted ( ) ;
}
// -------------------------------------------------------------------------
// XResultSetUpdate
2002-12-10 11:50:04 +00:00
sal_Bool ORowSetCache : : insertRow ( )
2000-09-18 23:16:46 +00:00
{
2006-02-06 15:54:31 +00:00
if ( ! m_bNew | | ! m_aInsertRow - > isValid ( ) )
2004-06-01 09:09:25 +00:00
throw SQLException ( DBACORE_RESSTRING ( RID_STR_NO_MOVETOINSERTROW_CALLED ) , NULL , SQLSTATE_GENERAL , 1000 , Any ( ) ) ;
2000-09-18 23:16:46 +00:00
2000-09-29 14:23:36 +00:00
m_pCacheSet - > insertRow ( * m_aInsertRow , m_aUpdateTable ) ;
2000-12-06 08:55:44 +00:00
2006-07-10 14:03:49 +00:00
sal_Bool bRet ( rowInserted ( ) ) ;
if ( bRet )
2000-09-29 14:23:36 +00:00
{
+ + m_nRowCount ;
2001-01-22 06:38:24 +00:00
Any aBookmark = ( * ( * m_aInsertRow ) ) [ 0 ] . makeAny ( ) ;
2000-12-06 08:55:44 +00:00
m_bAfterLast = m_bBeforeFirst = sal_False ;
2001-01-22 06:38:24 +00:00
if ( aBookmark . hasValue ( ) )
moveToBookmark ( aBookmark ) ;
else
{
2001-01-24 08:52:19 +00:00
OSL_ENSURE ( 0 , " There must be a bookmark after the row was inserted! " ) ;
2001-01-22 06:38:24 +00:00
}
2000-09-29 14:23:36 +00:00
}
2002-12-10 11:50:04 +00:00
return bRet ;
}
// -------------------------------------------------------------------------
void ORowSetCache : : resetInsertRow ( sal_Bool _bClearInsertRow )
{
if ( _bClearInsertRow )
clearInsertRow ( ) ;
2000-09-29 14:23:36 +00:00
m_bNew = sal_False ;
m_bModified = sal_False ;
}
// -------------------------------------------------------------------------
2002-12-05 08:54:54 +00:00
void ORowSetCache : : cancelRowModification ( )
2000-09-29 14:23:36 +00:00
{
2001-06-26 09:30:55 +00:00
// clear the insertrow references -> implies that the current row of the rowset changes as well
ORowSetCacheMap : : iterator aCacheIter = m_aCacheIterators . begin ( ) ;
2006-01-25 12:43:29 +00:00
ORowSetCacheMap : : iterator aCacheEnd = m_aCacheIterators . end ( ) ;
for ( ; aCacheIter ! = aCacheEnd ; + + aCacheIter )
2001-06-26 09:30:55 +00:00
{
2006-01-25 14:10:43 +00:00
if ( aCacheIter - > second . pRowSet - > isInsertRow ( ) & & aCacheIter - > second . aIterator = = m_aInsertRow )
2006-01-25 12:43:29 +00:00
aCacheIter - > second . aIterator = m_pMatrix - > end ( ) ;
} // for(;aCacheIter != aCacheEnd;++aCacheIter)
resetInsertRow ( sal_False ) ;
2001-01-22 06:38:24 +00:00
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
void ORowSetCache : : updateRow ( ORowSetMatrix : : iterator & _rUpdateRow )
2001-01-22 06:38:24 +00:00
{
if ( isAfterLast ( ) | | isBeforeFirst ( ) )
2004-06-01 09:09:25 +00:00
throw SQLException ( DBACORE_RESSTRING ( RID_STR_NO_UPDATEROW ) , NULL , SQLSTATE_GENERAL , 1000 , Any ( ) ) ;
2001-01-22 06:38:24 +00:00
2001-07-23 06:54:41 +00:00
Any aBookmark = ( * ( * _rUpdateRow ) ) [ 0 ] . makeAny ( ) ;
2001-07-24 12:25:26 +00:00
OSL_ENSURE ( aBookmark . hasValue ( ) , " Bookmark must have a value! " ) ;
2002-08-08 06:07:42 +00:00
// here we don't have to reposition our CacheSet, when we try to update a row,
// the row was already fetched
2001-07-23 06:54:41 +00:00
moveToBookmark ( aBookmark ) ;
2001-01-22 06:38:24 +00:00
m_pCacheSet - > updateRow ( * _rUpdateRow , * m_aMatrixIter , m_aUpdateTable ) ;
2001-05-22 12:08:22 +00:00
// *(*m_aMatrixIter) = *(*_rUpdateRow);
// refetch the whole row
( * m_aMatrixIter ) = NULL ;
2001-07-23 06:54:41 +00:00
moveToBookmark ( aBookmark ) ;
2001-05-11 05:14:11 +00:00
2001-01-22 06:38:24 +00:00
// moveToBookmark((*(*m_aInsertRow))[0].makeAny());
2000-09-29 14:23:36 +00:00
// if(m_pCacheSet->rowUpdated())
// *m_aMatrixIter = m_aInsertRow;
2000-09-18 23:16:46 +00:00
m_bModified = sal_False ;
2001-04-05 06:51:27 +00:00
// refreshRow( );
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2006-01-25 14:10:43 +00:00
bool ORowSetCache : : deleteRow ( )
2000-09-18 23:16:46 +00:00
{
if ( isAfterLast ( ) | | isBeforeFirst ( ) )
2004-06-01 09:09:25 +00:00
throw SQLException ( DBACORE_RESSTRING ( RID_STR_NO_DELETEROW ) , NULL , SQLSTATE_GENERAL , 1000 , Any ( ) ) ;
2000-09-18 23:16:46 +00:00
// m_pCacheSet->absolute(m_nPosition);
m_pCacheSet - > deleteRow ( * m_aMatrixIter , m_aUpdateTable ) ;
2006-01-25 14:10:43 +00:00
if ( ! m_pCacheSet - > rowDeleted ( ) )
return false ;
2000-12-06 08:55:44 +00:00
2006-01-25 14:10:43 +00:00
- - m_nRowCount ;
OSL_ENSURE ( ( ( m_nPosition - m_nStartPos ) - 1 ) < ( sal_Int32 ) m_pMatrix - > size ( ) , " Position is behind end()! " ) ;
ORowSetMatrix : : iterator aPos = calcPosition ( ) ;
( * aPos ) = NULL ;
// (*m_pMatrix)[(m_nPosition - m_nStartPos)] = NULL; // set the deleted row to NULL
2000-12-06 08:55:44 +00:00
2006-01-25 14:10:43 +00:00
for ( + + aPos ; aPos ! = m_pMatrix - > end ( ) & & aPos - > isValid ( ) ; + + aPos )
{
* ( aPos - 1 ) = * aPos ;
( * aPos ) = NULL ;
2000-09-18 23:16:46 +00:00
}
2006-01-25 14:10:43 +00:00
m_aMatrixIter = m_pMatrix - > end ( ) ;
- - m_nPosition ;
return true ;
2006-01-25 12:43:29 +00:00
}
2000-09-18 23:16:46 +00:00
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
void ORowSetCache : : cancelRowUpdates ( )
2000-09-18 23:16:46 +00:00
{
2006-02-06 15:54:31 +00:00
m_bNew = m_bModified = sal_False ;
2001-04-05 06:51:27 +00:00
if ( ! m_nPosition )
{
OSL_ENSURE ( 0 , " cancelRowUpdates:Invalid positions pos == 0 " ) ;
2001-04-19 06:14:49 +00:00
: : dbtools : : throwFunctionSequenceException ( NULL ) ;
2001-04-05 06:51:27 +00:00
}
if ( m_pCacheSet - > absolute ( m_nPosition ) )
m_pCacheSet - > fillValueRow ( * m_aMatrixIter , m_nPosition ) ;
else
{
OSL_ENSURE ( 0 , " cancelRowUpdates couldn't position right with absolute " ) ;
2001-04-19 06:14:49 +00:00
: : dbtools : : throwFunctionSequenceException ( NULL ) ;
2001-04-05 06:51:27 +00:00
}
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2002-12-05 13:10:11 +00:00
void ORowSetCache : : moveToInsertRow ( )
2000-09-18 23:16:46 +00:00
{
m_bNew = sal_True ;
2006-01-25 14:10:43 +00:00
m_bUpdated = m_bAfterLast = sal_False ;
2000-09-29 14:23:36 +00:00
m_aInsertRow = m_pInsertMatrix - > begin ( ) ;
if ( ! m_aInsertRow - > isValid ( ) )
2003-03-19 16:57:12 +00:00
* m_aInsertRow = new ORowSetValueVector ( m_xMetaData - > getColumnCount ( ) ) ;
2000-09-29 14:23:36 +00:00
// we don't unbound the bookmark column
2003-03-19 16:57:12 +00:00
ORowSetValueVector : : iterator aIter = ( * m_aInsertRow ) - > begin ( ) + 1 ;
2000-09-29 14:23:36 +00:00
for ( ; aIter ! = ( * m_aInsertRow ) - > end ( ) ; + + aIter )
{
aIter - > setBound ( sal_False ) ;
2000-12-06 08:55:44 +00:00
aIter - > setModified ( sal_False ) ;
2000-09-29 14:23:36 +00:00
aIter - > setNull ( ) ;
}
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2006-01-25 12:43:29 +00:00
ORowSetCacheIterator ORowSetCache : : createIterator ( ORowSetBase * _pRowSet )
2001-01-22 06:38:24 +00:00
{
2006-02-06 15:54:31 +00:00
2001-01-22 06:38:24 +00:00
ORowSetCacheIterator_Helper aHelper ;
aHelper . aIterator = m_pMatrix - > end ( ) ;
2006-01-25 12:43:29 +00:00
aHelper . pRowSet = _pRowSet ;
return ORowSetCacheIterator ( m_aCacheIterators . insert ( m_aCacheIterators . begin ( ) , ORowSetCacheMap : : value_type ( m_aCacheIterators . size ( ) + 1 , aHelper ) ) , this , _pRowSet ) ;
2001-01-22 06:38:24 +00:00
}
// -----------------------------------------------------------------------------
2006-07-26 06:46:13 +00:00
void ORowSetCache : : rotateCacheIterator ( ORowSetMatrix : : difference_type _nDist )
2001-01-22 06:38:24 +00:00
{
2001-06-26 09:30:55 +00:00
if ( _nDist )
2001-01-22 06:38:24 +00:00
{
2001-06-26 09:30:55 +00:00
// now correct the iterator in our iterator vector
ORowSetCacheMap : : iterator aCacheIter = m_aCacheIterators . begin ( ) ;
for ( ; aCacheIter ! = m_aCacheIterators . end ( ) ; + + aCacheIter )
2001-01-22 06:38:24 +00:00
{
2006-01-25 14:10:43 +00:00
if ( ! aCacheIter - > second . pRowSet - > isInsertRow ( )
2006-02-06 15:54:31 +00:00
& & aCacheIter - > second . aIterator ! = m_pMatrix - > end ( ) & & ! m_bModified )
2001-01-22 06:38:24 +00:00
{
2006-07-10 14:03:49 +00:00
ptrdiff_t nDist = ( aCacheIter - > second . aIterator - m_pMatrix - > begin ( ) ) ;
2001-06-26 09:30:55 +00:00
if ( nDist < _nDist )
{
2005-09-05 07:57:54 +00:00
aCacheIter - > second . aIterator = m_pMatrix - > end ( ) ;
2001-06-26 09:30:55 +00:00
}
else
2002-11-13 05:56:59 +00:00
{
2006-07-26 06:46:13 +00:00
OSL_ENSURE ( ( aCacheIter - > second . aIterator - m_pMatrix - > begin ( ) ) > = _nDist , " Invalid Dist value! " ) ;
2001-06-26 09:30:55 +00:00
aCacheIter - > second . aIterator - = _nDist ;
2002-11-13 05:56:59 +00:00
OSL_ENSURE ( aCacheIter - > second . aIterator > = m_pMatrix - > begin ( )
2002-12-05 08:54:54 +00:00
& & aCacheIter - > second . aIterator < m_pMatrix - > end ( ) , " Iterator out of area! " ) ;
2002-11-13 05:56:59 +00:00
}
2001-01-22 06:38:24 +00:00
}
}
}
}
2006-01-25 14:10:43 +00:00
// -----------------------------------------------------------------------------
void ORowSetCache : : clearModified ( )
{
m_bModified = sal_False ;
}
2000-09-18 23:16:46 +00:00
// -------------------------------------------------------------------------
2001-01-22 06:38:24 +00:00
void ORowSetCache : : setUpdateIterator ( const ORowSetMatrix : : iterator & _rOriginalRow )
{
m_aInsertRow = m_pInsertMatrix - > begin ( ) ;
if ( ! m_aInsertRow - > isValid ( ) )
2003-03-19 16:57:12 +00:00
* m_aInsertRow = new ORowSetValueVector ( m_xMetaData - > getColumnCount ( ) ) ;
2001-01-22 06:38:24 +00:00
( * ( * m_aInsertRow ) ) = ( * ( * _rOriginalRow ) ) ;
// we don't unbound the bookmark column
2003-03-19 16:57:12 +00:00
ORowSetValueVector : : iterator aIter = ( * m_aInsertRow ) - > begin ( ) ;
2001-01-22 06:38:24 +00:00
for ( ; aIter ! = ( * m_aInsertRow ) - > end ( ) ; + + aIter )
aIter - > setModified ( sal_False ) ;
}
2001-02-01 13:23:57 +00:00
// -----------------------------------------------------------------------------
2001-06-26 09:30:55 +00:00
void ORowSetCache : : checkPositionFlags ( )
{
if ( m_bRowCountFinal )
{
m_bAfterLast = m_nPosition > m_nRowCount ;
if ( m_bAfterLast )
m_nPosition = 0 ; //m_nRowCount;
}
}
// -----------------------------------------------------------------------------
void ORowSetCache : : checkUpdateConditions ( sal_Int32 columnIndex )
{
if ( m_bAfterLast | | columnIndex > = ( sal_Int32 ) ( * m_aInsertRow ) - > size ( ) )
throwFunctionSequenceException ( m_xSet . get ( ) ) ;
}
2006-08-15 09:42:22 +00:00
//------------------------------------------------------------------------------
sal_Bool ORowSetCache : : checkInnerJoin ( const : : connectivity : : OSQLParseNode * pNode , const Reference < XConnection > & _xConnection , const : : rtl : : OUString & _sUpdateTableName )
{
sal_Bool bOk = sal_False ;
if ( pNode - > count ( ) = = 3 & & // Ausdruck is geklammert
SQL_ISPUNCTUATION ( pNode - > getChild ( 0 ) , " ( " ) & &
SQL_ISPUNCTUATION ( pNode - > getChild ( 2 ) , " ) " ) )
{
bOk = checkInnerJoin ( pNode - > getChild ( 1 ) , _xConnection , _sUpdateTableName ) ;
}
else if ( ( SQL_ISRULE ( pNode , search_condition ) | | SQL_ISRULE ( pNode , boolean_term ) ) & & // AND/OR-Verknuepfung:
pNode - > count ( ) = = 3 )
{
// nur AND Verkn<6B> pfung zulassen
if ( SQL_ISTOKEN ( pNode - > getChild ( 1 ) , AND ) & & ( bOk = checkInnerJoin ( pNode - > getChild ( 0 ) , _xConnection , _sUpdateTableName ) ) )
bOk = checkInnerJoin ( pNode - > getChild ( 2 ) , _xConnection , _sUpdateTableName ) ;
}
else if ( SQL_ISRULE ( pNode , comparison_predicate ) )
{
// only the comparison of columns is allowed
DBG_ASSERT ( pNode - > count ( ) = = 3 , " checkInnerJoin: Fehler im Parse Tree " ) ;
if ( ! ( SQL_ISRULE ( pNode - > getChild ( 0 ) , column_ref ) & &
SQL_ISRULE ( pNode - > getChild ( 2 ) , column_ref ) & &
pNode - > getChild ( 1 ) - > getNodeType ( ) = = SQL_NODE_EQUAL ) )
{
bOk = sal_False ;
}
: : rtl : : OUString sColumnName , sTableRange ;
OSQLParseTreeIterator : : getColumnRange ( pNode - > getChild ( 0 ) , _xConnection - > getMetaData ( ) , sColumnName , sTableRange ) ;
if ( ! ( bOk = sTableRange = = _sUpdateTableName ) )
{
OSQLParseTreeIterator : : getColumnRange ( pNode - > getChild ( 2 ) , _xConnection - > getMetaData ( ) , sColumnName , sTableRange ) ;
bOk = sTableRange = = _sUpdateTableName ;
}
}
return bOk ;
}
2001-07-19 08:29:22 +00:00
// -----------------------------------------------------------------------------
sal_Bool ORowSetCache : : checkJoin ( const Reference < XConnection > & _xConnection ,
2004-11-17 13:42:39 +00:00
const Reference < XSingleSelectQueryAnalyzer > & _xAnalyzer ,
2001-07-19 08:29:22 +00:00
const : : rtl : : OUString & _sUpdateTableName )
{
2001-12-07 08:58:12 +00:00
sal_Bool bOk = sal_False ;
2004-11-17 13:42:39 +00:00
: : rtl : : OUString sSql = _xAnalyzer - > getQuery ( ) ;
2001-07-19 08:29:22 +00:00
: : rtl : : OUString sErrorMsg ;
: : connectivity : : OSQLParser aSqlParser ( m_xServiceFactory ) ;
2006-08-15 09:42:22 +00:00
: : std : : auto_ptr < : : connectivity : : OSQLParseNode > pSqlParseNode ( aSqlParser . parseTree ( sErrorMsg , sSql ) ) ;
if ( pSqlParseNode . get ( ) & & SQL_ISRULE ( pSqlParseNode , select_statement ) )
2001-07-19 08:29:22 +00:00
{
OSQLParseNode * pTableRefCommalist = pSqlParseNode - > getByRule ( : : connectivity : : OSQLParseNode : : table_ref_commalist ) ;
OSL_ENSURE ( pTableRefCommalist , " NO tables why!? " ) ;
if ( pTableRefCommalist & & pTableRefCommalist - > count ( ) = = 1 )
{
// we found only one element so it must some kind of join here
OSQLParseNode * pJoin = pTableRefCommalist - > getByRule ( : : connectivity : : OSQLParseNode : : qualified_join ) ;
if ( pJoin )
{ // we are only intereseted in qualified joins like RIGHT or LEFT
OSQLParseNode * pJoinType = pJoin - > getChild ( 1 ) ;
OSQLParseNode * pOuterType = NULL ;
if ( SQL_ISRULE ( pJoinType , join_type ) & & pJoinType - > count ( ) = = 2 )
pOuterType = pJoinType - > getChild ( 0 ) ;
else if ( SQL_ISRULE ( pJoinType , outer_join_type ) )
pOuterType = pJoinType ;
sal_Bool bCheck = sal_False ;
sal_Bool bLeftSide = sal_False ;
if ( pOuterType )
{ // found outer join
bLeftSide = SQL_ISTOKEN ( pOuterType - > getChild ( 0 ) , LEFT ) ;
bCheck = bLeftSide | | SQL_ISTOKEN ( pOuterType - > getChild ( 0 ) , RIGHT ) ;
}
2001-12-07 08:27:32 +00:00
2001-07-19 08:29:22 +00:00
if ( bCheck )
{ // here we know that we have to check on which side our table resides
OSQLParseNode * pTableRef = pJoin - > getByRule ( : : connectivity : : OSQLParseNode : : qualified_join ) ;
if ( bLeftSide )
pTableRef = pJoin - > getChild ( 0 ) ;
else
pTableRef = pJoin - > getChild ( 3 ) ;
OSL_ENSURE ( SQL_ISRULE ( pTableRef , table_ref ) , " Must be a tableref here! " ) ;
: : rtl : : OUString sTableRange ;
if ( pTableRef - > count ( ) = = 4 )
sTableRange = pTableRef - > getChild ( 2 ) - > getTokenValue ( ) ; // Tabellenrange an Pos 2
if ( ! sTableRange . getLength ( ) )
pTableRef - > getChild ( 0 ) - > parseNodeToStr ( sTableRange , _xConnection - > getMetaData ( ) , NULL , sal_False , sal_False ) ;
bOk = sTableRange = = _sUpdateTableName ;
}
}
}
2006-08-15 09:42:22 +00:00
else
{
OSQLParseNode * pWhereOpt = pSqlParseNode - > getChild ( 3 ) - > getChild ( 1 ) ;
if ( pWhereOpt & & ! pWhereOpt - > isLeaf ( ) )
bOk = checkInnerJoin ( pWhereOpt - > getChild ( 1 ) , _xConnection , _sUpdateTableName ) ;
}
2001-07-19 08:29:22 +00:00
}
return bOk ;
}
// -----------------------------------------------------------------------------
2001-08-09 12:12:51 +00:00
void ORowSetCache : : clearInsertRow ( )
{
// we don't unbound the bookmark column
2006-01-25 12:43:29 +00:00
if ( m_aInsertRow ! = m_pInsertMatrix - > end ( ) & & m_aInsertRow - > isValid ( ) )
2001-08-09 12:12:51 +00:00
{
2006-01-25 12:43:29 +00:00
ORowSetValueVector : : iterator aIter = ( * m_aInsertRow ) - > begin ( ) + 1 ;
ORowSetValueVector : : iterator aEnd = ( * m_aInsertRow ) - > end ( ) ;
for ( ; aIter ! = aEnd ; + + aIter )
{
aIter - > setBound ( sal_False ) ;
aIter - > setModified ( sal_False ) ;
aIter - > setNull ( ) ;
} // for(;aIter != (*m_aInsertRow)->end();++aIter)
2001-08-09 12:12:51 +00:00
}
}
// -----------------------------------------------------------------------------
2001-11-29 15:35:26 +00:00
ORowSetMatrix : : iterator ORowSetCache : : calcPosition ( ) const
{
sal_Int32 nValue = ( m_nPosition - m_nStartPos ) - 1 ;
2006-07-26 06:46:13 +00:00
CHECK_MATRIX_POS ( nValue ) ;
2005-03-18 09:05:15 +00:00
return ( nValue < 0 | | nValue > = static_cast < sal_Int32 > ( m_pMatrix - > size ( ) ) ) ? m_pMatrix - > end ( ) : ( m_pMatrix - > begin ( ) + nValue ) ;
2001-11-29 15:35:26 +00:00
}
// -----------------------------------------------------------------------------
2003-03-19 16:57:12 +00:00
TORowSetOldRowHelperRef ORowSetCache : : registerOldRow ( )
{
TORowSetOldRowHelperRef pRef = new ORowSetOldRowHelper ( ORowSetRow ( ) ) ;
m_aOldRows . push_back ( pRef ) ;
return pRef ;
}
// -----------------------------------------------------------------------------
void ORowSetCache : : deregisterOldRow ( const TORowSetOldRowHelperRef & _rRow )
{
for ( TOldRowSetRows : : iterator aOldRowIter = m_aOldRows . begin ( ) ; aOldRowIter ! = m_aOldRows . end ( ) ; + + aOldRowIter )
{
if ( aOldRowIter - > getBodyPtr ( ) = = _rRow . getBodyPtr ( ) )
{
m_aOldRows . erase ( aOldRowIter ) ;
break ;
}
}
}
// -----------------------------------------------------------------------------
sal_Bool ORowSetCache : : reFillMatrix ( sal_Int32 _nNewStartPos , sal_Int32 _nNewEndPos )
{
for ( TOldRowSetRows : : iterator aOldRowIter = m_aOldRows . begin ( ) ; aOldRowIter ! = m_aOldRows . end ( ) ; + + aOldRowIter )
{
if ( aOldRowIter - > isValid ( ) & & aOldRowIter - > getBody ( ) . getRow ( ) . isValid ( ) )
aOldRowIter - > getBody ( ) . setRow ( new ORowSetValueVector ( aOldRowIter - > getBody ( ) . getRow ( ) . getBody ( ) ) ) ;
}
sal_Int32 nNewSt = _nNewStartPos ;
sal_Bool bRet = fillMatrix ( nNewSt , _nNewEndPos ) ;
m_nStartPos = nNewSt - 1 ;
2004-08-02 14:01:13 +00:00
rotateCacheIterator ( static_cast < sal_Int16 > ( m_nFetchSize + 1 ) ) ; // forces that every iterator will be set to null
2003-03-19 16:57:12 +00:00
return bRet ;
}
// -----------------------------------------------------------------------------
sal_Bool ORowSetCache : : fill ( ORowSetMatrix : : iterator & _aIter , const ORowSetMatrix : : iterator & _aEnd , sal_Int32 & _nPos , sal_Bool _bCheck )
{
sal_Int32 nColumnCount = m_xMetaData - > getColumnCount ( ) ;
for ( ; _bCheck & & _aIter ! = _aEnd ; )
{
if ( ! _aIter - > isValid ( ) )
* _aIter = new ORowSetValueVector ( nColumnCount ) ;
else
{
for ( TOldRowSetRows : : iterator aOldRowIter = m_aOldRows . begin ( ) ; aOldRowIter ! = m_aOldRows . end ( ) ; + + aOldRowIter )
{
if ( aOldRowIter - > getBody ( ) . getRow ( ) . isEqualBody ( * _aIter ) )
* _aIter = new ORowSetValueVector ( nColumnCount ) ;
}
}
m_pCacheSet - > fillValueRow ( * _aIter + + , + + _nPos ) ;
_bCheck = m_pCacheSet - > next ( ) ;
}
return _bCheck ;
}
// -----------------------------------------------------------------------------