|
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.CollectionClassStore<T>
public class CollectionClassStore<T extends DBEntry>
a transient DBClassStore implementation based on a simple collection of DBEntries. The entries are optionally serialized when put into the embedded collection. Only if serialization is used, this store guarantees transactional integrity of the data; a non-serialized store is much faster, though, so it is ideal for read-only use. By adding itself as a TransactionListener to the given Database, it follows the logic of commits and aborts properly. Note that this implementation is not storing any data persistently!
AbstractDatabase,
Serialized Form| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.antelmann.db.DBClassStore |
|---|
DBClassStore.DBMethod |
| Constructor Summary | |
|---|---|
CollectionClassStore(Database<?> db,
boolean serialize,
Class<T> type,
T... entries)
|
|
CollectionClassStore(Database<?> db,
Class<T> type,
boolean serialize)
use serialization for transactional consistent updates and leave it out for read-only stores. |
|
CollectionClassStore(Database<?> db,
Class<T> type,
boolean serialize,
Collection<T> col)
|
|
| 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)
the display value of the returned Stub is based on the toString() method of the DBEntry instance |
void |
finalize()
allow this instance to be garbage-collected by removing it from the database as a listener |
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 |
IDFactory |
getIdFactory()
|
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)
always throws UnsupportedOperationException |
boolean |
isSerialized()
|
void |
put(T entry)
|
void |
remove(T entry)
|
void |
setIdFactory(IDFactory idFactory)
|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CollectionClassStore(Database<?> db,
Class<T> type,
boolean serialize)
public CollectionClassStore(Database<?> db,
Class<T> type,
boolean serialize,
Collection<T> col)
throws DatabaseException
DatabaseException
public CollectionClassStore(Database<?> db,
boolean serialize,
Class<T> type,
T... entries)
throws DatabaseException
DatabaseException| Method Detail |
|---|
@Warning(value="this method works directly on the committed data and disregards any transactional boundaries")
public void put(T entry)
throws DatabaseException,
IllegalStateException
DatabaseException
IllegalStateException
@Warning(value="this method works directly on the committed data and disregards any transactional boundaries")
public void remove(T entry)
throws IllegalStateException
IllegalStateExceptionpublic IDFactory getIdFactory()
public void setIdFactory(IDFactory idFactory)
public boolean isSerialized()
public void finalize()
throws Throwable
finalize in class ObjectThrowablepublic Database<?> getDatabase()
DBClassStore
getDatabase in interface DBClassStore<T extends DBEntry>public Class<T> getEntryClass()
DBClassStore
getEntryClass in interface DBClassStore<T extends DBEntry>
public boolean containsID(Object id)
throws DatabaseException
DBClassStore
containsID in interface DBClassStore<T extends DBEntry>DatabaseException
public boolean deleteEntry(Object id)
throws DatabaseException
DBClassStore
deleteEntry in interface DBClassStore<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>DatabaseExceptionDBClassStore.deleteEntry(Object)
public Object generateNewID()
throws DatabaseException,
UnsupportedOperationException
DBClassStore
generateNewID in interface DBClassStore<T extends DBEntry>DatabaseException
UnsupportedOperationExceptionSessionIdGenerator,
DBEntry.getID()
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>DatabaseExceptionDBClassStore.generateNewID()
public Object insertAsNew(T entry)
throws DatabaseException,
UnsupportedOperationException
insertAsNew in interface DBClassStore<T extends DBEntry>DatabaseException
UnsupportedOperationExceptionDBEntry.getID(),
DBClassStore.generateNewID()
public void update(T entry)
throws DatabaseException
DBClassStore
update in interface DBClassStore<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 DBEnumeration<T> fetch(Filter<? super T> filter)
throws DatabaseException
DBClassStoreAs 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.
fetch in interface DBClassStore<T extends DBEntry>filter - may be null, in which case all entries from are returned.
DatabaseExceptionAbstractIterator.list(java.util.Enumeration),
IterationException
public DBEnumeration<Stub<T>> fetchStubs(Filter<? super Stub<?>> filter)
throws DatabaseException
fetchStubs in interface DBClassStore<T extends DBEntry>DatabaseException
public T getEntry(Object id)
throws DatabaseException
DBClassStore
getEntry in interface DBClassStore<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>DatabaseException
public int size(Filter<? super T> filter)
throws DatabaseException
DBClassStore
size in interface DBClassStore<T extends DBEntry>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 | |||||||||