org.apache.derby.impl.store.raw.xact
Class Xact

java.lang.Object
  extended byjava.util.Observable
      extended byorg.apache.derby.iapi.store.raw.xact.RawTransaction
          extended byorg.apache.derby.impl.store.raw.xact.Xact
All Implemented Interfaces:
Limit, Transaction
Direct Known Subclasses:
InternalXact

public class Xact
extends RawTransaction
implements Limit

A transaction has five states

  1. CLOSED - cannot be used
  2. IDLE - no reads have been performed by the transaction.
  3. ACTIVE - at least one read has been attempted by the transaction
  4. UPDATE - at least one update has been attempted by the transaction
  5. PREPARED - the transaction is ready to commit (FUTURE).

Transaction identifiers are re-used for transactions that do not enter the UPDATE state during their lifetime.

See Also:
Transaction

Field Summary
protected static int ACTIVE
           
protected static int CLOSED
           
private static int COMMIT_NO_SYNC
           
private static int COMMIT_PREPARE
           
private static int COMMIT_SYNC
          private static - make sure these bits don't overwrite bits in Transaction.commit commitflag
protected  java.lang.Object compatibilitySpace
           
protected  DataFactory dataFactory
           
private  LockingPolicy defaultLocking
           
static int END_ABORTED
           
static int END_COMMITTED
           
static int END_PREPARED
           
protected static int IDLE
           
private  java.lang.Integer inComplete
           
private  boolean inPostCommitProcessing
           
static int INTERNAL_TRANSACTION
           
private  boolean justCreated
           
(package private)  DynamicByteArrayOutputStream logBuffer
           
protected  LogFactory logFactory
           
protected  Logger logger
           
private  LogInstant logLast
           
private  LogInstant logStart
           
private  GlobalTransactionId myGlobalId
           
private  TransactionId myId
           
private  boolean needSync
           
static int NESTED_TOP_TRANSACTION
           
protected  java.util.List postCommitWorks
           
private  boolean postCompleteMode
           
protected  java.util.List postTerminationWorks
           
protected static int PREPARED
           
private  boolean readOnly
           
static int RECOVERY_ROLLBACK_FIRST
           
private  boolean recoveryTransaction
           
private  boolean sanityCheck_xaclosed
           
private  int savedEndStatus
           
private  java.util.Stack savePoints
           
private  boolean seenUpdates
           
protected  int state
           
private  java.lang.String transName
           
protected static int UPDATE
           
protected  XactFactory xactFactory
           
protected  XactContext xc
           
 
Fields inherited from class org.apache.derby.iapi.store.raw.xact.RawTransaction
ABORT, COMMIT, LOCK_ESCALATE, observerException, SAVEPOINT_ROLLBACK
 
Fields inherited from class java.util.Observable
 
Fields inherited from interface org.apache.derby.iapi.store.raw.Transaction
KEEP_LOCKS, RELEASE_LOCKS, XA_OK, XA_RDONLY
 
Constructor Summary
protected Xact(XactFactory xactFactory, LogFactory logFactory, DataFactory dataFactory, boolean readOnly, java.lang.Object compatibilitySpace)
           
 
Method Summary
 void abort()
          Abort all changes made by this transaction since the last commit, abort or the point the transaction was started, whichever is the most recent.
 long addAndLoadStreamContainer(long segmentId, java.util.Properties tableProperties, RowSource rowSource)
          Add a new stream container to the segment and load the stream container.
 long addContainer(long segmentId, long containerid, int mode, java.util.Properties tableProperties, int temporaryFlag)
          Add a new container to the segment.
 void addPostCommitWork(Serviceable work)
          Add to the list of post commit work that may be processed after this transaction commits.
 void addPostTerminationWork(Serviceable work)
          Add to the list of post termination work that may be processed after this transaction commits or aborts.
 void addUpdateTransaction(int transactionStatus)
          Add this to the xactFactory list of update transaction.
 boolean anyoneBlocked()
          Return true if any transaction is currently blocked, even if not by this transaction.
protected  void assumeGlobalXactIdentity(TransactionTableEntry ent)
          Assume complete identity of the given Transaction Table Entry.
protected  void assumeIdentity(TransactionTableEntry ent)
          Transform this identity to the one stored in transaction table entry.
private  void checkObserverException()
           
 void checkpointInRollForwardRecovery(LogInstant cinstant, long redoLWM)
          perform a checkpoint during rollforward recovery
 void close()
          Close this transaction, the transaction must be idle.
 LogInstant commit()
          Commit this transaction.
private  LogInstant commit(int commitflag)
           
 LogInstant commitNoSync(int commitflag)
          "Commit" this transaction without sync'ing the log.
private  void completeCommit(int commitflag)
          Do work to complete a commit which is not just a prepare.
 void createXATransactionFromLocalTransaction(int format_id, byte[] global_id, byte[] branch_id)
          Convert a local transaction to a global transaction.
 LockingPolicy defaultLockingPolicy()
           
 void destroy()
          If this transaction is not idle, abort it.
protected  void doComplete(java.lang.Integer commitOrAbort)
           
protected  boolean doPostCommitWorkInTran()
          If this is a user transaction (not an internal or nested top transaction), and this is not already taking care of post commit work, and not an XA transaction, then take care of hi prioirty work right now using this thread and this context manager.
 void dropContainer(ContainerKey containerId)
          Drop a container.
 void dropStreamContainer(long segmentId, long containerId)
          Drop a stream container.
 java.lang.String getActiveStateTxIdString()
          get string ID of the actual transaction ID that will be used when transaction is in active state.
 long[] getCacheStats(java.lang.String cacheName)
          Get cache statistics for the specified cache
 java.lang.Object getCompatibilitySpace()
          Get the compatibility space of the transaction.
 java.lang.String getContextId()
          Get my transaction context Id
 ContextManager getContextManager()
          Return the context manager this transaction is associated with.
 DataFactory getDataFactory()
          Get the data factory to be used during this transaction.
 LockingPolicy getDefaultLockingPolicy()
          Get the current default locking policy for all operations within this transaction.
 FileResource getFileHandler()
          Get an object to handle non-transactional files.
 LogInstant getFirstLogInstant()
          Get the log instant for the first log record written by this transaction.
 GlobalTransactionId getGlobalId()
          get the Global (external to raw store) transaction id that is unique across all raw stores
 TransactionId getId()
          get the short (internal to raw store) transaction id that is unique only for this raw store
protected  TransactionId getIdNoCheck()
          Get the transaction id without sanity check, this should only be called by a cloned TransactionTableEntry
 LogInstant getLastLogInstant()
          Get the log instant for the last log record written by this transaction.
 LockFactory getLockFactory()
          Get the lock factory to be used during this transaction.
 DynamicByteArrayOutputStream getLogBuffer()
          Get the log buffer to be used during this transaction.
private  void getLogger()
          Get the Logger object used to write log records to the transaction log.
private  int getSavePointPosition(java.lang.String name, java.lang.Object kindOfSavepoint, boolean forRollbackOrRelease)
          Does a save point exist in the stack with the given name.
(package private)  java.lang.String getState()
           
 java.lang.String getTransName()
           
 boolean handlesPostTerminationWork()
          Can this transaction handles post termination work
 boolean inAbort()
          Is the transaction in the middle of an abort.
 boolean inRollForwardRecovery()
          Is the transaction in rollforward recovery
 boolean isActive()
          see if this transaction has ever done anything.
 boolean isIdle()
          See if this transaction is in the idle state, called by other thread to test the state of this transaction.
 boolean isPrepared()
          see if this transaction is in PREPARED state.
 boolean isPristine()
          see if this transaction is in a pristine state.
private  boolean isUserTransaction()
          see if this transaction is a user transaction.
 void logAndDo(Loggable operation)
          Log the operation and do it.
 void logAndUndo(Compensation compensation, LogInstant undoInstant, LimitObjectInput in)
          Log and apply a compensation operation.
 LockingPolicy newLockingPolicy(int mode, int isolation, boolean stricterOk)
          Obtain a locking policy for use in openContainer().
 ContainerHandle openContainer(ContainerKey containerId, int mode)
          Open a container, with the transaction's default locking policy.
 ContainerHandle openContainer(ContainerKey containerId, LockingPolicy locking, int mode)
          Open a container, with the defined locking policy, otherwise as openContainer(int containerId, boolean forUpdate).
 RawContainerHandle openDroppedContainer(ContainerKey containerId, LockingPolicy locking)
          Open a container that may already have been dropped.
 StreamContainerHandle openStreamContainer(long segmentId, long containerId, boolean hold)
          Open a stream container.
protected  boolean popSavePoints(int position, boolean release)
          Pop all savepoints upto the one with the given name and rollback all changes made since this savepoint was pushed.
protected  void postComplete(int commitflag, java.lang.Integer commitOrAbort)
           
private  void postTermination()
           
protected  void preComplete(java.lang.Integer commitOrAbort)
           
private  LogInstant prepareCommit(int commitflag)
          Do work of commit that is common to xa_prepare and commit.
 void prepareTransaction()
          Remove this from the xactFactory list of update transaction.
 void reached(java.lang.Object compatabilitySpace, java.lang.Object group, int limit, java.util.Enumeration lockList, int lockCount)
          Called by the lock factory when a limit has been reached.
 void recoveryTransaction()
          Make this transaction aware that it is being used by recovery
 void reCreateContainerForLoadTran(long segmentId, long containerId, ByteArray containerInfo)
          Recreate a container during load tran - use only by media recovery.
private  void releaseAllLocks()
           
 int releaseSavePoint(java.lang.String name, java.lang.Object kindOfSavepoint)
          Release the save point of the given name.
 void removeUpdateTransaction()
          Remove this from the xactFactory list of update transaction.
 void reprepare()
          During recovery re-prepare a transaction.
 void resetCacheStats(java.lang.String cacheName)
          Reset the cache statistics for the specified cache
(package private)  void resetDefaultLocking()
           
 int rollbackToSavePoint(java.lang.String name, java.lang.Object kindOfSavepoint)
          Rollback all changes made since the named savepoint was set.
protected  void setActiveState()
           
 void setDefaultLockingPolicy(LockingPolicy policy)
          Set the default locking policy for all operations within this transaction.
 void setFirstLogInstant(LogInstant instant)
          Set the log instant for the first log record written by this transaction.
protected  void setIdleState()
           
 void setLastLogInstant(LogInstant instant)
          Set the log instant for the last log record written by this transaction.
(package private)  void setPostComplete()
          Set the transaction to issue pre complete work at postComplete time, instead of preComplete time.
protected  void setPrepareState()
          Move the state of the transaction from UPDATE to PREPARE.
 int setSavePoint(java.lang.String name, java.lang.Object kindOfSavepoint)
          Set a save point in the current transaction.
 void setTransactionId(GlobalTransactionId extid, TransactionId localid)
          Set my transaction identifier.
 void setTransactionId(Loggable beginXact, TransactionId localId)
          Set the transactionId (Global and internal) of this transaction using a log record that contains the Global id
 void setTransName(java.lang.String name)
           
 void setup(PersistentSet set)
          The default value for LOCKS_ESCALATION_THRESHOLD
private  void setUpdateState()
          Move the transaction into the update state.
 RawTransaction startNestedTopTransaction()
          Start a nested top transaction.
protected  int statusForBeginXactLog()
          put this into the beginXact log record to help recovery if we needs to rolled back first, put that in
protected  int statusForEndXactLog()
          put this into the endXact log record to help recovery, nothing to add
private  void throwExceptionIfSQLSavepointNotAllowed(java.lang.Object kindOfSavepoint)
           
 java.lang.String toString()
          Return the xid as a string.
 void xa_commit(boolean onePhase)
          This method is called to commit the current XA global transaction.
 int xa_prepare()
          This method is called to ask the resource manager to prepare for a transaction commit of the transaction specified in xid.
 void xa_rollback()
          rollback the current global transaction.
 
Methods inherited from class org.apache.derby.iapi.store.raw.xact.RawTransaction
checkLogicalOperationOk, notifyObservers, recoveryRollbackFirst, setObserverException
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLOSED

protected static final int CLOSED
See Also:
Constant Field Values

IDLE

protected static final int IDLE
See Also:
Constant Field Values

ACTIVE

protected static final int ACTIVE
See Also:
Constant Field Values

UPDATE

protected static final int UPDATE
See Also:
Constant Field Values

PREPARED

protected static final int PREPARED
See Also:
Constant Field Values

END_ABORTED

public static final int END_ABORTED
See Also:
Constant Field Values

END_PREPARED

public static final int END_PREPARED
See Also:
Constant Field Values

END_COMMITTED

public static final int END_COMMITTED
See Also:
Constant Field Values

RECOVERY_ROLLBACK_FIRST

public static final int RECOVERY_ROLLBACK_FIRST
See Also:
Constant Field Values

INTERNAL_TRANSACTION

public static final int INTERNAL_TRANSACTION
See Also:
Constant Field Values

NESTED_TOP_TRANSACTION

public static final int NESTED_TOP_TRANSACTION
See Also:
Constant Field Values

COMMIT_SYNC

private static final int COMMIT_SYNC
private static - make sure these bits don't overwrite bits in Transaction.commit commitflag

See Also:
Constant Field Values

COMMIT_NO_SYNC

private static final int COMMIT_NO_SYNC
See Also:
Constant Field Values

COMMIT_PREPARE

private static final int COMMIT_PREPARE
See Also:
Constant Field Values

savedEndStatus

private int savedEndStatus

needSync

private boolean needSync

justCreated

private boolean justCreated

xc

protected XactContext xc

xactFactory

protected final XactFactory xactFactory

dataFactory

protected final DataFactory dataFactory

logFactory

protected final LogFactory logFactory

compatibilitySpace

protected final java.lang.Object compatibilitySpace

defaultLocking

private LockingPolicy defaultLocking

myGlobalId

private GlobalTransactionId myGlobalId

myId

private volatile TransactionId myId

logger

protected Logger logger

state

protected volatile int state

inComplete

private java.lang.Integer inComplete

seenUpdates

private boolean seenUpdates

inPostCommitProcessing

private boolean inPostCommitProcessing

logStart

private LogInstant logStart

logLast

private LogInstant logLast

savePoints

private java.util.Stack savePoints

postCommitWorks

protected java.util.List postCommitWorks

postTerminationWorks

protected java.util.List postTerminationWorks

recoveryTransaction

private boolean recoveryTransaction

logBuffer

DynamicByteArrayOutputStream logBuffer

postCompleteMode

private boolean postCompleteMode

sanityCheck_xaclosed

private boolean sanityCheck_xaclosed

transName

private java.lang.String transName

readOnly

private boolean readOnly
Constructor Detail

Xact

protected Xact(XactFactory xactFactory,
               LogFactory logFactory,
               DataFactory dataFactory,
               boolean readOnly,
               java.lang.Object compatibilitySpace)
Method Detail

getLockFactory

public final LockFactory getLockFactory()
Description copied from class: RawTransaction
Get the lock factory to be used during this transaction.

Specified by:
getLockFactory in class RawTransaction

getDataFactory

public final DataFactory getDataFactory()
Description copied from class: RawTransaction
Get the data factory to be used during this transaction.

Specified by:
getDataFactory in class RawTransaction

getCacheStats

public long[] getCacheStats(java.lang.String cacheName)
Get cache statistics for the specified cache

Specified by:
getCacheStats in interface Transaction
Specified by:
getCacheStats in class RawTransaction

resetCacheStats

public void resetCacheStats(java.lang.String cacheName)
Reset the cache statistics for the specified cache

Specified by:
resetCacheStats in interface Transaction
Specified by:
resetCacheStats in class RawTransaction

anyoneBlocked

public boolean anyoneBlocked()
Return true if any transaction is currently blocked, even if not by this transaction.

Specified by:
anyoneBlocked in interface Transaction

getLogBuffer

public DynamicByteArrayOutputStream getLogBuffer()
Description copied from class: RawTransaction
Get the log buffer to be used during this transaction.

Specified by:
getLogBuffer in class RawTransaction

logAndUndo

public void logAndUndo(Compensation compensation,
                       LogInstant undoInstant,
                       LimitObjectInput in)
                throws StandardException
Log and apply a compensation operation. Only need to write out the compensation op itself, the optional data has already been written by the rollforward operation this is attempting to undo.

Specified by:
logAndUndo in class RawTransaction
Parameters:
compensation - the Compensation Operation
undoInstant - the LogInstant of the Loggable Operation this compensation operation is going to roll back
in - optional data for the rollback operation
Throws:
StandardException - Standard cloudscape exception policy
See Also:
Transaction.logAndDo(org.apache.derby.iapi.store.raw.Loggable)

addUpdateTransaction

public void addUpdateTransaction(int transactionStatus)
Add this to the xactFactory list of update transaction.

Specified by:
addUpdateTransaction in class RawTransaction

removeUpdateTransaction

public void removeUpdateTransaction()
Remove this from the xactFactory list of update transaction.

Specified by:
removeUpdateTransaction in class RawTransaction

prepareTransaction

public void prepareTransaction()
Remove this from the xactFactory list of update transaction.

Specified by:
prepareTransaction in class RawTransaction

setFirstLogInstant

public void setFirstLogInstant(LogInstant instant)
Set the log instant for the first log record written by this transaction.

Specified by:
setFirstLogInstant in class RawTransaction

getFirstLogInstant

public LogInstant getFirstLogInstant()
Get the log instant for the first log record written by this transaction.

Specified by:
getFirstLogInstant in class RawTransaction

setLastLogInstant

public void setLastLogInstant(LogInstant instant)
Set the log instant for the last log record written by this transaction.

Specified by:
setLastLogInstant in class RawTransaction

getLastLogInstant

public LogInstant getLastLogInstant()
Get the log instant for the last log record written by this transaction.

Specified by:
getLastLogInstant in class RawTransaction

setTransactionId

public void setTransactionId(GlobalTransactionId extid,
                             TransactionId localid)
Set my transaction identifier.

Specified by:
setTransactionId in class RawTransaction

setTransactionId

public void setTransactionId(Loggable beginXact,
                             TransactionId localId)
Description copied from class: RawTransaction
Set the transactionId (Global and internal) of this transaction using a log record that contains the Global id

Specified by:
setTransactionId in class RawTransaction

setup

public void setup(PersistentSet set)
           throws StandardException
The default value for LOCKS_ESCALATION_THRESHOLD

Specified by:
setup in interface Transaction
Throws:
StandardException - Standard cloudscape exception policy

getGlobalId

public final GlobalTransactionId getGlobalId()
get the Global (external to raw store) transaction id that is unique across all raw stores

Specified by:
getGlobalId in interface Transaction
Specified by:
getGlobalId in class RawTransaction

getContextManager

public final ContextManager getContextManager()
Description copied from interface: Transaction
Return the context manager this transaction is associated with.

Specified by:
getContextManager in interface Transaction

getCompatibilitySpace

public java.lang.Object getCompatibilitySpace()
Get the compatibility space of the transaction.

Returns an object that can be used with the lock manager to provide the compatibility space of a transaction. 2 transactions with the same compatibility space will not conflict in locks. The usual case is that each transaction has it's own unique compatibility space.

Specified by:
getCompatibilitySpace in interface Transaction
Returns:
The compatibility space of the transaction.

getId

public final TransactionId getId()
get the short (internal to raw store) transaction id that is unique only for this raw store

Specified by:
getId in class RawTransaction

getIdNoCheck

protected final TransactionId getIdNoCheck()
Get the transaction id without sanity check, this should only be called by a cloned TransactionTableEntry


getContextId

public final java.lang.String getContextId()
Get my transaction context Id


getDefaultLockingPolicy

public LockingPolicy getDefaultLockingPolicy()
Get the current default locking policy for all operations within this transaction. The transaction is initially started with a default locking policy equivalent to
                         newLockingPolicy(
              LockingPolicy.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, true);
                
This default can be changed by subsequent calls to setDefaultLockingPolicy(LockingPolicy policy).

Specified by:
getDefaultLockingPolicy in interface Transaction
Returns:
The current default locking policy in this transaction.
See Also:
Transaction.getDefaultLockingPolicy()

newLockingPolicy

public final LockingPolicy newLockingPolicy(int mode,
                                            int isolation,
                                            boolean stricterOk)
Description copied from interface: Transaction
Obtain a locking policy for use in openContainer(). The mode and isolation must be constants from LockingPolicy. If higherOK is true then the object returned may implement a stricter form of locking than the one requested.
A null LockingPolicy reference is identical to a LockingPolicy obtained by using MODE_NONE which is guaranteed to exist.

Specified by:
newLockingPolicy in interface Transaction
Parameters:
mode - A constant of the form LockingPolicy.MODE_*
isolation - A constant of the form LockingPolicy.ISOLATION_*
Returns:
A object that can be used in an openContainer call, null if a matching policy cannot be found.
See Also:
Transaction.newLockingPolicy(int, int, boolean)

setDefaultLockingPolicy

public final void setDefaultLockingPolicy(LockingPolicy policy)
Description copied from interface: Transaction
Set the default locking policy for all operations within this transaction. The transaction is intially started with a default locking policy equivalent to
                         newLockingPolicy(
              LockingPolicy.MODE_RECORD, LockingPolicy.ISOLATION_SERIALIZABLE, true);
                

Specified by:
setDefaultLockingPolicy in interface Transaction
Parameters:
policy - The lock policy to use, if null then then a no locking policy will be installed as the default.
Returns:
true if a new locking policy was installed as the default, false of a matching policy could not be found.
See Also:
Transaction.setDefaultLockingPolicy(org.apache.derby.iapi.store.raw.LockingPolicy)

commit

public LogInstant commit()
                  throws StandardException
Description copied from interface: Transaction
Commit this transaction. All savepoints within this transaction are released.

Specified by:
commit in interface Transaction
Returns:
the commit instant of this transaction, or null if it didn't make any changes
Throws:
StandardException - Standard cloudscape exception policy

commitNoSync

public LogInstant commitNoSync(int commitflag)
                        throws StandardException
Description copied from interface: Transaction
"Commit" this transaction without sync'ing the log. Everything else is identical to commit(), use this at your own risk.
bits in the commitflag can turn on to fine tuned the "commit": KEEP_LOCKS - no locks will be released by the commit and no post commit processing will be initiated. If, for some reasons, the locks cannot be kept even if this flag is set, then the commit will sync the log, i.e., it will revert to the normal commit.

Specified by:
commitNoSync in interface Transaction
Throws:
StandardException - Standard cloudscape exception policy

prepareCommit

private LogInstant prepareCommit(int commitflag)
                          throws StandardException
Do work of commit that is common to xa_prepare and commit.

Do all the work necessary as part of a commit up to and including writing the commit log record. This routine is used by both prepare and commit. The work post commit is done by completeCommit().

Parameters:
commitflag - various flavors of commit.
Throws:
StandardException - Standard exception policy.
See Also:
Transaction.commit()

completeCommit

private void completeCommit(int commitflag)
                     throws StandardException
Do work to complete a commit which is not just a prepare.

Releases locks, does post commit work, and moves the state of the transaction to IDLE.

Parameters:
commitflag - various flavors of commit.
Throws:
StandardException - Standard exception policy.

commit

private LogInstant commit(int commitflag)
                   throws StandardException
Throws:
StandardException - Standard cloudscape exception policy
See Also:
Transaction.commit()

abort

public void abort()
           throws StandardException
Description copied from interface: Transaction
Abort all changes made by this transaction since the last commit, abort or the point the transaction was started, whichever is the most recent. All savepoints within this transaction are released.

Specified by:
abort in interface Transaction
Throws:
StandardException - Standard cloudscape exception policy
See Also:
Transaction.abort()

reprepare

public void reprepare()
               throws StandardException
During recovery re-prepare a transaction.

After redo() and undo(), this routine is called on all outstanding in-doubt (prepared) transactions. This routine re-acquires all logical write locks for operations in the xact, and then modifies the transaction table entry to make the transaction look as if it had just been prepared following startup after recovery.

This routine is only called during Recovery.

Specified by:
reprepare in class RawTransaction
Throws:
StandardException - Standard exception policy.

destroy

public void destroy()
             throws StandardException
If this transaction is not idle, abort it. After this call close().

Specified by:
destroy in interface Transaction
Throws:
StandardException - Standard Cloudscape error policy Thrown if the transaction is not idle.
See Also:
RawStoreFactory.startTransaction(org.apache.derby.iapi.services.context.ContextManager, java.lang.String)

close

public void close()
           throws StandardException
Description copied from interface: Transaction
Close this transaction, the transaction must be idle. This close will pop the transaction context off the stack that was pushed when the transaction was started.

Specified by:
close in interface Transaction
Throws:
StandardException - Standard cloudscape exception policy
StandardException - Thrown if the transaction is not idle, the transaction remains open.
StandardException - Standard cloudscape policy
See Also:
Transaction.close()

logAndDo

public void logAndDo(Loggable operation)
              throws StandardException
Log the operation and do it. If this transaction has not generated any log records prior to this, then log a beginXact log record. If the passed in operation is null, then do nothing (after logging the beginXact if needed).

Specified by:
logAndDo in interface Transaction
Parameters:
operation - the operation that is to be applied
Throws:
StandardException - Standard cloudscape exception policy
See Also:
Transaction.logAndDo(org.apache.derby.iapi.store.raw.Loggable)

addPostCommitWork

public void addPostCommitWork(Serviceable work)
Description copied from interface: Transaction
Add to the list of post commit work that may be processed after this transaction commits. If this transaction aborts, then the post commit work list will be thrown away. No post commit work will be taken out on a rollback to save point.

Specified by:
addPostCommitWork in interface Transaction
Parameters:
work - the post commit work that is added

addPostTerminationWork

public void addPostTerminationWork(Serviceable work)
Description copied from interface: Transaction
Add to the list of post termination work that may be processed after this transaction commits or aborts.

Specified by:
addPostTerminationWork in interface Transaction
Parameters:
work - the post termination work that is added

openContainer

public ContainerHandle openContainer(ContainerKey containerId,
                                     int mode)
                              throws StandardException
Description copied from interface: Transaction
Open a container, with the transaction's default locking policy.

Note that if NOWAIT has been specified lock will be requested with no wait time, and if lock is not granted a SQLState.LOCK_TIMEOUT exception will be thrown.

The release() method of ContainerHandle will be called when this transaction is aborted or commited, it may be called explicitly to release the ContainerHandle before the end of the transaction.

Specified by:
openContainer in interface Transaction
Returns:
a valid ContainerHandle or null if the container does not exist.
Throws:
StandardException - Standard cloudscape exception policy
See Also:
Transaction.openContainer(org.apache.derby.iapi.store.raw.ContainerKey, int)

openContainer

public ContainerHandle openContainer(ContainerKey containerId,
                                     LockingPolicy locking,
                                     int mode)
                              throws StandardException
Description copied from interface: Transaction
Open a container, with the defined locking policy, otherwise as openContainer(int containerId, boolean forUpdate).

Calls locking.lockContainer(this, returnValue, forUpdate) to lock the container. Note that if NOWAIT has been specified lock will be requested with no wait time, and if lock is not granted a SQLState.LOCK_TIMEOUT exception will be thrown.

Specified by:
openContainer in interface Transaction
Returns:
a valid ContainerHandle or null if the container does not exist.
Throws:
StandardException - Standard cloudscape exception policy
See Also:
Transaction.openContainer(org.apache.derby.iapi.store.raw.ContainerKey, int)

openDroppedContainer

public RawContainerHandle openDroppedContainer(ContainerKey containerId,
                                               LockingPolicy locking)
                                        throws StandardException
Open a container that may already have been dropped.

Specified by:
openDroppedContainer in class RawTransaction
Throws:
StandardException - Standard cloudscape exception policy
See Also:
RawTransaction.openDroppedContainer(org.apache.derby.iapi.store.raw.ContainerKey, org.apache.derby.iapi.store.raw.LockingPolicy)

addContainer

public long addContainer(long segmentId,
                         long containerid,
                         int mode,
                         java.util.Properties tableProperties,
                         int temporaryFlag)
                  throws StandardException
Description copied from interface: Transaction
Add a new container to the segment. The new container initially has one page, page Container.FIRST_PAGE_NUMBER.
If pageSize is equal to ContainerHandle.DEFAULT_PAGESIZE or invalid then a default page size will be picked.
SpareSpace indicates that percent (0% - 100%) of page space that will be attempted to be reserved for updates. E.g. with a value of 20 a page that would normally hold 40 rows will be limited to 32 rows, actual calculation for the threshold where no more inserts are all accepted is up to the implementation. Whatever the value of spaceSpace an empty page will always accept at least one insert. If spare space is equal to ContainerHandle.DEFAULT_PAGESIZE or invalid then a default value will be used.

Synchronisation

The new container is exclusivly locked by this transaction until it commits.

Specified by:
addContainer in interface Transaction
Parameters:
segmentId - segment to create the container in.
containerid - If not equal to 0 then this container id will be used to create the container, else if set to 0 then the raw store will assign a number.
mode - mode description in @see ContainerHandle. This mode is only effective for the duration of the addContainer call and not stored persistently for the lifetime of the container.
tableProperties - Implementation-specific properties of the conglomerate.
Returns:
a container identifer that can be used in openContainer() This id is only valid within this RawStoreFactory. Returns a negative number if a container could not be allocated.
Throws:
StandardException - Standard cloudscape exception policy
See Also:
Transaction.addContainer(long, long, int, java.util.Properties, int)

addAndLoadStreamContainer

public long addAndLoadStreamContainer(long segmentId,
                                      java.util.Properties tableProperties,
                                      RowSource rowSource)
                               throws StandardException
Description copied from interface: Transaction
Add a new stream container to the segment and load the stream container. This stream container doesn't not have locks, and do not log. It does not have the concept of a page. It is used by the external sort only.

Synchronisation

This call will mark the container as dropped and then obtain an CX lock on the container. Once a container has been marked as dropped it cannot be retrieved by any openContainer() call.

Once the exclusive lock has been obtained the container is removed and all its pages deallocated. The container will be fully removed at the commit time of the transaction.

Specified by:
addAndLoadStreamContainer in interface Transaction
Throws:
StandardException - Standard cloudscape exception policy
See Also:
Transaction.addAndLoadStreamContainer(long, java.util.Properties, org.apache.derby.iapi.store.access.RowSource)

openStreamContainer

public StreamContainerHandle openStreamContainer(long segmentId,
                                                 long containerId,
                                                 boolean hold)
                                          throws StandardException
Description copied from interface: Transaction
Open a stream container.

Specified by:
openStreamContainer in interface Transaction
Returns:
a valid StreamContainerHandle or null if the container does not exist.
Throws:
StandardException - Standard cloudscape exception policy
See Also:
Transaction.openStreamContainer(long, long, boolean)

dropStreamContainer

public void dropStreamContainer(long segmentId,
                                long containerId)
                         throws StandardException
Description copied from interface: Transaction
Drop a stream container.

Synchronisation

This call will remove the container.

Specified by:
dropStreamContainer in interface Transaction
Throws:
StandardException - Standard Cloudscape error policy
See Also:
Transaction.dropStreamContainer(long, long)

reCreateContainerForLoadTran

public void reCreateContainerForLoadTran(long segmentId,
                                         long containerId,
                                         ByteArray containerInfo)
                                  throws StandardException
Recreate a container during load tran - use only by media recovery.

Specified by:
reCreateContainerForLoadTran in class RawTransaction
Throws:
StandardException - Standard cloudscape exception policy
See Also:
RawTransaction.reCreateContainerForLoadTran(long, long, org.apache.derby.iapi.util.ByteArray)

dropContainer

public void dropContainer(ContainerKey containerId)
                   throws StandardException
Description copied from interface: Transaction
Drop a container.

Synchronisation

This call will mark the container as dropped and then obtain an CX lock on the container. Once a container has been marked as dropped it cannot be retrieved by any openContainer() call.

Once the exclusive lock has been obtained the container is removed and all its pages deallocated. The container will be fully removed at the commit time of the transaction.

Specified by:
dropContainer in interface Transaction
Throws:
StandardException - Standard Cloudscape error policy
See Also:
Transaction.dropContainer(org.apache.derby.iapi.store.raw.ContainerKey)

setSavePoint

public int setSavePoint(java.lang.String name,
                        java.lang.Object kindOfSavepoint)
                 throws StandardException
Description copied from interface: Transaction
Set a save point in the current transaction. A save point defines a point in time in the transaction that changes can be rolled back to. Savepoints can be nested and they behave like a stack. Setting save points "one" and "two" and the rolling back "one" will rollback all the changes made since "one" (including those made since "two") and release savepoint "two".

Specified by:
setSavePoint in interface Transaction
Parameters:
name - The user provided name of the savepoint
kindOfSavepoint - A NULL value means it is an internal savepoint (ie not a user defined savepoint) Non NULL value means it is a user defined savepoint which can be a SQL savepoint or a JDBC savepoint A String value for kindOfSavepoint would mean it is SQL savepoint A JDBC Savepoint object value for kindOfSavepoint would mean it is JDBC savepoint
Returns:
returns total number of savepoints in the stack.
Throws:
StandardException - Standard cloudscape exception policy
See Also:
Transaction.setSavePoint(java.lang.String, java.lang.Object)

throwExceptionIfSQLSavepointNotAllowed

private void throwExceptionIfSQLSavepointNotAllowed(java.lang.Object kindOfSavepoint)
                                             throws StandardException
Throws:
StandardException - Standard cloudscape exception policy
See Also:
Transaction.setSavePoint(java.lang.String, java.lang.Object)

releaseSavePoint

public int releaseSavePoint(java.lang.String name,
                            java.lang.Object kindOfSavepoint)
                     throws StandardException
Description copied from interface: Transaction
Release the save point of the given name. Relasing a savepoint removes all knowledge from this transaction of the named savepoint and any savepoints set since the named savepoint was set.

Specified by:
releaseSavePoint in interface Transaction
Parameters:
name - The user provided name of the savepoint, set by the user in the setSavePoint() call.
kindOfSavepoint - A NULL value means it is an internal savepoint (ie not a user defined savepoint) Non NULL value means it is a user defined savepoint which can be a SQL savepoint or a JDBC savepoint A String value for kindOfSavepoint would mean it is SQL savepoint A JDBC Savepoint object value for kindOfSavepoint would mean it is JDBC savepoint
Returns:
returns total number of savepoints in the stack.
Throws:
StandardException - Standard cloudscape exception policy
See Also:
Transaction.releaseSavePoint(java.lang.String, java.lang.Object)

rollbackToSavePoint

public int rollbackToSavePoint(java.lang.String name,
                               java.lang.Object kindOfSavepoint)
                        throws StandardException
Description copied from interface: Transaction
Rollback all changes made since the named savepoint was set. The named savepoint is not released, it remains valid within this transaction, and thus can be named it future rollbackToSavePoint() calls. Any savepoints set since this named savepoint are released (and their changes rolled back).

Specified by:
rollbackToSavePoint in interface Transaction
Parameters:
name - The user provided name of the savepoint, set by the user in the setSavePoint() call.
kindOfSavepoint - A NULL value means it is an internal savepoint (ie not a user defined savepoint) Non NULL value means it is a user defined savepoint which can be a SQL savepoint or a JDBC savepoint A String value for kindOfSavepoint would mean it is SQL savepoint A JDBC Savepoint object value for kindOfSavepoint would mean it is JDBC savepoint
Returns:
returns total number of savepoints in the stack.
Throws:
StandardException - Standard cloudscape exception policy
See Also:
Transaction.rollbackToSavePoint(java.lang.String, java.lang.Object)

getLogger

private void getLogger()
Get the Logger object used to write log records to the transaction log.


assumeIdentity

protected void assumeIdentity(TransactionTableEntry ent)
Transform this identity to the one stored in transaction table entry. Used by recovery only!


assumeGlobalXactIdentity

protected void assumeGlobalXactIdentity(TransactionTableEntry ent)
Assume complete identity of the given Transaction Table Entry.

Used by the final phase of the recovery to create new real transactions to take on the identity of in-doubt prepared transactions found during redo. Need to assume the globalId.

Returns:
The identifier to be used to open the conglomerate later.

setUpdateState

private final void setUpdateState()
                           throws StandardException
Move the transaction into the update state.

Throws:
StandardException - problem setting a transaction id

setIdleState

protected void setIdleState()

setActiveState

protected final void setActiveState()
                             throws StandardException
Throws:
StandardException

setPrepareState

protected final void setPrepareState()
                              throws StandardException
Move the state of the transaction from UPDATE to PREPARE.

The state transition should only be from UPDATE to PREPARE. Read-only transactions (IDLE and ACTIVE) will never be prepared, they will be commited when the prepare is requested. Only Update transactions will be allowed to go to prepared state.

Throws:
StandardException - Standard exception policy.

defaultLockingPolicy

public final LockingPolicy defaultLockingPolicy()

releaseAllLocks

private final void releaseAllLocks()

resetDefaultLocking

void resetDefaultLocking()

preComplete

protected void preComplete(java.lang.Integer commitOrAbort)
                    throws StandardException
Throws:
StandardException

postComplete

protected void postComplete(int commitflag,
                            java.lang.Integer commitOrAbort)
                     throws StandardException
Throws:
StandardException

doComplete

protected void doComplete(java.lang.Integer commitOrAbort)
                   throws StandardException
Throws:
StandardException

checkObserverException

private void checkObserverException()
                             throws StandardException
Throws:
StandardException

doPostCommitWorkInTran

protected boolean doPostCommitWorkInTran()
If this is a user transaction (not an internal or nested top transaction), and this is not already taking care of post commit work, and not an XA transaction, then take care of hi prioirty work right now using this thread and this context manager. Otherwise, leave it to the post commit daemon.


handlesPostTerminationWork

public boolean handlesPostTerminationWork()
Description copied from class: RawTransaction
Can this transaction handles post termination work

Specified by:
handlesPostTerminationWork in class RawTransaction

recoveryTransaction

public void recoveryTransaction()
Description copied from class: RawTransaction
Make this transaction aware that it is being used by recovery

Specified by:
recoveryTransaction in class RawTransaction

postTermination

private final void postTermination()
                            throws StandardException
Throws:
StandardException

getSavePointPosition

private int getSavePointPosition(java.lang.String name,
                                 java.lang.Object kindOfSavepoint,
                                 boolean forRollbackOrRelease)
Does a save point exist in the stack with the given name. Returns the position of the savepoint in the array


popSavePoints

protected boolean popSavePoints(int position,
                                boolean release)
                         throws StandardException
Pop all savepoints upto the one with the given name and rollback all changes made since this savepoint was pushed. If release is true then this savepoint is popped as well, otherwise it is left in the stack (at the top).

Returns:
true if any work is rolled back, false if no work is rolled back
Throws:
StandardException - Standard cloudscape policy
StandardException - Thrown if a error of severity less than TransactionException#SEVERITY is encountered during the rollback of this savepoint.

startNestedTopTransaction

public RawTransaction startNestedTopTransaction()
                                         throws StandardException
Description copied from class: RawTransaction
Start a nested top transaction. A nested top transaction behaves exactly like a user transaction. Nested top transaction allow system type work to proceed in a separate transaction to the current user transaction and be committed independently of the user transaction (usually before the user transaction). Only one nested top transaction can be active in a context at any one time. After a commit the transaction may be re-used. A nested top transaction conflicts on the logical locks of its "parent" transaction.

Specified by:
startNestedTopTransaction in class RawTransaction
Throws:
StandardException - Cloudscape Standard error policy

isUserTransaction

private boolean isUserTransaction()
see if this transaction is a user transaction.

Returns:
true if this transaction is a user transaction

isActive

public final boolean isActive()
see if this transaction has ever done anything. MT - single thread through synchronizing this. This method may be called by other thread to test the state of this transaction. That's why we need to synchronize with all methods which enters or exits the Idle state. Local method which read the state need not be synchronized because the other thread may look at the state but it may not change it.

Returns:
true if this transaction is not in idle or closed state

isPrepared

public final boolean isPrepared()
see if this transaction is in PREPARED state. MT - single thread through synchronizing this. This method may be called by other thread to test the state of this transaction.

Returns:
true if this transaction is in PREPARED state.

isIdle

public boolean isIdle()
See if this transaction is in the idle state, called by other thread to test the state of this transaction. That's why we need to synchronzied with all methods whcih enters or exits the idle state

Specified by:
isIdle in interface Transaction
Returns:
true if it is idle, otherwise false

isPristine

public boolean isPristine()
see if this transaction is in a pristine state.
MT - called only by the same thread that owns the xact, no need to synchronize.

Specified by:
isPristine in interface Transaction
Returns:
true if it hasn't done any updates, otherwise false

inAbort

public boolean inAbort()
Description copied from class: RawTransaction
Is the transaction in the middle of an abort.

Specified by:
inAbort in class RawTransaction

getFileHandler

public FileResource getFileHandler()
Description copied from interface: Transaction
Get an object to handle non-transactional files.

Specified by:
getFileHandler in interface Transaction

statusForBeginXactLog

protected int statusForBeginXactLog()
put this into the beginXact log record to help recovery if we needs to rolled back first, put that in

Specified by:
statusForBeginXactLog in class RawTransaction

statusForEndXactLog

protected int statusForEndXactLog()
put this into the endXact log record to help recovery, nothing to add

Specified by:
statusForEndXactLog in class RawTransaction

setPostComplete

void setPostComplete()
Set the transaction to issue pre complete work at postComplete time, instead of preComplete time. This means that latches and containers will be held open until after a commit or an abort.


reached

public void reached(java.lang.Object compatabilitySpace,
                    java.lang.Object group,
                    int limit,
                    java.util.Enumeration lockList,
                    int lockCount)
             throws StandardException
Description copied from interface: Limit
Called by the lock factory when a limit has been reached.

Specified by:
reached in interface Limit
Parameters:
compatabilitySpace - lock space the limit was set for
group - lock group the limit was set for
limit - the limit's setting
lockList - the list of Lockable's in the group
lockCount - the number of locks in the group
Throws:
StandardException - Standard Cloudscape error policy.

createXATransactionFromLocalTransaction

public void createXATransactionFromLocalTransaction(int format_id,
                                                    byte[] global_id,
                                                    byte[] branch_id)
                                             throws StandardException
Convert a local transaction to a global transaction.

Must only be called a previous local transaction was created and exists in the context. Can only be called if the current transaction is in the idle state, and no current global id.

Simply call setTransactionId() which takes care of error checking.

Specified by:
createXATransactionFromLocalTransaction in interface Transaction
Parameters:
format_id - the format id part of the Xid - ie. Xid.getFormatId().
global_id - the global transaction identifier part of XID - ie. Xid.getGlobalTransactionId().
branch_id - The branch qualifier of the Xid - ie. Xid.getBranchQaulifier()
Throws:
StandardException - Standard exception policy.

xa_commit

public void xa_commit(boolean onePhase)
               throws StandardException
This method is called to commit the current XA global transaction.

RESOLVE - how do we map to the "right" XAExceptions.

Specified by:
xa_commit in interface Transaction
Parameters:
onePhase - If true, the resource manager should use a one-phase commit protocol to commit the work done on behalf of current xid.
Returns:
The identifier to be used to open the conglomerate later.
Throws:
StandardException - Standard exception policy.

xa_prepare

public int xa_prepare()
               throws StandardException
This method is called to ask the resource manager to prepare for a transaction commit of the transaction specified in xid.

Specified by:
xa_prepare in interface Transaction
Returns:
A value indicating the resource manager's vote on the the outcome of the transaction. The possible values are: XA_RDONLY or XA_OK. If the resource manager wants to roll back the transaction, it should do so by throwing an appropriate XAException in the prepare method.
Throws:
StandardException - Standard exception policy.

xa_rollback

public void xa_rollback()
                 throws StandardException
rollback the current global transaction.

The given transaction is roll'ed back and it's history is not maintained in the transaction table or long term log.

Specified by:
xa_rollback in interface Transaction
Throws:
StandardException - Standard exception policy.

toString

public java.lang.String toString()
Return the xid as a string.

The virtual lock table depends on this routine returning just the local transaction id as a string, even if it is a global transaction. Joins between the lock table and the transaction table will not work if this routine returns anything other than myId.toString().

Returns:
The xid as a string.

getActiveStateTxIdString

public java.lang.String getActiveStateTxIdString()
Description copied from interface: Transaction
get string ID of the actual transaction ID that will be used when transaction is in active state.

Specified by:
getActiveStateTxIdString in interface Transaction

getState

java.lang.String getState()

getTransName

public java.lang.String getTransName()

setTransName

public void setTransName(java.lang.String name)

inRollForwardRecovery

public boolean inRollForwardRecovery()
Is the transaction in rollforward recovery

Specified by:
inRollForwardRecovery in class RawTransaction

checkpointInRollForwardRecovery

public void checkpointInRollForwardRecovery(LogInstant cinstant,
                                            long redoLWM)
                                     throws StandardException
perform a checkpoint during rollforward recovery

Specified by:
checkpointInRollForwardRecovery in class RawTransaction
Throws:
StandardException


Apache Derby V10.0 Engine Documentation - Copyright © 1997,2004 The Apache Software Foundation or its licensors, as applicable.