Class TableSerialHistory

java.lang.Object
org.tentackle.dbms.TableSerialHistory

@Service(TableSerialHistory.class) public class TableSerialHistory extends Object
Keeps track of all committed or rolled back deletions, updates or inserts in memory.
Applies to entities with a tableserial.
When loading the tableserials from the database via AbstractDbObject.selectExpiredTableSerials(long, long), gaps will be present for deletions, rolled back updates or inserts and PDOs updated more than once since the last query. Those id/tableserial tuples are picked up by the TableSerialExpirationBacklog to fill the gaps in its expiration sets avoiding unnecessary cache invalidations.
An IdSerialTuples with a positive tableserial and an ID of 0 represents an insert or update. A negative tableserial with a positive ID describes a deletion. The history is only maintained by the server connected to the database. Intermediate servers or clients retrieve their expiration sets from the remote server.
Consulting the expiration backlog usually happens when the ModificationTracker detects a modification and invokes the corresponding listeners, such as PDO-caches, which in turn ask the expiration backlog for the modifications.
If, for some reason, the modifications are counted for an entity type but the expiration backlog is never consulted (no PdoCache?), the oldest history entries will be silently removed if the maximum size is reached. This may be ok if the entity is updated frequently but not queried often via the cache, for example. Otherwise, the maximum size of the history should be increased for the given entity type (tablename).
See Also:
  • Constructor Details

    • TableSerialHistory

      public TableSerialHistory(int maxSize)
      Creates the history singleton.
      Parameters:
      maxSize - the initial max. number of history entries per tablename
      See Also:
    • TableSerialHistory

      public TableSerialHistory()
      Creates the history singleton with a default size.
  • Method Details

    • getInstance

      public static TableSerialHistory getInstance()
      The singleton.
      Returns:
      the singleton
    • memorize

      public void memorize(String tableName, long id, long tableSerial)
      Memorizes a history entry.
      Parameters:
      tableName - the tablename
      id - the object's ID, 0 for an update or insert
      tableSerial - the object's tableserial, negative if deletion
    • memorize

      public void memorize(String tableName, IdSerialTuple tuple)
      Memorizes a history entry.
      Parameters:
      tableName - the tablename
      tuple - the id/tableserial tuple
    • memorize

      public void memorize(String tableName, Collection<IdSerialTuple> tuples)
      Memorizes history entries described by id/tableserial tuples.
      Parameters:
      tableName - the tablename
      tuples - the gaps
    • retrieve

      public Collection<IdSerialTuple> retrieve(String tableName, long minSerial, long maxSerial, boolean forget)
      Retrieves history entries and optionally removes them.
      Parameters:
      tableName - the tablename
      minSerial - the lower serial bound of the query (minSerial < tableSerial)
      maxSerial - the upper serial bound of the query (tableSerial ≤ maxSerial)
      forget - true to remove the returned entries from memory
      Returns:
      the non-empty list of gaps sorted by abs(tableserial), null for none
    • setMaxSize

      public void setMaxSize(String tableName, int maxSize)
      Sets the maximum size of the history.
      Parameters:
      tableName - the tablename
      maxSize - the new size
    • getNaxSize

      public int getNaxSize(String tableName)
      Gets the maximum size of the history.
      Parameters:
      tableName - the tablename
      Returns:
      the size
    • getSize

      public int getSize(String tableName)
      Gets the number of history entries currently available.
      Parameters:
      tableName - the tablename
      Returns:
      the number of history entries