Transaction

public abstract class Transaction<C extends TransactionContainer> extends AbstractObservable implements EntityTransactionInterface, UseCacheResource

Abstract base implementation for all EntityTransactions (Transaction involving entities).

Handles caching, benchmark timing, the access to the back end, generates and checks entity ids, holds the state of the transaction and triggers the scheduler to run the jobs.

Author:

Timm Fitschen

Fields

CLEAN_UP

public static final String CLEAN_UP

idRegistry

protected EntityIdRegistry idRegistry

Constructors

Transaction

protected Transaction(C container)

Transaction

protected Transaction(C container, Observer o)

Methods

check

protected final void check()

See also: {@link.execute()}

cleanUp

protected abstract void cleanUp()

See also: {@link.execute()}

commit

protected void commit()

See also: {@link.execute()}

execute

public final void execute()

The main transaction execution method.

This method calls the following other internal methods and scheduled jobs stored in the internal Schedule object:

  1. init - Make Schedule, resolve names to ids, aquire read access.

  2. Schedule.runJobs(INIT) - See TransactionStage.INIT.

  3. preCheck - Load/generate EntityACLs, check if any updates are to be processed.

  4. Schedule.runJobs(PRE_CHECK) - See TransactionStage.PRE_CHECK.

  5. check - only run the jobs in the CHECK stage, see TransactionStage.CHECK.

  6. Schedule.runJobs(POST_CHECK) - See TransactionStage.POST_CHECK.

  7. postCheck - currently, nothing happens here (just there for consistency).

  8. preTransaction - acquire write access (if necessary)

  9. Schedule.runJobs(PRE_TRANSACTION) - See TransactionStage.PRE_TRANSACTION.

  10. transaction: This is typically the main method of a Transaction.

  11. Schedule.runJobs(POST_TRANSACTION) - See TransactionStage.POST_TRANSACTION.

  12. postTransaction - Add success messages

  13. writeHistory - write the transaction history logs

  14. commit - commit the changes

  15. rollBack: Only in the case of errors - rollback any changes (also file-system changes).

  16. cleanUp: Always - cleanup the transaction (e.g. remove temporary files).

  17. notifyObservers(CLEAN_UP): Also always - for any jobs that do their own clean-up.

See also: {@linkTransactionStage}.

getAccess

public final Access getAccess()

getAccessManager

public static DatabaseAccessManager getAccessManager()

getCache

public <S, T> Map<S, T> getCache(String name)

getContainer

public C getContainer()

getSchedule

public Schedule getSchedule()

Return the internal Schedule object.

The Schedule stores jobs which are also triggered by this transaction (see execute() for details).

getTimestamp

public UTCDateTime getTimestamp()

getTransactionBenchmark

public TransactionBenchmark getTransactionBenchmark()

getTransactor

public Subject getTransactor()

getUseCacheResourceDelegate

public UseCacheResource getUseCacheResourceDelegate()

init

protected abstract void init()

See also: {@link.execute()}

logHistory

public abstract boolean logHistory()

Return true iff this transaction should be logged in the transaction history logs.

makeSchedule

protected void makeSchedule()

Implementation note: Not called in this class, but may be used by subclasses.

E.g. in Retrieve and WriteTransaction.

matchIdPattern

public boolean matchIdPattern(String id)

postCheck

protected abstract void postCheck()

See also: {@link.execute()}

postTransaction

protected abstract void postTransaction()

See also: {@link.execute()}

preCheck

protected abstract void preCheck()

See also: {@link.execute()}

preTransaction

protected abstract void preTransaction()

See also: {@link.execute()}

rollBack

protected void rollBack()

See also: {@link.execute()}

setAccess

protected void setAccess(Access a)

setUseCacheResourceDelegate

public void setUseCacheResourceDelegate(UseCacheResource delegate)

transaction

protected abstract void transaction()

See also: {@link.execute()}