R
- row type that is cachedpublic class ReadWriteCache<R> extends WritableCache<R>
WritableCache.write()
, Table.flush()
, or Database.flush()
is invoked.
The selected and modified rows are retained in cache for life of Table
object or until
explicitly flushed with Table.flush()
, or Database.flush()
or evicted with
Cache.evict(Object)
or Cache.evictAll()
.
This is a transaction based cache which means that caching is performed relative to database transaction
boundaries of begin, commit, and rollback. Tables that are cached may not read/write unless a transaction
is active. Tables that are cached must use Transaction
obtained from Database.getTransaction()
or must use a subclass of Transaction
that is set with Database.setTransaction(Transaction)
.
Cached rows are stored in maps with primary keys as the map key. Primary keys are defined by
Column.primaryKey()
, Column.identity()
, or Row.primaryKeyFields()
.
Cache will be searched when selecting by primary key. Non primary key
selects will cause cache to write uncommitted rows to database prior to executing query.
Constructor and Description |
---|
ReadWriteCache(Table<R> table,
Cached cachedAnnotation)
Constructs for a table and cache annotation.
|
Modifier and Type | Method and Description |
---|---|
void |
close(SqlOperation<R> sqlOperation)
Notification that a
SqlOperation for the cached table is about to close. |
boolean |
delete(R row)
Performs an equivalent to SQL delete on cache for row.
|
void |
deleted(R row)
Throws IllegalCacheOperationException since writable
ReadWriteCache should never be
notified of a delete since ReadWriteCache will be deleting from the database. |
void |
execute(SqlOperation<R> sqlOperation)
Prepares cache for use.
|
boolean |
insert(R row)
Performs an equivalent to SQL insert on cache for row.
|
void |
inserted(R row)
If table does not have an identity column, then throws IllegalCacheOperationException
since writable
ReadWriteCache should never be notified of an insert of non identity
row since ReadWriteCache will be inserting the database. |
boolean |
save(R row)
Performs an equivalent to save operation on cache for row.
|
void |
saved(R row)
Throws IllegalCacheOperationException since writable
ReadWriteCache should never be
notified of an save since ReadWriteCache will be saving to the database. |
R |
select(java.lang.Object[] primaryKeys)
Performs an equivalent to SQL select on cache for a row with primary key(s).
|
R |
selected(R row)
Indicates row was selected from database.
|
boolean |
update(R row)
Performs an equivalent to SQL update on cache for row.
|
void |
updated(R row)
Throws IllegalCacheOperationException since writable
ReadWriteCache should never be
notified of an update since ReadWriteCache will be updating the database. |
commit, write
begin, check, contains, evict, evictAll, getCachedAnnotation, getCommitted, getCommittedCache, getHits, getMisses, getPercentHits, getPrimaryKeyExtractor, getPrimaryKeyValues, getTable, getUncommitted, getUncommittedCache, hit, initCommittedCache, initUncommittedCache, log, miss, putCommitted, putUncommitted, removeCommited, rollback, setCommittedCache, setUncommittedCache, transition
public ReadWriteCache(Table<R> table, Cached cachedAnnotation) throws CacheException
table
- cache rows for this tablecachedAnnotation
- cache configurationCacheException
- if errorpublic void execute(SqlOperation<R> sqlOperation) throws CacheException
sqlOperation
- operation that will use this cacheCacheException
- if cache has not been initialized (no transaction is active)public void close(SqlOperation<R> sqlOperation) throws CacheException
SqlOperation
for the cached table is about to close.sqlOperation
- operation that will used this cacheCacheException
- if errorpublic R select(java.lang.Object[] primaryKeys) throws CacheException
Cache.selected(Object)
when the row is selected from database. If true
is returned, then Cache.selected(Object)
must not be invoked.primaryKeys
- primary key(s) for one rowCacheException
- if errorpublic boolean insert(R row) throws CacheException
Cache.inserted(Object)
when the row is inserted into database. If true
is returned, then Cache.inserted(Object)
must not be invoked.row
- row to insertCacheException
- if errorpublic boolean update(R row) throws CacheException
Cache.updated(Object)
when the row is updated in database. If true
is returned, then Cache.updated(Object)
must not be invoked.row
- row to updateCacheException
- if errorpublic boolean save(R row) throws CacheException
Cache.saved(Object)
when the row is saved to database. If true
is returned, then Cache.saved(Object)
must not be invoked.row
- row to saveCacheException
- if errorpublic boolean delete(R row) throws CacheException
Cache.deleted(Object)
when the row is deleted from database. If true
is returned, then Cache.deleted(Object)
must not be invoked.row
- row to deleteCacheException
- if errorpublic R selected(R row) throws CacheException
row
- that was selectedCacheException
- if errorpublic void inserted(R row) throws CacheException
ReadWriteCache
should never be notified of an insert of non identity
row since ReadWriteCache
will be inserting the database.
If table has an identity column (Column.identity()
was set true on a field),
then row is added to cache. Row is not written to database since this method
indicates that it has already been written.
row
- row that has been insertedIllegalCacheOperationException
- if table does not have an identity columnCacheException
- if errorpublic void updated(R row) throws CacheException
ReadWriteCache
should never be
notified of an update since ReadWriteCache
will be updating the database.row
- ignoredIllegalCacheOperationException
- if errorCacheException
- if errorpublic void saved(R row) throws CacheException
ReadWriteCache
should never be
notified of an save since ReadWriteCache
will be saving to the database.row
- ignoredIllegalCacheOperationException
- if errorCacheException
- if errorpublic void deleted(R row) throws CacheException
ReadWriteCache
should never be
notified of a delete since ReadWriteCache
will be deleting from the database.row
- ignoredIllegalCacheOperationException
- if errorCacheException
- if error