Holger's
Java API

com.antelmann.db
Class ReadOnlyStore<T extends DBEntry>

java.lang.Object
  extended by com.antelmann.db.WrappedDBClassStore<T>
      extended by com.antelmann.db.ReadOnlyStore<T>
All Implemented Interfaces:
DBClassStore<T>, ProcessedFilterOption<T>, TransactionRequired, ProcessorHook<T,DatabaseException>, Wrapped<DBClassStore<T>>

public class ReadOnlyStore<T extends DBEntry>
extends WrappedDBClassStore<T>

a wrapper around a DBClassStore that disables altering the store's content

Since:
20. September 2007, 17:44
Author:
Holger Antelmann

Nested Class Summary
 
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
ReadOnlyStore(DBClassStore<T> store)
          calls this(store, false)
ReadOnlyStore(DBClassStore<T> store, boolean allowGenerateNewID)
          if allowGenerateNewID is true, the method generateNewID() will delegate to the embedded store
 
Method Summary
 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.
 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.WrappedDBClassStore
add, checkReadAccess, checkWriteAccess, containsID, deleteEntriesIndividually, exposesInterfaces, fetch, fetchStubs, getAccessFilter, getAccessStubFilter, getDatabase, getEntry, getEntryClass, getFetchProcessor, getPreStoreHandler, getStoreHandler, getStub, getStubProcessor, isApplyFilterProcessingRecursively, isDeleteEntriesIndividually, isEnsureTransactionsOnFetch, isProcessBeforeFiltering, queryForInterface, remove, setAccessFilter, setAccessStubFilter, setApplyFilterProcessingRecursively, setDeleteEntriesIndividually, setEnsureTransactionsOnFetch, setExposesInterfaces, setFetchProcessor, setPreStoreHandler, setProcessBeforeFiltering, setProcessBeforeFiltering, setStoreHandler, setStubProcessor, size, unwrap, wrapFilterForProcessing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReadOnlyStore

public ReadOnlyStore(DBClassStore<T> store)
calls this(store, false)


ReadOnlyStore

public ReadOnlyStore(DBClassStore<T> store,
                     boolean allowGenerateNewID)
if allowGenerateNewID is true, the method generateNewID() will delegate to the embedded store

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.

Specified by:
deleteEntry in interface DBClassStore<T extends DBEntry>
Overrides:
deleteEntry in class WrappedDBClassStore<T extends DBEntry>
Returns:
true only if the DBEntry with the given ID was actually found and deleted.
Throws:
DatabaseException

deleteEntries

public int deleteEntries(Filter<? super T> filter)
                  throws DatabaseException
Description copied from interface: DBClassStore
deletes all DBEntry objects that match the given filter; if the filter is null, all resources are deleted. Calling this method does not necessarily entail that DBClassStore.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.

Specified by:
deleteEntries in interface DBClassStore<T extends DBEntry>
Overrides:
deleteEntries in class WrappedDBClassStore<T extends DBEntry>
Returns:
the number of objects that were deleted
Throws:
DatabaseException
See Also:
WrappedDBClassStore.setProcessBeforeFiltering(boolean)

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.

Specified by:
insert in interface DBClassStore<T extends DBEntry>
Overrides:
insert in class WrappedDBClassStore<T extends DBEntry>
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.

Specified by:
generateNewID in interface DBClassStore<T extends DBEntry>
Overrides:
generateNewID in class WrappedDBClassStore<T extends DBEntry>
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.

Specified by:
insertAsNew in interface DBClassStore<T extends DBEntry>
Overrides:
insertAsNew in class WrappedDBClassStore<T extends DBEntry>
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,
                   IllegalArgumentException
Description copied from interface: DBClassStore
updates the given entry in the database.

Specified by:
update in interface DBClassStore<T extends DBEntry>
Overrides:
update in class WrappedDBClassStore<T extends DBEntry>
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
IllegalArgumentException


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