Class TransactionImpl
- java.lang.Object
-
- com.sun.jdo.spi.persistence.support.sqlstore.impl.TransactionImpl
-
- All Implemented Interfaces:
Transaction,Transaction,jakarta.transaction.Synchronization
public class TransactionImpl extends Object implements Transaction
The Transaction interface allows operations to be performed against the transaction in the target Transaction object. A Transaction object is created corresponding to each global transaction creation. The Transaction object can be used for resource enlistment, synchronization registration, transaction completion and status query operations. This implementation is completely internal. All externally documented methods are on the Transaction interface. Note on synchronized(this): There are a number of places that calls are made outside the transaction system. For example, Synchronization.beforeCompletion() and XAResource.start(). It is important that no locks are held when these callbacks are made. This requires more state checking up return from these calls, and the methods are careful to check state transitions after release the lock and reacquiring it. Also be careful NOT to call into a lower method with the lock, if that method may call out of the transaction system. Take care if you make methods "synchronized" because: synchronized methodName() is not the same lock as a more localized: synchronized(this) This is tested in the regression tests (see "Lock Test")
-
-
Field Summary
Fields Modifier and Type Field Description static intBMT_JDOstatic intBMT_UTstatic intCMTstatic intNON_MGDPossible values of txTypestatic intTRAN_DEFAULT_TIMEOUTstatic intTRAN_MAX_THREADS
-
Constructor Summary
Constructors Constructor Description TransactionImpl(PersistenceManager pm, String username, char[] password, int seconds)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterCompletion(int st)Called in the managed environment only for transaction completionvoidbeforeCompletion()Called in the managed environment only for transaction completionvoidbegin()Begin a transaction.voidbegin(jakarta.transaction.Transaction t)Begin a transaction in managed environmentvoidcommit()Commit the transaction represented by this Transaction objectConnectiongetConnection()Returns a Connection.booleangetNontransactionalRead()If this flag is set to true, then queries and navigation are allowed without an active transactionbooleangetOptimistic()Optimistic transactions do not hold data store locks until commit time.PersistenceManagergetPersistenceManager()Returns PersistenceManager associated with this transactionintgetQueryTimeout()Gets the number of seconds to wait for a query statement to execute in the datastore associated with this Transaction instancebooleangetRestoreValues()If true, at rollback time instances restore their field values.booleangetRetainValues()If true, at commit time instances retain their field values.intgetStatus()Obtain the status of this transaction object.jakarta.transaction.SynchronizationgetSynchronization()The user-specified Synchronization instance for this Transaction instance.intgetTransactionType()intgetUpdateTimeout()Gets the number of seconds to wait for an update statement to execute in the datastore associated with this Transaction instancebooleanisActive()Returns whether there is a transaction currently active.voidreleaseConnection()Close a connection.voidreplaceConnection()Replace a connection.voidrollback()Rollback the transaction represented by this transaction object.voidsetNontransactionalRead(boolean flag)If this flag is set to true, then queries and navigation are allowed without an active transactionvoidsetOptimistic(boolean flag)Optimistic transactions do not hold data store locks until commit time.voidsetPersistenceManager(PersistenceManager pm)Set PersistenceManagervoidsetQueryTimeout(int timeout)Sets the number of seconds to wait for a query statement to execute in the datastore associated with this Transaction instancevoidsetRestoreValues(boolean flag)If true, at rollback instances restore their values and the instances transition to persistent-nontransactional.voidsetRetainValues(boolean flag)If true, at commit instances retain their values and the instances transition to persistent-nontransactional.voidsetRollbackOnly()Modify the transaction object such that the only possible outcome of the transaction is to roll back.voidsetSynchronization(jakarta.transaction.Synchronization sync)The user can specify a Synchronization instance to be notified on transaction completions.voidsetUpdateTimeout(int timeout)Sets the number of seconds to wait for an update statement to execute in the datastore associated with this Transaction instancestatic StringstatusString(int status)Translates a jakarta.transaction.Status value into a string.StringtoString()Returns a string representation of this transaction object.booleanverify(String username, char[] password)Verify that username and password are equal to ones stored before
-
-
-
Field Detail
-
TRAN_DEFAULT_TIMEOUT
public static final int TRAN_DEFAULT_TIMEOUT
- See Also:
- Constant Field Values
-
TRAN_MAX_THREADS
public static final int TRAN_MAX_THREADS
- See Also:
- Constant Field Values
-
NON_MGD
public static final int NON_MGD
Possible values of txType- See Also:
- Constant Field Values
-
CMT
public static final int CMT
- See Also:
- Constant Field Values
-
BMT_UT
public static final int BMT_UT
- See Also:
- Constant Field Values
-
BMT_JDO
public static final int BMT_JDO
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TransactionImpl
public TransactionImpl(PersistenceManager pm, String username, char[] password, int seconds)
Constructor
-
-
Method Detail
-
setPersistenceManager
public void setPersistenceManager(PersistenceManager pm)
Set PersistenceManager
-
getPersistenceManager
public PersistenceManager getPersistenceManager()
Returns PersistenceManager associated with this transaction- Specified by:
getPersistenceManagerin interfaceTransaction- Returns:
- the PersistenceManager for this Transaction instance
-
isActive
public boolean isActive()
Description copied from interface:TransactionReturns whether there is a transaction currently active.- Specified by:
isActivein interfaceTransaction- Returns:
- boolean
-
setRetainValues
public void setRetainValues(boolean flag)
Description copied from interface:TransactionIf true, at commit instances retain their values and the instances transition to persistent-nontransactional.Setting this flag also sets the NontransactionalRead flag.
- Specified by:
setRetainValuesin interfaceTransaction- Parameters:
flag- the value of the retainValues property
-
getRetainValues
public boolean getRetainValues()
Description copied from interface:TransactionIf true, at commit time instances retain their field values.- Specified by:
getRetainValuesin interfaceTransaction- Returns:
- the value of the retainValues property
-
setRestoreValues
public void setRestoreValues(boolean flag)
Description copied from interface:TransactionIf true, at rollback instances restore their values and the instances transition to persistent-nontransactional.- Specified by:
setRestoreValuesin interfaceTransaction- Parameters:
flag- the value of the restoreValues property
-
getRestoreValues
public boolean getRestoreValues()
Description copied from interface:TransactionIf true, at rollback time instances restore their field values.- Specified by:
getRestoreValuesin interfaceTransaction- Returns:
- the value of the restoreValues property
-
setNontransactionalRead
public void setNontransactionalRead(boolean flag)
Description copied from interface:TransactionIf this flag is set to true, then queries and navigation are allowed without an active transaction- Specified by:
setNontransactionalReadin interfaceTransaction- Parameters:
flag- the value of the nontransactionalRead property.
-
getNontransactionalRead
public boolean getNontransactionalRead()
Description copied from interface:TransactionIf this flag is set to true, then queries and navigation are allowed without an active transaction- Specified by:
getNontransactionalReadin interfaceTransaction- Returns:
- the value of the nontransactionalRead property.
-
setQueryTimeout
public void setQueryTimeout(int timeout)
Sets the number of seconds to wait for a query statement to execute in the datastore associated with this Transaction instance- Specified by:
setQueryTimeoutin interfaceTransaction- Parameters:
timeout- new timout value in seconds; zero means unlimited
-
getQueryTimeout
public int getQueryTimeout()
Gets the number of seconds to wait for a query statement to execute in the datastore associated with this Transaction instance- Specified by:
getQueryTimeoutin interfaceTransaction- Returns:
- timout value in seconds; zero means unlimited
-
setUpdateTimeout
public void setUpdateTimeout(int timeout)
Sets the number of seconds to wait for an update statement to execute in the datastore associated with this Transaction instance- Specified by:
setUpdateTimeoutin interfaceTransaction- Parameters:
timeout- new timout value in seconds; zero means unlimited
-
getUpdateTimeout
public int getUpdateTimeout()
Gets the number of seconds to wait for an update statement to execute in the datastore associated with this Transaction instance- Specified by:
getUpdateTimeoutin interfaceTransaction- Returns:
- timout value in seconds; zero means unlimited
-
setOptimistic
public void setOptimistic(boolean flag)
Description copied from interface:TransactionOptimistic transactions do not hold data store locks until commit time.- Specified by:
setOptimisticin interfaceTransaction- Parameters:
flag- the value of the Optimistic flag.
-
getOptimistic
public boolean getOptimistic()
Description copied from interface:TransactionOptimistic transactions do not hold data store locks until commit time.- Specified by:
getOptimisticin interfaceTransaction- Returns:
- the value of the Optimistic property.
-
setSynchronization
public void setSynchronization(jakarta.transaction.Synchronization sync)
Description copied from interface:TransactionThe user can specify a Synchronization instance to be notified on transaction completions. The beforeCompletion method is called prior to flushing instances to the data store.The afterCompletion method is called after performing the data store commit operation.
- Specified by:
setSynchronizationin interfaceTransaction- Parameters:
sync- the Synchronization instance to be notified; null for none
-
getSynchronization
public jakarta.transaction.Synchronization getSynchronization()
Description copied from interface:TransactionThe user-specified Synchronization instance for this Transaction instance.- Specified by:
getSynchronizationin interfaceTransaction- Returns:
- the user-specified Synchronization instance.
-
getTransactionType
public int getTransactionType()
-
verify
public boolean verify(String username, char[] password)
Verify that username and password are equal to ones stored before- Parameters:
username- as Stringpassword- as String- Returns:
- true if they are equal
-
begin
public void begin()
Begin a transaction.- Specified by:
beginin interfaceTransaction- See Also:
Transaction.setOptimistic(boolean),Transaction.getOptimistic()
-
begin
public void begin(jakarta.transaction.Transaction t)
Begin a transaction in managed environment- Specified by:
beginin interfaceTransaction
-
commit
public void commit()
Commit the transaction represented by this Transaction object- Specified by:
commitin interfaceTransaction
-
beforeCompletion
public void beforeCompletion()
Called in the managed environment only for transaction completion- Specified by:
beforeCompletionin interfacejakarta.transaction.Synchronization
-
afterCompletion
public void afterCompletion(int st)
Called in the managed environment only for transaction completion- Specified by:
afterCompletionin interfacejakarta.transaction.Synchronization
-
rollback
public void rollback()
Rollback the transaction represented by this transaction object.- Specified by:
rollbackin interfaceTransaction
-
setRollbackOnly
public void setRollbackOnly()
Modify the transaction object such that the only possible outcome of the transaction is to roll back.- Specified by:
setRollbackOnlyin interfaceTransaction
-
getStatus
public int getStatus()
Obtain the status of this transaction object.- Returns:
- The transaction status.
-
statusString
public static String statusString(int status)
Translates a jakarta.transaction.Status value into a string.- Parameters:
status- Status object to translate.- Returns:
- Printable String for a Status object.
-
getConnection
public Connection getConnection()
Returns a Connection. If there is no existing one, asks ConnectionFactory for a new Connection- Specified by:
getConnectionin interfaceTransaction
-
replaceConnection
public void replaceConnection()
Replace a connection. Used in a managed environment only. In a J2EE RI Connection need to be replaced at the beforeCompletion.- Specified by:
replaceConnectionin interfaceTransaction
-
releaseConnection
public void releaseConnection()
Close a connection. Connection cannot be closed if it is part of the commit/rollback operation or inside a pessimistic transaction- Specified by:
releaseConnectionin interfaceTransaction
-
-