R
- cached row typepublic class ReadOnlyCache<R> extends AbstractCache<R>
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. The primary key is defined by
Column.primaryKey()
, Column.identity()
, or Row.primaryKeyFields()
.
Cache will be searched when selecting by primary key. Non primary key selects will not use cache.
Constructor and Description |
---|
ReadOnlyCache(Table<R> table,
Cached cachedAnnotation)
Constructs for a table and cache annotation.
|
Modifier and Type | Method and Description |
---|---|
void |
close(SqlOperation<R> sqlOperation)
Does nothing.
|
boolean |
delete(R row)
Returns false since read only cache never writes to database and is never authority
for row.
|
void |
deleted(R row)
Indicates that a row was deleted from database.
|
void |
execute(SqlOperation<R> sqlOperation)
Prepares cache for use.
|
boolean |
insert(R row)
Returns false since read only cache never writes to database and is never authority
for row.
|
void |
inserted(R row)
Indicates that a row was inserted into database.
|
boolean |
save(R row)
Returns false since read only cache never writes to database and is never authority
for row.
|
void |
saved(R row)
Indicates that a row was saved in 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)
Returns false since read only cache never writes to database and is never authority
for row.
|
void |
updated(R row)
Indicates that a row was updated in database.
|
void |
write()
Does nothing.
|
begin, check, commit, 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 ReadOnlyCache(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
- ignoredCacheException
- if cache has not been initialized (no transaction is active)public void close(SqlOperation<R> sqlOperation) throws CacheException
sqlOperation
- ignoredCacheException
- 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
row
- ignoredCacheException
- if errorpublic boolean update(R row) throws CacheException
row
- ignoredCacheException
- if errorpublic boolean save(R row) throws CacheException
row
- ignoredCacheException
- if errorpublic boolean delete(R row) throws CacheException
row
- ignoredCacheException
- if errorpublic R selected(R row) throws CacheException
row
- that was selectedCacheException
- if errorpublic void inserted(R row) throws CacheException
row
- that was insertedCacheException
- if errorpublic void updated(R row) throws CacheException
row
- that was updatedCacheException
- if errorpublic void saved(R row) throws CacheException
row
- that was savedCacheException
- if errorpublic void deleted(R row) throws CacheException
row
- that was deletedCacheException
- if errorpublic void write() throws CacheException
CacheException
- if error