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 int
BMT_JDO
static int
BMT_UT
static int
CMT
static int
NON_MGD
Possible values of txTypestatic int
TRAN_DEFAULT_TIMEOUT
static int
TRAN_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 void
afterCompletion(int st)
Called in the managed environment only for transaction completionvoid
beforeCompletion()
Called in the managed environment only for transaction completionvoid
begin()
Begin a transaction.void
begin(jakarta.transaction.Transaction t)
Begin a transaction in managed environmentvoid
commit()
Commit the transaction represented by this Transaction objectConnection
getConnection()
Returns a Connection.boolean
getNontransactionalRead()
If this flag is set to true, then queries and navigation are allowed without an active transactionboolean
getOptimistic()
Optimistic transactions do not hold data store locks until commit time.PersistenceManager
getPersistenceManager()
Returns PersistenceManager associated with this transactionint
getQueryTimeout()
Gets the number of seconds to wait for a query statement to execute in the datastore associated with this Transaction instanceboolean
getRestoreValues()
If true, at rollback time instances restore their field values.boolean
getRetainValues()
If true, at commit time instances retain their field values.int
getStatus()
Obtain the status of this transaction object.jakarta.transaction.Synchronization
getSynchronization()
The user-specified Synchronization instance for this Transaction instance.int
getTransactionType()
int
getUpdateTimeout()
Gets the number of seconds to wait for an update statement to execute in the datastore associated with this Transaction instanceboolean
isActive()
Returns whether there is a transaction currently active.void
releaseConnection()
Close a connection.void
replaceConnection()
Replace a connection.void
rollback()
Rollback the transaction represented by this transaction object.void
setNontransactionalRead(boolean flag)
If this flag is set to true, then queries and navigation are allowed without an active transactionvoid
setOptimistic(boolean flag)
Optimistic transactions do not hold data store locks until commit time.void
setPersistenceManager(PersistenceManager pm)
Set PersistenceManagervoid
setQueryTimeout(int timeout)
Sets the number of seconds to wait for a query statement to execute in the datastore associated with this Transaction instancevoid
setRestoreValues(boolean flag)
If true, at rollback instances restore their values and the instances transition to persistent-nontransactional.void
setRetainValues(boolean flag)
If true, at commit instances retain their values and the instances transition to persistent-nontransactional.void
setRollbackOnly()
Modify the transaction object such that the only possible outcome of the transaction is to roll back.void
setSynchronization(jakarta.transaction.Synchronization sync)
The user can specify a Synchronization instance to be notified on transaction completions.void
setUpdateTimeout(int timeout)
Sets the number of seconds to wait for an update statement to execute in the datastore associated with this Transaction instancestatic String
statusString(int status)
Translates a jakarta.transaction.Status value into a string.String
toString()
Returns a string representation of this transaction object.boolean
verify(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:
getPersistenceManager
in interfaceTransaction
- Returns:
- the PersistenceManager for this Transaction instance
-
isActive
public boolean isActive()
Description copied from interface:Transaction
Returns whether there is a transaction currently active.- Specified by:
isActive
in interfaceTransaction
- Returns:
- boolean
-
setRetainValues
public void setRetainValues(boolean flag)
Description copied from interface:Transaction
If true, at commit instances retain their values and the instances transition to persistent-nontransactional.Setting this flag also sets the NontransactionalRead flag.
- Specified by:
setRetainValues
in interfaceTransaction
- Parameters:
flag
- the value of the retainValues property
-
getRetainValues
public boolean getRetainValues()
Description copied from interface:Transaction
If true, at commit time instances retain their field values.- Specified by:
getRetainValues
in interfaceTransaction
- Returns:
- the value of the retainValues property
-
setRestoreValues
public void setRestoreValues(boolean flag)
Description copied from interface:Transaction
If true, at rollback instances restore their values and the instances transition to persistent-nontransactional.- Specified by:
setRestoreValues
in interfaceTransaction
- Parameters:
flag
- the value of the restoreValues property
-
getRestoreValues
public boolean getRestoreValues()
Description copied from interface:Transaction
If true, at rollback time instances restore their field values.- Specified by:
getRestoreValues
in interfaceTransaction
- Returns:
- the value of the restoreValues property
-
setNontransactionalRead
public void setNontransactionalRead(boolean flag)
Description copied from interface:Transaction
If this flag is set to true, then queries and navigation are allowed without an active transaction- Specified by:
setNontransactionalRead
in interfaceTransaction
- Parameters:
flag
- the value of the nontransactionalRead property.
-
getNontransactionalRead
public boolean getNontransactionalRead()
Description copied from interface:Transaction
If this flag is set to true, then queries and navigation are allowed without an active transaction- Specified by:
getNontransactionalRead
in 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:
setQueryTimeout
in 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:
getQueryTimeout
in 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:
setUpdateTimeout
in 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:
getUpdateTimeout
in interfaceTransaction
- Returns:
- timout value in seconds; zero means unlimited
-
setOptimistic
public void setOptimistic(boolean flag)
Description copied from interface:Transaction
Optimistic transactions do not hold data store locks until commit time.- Specified by:
setOptimistic
in interfaceTransaction
- Parameters:
flag
- the value of the Optimistic flag.
-
getOptimistic
public boolean getOptimistic()
Description copied from interface:Transaction
Optimistic transactions do not hold data store locks until commit time.- Specified by:
getOptimistic
in interfaceTransaction
- Returns:
- the value of the Optimistic property.
-
setSynchronization
public void setSynchronization(jakarta.transaction.Synchronization sync)
Description copied from interface:Transaction
The 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:
setSynchronization
in interfaceTransaction
- Parameters:
sync
- the Synchronization instance to be notified; null for none
-
getSynchronization
public jakarta.transaction.Synchronization getSynchronization()
Description copied from interface:Transaction
The user-specified Synchronization instance for this Transaction instance.- Specified by:
getSynchronization
in 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:
begin
in interfaceTransaction
- See Also:
Transaction.setOptimistic(boolean)
,Transaction.getOptimistic()
-
begin
public void begin(jakarta.transaction.Transaction t)
Begin a transaction in managed environment- Specified by:
begin
in interfaceTransaction
-
commit
public void commit()
Commit the transaction represented by this Transaction object- Specified by:
commit
in interfaceTransaction
-
beforeCompletion
public void beforeCompletion()
Called in the managed environment only for transaction completion- Specified by:
beforeCompletion
in interfacejakarta.transaction.Synchronization
-
afterCompletion
public void afterCompletion(int st)
Called in the managed environment only for transaction completion- Specified by:
afterCompletion
in interfacejakarta.transaction.Synchronization
-
rollback
public void rollback()
Rollback the transaction represented by this transaction object.- Specified by:
rollback
in interfaceTransaction
-
setRollbackOnly
public void setRollbackOnly()
Modify the transaction object such that the only possible outcome of the transaction is to roll back.- Specified by:
setRollbackOnly
in 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:
getConnection
in 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:
replaceConnection
in 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:
releaseConnection
in interfaceTransaction
-
-