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 booleanactiveWhether the transaction is active.protected booleanclosedprotected booleancommittingFlag for whether we are currently committing.protected ExecutionContextecprotected booleanrollbackOnlyWhether the transaction is only for roll-back.protected BooleanserializeReadWhether to serialise (lock) any read objects in this transaction.protected ResourcedTransactionManagertxnMgr-
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 voidaddTransactionEventListener(TransactionEventListener listener)Adds a transaction listener.voidbegin()Method to begin the transaction.voidbindTransactionEventListener(TransactionEventListener listener)Listeners that are never cleared, and invoked for all transactionsvoidclose()Method to inform the transaction that it is closed.voidcommit()Method to commit the transaction.voidend()Method to allow the transaction to flush any resources.voidflush()Method to flush the transaction.longgetBeginTime()Accessor for the time (millisecs) from System.currentTimeMillis when the transaction started.booleangetIsActive()Similar to "isActive" except that it just returns the "active" flag whereas the isActive() method can also embody rejoining to underlying transactions.booleangetNontransactionalRead()Accessor for the nontransactionalRead flag for this transaction.booleangetNontransactionalWrite()Accessor for the nontransactionalWrite flag for this transaction.booleangetNontransactionalWriteAutoCommit()Accessor for whether non-tx writes are auto-commit.booleangetOptimistic()Accessor for the Optimistic settingMap<String,Object>getOptions()Obtain all settings for this TransactionbooleangetRestoreValues()Accessor for the restoreValues flag for this transaction.booleangetRetainValues()Accessor for the retainValues flag for this transaction.booleangetRollbackOnly()Accessor for the "rollback only" flag.BooleangetSerializeRead()Accessor for the setting for whether to serialize read objects (lock them).javax.transaction.SynchronizationgetSynchronization()Accessor for the synchronization object to be notified on transaction completion.protected voidinternalBegin()Method to begin the transaction.protected voidinternalCommit()Internal commit, DataNucleus invokes it's own transaction manager implementation, if an external transaction manager is not used.protected voidinternalPostCommit()Method to perform any post-commit operations like calling the users "afterCompletion" and general clean up after the commit.protected voidinternalPreCommit()Method to perform any pre-commit operations like flushing to the datastore, calling the users "beforeCompletion", and general preparation for the commit.protected voidinternalPreRollback()protected voidinternalRollback()Internal rollback.booleanisActive()Accessor for whether the transaction is active.booleanisCommitting()Accessor for whether the transaction is comitting.voidpreFlush()Method to notify of preFlush.voidreleaseSavepoint(String name)Method to deregister the current position as a savepoint with the provided name (assuming the datastore supports it).voidremoveTransactionEventListener(TransactionEventListener listener)Removes the specified listener.voidrollback()Method to rollback the transaction.voidrollbackToSavepoint(String name)Method to rollback the transaction to the specified savepoint (assuming the datastore supports it).voidsetNontransactionalRead(boolean nontransactionalRead)Mutator for the setting of nontransactional read.voidsetNontransactionalWrite(boolean nontransactionalWrite)Mutator for the setting of nontransactional write.voidsetNontransactionalWriteAutoCommit(boolean autoCommit)Mutator for whether non-tx writes are auto-commit (false implies delayed til next transaction commit).voidsetOptimistic(boolean optimistic)Mutator for the optimistic transaction setting.voidsetOption(String option, boolean value)voidsetOption(String option, int value)voidsetOption(String option, Object value)voidsetOption(String option, String value)voidsetProperties(PropertyStore properties)voidsetRestoreValues(boolean restoreValues)Mutator for the setting of restore values.voidsetRetainValues(boolean retainValues)Mutator for the setting of retain values.voidsetRollbackOnly()Mutator for the "rollback only" flag.voidsetSavepoint(String name)Method to register the current position as a savepoint with the provided name (assuming the datastore supports it).voidsetSerializeRead(Boolean serializeRead)Mutator for whether to serialize (lock) any read objects in this transaction.voidsetSynchronization(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:TransactionAccessor for the time (millisecs) from System.currentTimeMillis when the transaction started.- Specified by:
getBeginTimein interfaceTransaction- Returns:
- Time at which the transaction started. -1 implies not yet started.
-
close
public void close()
Description copied from interface:TransactionMethod 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:
closein interfaceTransaction
-
begin
public void begin()
Method to begin the transaction.- Specified by:
beginin interfaceTransaction
-
internalBegin
protected void internalBegin()
Method to begin the transaction.
-
preFlush
public void preFlush()
Method to notify of preFlush.- Specified by:
preFlushin interfaceTransaction
-
flush
public void flush()
Method to flush the transaction.- Specified by:
flushin interfaceTransaction
-
end
public void end()
Method to allow the transaction to flush any resources.- Specified by:
endin interfaceTransaction
-
commit
public void commit()
Method to commit the transaction.- Specified by:
commitin 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:
rollbackin 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:
isActivein 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:
getIsActivein interfaceTransaction- Returns:
- The "active" flag
-
isCommitting
public boolean isCommitting()
Accessor for whether the transaction is comitting.- Specified by:
isCommittingin interfaceTransaction- Returns:
- Whether the transaction is committing.
-
getNontransactionalRead
public boolean getNontransactionalRead()
Accessor for the nontransactionalRead flag for this transaction.- Specified by:
getNontransactionalReadin interfaceTransaction- Returns:
- Whether nontransactionalRead is set.
-
getNontransactionalWrite
public boolean getNontransactionalWrite()
Accessor for the nontransactionalWrite flag for this transaction.- Specified by:
getNontransactionalWritein interfaceTransaction- Returns:
- Whether nontransactionalWrite is set.
-
getNontransactionalWriteAutoCommit
public boolean getNontransactionalWriteAutoCommit()
Accessor for whether non-tx writes are auto-commit.- Specified by:
getNontransactionalWriteAutoCommitin interfaceTransaction- Returns:
- Whether auto-committing non-tx writes.
-
getOptimistic
public boolean getOptimistic()
Accessor for the Optimistic setting- Specified by:
getOptimisticin interfaceTransaction- Returns:
- Whether optimistic transactions are in operation.
-
getRestoreValues
public boolean getRestoreValues()
Accessor for the restoreValues flag for this transaction.- Specified by:
getRestoreValuesin interfaceTransaction- Returns:
- Whether restoreValues is set.
-
getRetainValues
public boolean getRetainValues()
Accessor for the retainValues flag for this transaction.- Specified by:
getRetainValuesin interfaceTransaction- Returns:
- Whether retainValues is set.
-
getRollbackOnly
public boolean getRollbackOnly()
Accessor for the "rollback only" flag.- Specified by:
getRollbackOnlyin 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:
getSynchronizationin 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:
setNontransactionalReadin interfaceTransaction- Parameters:
nontransactionalRead- Whether to allow nontransactional read operations
-
setNontransactionalWrite
public void setNontransactionalWrite(boolean nontransactionalWrite)
Mutator for the setting of nontransactional write.- Specified by:
setNontransactionalWritein 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:
setNontransactionalWriteAutoCommitin interfaceTransaction- Parameters:
autoCommit- Whether auto-commit of non-tx writes
-
setOptimistic
public void setOptimistic(boolean optimistic)
Mutator for the optimistic transaction setting.- Specified by:
setOptimisticin interfaceTransaction- Parameters:
optimistic- The optimistic transaction setting.
-
setRestoreValues
public void setRestoreValues(boolean restoreValues)
Mutator for the setting of restore values.- Specified by:
setRestoreValuesin interfaceTransaction- Parameters:
restoreValues- Whether to restore values at commit
-
setRetainValues
public void setRetainValues(boolean retainValues)
Mutator for the setting of retain values.- Specified by:
setRetainValuesin 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:
setRollbackOnlyin interfaceTransaction
-
setSavepoint
public void setSavepoint(String name)
Description copied from interface:TransactionMethod to register the current position as a savepoint with the provided name (assuming the datastore supports it).- Specified by:
setSavepointin interfaceTransaction- Parameters:
name- Savepoint name
-
releaseSavepoint
public void releaseSavepoint(String name)
Description copied from interface:TransactionMethod to deregister the current position as a savepoint with the provided name (assuming the datastore supports it).- Specified by:
releaseSavepointin interfaceTransaction- Parameters:
name- Savepoint name
-
rollbackToSavepoint
public void rollbackToSavepoint(String name)
Description copied from interface:TransactionMethod to rollback the transaction to the specified savepoint (assuming the datastore supports it).- Specified by:
rollbackToSavepointin 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:
setSynchronizationin interfaceTransaction- Parameters:
sync- The synchronization object to be notified on transaction completion
-
addTransactionEventListener
public void addTransactionEventListener(TransactionEventListener listener)
Description copied from interface:TransactionAdds a transaction listener. After commit or rollback, listeners are cleared- Specified by:
addTransactionEventListenerin interfaceTransaction- Parameters:
listener- The listener to add
-
removeTransactionEventListener
public void removeTransactionEventListener(TransactionEventListener listener)
Description copied from interface:TransactionRemoves the specified listener.- Specified by:
removeTransactionEventListenerin interfaceTransaction- Parameters:
listener- Listener to remove
-
bindTransactionEventListener
public void bindTransactionEventListener(TransactionEventListener listener)
Description copied from interface:TransactionListeners that are never cleared, and invoked for all transactions- Specified by:
bindTransactionEventListenerin interfaceTransaction- Parameters:
listener- listener to bind
-
getSerializeRead
public Boolean getSerializeRead()
Description copied from interface:TransactionAccessor for the setting for whether to serialize read objects (lock them).- Specified by:
getSerializeReadin interfaceTransaction- Returns:
- the value of the serializeRead property
-
setSerializeRead
public void setSerializeRead(Boolean serializeRead)
Description copied from interface:TransactionMutator for whether to serialize (lock) any read objects in this transaction.- Specified by:
setSerializeReadin interfaceTransaction- Parameters:
serializeRead- Whether to serialise (lock) any read objects
-
getOptions
public Map<String,Object> getOptions()
Description copied from interface:TransactionObtain all settings for this Transaction- Specified by:
getOptionsin interfaceTransaction- Returns:
- a map with settings
-
setOption
public void setOption(String option, int value)
- Specified by:
setOptionin interfaceTransaction
-
setOption
public void setOption(String option, boolean value)
- Specified by:
setOptionin interfaceTransaction
-
setOption
public void setOption(String option, String value)
- Specified by:
setOptionin interfaceTransaction
-
setOption
public void setOption(String option, Object value)
- Specified by:
setOptionin interfaceTransaction
-
setProperties
public void setProperties(PropertyStore properties)
-
-