org.tentackle.db
Class ModificationCounter

java.lang.Object
  extended by org.tentackle.db.ModificationCounter

public class ModificationCounter
extends Object

Counter to track modifications for a class/table.
There is one ModificationCounter-object per DbObject-class *AND* Db-connection. The Db maintains a list of ModificationCounter-objects, one for each table.

The physical count for UPDATE and INSERT (i.e. update to the database) is minimized within transactions. If there are only updates and inserts the counter (i.e. the tableSerial) increments by 1. However, each DELETE gets its own tableSerial which will allow other JVMs to detect that "some objects have been deleted" by gaps in the sequence of tableSerials. AppDbObjectCache and DbPreferences make use of that trick.

Author:
harald

Field Summary
static String FIELD_TABLENAME
          column name for the tablename
static String TABLENAME
          the modification-table's name
 
Constructor Summary
ModificationCounter(Db db, String tableName)
          Creates a modification counter for a given tablename.
 
Method Summary
 void addModificationTable()
          Adds an entry for this counter (== database object class) to the modification table.
 long countModification(boolean checkModificationSerial, boolean optimize)
          Counts the modification for the table this counter belongs to.
If the counter does not exist in the modification table, an appropriate entry will be created.
 long selectModification()
          Get the current modification count by tablename.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TABLENAME

public static final String TABLENAME
the modification-table's name

See Also:
Constant Field Values

FIELD_TABLENAME

public static final String FIELD_TABLENAME
column name for the tablename

See Also:
Constant Field Values
Constructor Detail

ModificationCounter

public ModificationCounter(Db db,
                           String tableName)
Creates a modification counter for a given tablename.

Parameters:
db - the db connection
tableName - the tablename
Method Detail

countModification

public long countModification(boolean checkModificationSerial,
                              boolean optimize)
Counts the modification for the table this counter belongs to.
If the counter does not exist in the modification table, an appropriate entry will be created.

Parameters:
checkModificationSerial - is true if the new tableSerial should be returned
optimize - is true if counting should be optimized within transactions. Otherwise this and the succeeding invocation performs a physical count.
Returns:
the table serial

addModificationTable

public void addModificationTable()
Adds an entry for this counter (== database object class) to the modification table. The tableserial is derived from the highest serial of all objects (i.e. class) this counter refers to.


selectModification

public long selectModification()
Get the current modification count by tablename.

Returns:
the modification count


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