Class TableBackedCache
- java.lang.Object
-
- com.mckoi.database.TableBackedCache
-
- Direct Known Subclasses:
ConnectionTriggerManager.CTMBackedCache
abstract class TableBackedCache extends java.lang.Object
A TableBackedCache is a special type of a cache in a DataTableConglomerate that is backed by a table in the database. The purpose of this object is to provide efficient access to some specific information in a table via a cache.For example, we use this object to provide cached access to the system privilege tables. The engine often performs identical types of priv queries on the database and it's desirable to cache the access to this table.
This class provides the following services; 1) Allows for an instance of this object to be attached to a single DatabaseConnection 2) Listens for any changes that are committed to the table(s) and flushes the cache as neccessary.
Note that this object is designed to fit into the pure serializable transaction isolation system that Mckoi employs. This object will provide a view of the table as it was when the transaction started. When the transaction commits (or rollsback) the view is updated to the most current version. If a change is committed to the tables this cache is backed by, the cache is only flushed when there are no open transactions on the connection.
-
-
Field Summary
Fields Modifier and Type Field Description private IntegerVector
added_list
The list of added rows to the table above when a change is committed.private TableName
backed_by_table
The table that this cache is backed by.private TransactionModificationListener
listener
The listener object.private IntegerVector
removed_list
The list of removed rows from the table above when a change is committed.private boolean
transaction_active
Set to true when the backing DatabaseConnection has a transaction open.
-
Constructor Summary
Constructors Modifier Constructor Description protected
TableBackedCache(TableName table)
Constructs this object.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private void
addRowsToList(int[] from, IntegerVector list)
Adds new row ids to the given list.(package private) void
attachTo(TableDataConglomerate conglomerate)
Attaches this object to a conglomerate.(package private) void
detatchFrom(TableDataConglomerate conglomerate)
Call to detach this object from a TableDataConglomerate.private void
internalPurgeCache()
Internal method which copies the 'added' and 'removed' row lists and calls the 'purgeCacheOfInvalidatedEntries' method.(package private) abstract void
purgeCacheOfInvalidatedEntries(IntegerVector added_rows, IntegerVector removed_rows)
This method is called when the transaction starts and finishes and must purge the cache of all invalidated entries.(package private) void
transactionFinished()
Called from DatabaseConnection to notify that object that a transaction has closed.(package private) void
transactionStarted()
Called from DatabaseConnection to notify this object that a new transaction has been started.
-
-
-
Field Detail
-
backed_by_table
private TableName backed_by_table
The table that this cache is backed by.
-
added_list
private IntegerVector added_list
The list of added rows to the table above when a change is committed.
-
removed_list
private IntegerVector removed_list
The list of removed rows from the table above when a change is committed.
-
transaction_active
private boolean transaction_active
Set to true when the backing DatabaseConnection has a transaction open.
-
listener
private TransactionModificationListener listener
The listener object.
-
-
Constructor Detail
-
TableBackedCache
protected TableBackedCache(TableName table)
Constructs this object.
-
-
Method Detail
-
addRowsToList
private void addRowsToList(int[] from, IntegerVector list)
Adds new row ids to the given list.
-
attachTo
final void attachTo(TableDataConglomerate conglomerate)
Attaches this object to a conglomerate. This applies the appropriate listeners to the tables.
-
detatchFrom
final void detatchFrom(TableDataConglomerate conglomerate)
Call to detach this object from a TableDataConglomerate.
-
transactionStarted
final void transactionStarted()
Called from DatabaseConnection to notify this object that a new transaction has been started. When a transaction has started, any committed changes to the table must NOT be immediately reflected in this cache. Only when the transaction commits is there a possibility of the cache information being incorrect.
-
transactionFinished
final void transactionFinished()
Called from DatabaseConnection to notify that object that a transaction has closed. When a transaction is closed, information in the cache may be invalidated. For example, if rows 10 - 50 were delete then any information in the cache that touches this data must be flushed from the cache.
-
internalPurgeCache
private void internalPurgeCache()
Internal method which copies the 'added' and 'removed' row lists and calls the 'purgeCacheOfInvalidatedEntries' method.
-
purgeCacheOfInvalidatedEntries
abstract void purgeCacheOfInvalidatedEntries(IntegerVector added_rows, IntegerVector removed_rows)
This method is called when the transaction starts and finishes and must purge the cache of all invalidated entries.Note that this method must NOT make any queries on the database. It must only, at the most, purge the cache of invalid entries. A trivial implementation of this might completely clear the cache of all data if removed_row.size() > 0.
-
-