Package org.datanucleus.transaction
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. SeeTransaction
. This is not thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
active
Whether the transaction is active.protected boolean
closed
protected boolean
committing
Flag for whether we are currently committing.protected ExecutionContext
ec
protected boolean
rollbackOnly
Whether the transaction is only for roll-back.protected Boolean
serializeRead
Whether to serialise (lock) any read objects in this transaction.protected ResourcedTransactionManager
txnMgr
-
Fields inherited from interface org.datanucleus.transaction.Transaction
TRANSACTION_ISOLATION_OPTION
-
-
Constructor Summary
Constructors Constructor Description TransactionImpl(ExecutionContext ec, PropertyStore properties)
Constructor for a transaction for the specified ExecutionContext.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTransactionEventListener(TransactionEventListener listener)
Adds a transaction listener.void
begin()
Method to begin the transaction.void
bindTransactionEventListener(TransactionEventListener listener)
Listeners that are never cleared, and invoked for all transactionsvoid
close()
Method to inform the transaction that it is closed.void
commit()
Method to commit the transaction.void
end()
Method to allow the transaction to flush any resources.void
flush()
Method to flush the transaction.long
getBeginTime()
Accessor for the time (millisecs) from System.currentTimeMillis when the transaction started.boolean
getIsActive()
Similar to "isActive" except that it just returns the "active" flag whereas the isActive() method can also embody rejoining to underlying transactions.boolean
getNontransactionalRead()
Accessor for the nontransactionalRead flag for this transaction.boolean
getNontransactionalWrite()
Accessor for the nontransactionalWrite flag for this transaction.boolean
getNontransactionalWriteAutoCommit()
Accessor for whether non-tx writes are auto-commit.boolean
getOptimistic()
Accessor for the Optimistic settingMap<String,Object>
getOptions()
Obtain all settings for this Transactionboolean
getRestoreValues()
Accessor for the restoreValues flag for this transaction.boolean
getRetainValues()
Accessor for the retainValues flag for this transaction.boolean
getRollbackOnly()
Accessor for the "rollback only" flag.Boolean
getSerializeRead()
Accessor for the setting for whether to serialize read objects (lock them).javax.transaction.Synchronization
getSynchronization()
Accessor for the synchronization object to be notified on transaction completion.protected void
internalBegin()
Method to begin the transaction.protected void
internalCommit()
Internal commit, DataNucleus invokes it's own transaction manager implementation, if an external transaction manager is not used.protected void
internalPostCommit()
Method to perform any post-commit operations like calling the users "afterCompletion" and general clean up after the commit.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.protected void
internalPreRollback()
protected void
internalRollback()
Internal rollback.boolean
isActive()
Accessor for whether the transaction is active.boolean
isCommitting()
Accessor for whether the transaction is comitting.void
preFlush()
Method to notify of preFlush.void
releaseSavepoint(String name)
Method to deregister the current position as a savepoint with the provided name (assuming the datastore supports it).void
removeTransactionEventListener(TransactionEventListener listener)
Removes the specified listener.void
rollback()
Method to rollback the transaction.void
rollbackToSavepoint(String name)
Method to rollback the transaction to the specified savepoint (assuming the datastore supports it).void
setNontransactionalRead(boolean nontransactionalRead)
Mutator for the setting of nontransactional read.void
setNontransactionalWrite(boolean nontransactionalWrite)
Mutator for the setting of nontransactional write.void
setNontransactionalWriteAutoCommit(boolean autoCommit)
Mutator for whether non-tx writes are auto-commit (false implies delayed til next transaction commit).void
setOptimistic(boolean optimistic)
Mutator for the optimistic transaction setting.void
setOption(String option, boolean value)
void
setOption(String option, int value)
void
setOption(String option, Object value)
void
setOption(String option, String value)
void
setProperties(PropertyStore properties)
void
setRestoreValues(boolean restoreValues)
Mutator for the setting of restore values.void
setRetainValues(boolean retainValues)
Mutator for the setting of retain values.void
setRollbackOnly()
Mutator for the "rollback only" flag.void
setSavepoint(String name)
Method to register the current position as a savepoint with the provided name (assuming the datastore supports it).void
setSerializeRead(Boolean serializeRead)
Mutator for whether to serialize (lock) any read objects in this transaction.void
setSynchronization(javax.transaction.Synchronization sync)
Mutator for the synchronization object to be notified on transaction completion.
-
-
-
Field Detail
-
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.
-
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.
-
closed
protected boolean closed
-
-
Constructor Detail
-
TransactionImpl
public TransactionImpl(ExecutionContext ec, PropertyStore properties)
Constructor for a transaction for the specified ExecutionContext.- Parameters:
ec
- ExecutionContextproperties
- Properties to use with the transaction
-
-
Method Detail
-
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 interfaceTransaction
- 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 interfaceTransaction
-
begin
public void begin()
Method to begin the transaction.- Specified by:
begin
in interfaceTransaction
-
internalBegin
protected void internalBegin()
Method to begin the transaction.
-
preFlush
public void preFlush()
Method to notify of preFlush.- Specified by:
preFlush
in interfaceTransaction
-
flush
public void flush()
Method to flush the transaction.- Specified by:
flush
in interfaceTransaction
-
end
public void end()
Method to allow the transaction to flush any resources.- Specified by:
end
in interfaceTransaction
-
commit
public void commit()
Method to commit the transaction.- Specified by:
commit
in interfaceTransaction
-
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 interfaceTransaction
-
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.
-
isActive
public boolean isActive()
Accessor for whether the transaction is active.- Specified by:
isActive
in interfaceTransaction
- 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 interfaceTransaction
- Returns:
- The "active" flag
-
isCommitting
public boolean isCommitting()
Accessor for whether the transaction is comitting.- Specified by:
isCommitting
in interfaceTransaction
- Returns:
- Whether the transaction is committing.
-
getNontransactionalRead
public boolean getNontransactionalRead()
Accessor for the nontransactionalRead flag for this transaction.- Specified by:
getNontransactionalRead
in interfaceTransaction
- Returns:
- Whether nontransactionalRead is set.
-
getNontransactionalWrite
public boolean getNontransactionalWrite()
Accessor for the nontransactionalWrite flag for this transaction.- Specified by:
getNontransactionalWrite
in interfaceTransaction
- Returns:
- Whether nontransactionalWrite is set.
-
getNontransactionalWriteAutoCommit
public boolean getNontransactionalWriteAutoCommit()
Accessor for whether non-tx writes are auto-commit.- Specified by:
getNontransactionalWriteAutoCommit
in interfaceTransaction
- Returns:
- Whether auto-committing non-tx writes.
-
getOptimistic
public boolean getOptimistic()
Accessor for the Optimistic setting- Specified by:
getOptimistic
in interfaceTransaction
- Returns:
- Whether optimistic transactions are in operation.
-
getRestoreValues
public boolean getRestoreValues()
Accessor for the restoreValues flag for this transaction.- Specified by:
getRestoreValues
in interfaceTransaction
- Returns:
- Whether restoreValues is set.
-
getRetainValues
public boolean getRetainValues()
Accessor for the retainValues flag for this transaction.- Specified by:
getRetainValues
in interfaceTransaction
- Returns:
- Whether retainValues is set.
-
getRollbackOnly
public boolean getRollbackOnly()
Accessor for the "rollback only" flag.- Specified by:
getRollbackOnly
in interfaceTransaction
- Returns:
- The rollback only flag
-
getSynchronization
public javax.transaction.Synchronization getSynchronization()
Accessor for the synchronization object to be notified on transaction completion.- Specified by:
getSynchronization
in interfaceTransaction
- 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 interfaceTransaction
- 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 interfaceTransaction
- 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 interfaceTransaction
- 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 interfaceTransaction
- Parameters:
optimistic
- The optimistic transaction setting.
-
setRestoreValues
public void setRestoreValues(boolean restoreValues)
Mutator for the setting of restore values.- Specified by:
setRestoreValues
in interfaceTransaction
- 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 interfaceTransaction
- 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 interfaceTransaction
-
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 interfaceTransaction
- 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 interfaceTransaction
- 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 interfaceTransaction
- Parameters:
name
- Savepoint name
-
setSynchronization
public void setSynchronization(javax.transaction.Synchronization sync)
Mutator for the synchronization object to be notified on transaction completion.- Specified by:
setSynchronization
in interfaceTransaction
- 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 interfaceTransaction
- 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 interfaceTransaction
- 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 interfaceTransaction
- 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 interfaceTransaction
- 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 interfaceTransaction
- 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 interfaceTransaction
- Returns:
- a map with settings
-
setOption
public void setOption(String option, int value)
- Specified by:
setOption
in interfaceTransaction
-
setOption
public void setOption(String option, boolean value)
- Specified by:
setOption
in interfaceTransaction
-
setOption
public void setOption(String option, String value)
- Specified by:
setOption
in interfaceTransaction
-
setOption
public void setOption(String option, Object value)
- Specified by:
setOption
in interfaceTransaction
-
setProperties
public void setProperties(PropertyStore properties)
-
-