Home

xl2.odb
Class XL2Transaction

java.lang.Object
  |
  +--xl2.transaction.AbstractTransaction
        |
        +--xl2.odb.XL2Transaction
All Implemented Interfaces:
Transaction

public class XL2Transaction
extends AbstractTransaction

A transaction of a single XL2database.

Like thread cooperation using the synchronized keyword, applications must cooperate by successfully locking objects before using them. Any transaction can modify another XL2Transaction's object if no attempt is made to lock the object first!

Locking
New and modified objects get saved to the database via locking. If an object is not locked, it may be lost. XL2References automatically lock objects, but for modifications to second class objects and primitive fields, one must manually lock parent first class objects.

Threads
Threads must be joined to transactions. This is so XL2References can "find" their database.

Since:
Java 2
See Also:
InvalidObjectException, LockNotGrantedException, XL2TransactionMgr.currentTransaction()

Field Summary
static int READ
          Lock type.
static int WRITE
          Lock type.
 
Fields inherited from interface xl2.transaction.Transaction
STATUS_ABORT_FAILED, STATUS_ABORTED, STATUS_ABORTING, STATUS_BEGINNING, STATUS_COMMITTED, STATUS_COMMITTING, STATUS_IN_PROGRESS, STATUS_INSTANTIATED, STATUS_MARKED_ABORT
 
Method Summary
 void abort()
          Rollback the transaction.
 void begin()
          Calling begin multiple times on the same transaction, without an intervening call to commit or abort, causes TransactionNotClosedException to be thrown on the second and subsequent calls.
 void commit()
          Save the transaction state.
 XL2Database getDatabase()
          The database of the transaction.
 long getExpiration()
          The time (System.currentTimeMillis) after which the open transaction will be automatically aborted.
 long getTimeout()
          The length of time after which an open transaction will be automatically aborted.
static boolean isReadLocked(java.lang.Object obj)
          Returns true if the object is read locked by one or more transactions.
 boolean isReadOnly()
          True if the transaction can not write lock objects.
static boolean isWriteLocked(java.lang.Object obj)
          Returns true if the object is write locked by any transaction.
 void lock(java.lang.Object object, int mode)
          Attempts to lock the object with the given mode.
 void readLock(java.lang.Object object)
          A convenience function that calls lock(object,XL2Transaction.READ).
 void setReadOnly(boolean readonly)
          Only to be called when the transaction is closed.
 void setTimeout(long millis)
          The length of time after which an open transaction will be automatically aborted.
 boolean tryLock(java.lang.Object obj, int mode)
          Same as lock(Object,int) except no exception is thrown.
 void writeLock(java.lang.Object object)
          A convenience function that calls lock(object,XL2Transaction.WRITE).
 
Methods inherited from class xl2.transaction.AbstractTransaction
getStatus, isClosed, isOpen, join, leave, setAbortOnly
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

READ

public static int READ
Lock type.

WRITE

public static int WRITE
Lock type.
Method Detail

abort

public void abort()
           throws AbortFailedException,
                  TransactionNotOpenException
Description copied from interface: Transaction
Rollback the transaction. If an exception occurs while aborting the status of the transaction becomes STATUS_ABORT_FAILED. Only abort can be called if the status is STATUS_ABORT_FAILED.
Overrides:
abort in class AbstractTransaction
Following copied from interface: xl2.transaction.Transaction
Throws:
AbortFailedException -  
TransactionNotOpenException -  

begin

public void begin()
           throws TransactionNotClosedException
Description copied from interface: Transaction
Calling begin multiple times on the same transaction, without an intervening call to commit or abort, causes TransactionNotClosedException to be thrown on the second and subsequent calls.
Overrides:
begin in class AbstractTransaction
Following copied from interface: xl2.transaction.Transaction
Throws:
TransactionNotClosedException -  

commit

public void commit()
            throws TransactionAbortedException,
                   TransactionNotOpenException
Description copied from interface: Transaction
Save the transaction state.
Overrides:
commit in class AbstractTransaction
Following copied from interface: xl2.transaction.Transaction
Throws:
AbortedFailedException - If the transaction attempts to abort and an exception occurrs.
TransactionAbortedException - If an exeception occurs.
TransactionNotOpenException -  
See Also:
Transaction.isOpen()

getDatabase

public XL2Database getDatabase()
The database of the transaction.

getExpiration

public long getExpiration()
The time (System.currentTimeMillis) after which the open transaction will be automatically aborted. This only has meaning when the transaction is open.
Returns:
<=0 Is an infinite expiration, and the default.

getTimeout

public long getTimeout()
The length of time after which an open transaction will be automatically aborted.
Returns:
<=0 Is an infinite lifetime, and the default.

isReadLocked

public static boolean isReadLocked(java.lang.Object obj)
Returns true if the object is read locked by one or more transactions.

isReadOnly

public boolean isReadOnly()
True if the transaction can not write lock objects.

isWriteLocked

public static boolean isWriteLocked(java.lang.Object obj)
Returns true if the object is write locked by any transaction.

lock

public void lock(java.lang.Object object,
                 int mode)
          throws InvalidObjectException,
                 LockNotGrantedException,
                 TransactionNotOpenException
Attempts to lock the object with the given mode. A READ lock prevents another transaction from obtaining a WRITE lock. A WRITE lock prevents another transaction from obtaining any lock, and a WRITE locked object will be serialized into the database upon committal.
Throws:
InvalidObjectException -  
TransactionNotOpenException -  
LockNotGrantedException -  

readLock

public void readLock(java.lang.Object object)
A convenience function that calls lock(object,XL2Transaction.READ).
See Also:
lock(Object,int)

setReadOnly

public void setReadOnly(boolean readonly)
Only to be called when the transaction is closed. When true, prevents the transaction write locking objects.
Throws:
XL2TransactionNotClosedException -  

setTimeout

public void setTimeout(long millis)
The length of time after which an open transaction will be automatically aborted. If the transaction is closed when this is called, the lifetime begins when the transaction begins. If the transaction is open when this is called, the lifetime is reset, beginning at the time of the method call.
Parameters:
millis - <=0 Is an infinite lifetime, and the default.

tryLock

public boolean tryLock(java.lang.Object obj,
                       int mode)
Same as lock(Object,int) except no exception is thrown.
Returns:
False if the lock is not granted.

writeLock

public void writeLock(java.lang.Object object)
A convenience function that calls lock(object,XL2Transaction.WRITE).
See Also:
lock(Object,int)

Home