|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.db.WrappedDBClassStore<T>
com.antelmann.db.DBClassStoreCache<T>
public class DBClassStoreCache<T extends DBEntry>
a special store that has the ability of caching entries, so that
multiple calls to retrieve an entry may be answered through cache hits.
This implementation adds itself as a TransactionListener to the
database, so in order to remove this instance itself from memory,
it has to be removed as a listener, which can be done by calling stopListening().
| Nested Class Summary | |
|---|---|
static class |
DBClassStoreCache.PrefetchedFilter<T>
a special interface supported by the enclosing class store that indicates that only pre-fetched (cached) instances should be returned from a fetch. |
| Nested classes/interfaces inherited from interface com.antelmann.db.TransactionListener |
|---|
TransactionListener.Adapter |
| Nested classes/interfaces inherited from interface com.antelmann.db.DBClassStore |
|---|
DBClassStore.DBMethod |
| Field Summary |
|---|
| Fields inherited from class com.antelmann.db.WrappedDBClassStore |
|---|
store |
| Constructor Summary | |
|---|---|
DBClassStoreCache(DBClassStore<T> store)
|
|
| Method Summary | |
|---|---|
boolean |
containsID(Object id)
determines whether the given ID is present in this store. |
int |
deleteEntries(Filter<? super T> filter)
deletes all DBEntry objects that match the given filter; if the filter is null, all resources are deleted. |
boolean |
deleteEntry(Object id)
removes the entry with the given ID from this store in the database. |
DBEnumeration<T> |
fetch(Filter<? super T> filter)
adds support for DBClassStoreCache.PrefetchedFilter |
void |
finishTransaction(DBTransaction transaction)
called before the transaction commits (and before TransactionListener.prepareToCommit(DBTransaction)),
so that the commit at the database level can be prevented by
throwing a DatabaseException here. |
int |
getCacheHitCounter()
|
int |
getCacheSize()
|
T |
getEntry(Object id)
returns the DBEntry based on its ID. |
Stub<T> |
getStub(Object id)
returns a Stub representing the resource for the given ID or null. |
void |
insert(T entry)
it is suggested to create the entry with an ID obtained through generateNewID() before passing it into
this method. |
void |
prepareToCommit(DBTransaction transaction)
called right before the transaction actually commits and after TransactionListener.finishTransaction(DBTransaction). |
void |
resetCacheHitCounter()
|
void |
stopListening()
removes itself as a TransactionListener from the database. |
void |
transactionAborted(DBTransaction transaction)
called after a database transaction was aborted; the transaction is already inactive. |
void |
transactionBegin(DBTransaction transaction)
called upon beginning a transaction (the transaction is already active) |
void |
transactionCommitted(DBTransaction transaction)
called after a successful database commit; the transaction is already inactive. |
void |
update(T entry)
updates the given entry in the database. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DBClassStoreCache(DBClassStore<T> store)
throws ClassCastException
ClassCastException| Method Detail |
|---|
public void stopListening()
public int getCacheSize()
public int getCacheHitCounter()
public void resetCacheHitCounter()
public boolean containsID(Object id)
throws DatabaseException
DBClassStore
containsID in interface DBClassStore<T extends DBEntry>containsID in class WrappedDBClassStore<T extends DBEntry>DatabaseException
public int deleteEntries(Filter<? super T> filter)
throws DatabaseException
DBClassStoreDBClassStore.deleteEntry(Object)
is called for each entry passing the filter (although stores may choose to do so)!
Consequently, if a store's implementation does not call DBClassStore.deleteEntry(Object)
on each instance, calling this method may result in changes that are hard to monitor
for versioning purposes.
deleteEntries in interface DBClassStore<T extends DBEntry>deleteEntries in class WrappedDBClassStore<T extends DBEntry>DatabaseExceptionWrappedDBClassStore.setProcessBeforeFiltering(boolean)
public boolean deleteEntry(Object id)
throws DatabaseException
DBClassStore
deleteEntry in interface DBClassStore<T extends DBEntry>deleteEntry in class WrappedDBClassStore<T extends DBEntry>DatabaseException
public DBEnumeration<T> fetch(Filter<? super T> filter)
throws DatabaseException
DBClassStoreCache.PrefetchedFilter
fetch in interface DBClassStore<T extends DBEntry>fetch in class WrappedDBClassStore<T extends DBEntry>filter - may be null, in which case all entries from are returned.
DatabaseExceptionDBClassStoreCache.PrefetchedFilter
public T getEntry(Object id)
throws DatabaseException
DBClassStore
getEntry in interface DBClassStore<T extends DBEntry>getEntry in class WrappedDBClassStore<T extends DBEntry>id - the ID that is retrieved from Resource.getID()
DatabaseExceptionDBEntry.getID()
public Stub<T> getStub(Object id)
throws DatabaseException
DBClassStore
getStub in interface DBClassStore<T extends DBEntry>getStub in class WrappedDBClassStore<T extends DBEntry>DatabaseException
public void insert(T entry)
throws DatabaseException
DBClassStoregenerateNewID() before passing it into
this method.
The ID of the entry must not already exist in the database.
insert in interface DBClassStore<T extends DBEntry>insert in class WrappedDBClassStore<T extends DBEntry>DatabaseExceptionDBClassStore.generateNewID()
public void update(T entry)
throws DatabaseException
DBClassStore
update in interface DBClassStore<T extends DBEntry>update in class WrappedDBClassStore<T extends DBEntry>DatabaseException - if the database was not able to perform the update
or it the entry didn't exist in the database before calling this method
public void finishTransaction(DBTransaction transaction)
throws DatabaseException
TransactionListenerTransactionListener.prepareToCommit(DBTransaction)),
so that the commit at the database level can be prevented by
throwing a DatabaseException here.
This method can also be used to make some updates on another database
or checking on certain data before the transaction is allowed to commit.
In other words, this method may effectively veto the commit of a transaction
After this call, the transaction is soon either going to be committed or aborted
(right after all listeners have been called).
As this method runs within the transaction, it is possible to access/update
any resources from the database.
finishTransaction in interface TransactionListenerDatabaseExceptionpublic void prepareToCommit(DBTransaction transaction)
TransactionListenerTransactionListener.finishTransaction(DBTransaction).
Any exception thrown is ignored; listeners must not do any lengthy operations here.
This may be used for supporting the implementation of a 2-phase-commit.
prepareToCommit in interface TransactionListenertransaction - the transaction (being still active) that is about to be committedpublic void transactionAborted(DBTransaction transaction)
TransactionListenerTransactionException will be thrown.
If you need to access/update resources of this database from this method,
start a new thread that opens a new transaction.
transactionAborted in interface TransactionListenerpublic void transactionBegin(DBTransaction transaction)
TransactionListener
transactionBegin in interface TransactionListenerpublic void transactionCommitted(DBTransaction transaction)
TransactionListenerTransactionException will be thrown.
If you need to access/update resources of this database from this method,
start a new thread that opens a new transaction.
transactionCommitted in interface TransactionListener
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||