|
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.AbstractDatabase<S>
S - the underlying service that this database is based uponpublic abstract class AbstractDatabase<S>
a base class for implementing a database.
All methods are synchronized on the transaction rather than this instance!
It leaves the transaction management to the inheriting class
by omitting the implementation of getTransaction()
and also requires close() to be implemented.
Each databaseService access through DBClassStore objects is monitored
by this implementation as every DBClassStore instance is wrapped
by a proxy.
In addition, this implementation also provides a mechanism to control
access to its DBClassStore instances via DBAccessController interface.
Also, this implementation serves as a LoginListener and can thus
automatically update its current user when appropriately added as a listener.
Other than that, the logging itself is also left to an inheriting class.
Unless otherwise specified, all methods in this class that throw a DatabaseException
are implemented via DBUtils.runInTransaction(Task, DBTransaction, boolean) to
ensure proper transactional behavior.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.antelmann.db.LoginListener |
|---|
LoginListener.Adapter |
| Constructor Summary | |
|---|---|
AbstractDatabase(S databaseService)
|
|
AbstractDatabase(S databaseService,
User user)
sets the current user (may be null) |
|
AbstractDatabase(S databaseService,
User user,
DBAccessController controller,
LogWriter logWriter)
|
|
AbstractDatabase(S databaseService,
User user,
DBAccessController controller,
LogWriter logWriter,
boolean automatedTransactions)
|
|
AbstractDatabase(S databaseService,
User user,
LogWriter logWriter)
the given logWriter - assumed to write into the databaseService if not null - will be added to the embedded Logger |
|
| Method Summary | ||
|---|---|---|
boolean |
addConfigListener(DBConfigListener listener)
|
|
boolean |
addStoreListener(DBStoreListener listener)
|
|
void |
checkAccessRight(Object right)
checks whether there is a current user on the database with the given access right and throws an exception if that's not the case |
|
void |
checkTransactionActive()
test for an active transaction; implies ownership of the transaction |
|
protected void |
clearAllData()
this method clears all stores, listeners, writers and users from this database in preparation for calling close() |
|
void |
close()
|
|
boolean |
contains(DBReference ref)
|
|
|
contains(T entry)
|
|
|
count(Class<T> c,
Filter<? super T> filter)
|
|
|
countStubs(Class<T> c,
Filter<Stub<?>> filter)
|
|
boolean |
delete(DBReference ref)
|
|
boolean |
delete(Stub<?> stub)
|
|
|
delete(T entry)
|
|
static
|
extractInterface(DBClassStore<E> store,
Class<I> desiredInterface)
allows to extract an interface from a store only if it is 'exposed' |
|
void |
failedLogin(UserLoginStore uls,
String location,
Exception exception)
called when a login was either canceled or failed due to an exception |
|
protected void |
finalize()
|
|
protected void |
fireStoreChanges()
|
|
DBAccessController |
getAccessController()
|
|
Set<Class<? extends DBEntry>> |
getAvailableClassStores()
returns an unmodifiable view of the existing classes that map to a DBClassStore in this database |
|
DBConfigListener[] |
getConfigListeners()
|
|
User |
getCurrentUser()
returns the user credentials of the one currently using this database |
|
S |
getDatabaseService()
provides access to the actual database service that is used by the implementation of this interface |
|
|
getEntry(Class<T> c,
Object id)
a shortcut w/o having to go through the DBClassStore |
|
DBEntry |
getEntry(DBReference ref)
This method will begin and abort a transaction if none is active at the time. |
|
|
getEntry(Stub<T> stub)
This method will begin and abort a transaction if none is active at the time. |
|
|
getFirstEntry(Class<T> type,
Filter<? super T> filter)
|
|
|
getFirstStub(Class<T> type,
Filter<Stub<?>> filter)
|
|
Logger |
getLogger()
a logger that contains the logWriter given in the constructor; it is used to log all databaseService access with the special level 'dbaccess' by default |
|
protected
|
getOriginalClassStore(Class<T> c)
returns the original class store that was put in here directly (not the proxy/wrapper that ensures listeners are notified and transactional integrity is guaranteed) |
|
|
getRandomEntry(Class<T> type)
|
|
|
getRandomEntry(Class<T> type,
Filter<? super T> filter)
|
|
|
getRandomStub(Class<T> type)
|
|
|
getStore(Class<T> c)
returns a monitored Proxy of the previously added DBClassStore for c or null |
|
|
getStoreForEntry(T entry)
provides a save cast to obtain the relevant DBClassStore |
|
DBStoreListener[] |
getStoreListeners()
|
|
|
getStub(Class<T> c,
Object id)
a shortcut w/o having to go through the DBClassStore |
|
Stub<? extends DBEntry> |
getStub(DBReference ref)
This method will begin and abort a transaction if none is active at the time. |
|
boolean |
hasAutomatedTransactions()
determines whether the DBClassStoreWrapper instances used by this database use automatic transaction handling. |
|
boolean |
isEnsureTransactions()
|
|
|
isVersioningEnabled(Class<E> type,
boolean flag)
|
|
|
listEntries(Class<T> c,
Filter<? super T> filter)
This method will begin and abort a transaction if none is active at the time. |
|
|
listEntries(Class<T> type,
Filter<? super T> filter,
int maxEntries)
|
|
|
listStubs(Class<T> c,
Filter<? super Stub<?>> filter)
This method will begin and abort a transaction if none is active at the time. |
|
void |
loginPerformed(UserLoginStore uls,
User user,
String location)
called when a user logged into the store |
|
void |
logoutPerformed(UserLoginStore uls,
User user)
called when a user logged out |
|
|
mapEntries(Class<T> c,
Filter<? super T> filter)
returns a Hashtable mapping the ID to its DBEntry of those that apply to the given filter. |
|
|
mapStubs(Class<T> c,
Filter<? super Stub<?>> filter)
returns a Hashtable mapping the ID to its Stub of those that apply to the given filter. |
|
|
putClassStore(Class<T> c,
DBClassStore<T> dbcs)
puts the given dbcs into this database, which is then available in a wrapped Proxy when accessing the class store via interface method getClassStore(Class). |
|
|
query(Class<T> requiredReturnType,
Object context)
implements the query mechanism based on queryStoreForInterface(Class, Class)
and also allows to effectively cast to the subclass. |
|
|
queryStoreForInterface(Class<E> type,
Class<I> desiredInterface)
supports WrappedDBClassStore instances for querying the interface from embedded stores |
|
|
remove(Class<T> c)
|
|
boolean |
removeConfigListener(DBConfigListener listener)
|
|
boolean |
removeStoreListener(DBStoreListener listener)
|
|
void |
setAccessController(DBAccessController controller)
|
|
void |
setAutomatedTransactions(boolean flag)
|
|
void |
setCurrentUser(User user)
sets the user credentials for accessing resources |
|
void |
setEnsureTransactions(boolean flag)
|
|
|
setVersioningEnabled(Class<E> type,
boolean flag)
Enabling versioning on a class store results on additional overhead for insert, update and delete operations, as for each update and delete operation the store first retrieves the existing instance from the database before storing the new version. |
|
|
store(T... entries)
inserts/updates the given entries in the database depending on whether it already exists |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.antelmann.db.Database |
|---|
getTransaction |
| Constructor Detail |
|---|
public AbstractDatabase(S databaseService)
public AbstractDatabase(S databaseService,
User user)
public AbstractDatabase(S databaseService,
User user,
LogWriter logWriter)
public AbstractDatabase(S databaseService,
User user,
DBAccessController controller,
LogWriter logWriter)
public AbstractDatabase(S databaseService,
User user,
DBAccessController controller,
LogWriter logWriter,
boolean automatedTransactions)
| Method Detail |
|---|
protected void clearAllData()
close()
protected void fireStoreChanges()
protected void finalize()
throws Throwable
finalize in class ObjectThrowablepublic final S getDatabaseService()
Database
getDatabaseService in interface Database<S>public final boolean hasAutomatedTransactions()
public final void setAutomatedTransactions(boolean flag)
public final boolean isEnsureTransactions()
public final void setEnsureTransactions(boolean flag)
public void setAccessController(DBAccessController controller)
public DBAccessController getAccessController()
public void checkAccessRight(Object right)
throws DBAccessDeniedWarning
DBAccessDeniedWarningpublic Set<Class<? extends DBEntry>> getAvailableClassStores()
Database
getAvailableClassStores in interface Database<S>public <T extends DBEntry> DBClassStore<T> remove(Class<T> c)
public <T extends DBEntry> DBClassStore<T> getStore(Class<T> c)
getStore in interface Database<S>protected <T extends DBEntry> DBClassStore<T> getOriginalClassStore(Class<T> c)
public <T extends DBEntry> DBClassStore<T> putClassStore(Class<T> c,
DBClassStore<T> dbcs)
getClassStore(Class). The original object put in here can still be accessed by the
protected method getOriginalClassStore(Class).
public <T extends DBEntry> Hashtable<Object,T> mapEntries(Class<T> c,
Filter<? super T> filter)
throws DatabaseException
DatabaseException
public <T extends DBEntry> Hashtable<Object,Stub<T>> mapStubs(Class<T> c,
Filter<? super Stub<?>> filter)
throws DatabaseException
DatabaseException
public <T extends DBEntry> int count(Class<T> c,
Filter<? super T> filter)
throws DatabaseException
DatabaseException
public <T extends DBEntry> int countStubs(Class<T> c,
Filter<Stub<?>> filter)
throws DatabaseException
DatabaseException
public <T extends DBEntry> ArrayList<T> listEntries(Class<T> type,
Filter<? super T> filter,
int maxEntries)
throws DatabaseException
DatabaseException
public <T extends DBEntry> ArrayList<T> listEntries(Class<T> c,
Filter<? super T> filter)
throws DatabaseException
DatabaseException
public <T extends DBEntry> ArrayList<Stub<T>> listStubs(Class<T> c,
Filter<? super Stub<?>> filter)
throws DatabaseException
DatabaseException
public <T extends DBEntry> T getEntry(Class<T> c,
Object id)
throws DatabaseException
DatabaseException
public <T extends DBEntry> T getEntry(Stub<T> stub)
throws DatabaseException
DatabaseException
public <T extends DBEntry> Stub<T> getStub(Class<T> c,
Object id)
throws DatabaseException
DatabaseException
public DBEntry getEntry(DBReference ref)
throws DatabaseException
DatabaseException
public Stub<? extends DBEntry> getStub(DBReference ref)
throws DatabaseException
DatabaseExceptionpublic <T extends DBEntry> DBClassStore<T> getStoreForEntry(T entry)
public <T extends DBEntry> void store(T... entries)
throws DatabaseException
DatabaseException
public boolean contains(DBReference ref)
throws DatabaseException
DatabaseException
public <T extends DBEntry> boolean contains(T entry)
throws DatabaseException
DatabaseException
public <T extends DBEntry> boolean delete(T entry)
throws DatabaseException
DatabaseException
public boolean delete(DBReference ref)
throws DatabaseException
DatabaseException
public boolean delete(Stub<?> stub)
throws DatabaseException
DatabaseException
public <T extends DBEntry> T getFirstEntry(Class<T> type,
Filter<? super T> filter)
throws DatabaseException
DatabaseException
public <T extends DBEntry> Stub<T> getFirstStub(Class<T> type,
Filter<Stub<?>> filter)
throws DatabaseException
DatabaseExceptionpublic User getCurrentUser()
Database
getCurrentUser in interface Database<S>public void setCurrentUser(User user)
Database
setCurrentUser in interface Database<S>public Logger getLogger()
getLogger in interface Database<S>getLogger in interface LoggerProviderpublic boolean addStoreListener(DBStoreListener listener)
addStoreListener in interface Database<S>public boolean removeStoreListener(DBStoreListener listener)
removeStoreListener in interface Database<S>public DBStoreListener[] getStoreListeners()
getStoreListeners in interface Database<S>public boolean addConfigListener(DBConfigListener listener)
addConfigListener in interface Database<S>public boolean removeConfigListener(DBConfigListener listener)
removeConfigListener in interface Database<S>public DBConfigListener[] getConfigListeners()
getConfigListeners in interface Database<S>
public void loginPerformed(UserLoginStore uls,
User user,
String location)
LoginListener
loginPerformed in interface LoginListener
public void logoutPerformed(UserLoginStore uls,
User user)
LoginListener
logoutPerformed in interface LoginListener
public void failedLogin(UserLoginStore uls,
String location,
Exception exception)
LoginListener
failedLogin in interface LoginListenerlocation - denotes where the event occurredexception - is commonly either a DatabaseException or a FailedLoginExceptionDatabaseException,
FailedLoginException
public void checkTransactionActive()
throws TransactionException
TransactionException - if the transaction is not active
public <T extends DBEntry> Stub<T> getRandomStub(Class<T> type)
throws DatabaseException
DatabaseException
public <T extends DBEntry> T getRandomEntry(Class<T> type)
throws DatabaseException
DatabaseException
public <T extends DBEntry> T getRandomEntry(Class<T> type,
Filter<? super T> filter)
throws DatabaseException
DatabaseException
public <T> T query(Class<T> requiredReturnType,
Object context)
throws IOException,
IllegalArgumentException
queryStoreForInterface(Class, Class)
and also allows to effectively cast to the subclass.
query in interface QueryMechanismT - the required return typerequiredReturnType - specifies the return type that is needed for this operation;
if Object.class is given, any returned object is admissiblecontext - provides a context parameter for which the desired instance is to be returned.
Often (if no other meaningful context is required or applicable), it makes sense to pass a reference
to the calling object source; null may also be allowed
IOException - if any resource could not be acquired to fulfill the given query
IllegalArgumentException - if either parameter is generally not acceptable by the implementation
public <E extends DBEntry,I> I queryStoreForInterface(Class<E> type,
Class<I> desiredInterface)
WrappedDBClassStore instances for querying the interface from embedded stores
queryStoreForInterface in interface Database<S>type - the DBEntry-type of the DBClassStore that is to implement the desired interfacedesiredInterface - the class of the interface that the store is implementing
WrappedDBClassStore.exposesInterfaces()
@Warning(value="the returned interface may not be save to be used without proper transactional context")
public static <E extends DBEntry,I> I extractInterface(DBClassStore<E> store,
Class<I> desiredInterface)
WrappedDBClassStore.exposesInterfaces(),
queryStoreForInterface(Class, Class),
DBUtils.wrapTransactional(DBTransaction, Object, Class)
public <E extends DBEntry> void setVersioningEnabled(Class<E> type,
boolean flag)
DatabaseDBStoreListener will then receive
DBVersionedUpdateEvent objects instead of DBUpdateEvent objects
for database updates on such store.
setVersioningEnabled in interface Database<S>DBVersionedUpdateEvent
public <E extends DBEntry> boolean isVersioningEnabled(Class<E> type,
boolean flag)
public void close()
throws IOException
close in interface CloseableIOException
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||