|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
T - the DBEntry class that this class store handlespublic interface DBClassStore<T extends DBEntry>
provides persistence service for a DBEntry class in the context of a Database. This interface defines the CRUD operations for the implementation. Note that all operations on a DBClassStore instance require to be synchronized on the transaction of its Database and must check for the transaction to be active to guarantee the ACID concept!
Database,
DBTransaction,
TransactionException,
DBEntry| Nested Class Summary | |
|---|---|
static class |
DBClassStore.DBMethod
|
| 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)
allows to retrieve the entries of this storage via iteration. |
DBEnumeration<Stub<T>> |
fetchStubs(Filter<? super Stub<?>> filter)
allows to access objects from this store w/o having to instantiate the entire original objects, but instead use Stubs to be able to display the list properly for selection. |
Object |
generateNewID()
this method is to generate unique new IDs for the DBEntry at hand - if the application has no other specific way of providing new IDs for this implementation. |
Database<?> |
getDatabase()
provides access to the database instance that also coordinates the transaction management. |
T |
getEntry(Object id)
returns the DBEntry based on its ID. |
Class<T> |
getEntryClass()
returns the runtime class type this store represents |
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. |
Object |
insertAsNew(T entry)
inserts the given entry using an ID generated by generateNewID
while ignoring the ID of the given entry. |
int |
size(Filter<? super T> filter)
returns the total number of T elements in this store based on the given filter (which may be null) |
void |
update(T entry)
updates the given entry in the database. |
| Method Detail |
|---|
Database<?> getDatabase()
Class<T> getEntryClass()
boolean containsID(Object id)
throws DatabaseException
DatabaseException
boolean deleteEntry(Object id)
throws DatabaseException
DatabaseException
@Warning(value="using this method may result in not being able to monitor each individual change of an entry depending on the store\'s implementation")
int deleteEntries(Filter<? super T> filter)
throws DatabaseException
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 deleteEntry(Object)
on each instance, calling this method may result in changes that are hard to monitor
for versioning purposes.
DatabaseExceptiondeleteEntry(Object)
void insert(T entry)
throws DatabaseException
generateNewID() before passing it into
this method.
The ID of the entry must not already exist in the database.
DatabaseExceptiongenerateNewID()
Object generateNewID()
throws DatabaseException,
UnsupportedOperationException
DatabaseException
UnsupportedOperationExceptionSessionIdGenerator,
DBEntry.getID()
Object insertAsNew(T entry)
throws DatabaseException,
UnsupportedOperationException
generateNewID
while ignoring the ID of the given entry.
With this method, the same Object (with the same ID) can be inserted
multiple times, stored with a new ID on each call; the ID creation is handled
automatically.
This is an optional feature that might not be implemented in all cases.
DatabaseException
UnsupportedOperationExceptionDBEntry.getID(),
generateNewID()
void update(T entry)
throws DatabaseException
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
DBEnumeration<T> fetch(Filter<? super T> filter)
throws DatabaseException
As all relevant entries may not completely fit into memory, an Enumeration is returned instead of a list. To directly get all entries as a list (and thus avoid concurrency problems), consider using methods from AbstractIterator to quickly retrieve all resources before processing them.
Be aware that the result of the enumeration may become undefined if data is inserted/deleted/updated while the elements are accessed. To guarantee consistency, all access to the returned Enumeration must be externally synchronized by holding the monitor of the database transaction throughout maintaining the Enumeration.
Note that you may have IterationExceptions being thrown on calling methods on the returned Enumeration, which are caused by either DatabaseExceptions or InstantiationExceptions on trying to fetch the next element, as not all possible errors may be caught on calling this method (as it possibly cannot instantiate all entries in advance).
All access to the returned Enumeration must be made within an active transaction.
As the returned Enumeration may hold resources to the database while iterating, the caller must ensure that these resources can be properly release. This is usually achieved by simply completely iterating through the return value, in which case the DBEnumeration is expected to properly clean up automatically. But in cases where the caller doesn't intend to go all the way through the Enumeration, the caller has to clean up explicitly, which can be done by calling the close() method on the returned DBEnumeration.
filter - may be null, in which case all entries from are returned.
DatabaseExceptionAbstractIterator.list(java.util.Enumeration),
IterationException
DBEnumeration<Stub<T>> fetchStubs(Filter<? super Stub<?>> filter)
throws DatabaseException
fetch(Filter) .
DatabaseException
T getEntry(Object id)
throws DatabaseException
id - the ID that is retrieved from Resource.getID()
DatabaseExceptionDBEntry.getID()
Stub<T> getStub(Object id)
throws DatabaseException
DatabaseException
int size(Filter<? super T> filter)
throws DatabaseException
filter - if non-null, only those elements will be counted that are applicable to the filter
DatabaseException
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||