|
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.TransactionalNumberGenerator
public class TransactionalNumberGenerator
provides a wrapper around a given number generator that provides a counter that can increment and cache its generated values within a running transaction without having to make the potentially expensive call to the embedded ValueRetriever. In addition, this class implements various related interfaces to allow for flexible usage.
SQLNumberGenerator| Constructor Summary | |
|---|---|
TransactionalNumberGenerator(ValueRetriever<Long> numberGenerator,
DBTransaction tx)
|
|
| Method Summary | |
|---|---|
Long |
createInstance(EventObject eo)
calls getRelevantValue() |
TransactionListener |
enableUpdateOnFinishTransaction(ValueSetter<Long> setter)
calling this method will add a TransactionListener to the database that will call the given setter with the current count if this instance is 'dirty' upon finishTransaction. |
protected long |
generateNewCount()
this method requires to be synchronized on the transaction |
Object |
generateNewID(Class<? extends DBEntry> entryClass)
calls getRelevantValue() |
Long |
getCurrentCount()
may return -1 if getRelevantValue() has never been called |
Long |
getRelevantValue()
calls generateNewCount() in a transactionally synchronized context |
DBTransaction |
getTransaction()
|
boolean |
isDirty()
the instance is 'dirty' if getRelevantValue() was called and returned
a cached value that was not directly retrieved from the embedded NumberGenerator |
ValueRetriever<Long> |
unwrap()
returns the embedded instance that this wrapper encloses |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TransactionalNumberGenerator(ValueRetriever<Long> numberGenerator,
DBTransaction tx)
| Method Detail |
|---|
public DBTransaction getTransaction()
public ValueRetriever<Long> unwrap()
Wrapped
unwrap in interface Wrapped<ValueRetriever<Long>>public boolean isDirty()
getRelevantValue() was called and returned
a cached value that was not directly retrieved from the embedded NumberGenerator
getCurrentCount()public TransactionListener enableUpdateOnFinishTransaction(ValueSetter<Long> setter)
TransactionListener.finishTransaction(DBTransaction),
isDirty(),
getCurrentCount()
protected long generateNewCount()
throws IOException
IOExceptionpublic Long getCurrentCount()
getRelevantValue() has never been called
isDirty()
public Long getRelevantValue()
throws DatabaseException
generateNewCount() in a transactionally synchronized context
getRelevantValue in interface ValueRetriever<Long>DatabaseException
public Long createInstance(EventObject eo)
throws Exception
getRelevantValue()
createInstance in interface Factory<Long>eo - the event that triggered this instance creation; normally, this method
should also cope with the event to be null.
Exception
public Object generateNewID(Class<? extends DBEntry> entryClass)
throws DatabaseException
getRelevantValue()
generateNewID in interface IDFactoryDatabaseException
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||