Holger's
Java API

com.antelmann.db
Class EnumDBStore<T extends Enum<?> & DBEntry>

java.lang.Object
  extended by com.antelmann.db.AbstractDBClassStore<T>
      extended by com.antelmann.db.EnumDBStore<T>
All Implemented Interfaces:
DBClassStore<T>, TransactionRequired

public class EnumDBStore<T extends Enum<?> & DBEntry>
extends AbstractDBClassStore<T>

allows any Enum that also implements DBEntry to be made available via DBClassStore.

Since:
27.01.2016, 22:59:21
Author:
holger

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.antelmann.db.DBClassStore
DBClassStore.DBMethod
 
Constructor Summary
EnumDBStore(Database<?> db, Class<T> type)
           
 
Method Summary
 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.
 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.
 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.
 void update(T entry)
          updates the given entry in the database.
 
Methods inherited from class com.antelmann.db.AbstractDBClassStore
containsID, deleteEntries, fetchStubs, getDatabase, getEntry, getEntryClass, getStub, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnumDBStore

public EnumDBStore(Database<?> db,
                   Class<T> type)
Method Detail

deleteEntry

public boolean deleteEntry(Object id)
                    throws DatabaseException
Description copied from interface: DBClassStore
removes the entry with the given ID from this store in the database.

Returns:
true only if the DBEntry with the given ID was actually found and deleted.
Throws:
DatabaseException

insert

public void insert(T entry)
            throws DatabaseException
Description copied from interface: DBClassStore
it is suggested to create the entry with an ID obtained through generateNewID() before passing it into this method. The ID of the entry must not already exist in the database.

Throws:
DatabaseException
See Also:
DBClassStore.generateNewID()

generateNewID

public Object generateNewID()
                     throws DatabaseException,
                            UnsupportedOperationException
Description copied from interface: DBClassStore
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. Note that not every implementation may embrace this method of providing DBEntry IDs; but this method may be preferred if the ID is merely to distinguish the Resources in the database (rather than being derived for another purpose as well). Not every call must necessarily return a new value, but it must return an ID not yet present in the persistent storage. In particular, an unused ID (i.e. returned earlier for creating an object, but that object was never inserted and committed into the database) may be returned again in a subsequent call in another transaction. Within one transaction, however, the returned ID must be different on each call. As a returned ID may not be actually be used, it would be unwise to rely on the return value to generate IDs that are required to provide for consecutive counters. An implementing class should document the exact behavior, so that the implications of usage are clear for that specific class - as they may be different (sometimes, each call to this method generates a unique value, sometimes that is only guaranteed within the same transaction). Generally, it is advisable, to always create unique IDs that are valid over transaction boundaries.

Throws:
DatabaseException
UnsupportedOperationException
See Also:
SessionIdGenerator, DBEntry.getID()

insertAsNew

public Object insertAsNew(T entry)
                   throws DatabaseException,
                          UnsupportedOperationException
Description copied from interface: DBClassStore
inserts the given entry using an ID generated by 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.

Returns:
the newly created ID of the object used as ID for the given entry to be inserted
Throws:
DatabaseException
UnsupportedOperationException
See Also:
DBEntry.getID(), DBClassStore.generateNewID()

update

public void update(T entry)
            throws DatabaseException
Description copied from interface: DBClassStore
updates the given entry in the database.

Throws:
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

fetch

public DBEnumeration<T> fetch(Filter<? super T> filter)
                                                throws DatabaseException
Description copied from interface: DBClassStore
allows to retrieve the entries of this storage via iteration. Note that the order of the entries is undefined, unless a specially designed filter hints a sorting order to an implementing class that additionally supports sorting.

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.

Parameters:
filter - may be null, in which case all entries from are returned.
Throws:
DatabaseException
See Also:
AbstractIterator.list(java.util.Enumeration), IterationException


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads