R
- class of row to cachepublic interface Cache<R>
Cached.type()
.
Implementations have the option to cache all rows for the table or only subset of rows. The row parameter in the interface methods, allow cache implementations to cache a subset based upon a row's values.
A design goal was to keep this interface as simple as possible and to allow optimal performance with the sormula api. Therefore, only local transactions are supported and there is no attempt to support JTA, nor generic caches like JCache.
Cache implementations require a two parameter constructor of types Table
and Cached
.
Modifier and Type | Method and Description |
---|---|
void |
begin(Transaction transaction)
Notification of database transaction start.
|
void |
close(SqlOperation<R> sqlOperation)
Notification that a
SqlOperation for the cached table is about to close. |
void |
commit(Transaction transaction)
Notification of database transaction normal end.
|
boolean |
contains(java.lang.Object[] primaryKeys)
Tests if cache contains a row with the primary key(s).
|
boolean |
delete(R row)
Performs an equivalent to SQL delete on cache for row.
|
void |
deleted(R row)
Indicates that a row was deleted from database.
|
void |
evict(R row)
Removes row from cache.
|
void |
evictAll()
Removes all rows from cache.
|
void |
execute(SqlOperation<R> sqlOperation)
Notification that a
SqlOperation for the cached table is about to execute. |
boolean |
insert(R row)
Performs an equivalent to SQL insert on cache for row.
|
void |
inserted(R row)
Indicates that a row was inserted into database.
|
void |
log()
Writes state of cache to log for debugging.
|
void |
rollback(Transaction transaction)
Notification of database transaction abnormal end.
|
boolean |
save(R row)
Performs an equivalent to save operation on cache 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)
Performs an equivalent to SQL update on cache for row.
|
void |
updated(R row)
Indicates that a row was updated in database.
|
void |
write()
Writes uncommitted changes to database.
|
void begin(Transaction transaction) throws CacheException
Table.begin(Transaction)
.transaction
- database transactionCacheException
- if errorvoid commit(Transaction transaction) throws CacheException
Table.commit(Transaction)
.
Some cache implementations write rows to the database when this method is invoked.transaction
- database transactionCacheException
- if errorvoid rollback(Transaction transaction) throws CacheException
Table.rollback(Transaction)
.
Typical cache implementations discard uncommitted rows from cache when this method is invoked.transaction
- database transactionCacheException
- if errorvoid execute(SqlOperation<R> sqlOperation) throws CacheException
SqlOperation
for the cached table is about to execute.sqlOperation
- operation that will use this cacheCacheException
- if errorvoid close(SqlOperation<R> sqlOperation) throws CacheException
SqlOperation
for the cached table is about to close.sqlOperation
- operation that will used this cacheCacheException
- if errorboolean contains(java.lang.Object[] primaryKeys) throws CacheException
primaryKeys
- primary key(s) for one rowCacheException
- if errorR select(java.lang.Object[] primaryKeys) throws CacheException
selected(Object)
when the row is selected from database. If true
is returned, then selected(Object)
must not be invoked.primaryKeys
- primary key(s) for one rowCacheException
- if errorboolean insert(R row) throws CacheException
inserted(Object)
when the row is inserted into database. If true
is returned, then inserted(Object)
must not be invoked.row
- row to insertCacheException
- if errorboolean update(R row) throws CacheException
updated(Object)
when the row is updated in database. If true
is returned, then updated(Object)
must not be invoked.row
- row to updateCacheException
- if errorboolean save(R row) throws CacheException
saved(Object)
when the row is saved to database. If true
is returned, then saved(Object)
must not be invoked.row
- row to saveCacheException
- if errorboolean delete(R row) throws CacheException
deleted(Object)
when the row is deleted from database. If true
is returned, then deleted(Object)
must not be invoked.row
- row to deleteCacheException
- if errorR selected(R row) throws CacheException
row
- that was selectedCacheException
- if errorvoid inserted(R row) throws CacheException
row
- that was insertedCacheException
- if errorvoid updated(R row) throws CacheException
row
- that was updatedCacheException
- if errorvoid saved(R row) throws CacheException
row
- that was savedCacheException
- if errorvoid deleted(R row) throws CacheException
row
- that was deletedCacheException
- if errorvoid write() throws CacheException
CacheException
- if errorvoid evict(R row) throws CacheException
row
- row to remove from cacheCacheException
- if errorvoid evictAll() throws CacheException
CacheException
- if errorvoid log()