Class TransactionImpl

java.lang.Object
org.datanucleus.transaction.TransactionImpl
All Implemented Interfaces:
Transaction
Direct Known Subclasses:
JTAJCATransactionImpl, JTATransactionImpl

public class TransactionImpl extends Object implements Transaction
Implementation of a (local) transaction for an ExecutionContext, for a datastore. See Transaction. This is not thread-safe.
  • Field Details

    • ec

      protected ExecutionContext ec
    • txnMgr

      protected ResourcedTransactionManager txnMgr
    • active

      protected boolean active
      Whether the transaction is active.
    • committing

      protected boolean committing
      Flag for whether we are currently committing.
    • sync

      Synchronisation object, for committing and rolling back. Only for JDO.
    • rollbackOnly

      protected boolean rollbackOnly
      Whether the transaction is only for roll-back.
    • serializeRead

      protected Boolean serializeRead
      Whether to serialise (lock) any read objects in this transaction.
    • listenersPerTransaction

      private Set<TransactionEventListener> listenersPerTransaction
      Listeners for the lifecycle of the active transaction.
    • ecListener

      private TransactionEventListener ecListener
      Listener to inform the ExecutionContext of transaction events.
    • userListeners

      private List<TransactionEventListener> userListeners
      Listeners that apply to all transactions.
    • options

      private Map<String,Object> options
    • beginTime

      long beginTime
      start time of the transaction
    • closed

      protected boolean closed
    • properties

      private PropertyStore properties
  • Constructor Details

    • TransactionImpl

      public TransactionImpl(ExecutionContext ec, PropertyStore properties)
      Constructor for a transaction for the specified ExecutionContext.
      Parameters:
      ec - ExecutionContext
      properties - Properties to use with the transaction
  • Method Details

    • getBeginTime

      public long getBeginTime()
      Description copied from interface: Transaction
      Accessor for the time (millisecs) from System.currentTimeMillis when the transaction started.
      Specified by:
      getBeginTime in interface Transaction
      Returns:
      Time at which the transaction started. -1 implies not yet started.
    • close

      public void close()
      Description copied from interface: Transaction
      Method to inform the transaction that it is closed. This is only necessary for JBoss usage of JPA where it doesn't bother calling afterCompletion on the JTA txn until after it closes the EntityManager so we need a hook to inform the transaction that it is closed so ignore any subsequent afterCompletion.
      Specified by:
      close in interface Transaction
    • begin

      public void begin()
      Method to begin the transaction.
      Specified by:
      begin in interface Transaction
    • internalBegin

      protected void internalBegin()
      Method to begin the transaction.
    • preFlush

      public void preFlush()
      Method to notify of preFlush.
      Specified by:
      preFlush in interface Transaction
    • flush

      public void flush()
      Method to flush the transaction.
      Specified by:
      flush in interface Transaction
    • end

      public void end()
      Method to allow the transaction to flush any resources.
      Specified by:
      end in interface Transaction
    • commit

      public void commit()
      Method to commit the transaction.
      Specified by:
      commit in interface Transaction
    • internalPreCommit

      protected void internalPreCommit()
      Method to perform any pre-commit operations like flushing to the datastore, calling the users "beforeCompletion", and general preparation for the commit.
    • internalCommit

      protected void internalCommit()
      Internal commit, DataNucleus invokes it's own transaction manager implementation, if an external transaction manager is not used.
    • rollback

      public void rollback()
      Method to rollback the transaction.
      Specified by:
      rollback in interface Transaction
    • internalPreRollback

      protected void internalPreRollback()
    • internalRollback

      protected void internalRollback()
      Internal rollback. DataNucleus invokes it's own transaction manager implementation, if an external transaction manager is not used.
    • internalPostCommit

      protected void internalPostCommit()
      Method to perform any post-commit operations like calling the users "afterCompletion" and general clean up after the commit.
    • getListenersForEvent

      private TransactionEventListener[] getListenersForEvent()
    • isActive

      public boolean isActive()
      Accessor for whether the transaction is active.
      Specified by:
      isActive in interface Transaction
      Returns:
      Whether the transaction is active.
    • getIsActive

      public boolean getIsActive()
      Similar to "isActive" except that it just returns the "active" flag whereas the isActive() method can also embody rejoining to underlying transactions.
      Specified by:
      getIsActive in interface Transaction
      Returns:
      The "active" flag
    • isCommitting

      public boolean isCommitting()
      Accessor for whether the transaction is comitting.
      Specified by:
      isCommitting in interface Transaction
      Returns:
      Whether the transaction is committing.
    • getNontransactionalRead

      public boolean getNontransactionalRead()
      Accessor for the nontransactionalRead flag for this transaction.
      Specified by:
      getNontransactionalRead in interface Transaction
      Returns:
      Whether nontransactionalRead is set.
    • getNontransactionalWrite

      public boolean getNontransactionalWrite()
      Accessor for the nontransactionalWrite flag for this transaction.
      Specified by:
      getNontransactionalWrite in interface Transaction
      Returns:
      Whether nontransactionalWrite is set.
    • getNontransactionalWriteAutoCommit

      public boolean getNontransactionalWriteAutoCommit()
      Accessor for whether non-tx writes are auto-commit.
      Specified by:
      getNontransactionalWriteAutoCommit in interface Transaction
      Returns:
      Whether auto-committing non-tx writes.
    • getOptimistic

      public boolean getOptimistic()
      Accessor for the Optimistic setting
      Specified by:
      getOptimistic in interface Transaction
      Returns:
      Whether optimistic transactions are in operation.
    • getRestoreValues

      public boolean getRestoreValues()
      Accessor for the restoreValues flag for this transaction.
      Specified by:
      getRestoreValues in interface Transaction
      Returns:
      Whether restoreValues is set.
    • getRetainValues

      public boolean getRetainValues()
      Accessor for the retainValues flag for this transaction.
      Specified by:
      getRetainValues in interface Transaction
      Returns:
      Whether retainValues is set.
    • getRollbackOnly

      public boolean getRollbackOnly()
      Accessor for the "rollback only" flag.
      Specified by:
      getRollbackOnly in interface Transaction
      Returns:
      The rollback only flag
    • getSynchronization

      public Synchronization getSynchronization()
      Accessor for the synchronization object to be notified on transaction completion.
      Specified by:
      getSynchronization in interface Transaction
      Returns:
      The synchronization instance to be notified on transaction completion.
    • setNontransactionalRead

      public void setNontransactionalRead(boolean nontransactionalRead)
      Mutator for the setting of nontransactional read.
      Specified by:
      setNontransactionalRead in interface Transaction
      Parameters:
      nontransactionalRead - Whether to allow nontransactional read operations
    • setNontransactionalWrite

      public void setNontransactionalWrite(boolean nontransactionalWrite)
      Mutator for the setting of nontransactional write.
      Specified by:
      setNontransactionalWrite in interface Transaction
      Parameters:
      nontransactionalWrite - Whether to allow nontransactional write operations
    • setNontransactionalWriteAutoCommit

      public void setNontransactionalWriteAutoCommit(boolean autoCommit)
      Mutator for whether non-tx writes are auto-commit (false implies delayed til next transaction commit).
      Specified by:
      setNontransactionalWriteAutoCommit in interface Transaction
      Parameters:
      autoCommit - Whether auto-commit of non-tx writes
    • setOptimistic

      public void setOptimistic(boolean optimistic)
      Mutator for the optimistic transaction setting.
      Specified by:
      setOptimistic in interface Transaction
      Parameters:
      optimistic - The optimistic transaction setting.
    • setRestoreValues

      public void setRestoreValues(boolean restoreValues)
      Mutator for the setting of restore values.
      Specified by:
      setRestoreValues in interface Transaction
      Parameters:
      restoreValues - Whether to restore values at commit
    • setRetainValues

      public void setRetainValues(boolean retainValues)
      Mutator for the setting of retain values.
      Specified by:
      setRetainValues in interface Transaction
      Parameters:
      retainValues - Whether to retain values at commit
    • setRollbackOnly

      public void setRollbackOnly()
      Mutator for the "rollback only" flag. Sets the transaction as for rollback only.
      Specified by:
      setRollbackOnly in interface Transaction
    • setSavepoint

      public void setSavepoint(String name)
      Description copied from interface: Transaction
      Method to register the current position as a savepoint with the provided name (assuming the datastore supports it).
      Specified by:
      setSavepoint in interface Transaction
      Parameters:
      name - Savepoint name
    • releaseSavepoint

      public void releaseSavepoint(String name)
      Description copied from interface: Transaction
      Method to deregister the current position as a savepoint with the provided name (assuming the datastore supports it).
      Specified by:
      releaseSavepoint in interface Transaction
      Parameters:
      name - Savepoint name
    • rollbackToSavepoint

      public void rollbackToSavepoint(String name)
      Description copied from interface: Transaction
      Method to rollback the transaction to the specified savepoint (assuming the datastore supports it).
      Specified by:
      rollbackToSavepoint in interface Transaction
      Parameters:
      name - Savepoint name
    • setSynchronization

      public void setSynchronization(Synchronization sync)
      Mutator for the synchronization object to be notified on transaction completion.
      Specified by:
      setSynchronization in interface Transaction
      Parameters:
      sync - The synchronization object to be notified on transaction completion
    • addTransactionEventListener

      public void addTransactionEventListener(TransactionEventListener listener)
      Description copied from interface: Transaction
      Adds a transaction listener. After commit or rollback, listeners are cleared
      Specified by:
      addTransactionEventListener in interface Transaction
      Parameters:
      listener - The listener to add
    • removeTransactionEventListener

      public void removeTransactionEventListener(TransactionEventListener listener)
      Description copied from interface: Transaction
      Removes the specified listener.
      Specified by:
      removeTransactionEventListener in interface Transaction
      Parameters:
      listener - Listener to remove
    • bindTransactionEventListener

      public void bindTransactionEventListener(TransactionEventListener listener)
      Description copied from interface: Transaction
      Listeners that are never cleared, and invoked for all transactions
      Specified by:
      bindTransactionEventListener in interface Transaction
      Parameters:
      listener - listener to bind
    • getSerializeRead

      public Boolean getSerializeRead()
      Description copied from interface: Transaction
      Accessor for the setting for whether to serialize read objects (lock them).
      Specified by:
      getSerializeRead in interface Transaction
      Returns:
      the value of the serializeRead property
    • setSerializeRead

      public void setSerializeRead(Boolean serializeRead)
      Description copied from interface: Transaction
      Mutator for whether to serialize (lock) any read objects in this transaction.
      Specified by:
      setSerializeRead in interface Transaction
      Parameters:
      serializeRead - Whether to serialise (lock) any read objects
    • getOptions

      public Map<String,Object> getOptions()
      Description copied from interface: Transaction
      Obtain all settings for this Transaction
      Specified by:
      getOptions in interface Transaction
      Returns:
      a map with settings
    • setOption

      public void setOption(String option, int value)
      Specified by:
      setOption in interface Transaction
    • setOption

      public void setOption(String option, boolean value)
      Specified by:
      setOption in interface Transaction
    • setOption

      public void setOption(String option, String value)
      Specified by:
      setOption in interface Transaction
    • setOption

      public void setOption(String option, Object value)
      Specified by:
      setOption in interface Transaction
    • setProperties

      public void setProperties(PropertyStore properties)