Class TableSerialHistory
java.lang.Object
org.tentackle.dbms.TableSerialHistory
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
An
Consulting the expiration backlog usually happens when the
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).
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 Summary
ConstructorsConstructorDescriptionCreates the history singleton with a default size.TableSerialHistory(int maxSize) Creates the history singleton. -
Method Summary
Modifier and TypeMethodDescriptionstatic TableSerialHistoryThe singleton.intgetNaxSize(String tableName) Gets the maximum size of the history.intGets the number of history entries currently available.voidMemorizes a history entry.voidmemorize(String tableName, Collection<IdSerialTuple> tuples) Memorizes history entries described by id/tableserial tuples.voidmemorize(String tableName, IdSerialTuple tuple) Memorizes a history entry.Retrieves history entries and optionally removes them.voidsetMaxSize(String tableName, int maxSize) Sets the maximum size of the history.
-
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
-
memorize
Memorizes a history entry.- Parameters:
tableName- the tablenameid- the object's ID, 0 for an update or inserttableSerial- the object's tableserial, negative if deletion
-
memorize
Memorizes a history entry.- Parameters:
tableName- the tablenametuple- the id/tableserial tuple
-
memorize
Memorizes history entries described by id/tableserial tuples.- Parameters:
tableName- the tablenametuples- 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 tablenameminSerial- 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
Sets the maximum size of the history.- Parameters:
tableName- the tablenamemaxSize- the new size
-
getNaxSize
Gets the maximum size of the history.- Parameters:
tableName- the tablename- Returns:
- the size
-
getSize
Gets the number of history entries currently available.- Parameters:
tableName- the tablename- Returns:
- the number of history entries
-