org.tentackle.appworx
Class AppDbCursor<T extends AppDbObject>

java.lang.Object
  extended by org.tentackle.db.SimpleDbCursor<T>
      extended by org.tentackle.appworx.AppDbCursor<T>
Type Parameters:
T - the data object class
All Implemented Interfaces:
DbCursor<T>

public class AppDbCursor<T extends AppDbObject>
extends SimpleDbCursor<T>

Extends SimpleDbCursor for AppDbObjects. Furthermore, adds warning thresholds, fetchsize, sleep intervals (be nice to other users) and a progress dialog if many rows are retrieved.

Author:
harald

Field Summary
protected  boolean abortRequested
          user requested to abort the loading of data
protected  ContextDb contextDb
          database context
protected  int estimatedRowCount
          expected number of rows retrieved, 0 = unknown (default)
protected  int maxRowCount
          != 0 if ask user can't receive more objects
protected  int updateFetchCount
          for fetch() only: number of rows fetched since progress shown
protected  int updateRowCount
          if != 0: show user progress in this intervals
protected  int warnRowCount
          != 0 if ask user if more objects retrieved
protected  long warnSleep
          time [ms] to sleep between warnRowCount packets, 0 = no sleep (default)
 
Fields inherited from class org.tentackle.db.SimpleDbCursor
db, dbClass, object, rc, rcName, row, rows, rs, withLinkedObjects
 
Constructor Summary
AppDbCursor(ContextDb contextDb, Class<T> dbClass, ResultSetWrapper rs)
          Creates a cursor for a local connection.
AppDbCursor(ContextDb contextDb, Class<T> dbClass, ResultSetWrapper rs, boolean withLinkedObjects)
          Creates a cursor for a local connection.
AppDbCursor(ContextDb contextDb, RemoteDbCursor rc)
          Creates a cursor for a remote connection.
AppDbCursor(QbfParameter par, RemoteDbCursor rc)
          Creates a cursor for a remote connection.
 
Method Summary
 void applyQbfParameter(QbfParameter par)
          Applies the qbf parameter to a local cursor.
 void applyQbfParameterLocalOnly(QbfParameter par)
          Applies local settings of the qbf parameter to a remote cursor.
 List<T> fetch()
          Fetches the next objects up to the fetchsize.
 int getEstimatedRowCount()
          Gets the expected query count.
 int getMaxRowCount()
          Gets the maximum number of rows to retrieve.
 int getWarnRowCount()
          Gets the current warning row count.
 long getWarnSleep()
          Gets the sleep interval.
 boolean isAbortRequested()
          Gets the abort flag.
 boolean next()
          Moves the cursor to the next row.
 void setAbortRequested(boolean abortRequested)
          Sets the abort requestion flag.
 void setDbContext(T object)
          Sets the db-context for objects retrieved from the remote cursor.
 void setEstimatedRowCount(int estimatedRowCount)
          Sets the expected query count.
 void setMaxRowCount(int maxRowCount)
          Sets the maximum number of rows to retrieve.
 void setWarnRowCount(int warnRowCount)
          Sets the threshold for the number of rows to warn the user in an infodialog and ask him whether more rows should really be retrieved.
 void setWarnSleep(long warnSleep)
          Sets the sleep interval between two warnRowCount packets retrieved.
 
Methods inherited from class org.tentackle.db.SimpleDbCursor
afterLast, beforeFirst, close, deleteObject, deleteObjectAt, finalize, first, getDbClass, getFetchDirection, getFetchSize, getObject, getObjectAt, getRow, getRowCount, isAfterLast, isBeforeFirst, isOpen, isRemote, last, newObject, previous, setFetchDirection, setFetchSize, setRow, toList, toListAndClose, toString, updateDbContext, updateObject, updateObjectAt, updateObjectOnly
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

contextDb

protected ContextDb contextDb
database context


warnRowCount

protected int warnRowCount
!= 0 if ask user if more objects retrieved


maxRowCount

protected int maxRowCount
!= 0 if ask user can't receive more objects


updateRowCount

protected int updateRowCount
if != 0: show user progress in this intervals


updateFetchCount

protected int updateFetchCount
for fetch() only: number of rows fetched since progress shown


warnSleep

protected long warnSleep
time [ms] to sleep between warnRowCount packets, 0 = no sleep (default)


abortRequested

protected boolean abortRequested
user requested to abort the loading of data


estimatedRowCount

protected int estimatedRowCount
expected number of rows retrieved, 0 = unknown (default)

Constructor Detail

AppDbCursor

public AppDbCursor(ContextDb contextDb,
                   Class<T> dbClass,
                   ResultSetWrapper rs,
                   boolean withLinkedObjects)
Creates a cursor for a local connection.

Parameters:
contextDb - the db connection
dbClass - the DbObject class
rs - the resultset
withLinkedObjects - true if load linked objects, false otherwise

AppDbCursor

public AppDbCursor(ContextDb contextDb,
                   Class<T> dbClass,
                   ResultSetWrapper rs)
Creates a cursor for a local connection.

Parameters:
contextDb - the db connection
dbClass - the DbObject class
rs - the resultset

AppDbCursor

public AppDbCursor(ContextDb contextDb,
                   RemoteDbCursor rc)
Creates a cursor for a remote connection.

Parameters:
contextDb - the db connection
rc - the remote cursor

AppDbCursor

public AppDbCursor(QbfParameter par,
                   RemoteDbCursor rc)
Creates a cursor for a remote connection.

Parameters:
par - the qbf parameter
rc - the remote cursor
Method Detail

applyQbfParameterLocalOnly

public void applyQbfParameterLocalOnly(QbfParameter par)
Applies local settings of the qbf parameter to a remote cursor. This sets warnRowCount, warnSleep and maxRowCount, i.e. only attributes of the parameter that affect the local side of a remote cursor.

Parameters:
par - the qbf parameter

applyQbfParameter

public void applyQbfParameter(QbfParameter par)
Applies the qbf parameter to a local cursor.

Parameters:
par - the qbf parameter

setDbContext

public void setDbContext(T object)
Sets the db-context for objects retrieved from the remote cursor.

Overridden to set the contextdb instead of db only.

Overrides:
setDbContext in class SimpleDbCursor<T extends AppDbObject>
Parameters:
object - the AppDbObject to set the contextDb for, never null

next

public boolean next()
Moves the cursor to the next row. If there are no more rows the current row remains unchanged.

Overridden to check for warnRowCount and maxRowCount.

Specified by:
next in interface DbCursor<T extends AppDbObject>
Overrides:
next in class SimpleDbCursor<T extends AppDbObject>
Returns:
true if moved, false if no more rows

fetch

public List<T> fetch()
Fetches the next objects up to the fetchsize. This method is provided to minimize the number of roundtrips especially for remote cursors. The cursor is closed at the end of the cursor.

If the fetchsize is 0 (auto), the method will fall back to toList. After having read the last row the cursor is closed! This saves two roundtrips for remote dbs.

Overridden to check for warnRowCount and maxRowCount.

Specified by:
fetch in interface DbCursor<T extends AppDbObject>
Overrides:
fetch in class SimpleDbCursor<T extends AppDbObject>
Returns:
the list of objects, null if no more objects found

getWarnRowCount

public int getWarnRowCount()
Gets the current warning row count.

Returns:
the warnRowCount.

setWarnRowCount

public void setWarnRowCount(int warnRowCount)
Sets the threshold for the number of rows to warn the user in an infodialog and ask him whether more rows should really be retrieved.

Parameters:
warnRowCount - the warnRowCount, 0 to disable the feature

getMaxRowCount

public int getMaxRowCount()
Gets the maximum number of rows to retrieve.

Returns:
the maxRowCount

setMaxRowCount

public void setMaxRowCount(int maxRowCount)
Sets the maximum number of rows to retrieve. This will prevent "dumb" queries from using too much memory.

Parameters:
maxRowCount - the maxRowCount, 0 = unlimited

isAbortRequested

public boolean isAbortRequested()
Gets the abort flag.

Returns:
true if abort has been requested

setAbortRequested

public void setAbortRequested(boolean abortRequested)
Sets the abort requestion flag. If set, the cursor will be closed before all data has been retrieved. Used by progress dialogs, for example AppDbCursorProgressDialog.

Parameters:
abortRequested - true if the query should be aborted asap.

getWarnSleep

public long getWarnSleep()
Gets the sleep interval.

Returns:
the interval in [ms]

setWarnSleep

public void setWarnSleep(long warnSleep)
Sets the sleep interval between two warnRowCount packets retrieved. This gives the user a chance to abort the retrieval in the progress dialog and reduces the db-server's load temporarily, being nice to other users.

Parameters:
warnSleep - the interval, 0 to disable

setEstimatedRowCount

public void setEstimatedRowCount(int estimatedRowCount)
Sets the expected query count. Usually determined by a prior select count(*). Affects only the message displayed to the user if more than warnRowCount objects are retrieved.

Parameters:
estimatedRowCount - the expected count, 0 = unknown (default)

getEstimatedRowCount

public int getEstimatedRowCount()
Gets the expected query count.

Returns:
the expected count, 0 = unknown (default)


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de