2000-09-18 23:16:46 +00:00
/*************************************************************************
*
2008-04-10 11:26:52 +00:00
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER .
2000-09-18 23:16:46 +00:00
*
2010-02-12 15:01:35 +01:00
* Copyright 2000 , 2010 Oracle and / or its affiliates .
2000-09-18 23:16:46 +00:00
*
2008-04-10 11:26:52 +00:00
* OpenOffice . org - a multi - platform office productivity suite
2000-09-18 23:16:46 +00:00
*
2008-04-10 11:26:52 +00:00
* This file is part of OpenOffice . org .
2000-09-18 23:16:46 +00:00
*
2008-04-10 11:26:52 +00:00
* OpenOffice . org is free software : you can redistribute it and / or modify
* it under the terms of the GNU Lesser General Public License version 3
* only , as published by the Free Software Foundation .
2000-09-18 23:16:46 +00:00
*
2008-04-10 11:26:52 +00:00
* OpenOffice . org 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 version 3 for more details
* ( a copy is included in the LICENSE file that accompanied this code ) .
2000-09-18 23:16:46 +00:00
*
2008-04-10 11:26:52 +00:00
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice . org . If not , see
* < http : //www.openoffice.org/license.html>
* for a copy of the LGPLv3 License .
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"
2010-09-22 11:08:30 +02:00
# include "BookmarkSet.hxx"
2000-09-18 23:16:46 +00:00
# include "CRowSetColumn.hxx"
2010-09-22 11:08:30 +02:00
# include "CRowSetDataColumn.hxx"
# include "KeySet.hxx"
# include "OptimisticSet.hxx"
2006-01-25 12:43:29 +00:00
# include "RowSetBase.hxx"
2010-09-22 11:08:30 +02:00
# include "RowSetCache.hxx"
# include "StaticSet.hxx"
# include "WrappedResultSet.hxx"
# include "core_resource.hrc"
# include "core_resource.hxx"
# include "dbastrings.hrc"
/** === begin UNO includes === **/
# include <com/sun/star/sdbc/ColumnValue.hpp>
# include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
# include <com/sun/star/sdbcx/CompareBookmark.hpp>
# include <com/sun/star/sdbcx/KeyType.hpp>
# include <com/sun/star/sdbcx/Privilege.hpp>
# include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
# include <com/sun/star/sdbcx/XKeysSupplier.hpp>
# include <com/sun/star/sdbcx/XTablesSupplier.hpp>
/** === end UNO includes === **/
# include <comphelper/extract.hxx>
# include <comphelper/property.hxx>
# include <comphelper/seqstream.hxx>
# include <comphelper/uno3.hxx>
2000-10-25 06:32:52 +00:00
# include <connectivity/dbexception.hxx>
2010-02-15 09:53:53 +01:00
# include <connectivity/dbtools.hxx>
2006-08-15 09:42:22 +00:00
# include <connectivity/sqliterator.hxx>
2010-09-22 11:08:30 +02:00
# include <connectivity/sqlnode.hxx>
# include <connectivity/sqlparse.hxx>
2005-09-23 11:03:25 +00:00
# include <tools/debug.hxx>
2010-09-22 11:08:30 +02:00
# include <tools/diagnose_ex.h>
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 ,
2007-11-21 14:33:03 +00:00
const : : comphelper : : ComponentContext & _rContext ,
2000-10-17 09:19:03 +00:00
const : : rtl : : OUString & _rUpdateTableName ,
sal_Bool & _bModified ,
CWS-TOOLING: integrate CWS dba32c
2009-06-29 20:53:25 +0200 fs r273484 : #i103138# Rectangle conversion
2009-06-29 20:51:50 +0200 fs r273483 : #i103138# yet more refactoring, now also setting the proper zoom level at the proper point in time
2009-06-29 13:40:26 +0200 fs r273470 : added svn:ignore to ignore output paths
2009-06-29 10:08:54 +0200 fs r273455 : #i103138#
refactored the code for positioning/zooming the control
Basically, we now allow adjustControlGeometry_throw (formerly known as positionControl_throw and setControlZoom) to
take an additional ViewTransformation parameter, describing the transformation to obtain the actual
control position/size. Consequently, positionControl itself also allows for a ViewTransformation parameter.
This has become necessary since during painting, the device which we created our control for might not necessarily
have a proper MapMode set. In this case, if we would use this map mode for calculating the control's position/size,
this would lead to wrong results.
Note that this problem was introduced by the fix for #i101398#: During the fix, we postponed the control creation
to a later time (when it is really needed). At this later time, the MapMode at the device is broken, at the earlier
time where we formerly crearted the control (createPrimitive2DSequence), it is not yet broken.
Whether or not the MapMode is defined as "broken" might depend on one's point of view, however ...
I consider it broken, since:
- we need the map mode to obtain the proper zoom level, which is to be forwarded to the control
- there are scenarios where the MapMode is *not* set to MAP_PIXEL (in those scenarios, everything works
fine), and there are scenarios where it *is* set to MAP_PIXEL (in those the bug 103138 appears).
It somehow feels wrong that one cannot rely on the device's map mode this way, but on the other hand
one has no possibility to obtain the current zoom by other means.
Note that one issue (still to be submitted) is left: In the page pane of a Draw/Impress document, controls
have a wrong text size. This is because in this pane, the above-mentioned "broken" map mode is used,
which means the controls have a zoom of "1:1" set, which is wrong here.
2009-06-25 13:41:35 +0200 msc r273380 : #100000# the tabs changed die to new properties
2009-06-24 12:42:40 +0200 msc r273330 : #102082# remove issue warning
2009-06-22 10:43:14 +0200 fs r273201 : createPrimitive2DSequence: care for being disposed
2009-06-18 12:35:13 +0200 oj r273109 : #i102305# make nooptfiles for gcc
2009-06-17 12:14:37 +0200 oj r273056 : #i102305# fix for linux
2009-06-17 07:20:22 +0200 oj r273046 : #i102305# move ValueTransfer into the for loop to avoid a crash under Linux
2009-06-17 07:17:28 +0200 oj r273045 : #i102305# use varchar
2009-06-15 14:11:27 +0200 fs r272983 : added since tag
2009-06-15 12:11:39 +0200 oj r272973 : #i102305# SAL_DLLPUBLIC_EXPORT inserted
2009-06-15 11:08:53 +0200 fs r272969 : #i10000#
2009-06-15 09:25:13 +0200 fs r272963 : merging fix for P1 issue #i102701#
2009-06-11 11:31:24 +0200 fs r272858 : #i10000# copied the fix which before the rebase was done in ../dialog/macropg.src
2009-06-11 09:38:14 +0200 fs r272846 : CWS-TOOLING: rebase CWS dba32c to trunk@272827 (milestone: DEV300:m50)
2009-06-02 09:53:10 +0200 fs r272483 : #i10000#
2009-05-29 15:55:03 +0200 fs r272465 : #i100818#
2009-05-29 12:58:43 +0200 fs r272452 : don't apply comphelper::getString on possibly VOID any
2009-05-29 10:38:35 +0200 oj r272437 : #i101519# handle where condition
2009-05-29 09:53:39 +0200 fs r272434 : #i100818# call into releaseStubs /without/ locked GlobalMutex
2009-05-28 07:53:44 +0200 oj r272375 : #i101369# parse tree changed
2009-05-27 14:53:36 +0200 fs r272347 : #i10000#
2009-05-27 09:29:15 +0200 oj r272327 : #i101626# check for double before hard cast
2009-05-27 09:13:58 +0200 oj r272326 : #i101626# handle void correctly
2009-05-27 08:04:39 +0200 oj r272321 : #i102256# wrong method signature used
2009-05-27 07:55:52 +0200 oj r272320 : #i101519# look up parameter typ if used in function
2009-05-27 06:49:07 +0200 oj r272319 : #i101519# set parameter from rowset as well
2009-05-26 13:30:56 +0200 oj r272297 : #i101987# impl XBatchExecution
2009-05-26 12:44:34 +0200 oj r272293 : #i101700# check if group is not set
2009-05-26 12:16:53 +0200 oj r272290 : #i101369# resolved some reduce7reduce problems with boolean_term and search_condition
2009-05-26 12:12:42 +0200 oj r272289 : #i101369# fix for or on one line criteria
2009-05-25 16:02:25 +0200 fs r272257 : #i999704# +PROPERTY_MOUSE_WHEEL_BEHAVIOR
2009-05-25 16:01:55 +0200 fs r272256 : merging the changes from CWS dba32b herein
2009-05-25 15:49:57 +0200 fs r272254 : #i999704#
2009-05-25 15:32:57 +0200 fs r272252 : #i99704# grid columns also to respect the MouseWheelBehavior property
2009-05-25 15:23:43 +0200 fs r272251 : don't pass empty Anys to ::comphelper::getString
2009-05-25 14:48:43 +0200 fs r272248 : merged changes from CWS dba32b herein
2009-05-25 14:44:40 +0200 fs r272247 : #i99704# support new MouseWheelBehavior property
2009-05-25 14:43:18 +0200 fs r272246 : #i99704# WheelWithoutFocus (peer property) superseded by MouseWheelBehavior (model property)
2009-05-25 14:41:03 +0200 fs r272245 : #i99704# no need to set the mouse wheel behavior at the peer, this is now a model property, having the right default
2009-05-25 14:39:31 +0200 fs r272243 : removed dead import
2009-05-25 14:35:36 +0200 fs r272242 : the new EnableVisible doesn't make sense for grid columns
2009-05-25 14:34:33 +0200 fs r272241 : #i99704# +MouseWheelBehavior - allow to enable/disable the mouse wheel for the control, or make it focus-dependent
2009-05-25 14:26:11 +0200 fs r272240 : #i99704# change MouseSettings wheel flag (NoWheelActionWithoutFocus) to a three-state option, allowing to completely ignore the mouse wheel
2009-05-23 21:35:59 +0200 fs r272213 : localize 'sub component opened/closed' event
2009-05-22 21:42:47 +0200 fs r272211 : #i102003#
2009-05-22 21:42:20 +0200 fs r272210 : grammar
2009-05-22 21:36:10 +0200 fs r272209 : #i102140# load only once, not twice, and show error messages during loading (and during any form action, that is) asynchronously
2009-05-22 21:35:11 +0200 fs r272208 : #i102140# +clear
2009-05-22 14:50:30 +0200 fs r272194 : #i102139# for newly created DB docs, set the MacroExecutionMode to USE_CONFIG
2009-05-22 12:03:42 +0200 fs r272180 : #i88878#
provided by noel.power@novell.com
implement a visibility property (EnableVisible) for toolkit controls, and usage in forms and UNO dialogs
2009-05-15 15:37:31 +0200 fs r271942 : #i100671# corrected some @since tags, so autodoc has better chances of correctly reading them
2009-05-15 15:33:11 +0200 fs r271940 : don't call comphelper::getFOO for VOID values
2009-05-15 15:08:31 +0200 fs r271937 : includes
2009-05-15 13:39:22 +0200 fs r271934 : #i101398# createPrimitive2DSequence: when we already have a control, use the old code. In particular, call positionControlForPaint
2009-05-15 12:33:48 +0200 fs r271933 : make the geometry a part of the ControlPrimitive2D's identity
2009-05-15 10:15:44 +0200 fs r271928 : #i10000#
2009-05-14 20:55:38 +0200 fs r271921 : #i101398# don't reuse the name PRIMITIVE_ID_CONTROLPRIMITIVE2D, make the name of our own ControlPrimitive2D unique
2009-05-14 20:55:31 +0200 fs r271920 : #i101398# don't reuse the name PRIMITIVE_ID_CONTROLPRIMITIVE2D, make the name of our own ControlPrimitive2D unique
2009-05-14 20:23:23 +0200 fs r271919 : #i101622#
2009-05-14 16:04:38 +0200 fs r271898 : don't use comphelper::getInt32 on voids
2009-05-14 16:04:12 +0200 fs r271897 : merge fix for issue whose number just slipped my memory ... (originally fixed in CWS dba32b)
2009-05-14 15:36:55 +0200 fs r271895 : merging changes from DEV300:m48
2009-05-07 14:43:19 +0200 fs r271670 : #i101477#
2009-05-07 14:37:30 +0200 fs r271668 : #i101477#
2009-05-07 09:27:30 +0200 oj r271628 : #i101343# remove pch
2009-05-06 09:36:02 +0200 fs r271568 : getFoo: diagnostics
2009-05-04 09:23:06 +0200 oj r271438 : CWS-TOOLING: rebase CWS dba32c to trunk@271427 (milestone: DEV300:m47)
2009-04-29 23:18:13 +0200 fs r271394 : #i101398# use a dedicated 2DPrimitive for UNO Controls, which is able to provide the B2DRange *without* actually creating the control
2009-04-29 13:52:25 +0200 fs r271366 : #i101308#
2009-07-03 14:21:50 +00:00
sal_Bool & _bNew ,
2010-01-19 09:16:12 +00:00
const ORowSetValueVector & _aParameterValueForCache ,
2010-11-24 14:23:06 +01:00
const : : rtl : : OUString & i_sRowSetFilter ,
sal_Int32 i_nMaxRows )
2006-06-20 01:36:29 +00:00
: m_xSet ( _xRs )
, m_xMetaData ( Reference < XResultSetMetaDataSupplier > ( _xRs , UNO_QUERY ) - > getMetaData ( ) )
2007-11-21 14:33:03 +00:00
, m_aContext ( _rContext )
2006-06-20 01:36:29 +00:00
, 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 ) ;
2010-02-15 09:53:53 +01:00
// first try if the result can be used to do inserts and updates
try
{
Reference < XResultSetUpdate > xUp ( _xRs , UNO_QUERY_THROW ) ;
2010-07-09 14:49:18 +02:00
Reference < XPropertySet > xProp ( _xRs , UNO_QUERY ) ;
Reference < XPropertySetInfo > xPropInfo = xProp - > getPropertySetInfo ( ) ;
sal_Bool bBookmarkable = xPropInfo - > hasPropertyByName ( PROPERTY_ISBOOKMARKABLE ) & &
any2bool ( xProp - > getPropertyValue ( PROPERTY_ISBOOKMARKABLE ) ) & & Reference < XRowLocate > ( _xRs , UNO_QUERY ) . is ( ) ;
if ( bBookmarkable )
{
xUp - > moveToInsertRow ( ) ;
xUp - > cancelRowUpdates ( ) ;
_xRs - > beforeFirst ( ) ;
m_nPrivileges = Privilege : : SELECT | Privilege : : DELETE | Privilege : : INSERT | Privilege : : UPDATE ;
2010-11-24 14:23:06 +01:00
m_pCacheSet = new WrappedResultSet ( i_nMaxRows ) ;
2010-07-09 14:49:18 +02:00
m_xCacheSet = m_pCacheSet ;
m_pCacheSet - > construct ( _xRs , i_sRowSetFilter ) ;
return ;
}
2010-02-15 09:53:53 +01:00
}
2010-07-06 15:20:20 +02:00
catch ( const Exception & ex )
2010-02-15 09:53:53 +01:00
{
2010-07-06 15:20:20 +02:00
( void ) ex ;
2010-02-15 09:53:53 +01:00
}
2010-06-01 08:19:45 +02:00
_xRs - > beforeFirst ( ) ;
2010-02-15 09:53:53 +01:00
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
2010-02-15 09:53:53 +01:00
Reference < XPropertySet > xProp ( _xRs , UNO_QUERY ) ;
Reference < XPropertySetInfo > xPropInfo = xProp - > getPropertySetInfo ( ) ;
sal_Bool bNeedKeySet = ! ( xPropInfo - > hasPropertyByName ( PROPERTY_ISBOOKMARKABLE ) & &
any2bool ( xProp - > getPropertyValue ( PROPERTY_ISBOOKMARKABLE ) ) & & Reference < XRowLocate > ( _xRs , UNO_QUERY ) . is ( ) ) ;
bNeedKeySet = bNeedKeySet | | ( xPropInfo - > hasPropertyByName ( PROPERTY_RESULTSETCONCURRENCY ) & &
: : comphelper : : getINT32 ( xProp - > getPropertyValue ( PROPERTY_RESULTSETCONCURRENCY ) ) = = ResultSetConcurrency : : READ_ONLY ) ;
2008-06-06 12:59:08 +00:00
Reference < XIndexAccess > xUpdateTableKeys ;
2001-02-01 13:23:57 +00:00
: : rtl : : OUString aUpdateTableName = _rUpdateTableName ;
Reference < XConnection > xConnection ;
2009-11-11 14:16:42 +01: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! " ) ;
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 ( ) ;
2010-02-15 09:53:53 +01:00
Sequence < : : rtl : : OUString > aTableNames = xTables - > getElementNames ( ) ;
if ( aTableNames . getLength ( ) > 1 & & ! _rUpdateTableName . getLength ( ) & & bNeedKeySet )
{ // here we have a join or union and nobody told us which table to update, so we update them all
m_nPrivileges = Privilege : : SELECT | Privilege : : DELETE | Privilege : : INSERT | Privilege : : UPDATE ;
2010-11-24 14:23:06 +01:00
OptimisticSet * pCursor = new OptimisticSet ( m_aContext , xConnection , _xAnalyzer , _aParameterValueForCache , i_nMaxRows ) ;
2010-02-15 09:53:53 +01:00
m_pCacheSet = pCursor ;
m_xCacheSet = m_pCacheSet ;
try
{
m_pCacheSet - > construct ( _xRs , i_sRowSetFilter ) ;
if ( pCursor - > isReadOnly ( ) )
m_nPrivileges = Privilege : : SELECT ;
m_aKeyColumns = pCursor - > getJoinedKeyColumns ( ) ;
return ;
}
catch ( const Exception & )
{
2010-10-18 12:38:57 +02:00
// DBG_UNHANDLED_EXCEPTION();
2010-02-15 09:53:53 +01:00
}
2010-09-22 11:08:30 +02:00
m_pCacheSet = NULL ;
m_xCacheSet . clear ( ) ;
2001-11-29 15:35:26 +00:00
}
else
2000-11-10 13:17:54 +00:00
{
2010-02-15 09:53:53 +01:00
if ( _rUpdateTableName . getLength ( ) & & xTables - > hasByName ( _rUpdateTableName ) )
xTables - > getByName ( _rUpdateTableName ) > > = m_aUpdateTable ;
else if ( xTables - > getElementNames ( ) . getLength ( ) )
2000-11-10 13:17:54 +00:00
{
2010-02-15 09:53:53 +01:00
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-11-10 13:17:54 +00:00
2010-02-15 09:53:53 +01:00
if ( m_aUpdateTable . is ( ) & & nTablesCount < 3 ) // for we can't handle more than 2 tables in our keyset
{
Reference < XPropertySet > xSet ( m_aUpdateTable , UNO_QUERY ) ;
const Reference < XNameAccess > xPrimaryKeyColumns = dbtools : : getPrimaryKeyColumns_throw ( xSet ) ;
if ( xPrimaryKeyColumns . is ( ) )
{
Reference < XColumnsSupplier > xColSup ( _xAnalyzer , UNO_QUERY ) ;
if ( xColSup . is ( ) )
2001-11-29 15:35:26 +00:00
{
2010-02-15 09:53:53 +01:00
Reference < XNameAccess > xSelColumns = xColSup - > getColumns ( ) ;
Reference < XDatabaseMetaData > xMeta = xConnection - > getMetaData ( ) ;
SelectColumnsMetaData aColumnNames ( xMeta . is ( ) & & xMeta - > supportsMixedCaseQuotedIdentifiers ( ) ? true : false ) ;
: : dbaccess : : getColumnPositions ( xSelColumns , xPrimaryKeyColumns - > getElementNames ( ) , aUpdateTableName , aColumnNames ) ;
bAllKeysFound = ! aColumnNames . empty ( ) & & sal_Int32 ( aColumnNames . size ( ) ) = = xPrimaryKeyColumns - > getElementNames ( ) . getLength ( ) ;
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
}
2001-11-29 15:35:26 +00:00
2000-09-18 23:16:46 +00:00
// first check if resultset is bookmarkable
2009-07-03 12:24:35 +00:00
if ( ! bNeedKeySet )
2000-09-18 23:16:46 +00:00
{
2009-07-03 12:24:35 +00:00
try
{
2010-11-24 14:23:06 +01:00
m_pCacheSet = new OBookmarkSet ( i_nMaxRows ) ;
2009-07-03 12:24:35 +00:00
m_xCacheSet = m_pCacheSet ;
2010-01-19 09:16:12 +00:00
m_pCacheSet - > construct ( _xRs , i_sRowSetFilter ) ;
2009-07-03 12:24:35 +00:00
// check privileges
m_nPrivileges = Privilege : : SELECT ;
if ( Reference < XResultSetUpdate > ( _xRs , UNO_QUERY ) . is ( ) ) // this interface is optional so we have to check it
{
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 ;
}
}
}
catch ( const SQLException & )
{
bNeedKeySet = sal_True ;
}
2000-09-18 23:16:46 +00:00
}
2009-07-03 12:24:35 +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)
2009-07-03 12:24:35 +00:00
if ( ! bAllKeysFound )
2000-09-18 23:16:46 +00:00
{
2010-11-24 14:23:06 +01:00
m_pCacheSet = new OStaticSet ( i_nMaxRows ) ;
2009-07-03 12:24:35 +00:00
m_xCacheSet = m_pCacheSet ;
2010-01-19 09:16:12 +00:00
m_pCacheSet - > construct ( _xRs , i_sRowSetFilter ) ;
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 ( ) ;
2009-11-11 14:16:42 +01:00
: : dbaccess : : getColumnPositions ( xSelColumns , xColumns - > getElementNames ( ) , aUpdateTableName , aColumnNames ) ;
2001-02-01 13:23:57 +00:00
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
{
2010-02-15 09:53:53 +01:00
Reference < XPropertySet > xColumn ( xColumns - > getByName ( * pIter ) , UNO_QUERY ) ;
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
}
}
}
2010-11-24 14:23:06 +01:00
OKeySet * pKeySet = new OKeySet ( m_aUpdateTable , xUpdateTableKeys , aUpdateTableName , _xAnalyzer , _aParameterValueForCache , i_nMaxRows ) ;
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 ;
2010-01-19 09:16:12 +00:00
pKeySet - > construct ( _xRs , i_sRowSetFilter ) ;
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 ;
2010-11-24 14:23:06 +01:00
m_pCacheSet = new OStaticSet ( i_nMaxRows ) ;
2004-03-02 11:41:52 +00:00
m_xCacheSet = m_pCacheSet ;
2010-01-19 09:16:12 +00:00
m_pCacheSet - > construct ( _xRs , i_sRowSetFilter ) ;
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
}
2009-07-03 12:24:35 +00:00
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
// -------------------------------------------------------------------------
2010-11-24 14:23:06 +01:00
void ORowSetCache : : setFetchSize ( sal_Int32 _nSize )
2000-09-18 23:16:46 +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 ( ) ;
2009-07-03 12:24:35 +00:00
ORowSetCacheMap : : iterator aCacheEnd = m_aCacheIterators . end ( ) ;
for ( ; aCacheIter ! = aCacheEnd ; + + aCacheIter )
2001-01-24 08:52:19 +00:00
{
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
2006-10-18 12:26:03 +00:00
if ( nKeyPos < _nSize )
m_aMatrixIter = m_pMatrix - > begin ( ) + nKeyPos ;
else
m_aMatrixIter = m_pMatrix - > end ( ) ;
2001-01-24 08:52:19 +00:00
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 ) ;
2006-10-18 12:26:03 +00:00
if ( * aIter < _nSize )
aCacheIter - > second . aIterator = m_pMatrix - > begin ( ) + * aIter + + ;
else
aCacheIter - > second . aIterator = m_pMatrix - > end ( ) ;
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 ;
}
// -------------------------------------------------------------------------
2010-02-15 09:53:53 +01:00
Any lcl_getBookmark ( ORowSetValue & i_aValue , OCacheSet * i_pCacheSet )
{
switch ( i_aValue . getTypeKind ( ) )
{
case DataType : : TINYINT :
case DataType : : SMALLINT :
case DataType : : INTEGER :
return makeAny ( ( sal_Int32 ) i_aValue ) ;
default :
if ( i_pCacheSet & & i_aValue . isNull ( ) )
i_aValue = i_pCacheSet - > getBookmark ( ) ;
return i_aValue . getAny ( ) ;
}
}
// -------------------------------------------------------------------------
2000-09-18 23:16:46 +00:00
// ::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
2010-02-15 09:53:53 +01:00
return lcl_getBookmark ( ( ( * m_aMatrixIter ) - > get ( ) ) [ 0 ] , m_pCacheSet ) ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
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
{
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
{
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
// -----------------------------------------------------------------------------
2010-02-15 09:53:53 +01:00
void ORowSetCache : : updateNull ( sal_Int32 columnIndex , ORowSetValueVector : : Vector & io_aRow
, : : std : : vector < sal_Int32 > & o_ChangedColumns
)
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
2010-02-15 09:53:53 +01:00
ORowSetValueVector : : Vector & rInsert = ( ( * m_aInsertRow ) - > get ( ) ) ;
rInsert [ columnIndex ] . setBound ( sal_True ) ;
rInsert [ columnIndex ] . setNull ( ) ;
rInsert [ columnIndex ] . setModified ( ) ;
io_aRow [ columnIndex ] . setNull ( ) ;
2006-02-06 15:54:31 +00:00
2010-02-15 09:53:53 +01:00
m_pCacheSet - > mergeColumnValues ( columnIndex , rInsert , io_aRow , o_ChangedColumns ) ;
impl_updateRowFromCache_throw ( io_aRow , o_ChangedColumns ) ;
2000-09-18 23:16:46 +00:00
}
2010-02-15 09:53:53 +01:00
// -----------------------------------------------------------------------------
void ORowSetCache : : updateValue ( sal_Int32 columnIndex , const ORowSetValue & x
, ORowSetValueVector : : Vector & io_aRow
, : : std : : vector < sal_Int32 > & o_ChangedColumns
)
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
2010-02-15 09:53:53 +01:00
ORowSetValueVector : : Vector & rInsert = ( ( * m_aInsertRow ) - > get ( ) ) ;
rInsert [ columnIndex ] . setBound ( sal_True ) ;
rInsert [ columnIndex ] = x ;
rInsert [ columnIndex ] . setModified ( ) ;
io_aRow [ columnIndex ] = rInsert [ columnIndex ] ;
2006-02-06 15:54:31 +00:00
2010-02-15 09:53:53 +01:00
m_pCacheSet - > mergeColumnValues ( columnIndex , rInsert , io_aRow , o_ChangedColumns ) ;
impl_updateRowFromCache_throw ( io_aRow , o_ChangedColumns ) ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2010-02-15 09:53:53 +01:00
void ORowSetCache : : updateCharacterStream ( sal_Int32 columnIndex , const Reference < : : com : : sun : : star : : io : : XInputStream > & x
, sal_Int32 length , ORowSetValueVector : : Vector & io_aRow
, : : std : : vector < sal_Int32 > & o_ChangedColumns
)
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
Sequence < sal_Int8 > aSeq ;
if ( x . is ( ) )
2008-12-01 12:31:27 +00:00
x - > readBytes ( aSeq , length ) ;
2001-04-02 10:14:53 +00:00
2010-02-15 09:53:53 +01:00
ORowSetValueVector : : Vector & rInsert = ( ( * m_aInsertRow ) - > get ( ) ) ;
rInsert [ columnIndex ] . setBound ( sal_True ) ;
rInsert [ columnIndex ] = aSeq ;
rInsert [ columnIndex ] . setModified ( ) ;
io_aRow [ columnIndex ] = makeAny ( x ) ;
m_pCacheSet - > mergeColumnValues ( columnIndex , rInsert , io_aRow , o_ChangedColumns ) ;
impl_updateRowFromCache_throw ( io_aRow , o_ChangedColumns ) ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2010-02-15 09:53:53 +01:00
void ORowSetCache : : updateObject ( sal_Int32 columnIndex , const Any & x
, ORowSetValueVector : : Vector & io_aRow
, : : std : : vector < sal_Int32 > & o_ChangedColumns
)
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
2010-02-15 09:53:53 +01:00
ORowSetValueVector : : Vector & rInsert = ( ( * m_aInsertRow ) - > get ( ) ) ;
rInsert [ columnIndex ] . setBound ( sal_True ) ;
rInsert [ columnIndex ] = x ;
rInsert [ columnIndex ] . setModified ( ) ;
io_aRow [ columnIndex ] = rInsert [ columnIndex ] ;
2006-02-06 15:54:31 +00:00
2010-02-15 09:53:53 +01:00
m_pCacheSet - > mergeColumnValues ( columnIndex , rInsert , io_aRow , o_ChangedColumns ) ;
impl_updateRowFromCache_throw ( io_aRow , o_ChangedColumns ) ;
2000-09-18 23:16:46 +00:00
}
// -------------------------------------------------------------------------
2010-02-15 09:53:53 +01:00
void ORowSetCache : : updateNumericObject ( sal_Int32 columnIndex , const Any & x , sal_Int32 /*scale*/
, ORowSetValueVector : : Vector & io_aRow
, : : std : : vector < sal_Int32 > & o_ChangedColumns
)
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
2010-02-15 09:53:53 +01:00
ORowSetValueVector : : Vector & rInsert = ( ( * m_aInsertRow ) - > get ( ) ) ;
rInsert [ columnIndex ] . setBound ( sal_True ) ;
rInsert [ columnIndex ] = x ;
rInsert [ columnIndex ] . setModified ( ) ;
io_aRow [ columnIndex ] = rInsert [ columnIndex ] ;
2006-02-06 15:54:31 +00:00
2010-02-15 09:53:53 +01:00
m_pCacheSet - > mergeColumnValues ( columnIndex , rInsert , io_aRow , o_ChangedColumns ) ;
impl_updateRowFromCache_throw ( io_aRow , o_ChangedColumns ) ;
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
{
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 ( ) )
2009-07-03 12:24:35 +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 ;
2009-07-03 12:24:35 +00:00
ORowSetMatrix : : iterator aRealEnd = m_pMatrix - > end ( ) ;
2001-01-24 08:52:19 +00:00
sal_Int32 nPos = m_nRowCount - m_nFetchSize + 1 ;
_nNewStartPos = nPos ;
bCheck = m_pCacheSet - > absolute ( _nNewStartPos ) ;
2009-07-03 12:24:35 +00:00
for ( ; bCheck & & aIter ! = aRealEnd ; + + aIter )
2000-09-18 23:16:46 +00:00
{
2001-01-24 08:52:19 +00:00
if ( bCheck )
{
if ( ! aIter - > isValid ( ) )
2009-07-03 12:24:35 +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 )
2009-07-03 12:24:35 +00:00
: : std : : rotate ( m_pMatrix - > begin ( ) , aEnd , aRealEnd ) ;
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 ( ) ;
2009-07-03 12:24:35 +00:00
ORowSetCacheMap : : iterator aCacheEnd = m_aCacheIterators . end ( ) ;
for ( ; aCacheIter ! = aCacheEnd ; + + aCacheIter )
2001-01-24 08:52:19 +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-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 ) ;
2009-11-27 10:17:16 +01:00
// we have to read one row forward to ensure that we know when we are on last row
2000-11-07 12:19:27 +00:00
// 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
2010-02-15 09:53:53 +01:00
sal_Bool ORowSetCache : : insertRow ( : : std : : vector < Any > & o_aBookmarks )
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 ;
2008-12-30 13:32:01 +00:00
Any aBookmark = ( ( * m_aInsertRow ) - > get ( ) ) [ 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 ( ) )
2010-02-15 09:53:53 +01:00
{
2001-01-22 06:38:24 +00:00
moveToBookmark ( aBookmark ) ;
2010-02-15 09:53:53 +01:00
// update the cached values
ORowSetValueVector : : Vector & rCurrentRow = ( ( * m_aMatrixIter ) ) - > get ( ) ;
ORowSetMatrix : : iterator aIter = m_pMatrix - > begin ( ) ;
for ( ; aIter ! = m_pMatrix - > end ( ) ; + + aIter )
{
if ( m_aMatrixIter ! = aIter & & aIter - > isValid ( ) & & m_pCacheSet - > columnValuesUpdated ( ( * aIter ) - > get ( ) , rCurrentRow ) )
{
o_aBookmarks . push_back ( lcl_getBookmark ( ( * aIter ) - > get ( ) [ 0 ] , m_pCacheSet ) ) ;
}
}
}
2001-01-22 06:38:24 +00:00
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
}
// -------------------------------------------------------------------------
2010-02-15 09:53:53 +01:00
void ORowSetCache : : updateRow ( ORowSetMatrix : : iterator & _rUpdateRow , : : std : : vector < Any > & o_aBookmarks )
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
2008-12-30 13:32:01 +00:00
Any aBookmark = ( ( * _rUpdateRow ) - > get ( ) ) [ 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
// refetch the whole row
( * m_aMatrixIter ) = NULL ;
2009-11-27 10:17:16 +01:00
2010-02-15 09:53:53 +01:00
if ( moveToBookmark ( aBookmark ) )
{
// update the cached values
ORowSetValueVector : : Vector & rCurrentRow = ( ( * m_aMatrixIter ) ) - > get ( ) ;
ORowSetMatrix : : iterator aIter = m_pMatrix - > begin ( ) ;
for ( ; aIter ! = m_pMatrix - > end ( ) ; + + aIter )
{
if ( m_aMatrixIter ! = aIter & & aIter - > isValid ( ) & & m_pCacheSet - > columnValuesUpdated ( ( * aIter ) - > get ( ) , rCurrentRow ) )
{
o_aBookmarks . push_back ( lcl_getBookmark ( ( * aIter ) - > get ( ) [ 0 ] , m_pCacheSet ) ) ;
}
}
}
2001-05-11 05:14:11 +00:00
2000-09-18 23:16:46 +00:00
m_bModified = sal_False ;
}
// -------------------------------------------------------------------------
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 ;
2000-12-06 08:55:44 +00:00
2009-07-03 12:24:35 +00:00
ORowSetMatrix : : iterator aEnd = m_pMatrix - > end ( ) ;
for ( + + aPos ; aPos ! = aEnd & & aPos - > isValid ( ) ; + + aPos )
2006-01-25 14:10:43 +00:00
{
* ( 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
2008-12-30 13:32:01 +00:00
ORowSetValueVector : : Vector : : iterator aIter = ( * m_aInsertRow ) - > get ( ) . begin ( ) + 1 ;
2009-07-03 12:24:35 +00:00
ORowSetValueVector : : Vector : : iterator aEnd = ( * m_aInsertRow ) - > get ( ) . end ( ) ;
2009-11-13 13:30:51 +01:00
for ( sal_Int32 i = 1 ; aIter ! = aEnd ; + + aIter , + + i )
2000-09-29 14:23:36 +00:00
{
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 ( ) ;
2009-11-13 13:30:51 +01:00
aIter - > setTypeKind ( m_xMetaData - > getColumnType ( i ) ) ;
2000-09-29 14:23:36 +00:00
}
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
}
// -----------------------------------------------------------------------------
CWS-TOOLING: integrate CWS dba32e
2009-08-10 13:16:25 +0200 fs r274805 : #i84390# typo corrected
2009-08-10 13:04:28 +0200 fs r274804 : #i103741# properly terminate the last token in a string with a 0 byte
2009-07-24 08:54:05 +0200 msc r274286 : #103219# changed long name
2009-07-24 08:42:28 +0200 msc r274285 : #i79649# changed behaviour of the wizard
2009-07-22 14:17:49 +0200 oj r274238 : GrabFocus
2009-07-22 13:38:01 +0200 oj r274232 : #i102934# mixed up
2009-07-22 13:37:16 +0200 oj r274231 : #i102934# mixed up
2009-07-21 12:30:36 +0200 oj r274176 : crash when using distinct
2009-07-21 10:03:44 +0200 oj r274163 : set last char to 0
2009-07-21 09:31:22 +0200 oj r274161 : mediatype corrected
2009-07-20 11:45:33 +0200 fs r274118 : typo in formatting string
2009-07-20 11:40:39 +0200 fs r274117 : removed unused include
2009-07-20 11:40:01 +0200 fs r274116 : class name corrected
2009-07-16 13:41:45 +0200 oj r274046 : i101587 wrong check for embeddeddatabase url in confguration, have to check path
2009-07-16 13:12:05 +0200 tbo r274044 : #i103219# adjust declarion to new hid.lst
2009-07-16 12:43:48 +0200 oj r274041 : #i102497# check also fot longvarchar
2009-07-16 12:15:41 +0200 oj r274039 : #i103030# handle type description and exceptions as well
2009-07-16 11:14:26 +0200 fs r274035 : let SVN ignore output paths
2009-07-16 09:23:43 +0200 fs r274030 : TransforFormComponentProperties: no need to check for attribute equality
2009-07-10 14:16:23 +0200 oj r273892 : CWS-TOOLING: rebase CWS dba32e to trunk@273858 (milestone: DEV300:m52)
2009-07-01 21:41:50 +0200 fs r273614 : #i10000#
2009-07-01 15:01:10 +0200 fs r273589 : Input required doesn't make sense at all in XML form documents
2009-07-01 12:10:31 +0200 fs r273562 : updated
2009-07-01 11:46:12 +0200 fs r273560 : #i103219# add about 100 missing long names
2009-07-01 10:11:41 +0200 fs r273551 : moved from socket/port usage to pipe/name usage, which is more common nowadays
2009-07-01 09:50:03 +0200 fs r273549 : removed obsolete (empty) folder
2009-07-01 09:47:35 +0200 fs r273548 : copied the code for the Accessibility Workbench herein, formerly located in the old CVS repository, at gsl/awb
2009-06-30 10:07:47 +0200 fs r273493 : merging latest changes from CWS dba32d
2009-06-29 20:46:31 +0200 fs r273482 : #i103138# Rectangle conversions
2009-06-29 10:01:13 +0200 fs r273453 : #i103138#
refactored the code for positioning/zooming the control
Basically, we now allow adjustControlGeometry_throw (formerly known as positionControl_throw and setControlZoom) to
take an additional ViewTransformation parameter, describing the transformation to obtain the actual
control position/size. Consequently, positionControl itself also allows for a ViewTransformation parameter.
This has become necessary since during painting, the device which we created our control for might not necessarily
have a proper MapMode set. In this case, if we would use this map mode for calculating the control's position/size,
this would lead to wrong results.
Note that this problem was introduced by the fix for #i101398#: During the fix, we postponed the control creation
to a later time (when it is really needed). At this later time, the MapMode at the device is broken, at the earlier
time where we formerly crearted the control (createPrimitive2DSequence), it is not yet broken.
Whether or not the MapMode is defined as "broken" might depend on one's point of view, however ...
I consider it broken, since:
- we need the map mode to obtain the proper zoom level, which is to be forwarded to the control
- there are scenarios where the MapMode is *not* set to MAP_PIXEL (in those scenarios, everything works
fine), and there are scenarios where it *is* set to MAP_PIXEL (in those the bug 103138 appears).
It somehow feels wrong that one cannot rely on the device's map mode this way, but on the other hand
one has no possibility to obtain the current zoom by other means.
Note that one issue (still to be submitted) is left: In the page pane of a Draw/Impress document, controls
have a wrong text size. This is because in this pane, the above-mentioned "broken" map mode is used,
which means the controls have a zoom of "1:1" set, which is wrong here.
2009-06-29 09:52:13 +0200 fs r273452 : during #i103138#: belongsToDevice is unused nowadays
2009-06-24 12:40:06 +0200 fs r273329 : #i102888# #i102899#
2009-06-24 12:10:29 +0200 oj r273327 : #i103030# some code changes
2009-06-24 09:44:14 +0200 oj r273311 : #i103030# some code changes
2009-06-24 09:24:42 +0200 oj r273309 : #i103030# add log
2009-06-24 09:03:29 +0200 fs r273308 : if a col's table name is schema.table, properly quote all parts
2009-06-24 08:56:06 +0200 oj r273307 : #i102691# changed string
2009-06-23 13:31:43 +0200 oj r273280 : #i102479# fix date, time and datetime
2009-06-23 12:51:28 +0200 oj r273277 : #i103020# clear old expression when updating to avoid dead pointers in treelist userdata
2009-06-23 12:17:16 +0200 oj r273275 : #i103030# add LogBridge
2009-06-23 11:53:10 +0200 oj r273272 : shawdowed var resolved
2009-06-23 11:48:49 +0200 oj r273270 : #i103030# add :log to uno env if var UNO_ENV_LOG is set
2009-06-23 11:47:47 +0200 oj r273269 : #i103030# add LogBridge
2009-06-23 11:47:11 +0200 oj r273268 : #i103030# add LogBridge
2009-06-23 08:05:08 +0200 oj r273253 : #i102934# add key for collapsing
2009-06-22 13:21:33 +0200 fs r273225 : merging latest changes from CWS dba32d
2009-06-22 13:15:22 +0200 fs r273221 : why restrict to 12 entries?
2009-06-22 08:12:21 +0200 oj r273196 : #i102655# choosen > chosen typo fixed
2009-06-22 08:08:04 +0200 oj r273195 : #i102657# typo fix
2009-06-22 08:06:28 +0200 oj r273194 : #i102934# expanding and collasping of section
2009-06-22 08:05:52 +0200 oj r273193 : #i102930# set focus in treelistbox
2009-06-22 08:04:56 +0200 oj r273192 : #i102929# enable tabstop
2009-06-19 13:18:26 +0200 oj r273157 : remove unused param
2009-06-19 10:07:05 +0200 oj r273149 : CWS-TOOLING: rebase CWS dba32e to trunk@272827 (milestone: DEV300:m50)
2009-06-19 07:32:40 +0200 oj r273146 : merge from dba32d to dba32e
2009-06-19 07:22:56 +0200 oj r273145 : merge from dba32d to dba32e
2009-06-19 07:22:33 +0200 oj r273144 : merge from dba32d to dba32e
2009-06-18 14:09:34 +0200 fs r273116 : merging the latest changes from CWS dba32d (up to revision 273108) herein, which effectively is a rebase to DEV300.m50
2009-06-18 08:50:35 +0200 oj r273098 : #i102894# fix for new line in text
2009-06-18 08:28:48 +0200 oj r273097 : #i102892# check any
2009-06-18 08:21:34 +0200 oj r273096 : check if error is valid
2009-06-16 13:49:28 +0200 fs r273019 : why make a drop down control by default? The form control factory in SVX does this better those days ...
2009-06-10 09:53:20 +0200 oj r272797 : add lic text
2009-06-10 09:48:55 +0200 oj r272796 : test added for i101618
2009-06-09 14:57:39 +0200 oj r272771 : #i101618# access database document only when script container is needed
2009-06-09 12:42:25 +0200 oj r272765 : #i102497# check type property
2009-06-09 12:32:49 +0200 oj r272764 : adjust test cases
2009-06-09 12:31:58 +0200 oj r272763 : adjust test cases
2009-06-09 12:31:22 +0200 oj r272762 : adjust test cases
2009-06-09 11:35:42 +0200 oj r272761 : check if error is valid
2009-06-09 11:29:42 +0200 oj r272760 : #i102497# longvarchar was missing
2009-06-08 14:52:49 +0200 fs r272733 : #i102564# when setting a new field, also set m_nFieldType
2009-06-08 13:51:20 +0200 oj r272730 : add tests
2009-06-05 14:38:01 +0200 oj r272686 : add dep
2009-06-05 14:35:00 +0200 oj r272684 : add new tests
2009-06-05 13:41:18 +0200 oj r272681 : code clean ups
2009-06-05 12:40:51 +0200 oj r272678 : code cleanup
2009-06-05 12:02:57 +0200 oj r272677 : code cleanup
2009-06-05 10:42:38 +0200 oj r272670 : #i49320# impl export of single rows and as RTF and HTML
2009-06-03 14:30:37 +0200 oj r272576 : #i79649# check if file matches filter wildcard
2009-06-03 13:41:57 +0200 oj r272560 : #i102470# impl not b like 'c'
2009-08-26 10:09:17 +00:00
void ORowSetCache : : deleteIterator ( const ORowSetBase * _pRowSet )
{
ORowSetCacheMap : : iterator aCacheIter = m_aCacheIterators . begin ( ) ;
for ( ; aCacheIter ! = m_aCacheIterators . end ( ) ; )
{
if ( aCacheIter - > second . pRowSet = = _pRowSet )
{
m_aCacheIterators . erase ( aCacheIter ) ;
aCacheIter = m_aCacheIterators . begin ( ) ;
} // if ( aCacheIter->second.pRowSet == _pRowSet )
else
+ + aCacheIter ;
}
}
// -----------------------------------------------------------------------------
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 ( ) ;
2009-07-03 12:24:35 +00:00
ORowSetCacheMap : : iterator aCacheEnd = m_aCacheIterators . end ( ) ;
for ( ; aCacheIter ! = aCacheEnd ; + + 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
}
}
}
}
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
2008-12-30 13:32:01 +00:00
ORowSetValueVector : : Vector : : iterator aIter = ( * m_aInsertRow ) - > get ( ) . begin ( ) ;
2009-07-03 12:24:35 +00:00
ORowSetValueVector : : Vector : : iterator aEnd = ( * m_aInsertRow ) - > get ( ) . end ( ) ;
for ( ; aIter ! = aEnd ; + + aIter )
2001-01-22 06:38:24 +00:00
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 )
{
2008-12-30 13:32:01 +00:00
if ( m_bAfterLast | | columnIndex > = ( sal_Int32 ) ( * m_aInsertRow ) - > get ( ) . size ( ) )
2001-06-26 09:30:55 +00:00
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
2006-10-12 12:32:14 +00:00
if ( SQL_ISTOKEN ( pNode - > getChild ( 1 ) , AND ) )
bOk = checkInnerJoin ( pNode - > getChild ( 0 ) , _xConnection , _sUpdateTableName )
& & checkInnerJoin ( pNode - > getChild ( 2 ) , _xConnection , _sUpdateTableName ) ;
2006-08-15 09:42:22 +00:00
}
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 ;
2006-12-13 15:44:26 +00:00
OSQLParseTreeIterator : : getColumnRange ( pNode - > getChild ( 0 ) , _xConnection , sColumnName , sTableRange ) ;
2006-10-12 12:32:14 +00:00
bOk = sTableRange = = _sUpdateTableName ;
if ( ! bOk )
2006-08-15 09:42:22 +00:00
{
2006-12-13 15:44:26 +00:00
OSQLParseTreeIterator : : getColumnRange ( pNode - > getChild ( 2 ) , _xConnection , sColumnName , sTableRange ) ;
2006-08-15 09:42:22 +00:00
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 ;
2007-11-21 14:33:03 +00:00
: : connectivity : : OSQLParser aSqlParser ( m_aContext . getLegacyServiceFactory ( ) ) ;
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
2008-06-16 11:30:34 +00:00
const OSQLParseNode * pTableRef = pJoin - > getByRule ( : : connectivity : : OSQLParseNode : : qualified_join ) ;
2001-07-19 08:29:22 +00:00
if ( bLeftSide )
pTableRef = pJoin - > getChild ( 0 ) ;
else
pTableRef = pJoin - > getChild ( 3 ) ;
OSL_ENSURE ( SQL_ISRULE ( pTableRef , table_ref ) , " Must be a tableref here! " ) ;
2008-06-16 11:30:34 +00:00
: : rtl : : OUString sTableRange = OSQLParseNode : : getTableRange ( pTableRef ) ;
2001-07-19 08:29:22 +00:00
if ( ! sTableRange . getLength ( ) )
2006-12-13 15:44:26 +00:00
pTableRef - > getChild ( 0 ) - > parseNodeToStr ( sTableRange , _xConnection , NULL , sal_False , sal_False ) ;
2001-07-19 08:29:22 +00:00
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
{
2008-12-30 13:32:01 +00:00
ORowSetValueVector : : Vector : : iterator aIter = ( * m_aInsertRow ) - > get ( ) . begin ( ) + 1 ;
ORowSetValueVector : : Vector : : iterator aEnd = ( * m_aInsertRow ) - > get ( ) . end ( ) ;
2006-01-25 12:43:29 +00:00
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 )
{
2009-07-03 12:24:35 +00:00
TOldRowSetRows : : iterator aOldRowEnd = m_aOldRows . end ( ) ;
for ( TOldRowSetRows : : iterator aOldRowIter = m_aOldRows . begin ( ) ; aOldRowIter ! = aOldRowEnd ; + + aOldRowIter )
2003-03-19 16:57:12 +00:00
{
if ( aOldRowIter - > getBodyPtr ( ) = = _rRow . getBodyPtr ( ) )
{
m_aOldRows . erase ( aOldRowIter ) ;
break ;
}
}
}
// -----------------------------------------------------------------------------
sal_Bool ORowSetCache : : reFillMatrix ( sal_Int32 _nNewStartPos , sal_Int32 _nNewEndPos )
{
2009-07-03 12:24:35 +00:00
TOldRowSetRows : : iterator aOldRowEnd = m_aOldRows . end ( ) ;
for ( TOldRowSetRows : : iterator aOldRowIter = m_aOldRows . begin ( ) ; aOldRowIter ! = aOldRowEnd ; + + aOldRowIter )
2003-03-19 16:57:12 +00:00
{
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
{
2009-07-03 12:24:35 +00:00
TOldRowSetRows : : iterator aOldRowEnd = m_aOldRows . end ( ) ;
for ( TOldRowSetRows : : iterator aOldRowIter = m_aOldRows . begin ( ) ; aOldRowIter ! = aOldRowEnd ; + + aOldRowIter )
2003-03-19 16:57:12 +00:00
{
if ( aOldRowIter - > getBody ( ) . getRow ( ) . isEqualBody ( * _aIter ) )
* _aIter = new ORowSetValueVector ( nColumnCount ) ;
}
}
m_pCacheSet - > fillValueRow ( * _aIter + + , + + _nPos ) ;
_bCheck = m_pCacheSet - > next ( ) ;
}
return _bCheck ;
}
// -----------------------------------------------------------------------------
2010-02-15 09:53:53 +01:00
bool ORowSetCache : : isResultSetChanged ( ) const
{
return m_pCacheSet - > isResultSetChanged ( ) ;
}
// -----------------------------------------------------------------------------
void ORowSetCache : : reset ( const Reference < XResultSet > & _xDriverSet )
{
m_xMetaData . set ( Reference < XResultSetMetaDataSupplier > ( _xDriverSet , UNO_QUERY ) - > getMetaData ( ) ) ;
m_pCacheSet - > reset ( _xDriverSet ) ;
2008-06-24 15:44:35 +00:00
2010-02-15 09:53:53 +01:00
m_bRowCountFinal = sal_False ;
m_nRowCount = 0 ;
reFillMatrix ( m_nStartPos + 1 , m_nEndPos + 1 ) ;
}
// -----------------------------------------------------------------------------
void ORowSetCache : : impl_updateRowFromCache_throw ( ORowSetValueVector : : Vector & io_aRow
, : : std : : vector < sal_Int32 > & o_ChangedColumns )
{
if ( o_ChangedColumns . size ( ) > 1 )
{
ORowSetMatrix : : iterator aIter = m_pMatrix - > begin ( ) ;
for ( ; aIter ! = m_pMatrix - > end ( ) ; + + aIter )
{
if ( aIter - > isValid ( ) & & m_pCacheSet - > updateColumnValues ( ( * aIter ) - > get ( ) , io_aRow , o_ChangedColumns ) )
{
break ;
}
}
2008-06-24 15:44:35 +00:00
2010-02-15 09:53:53 +01:00
if ( aIter = = m_pMatrix - > end ( ) )
{
m_pCacheSet - > fillMissingValues ( io_aRow ) ;
}
}
}
// -----------------------------------------------------------------------------