net.sf.farrago.fennel
Class FennelTxnContext

java.lang.Object
  extended by net.sf.farrago.fennel.FennelTxnContext

public class FennelTxnContext
extends Object

FennelTxnContext manages the state of at most one Fennel transaction. A context may be inactive, meaning it has no current transaction.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/fennel/FennelTxnContext.java#26 $
Author:
John V. Sichi

Field Summary
private  FennelDbHandle fennelDbHandle
           
private  long hTxn
           
private  FarragoMetadataFactory metadataFactory
           
private  boolean readOnly
           
 
Constructor Summary
FennelTxnContext(FarragoMetadataFactory metadataFactory, FennelDbHandle fennelDbHandle)
          Creates a new FennelTxnContext object.
 
Method Summary
 void commit()
          Commits the current txn, if any.
private  FemSvptHandle getFemSvptHandle(FennelSvptHandle fennelSvptHandle)
           
 FennelDbHandle getFennelDbHandle()
           
 long getRawTxnHandle()
          You really don't want to use this.
 long getTxnCsn()
          Retrieves the commit sequence number associated with the current transaction
 FemTxnHandle getTxnHandle()
           
(package private)  long getTxnHandleLong()
          Gets the handle to the current txn.
 void initiateReadOnlyTxn()
          Starts a read-only transaction; no transaction is allowed to be in progress already.
 void initiateTxn()
          Forces a transaction to begin unless one is already in progress.
 void initiateTxnWithCsn(long csn)
          Starts a transaction with a commit sequence number so the transaction will read data based on a specific snapshot time.
 boolean isTxnInProgress()
           
 FennelSvptHandle newSavepoint()
          Creates a new savepoint, starting a new transaction if necessary.
 FennelStreamGraph newStreamGraph(FarragoAllocationOwner owner)
          Wrapper for executeCmd in the case where cmd is a FemCmdCreateExecutionStreamGraph.
private  void onEndOfTxn()
           
 void rollback()
          Rolls back the current txn, if any.
 void rollbackToSavepoint(FennelSvptHandle fennelSvptHandle)
          Rolls back to an existing savepoint.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

metadataFactory

private final FarragoMetadataFactory metadataFactory

fennelDbHandle

private final FennelDbHandle fennelDbHandle

hTxn

private long hTxn

readOnly

private boolean readOnly
Constructor Detail

FennelTxnContext

public FennelTxnContext(FarragoMetadataFactory metadataFactory,
                        FennelDbHandle fennelDbHandle)
Creates a new FennelTxnContext object.

Parameters:
metadataFactory - FarragoMetadataFactory for creating Fem instances
fennelDbHandle - handle to database affected by txns in this context
Method Detail

getFennelDbHandle

public FennelDbHandle getFennelDbHandle()
Returns:
handle to Fennel database accessed by this txn context

initiateTxn

public void initiateTxn()
Forces a transaction to begin unless one is already in progress.


initiateReadOnlyTxn

public void initiateReadOnlyTxn()
Starts a read-only transaction; no transaction is allowed to be in progress already.


initiateTxnWithCsn

public void initiateTxnWithCsn(long csn)
Starts a transaction with a commit sequence number so the transaction will read data based on a specific snapshot time.

Parameters:
csn - the commit sequence number

getTxnHandleLong

long getTxnHandleLong()
Gets the handle to the current txn. If no txn is in progress, starts one and returns the new handle.

Returns:
txn handle as long

getTxnHandle

public FemTxnHandle getTxnHandle()

getRawTxnHandle

public long getRawTxnHandle()
You really don't want to use this. Needed for a specific Farrago extension.


isTxnInProgress

public boolean isTxnInProgress()
Returns:
whether a txn is in progress on this connection

getTxnCsn

public long getTxnCsn()
Retrieves the commit sequence number associated with the current transaction

Returns:
the commit sequence number of the current transaction

commit

public void commit()
Commits the current txn, if any.


rollback

public void rollback()
Rolls back the current txn, if any.


onEndOfTxn

private void onEndOfTxn()

newSavepoint

public FennelSvptHandle newSavepoint()
Creates a new savepoint, starting a new transaction if necessary. Note that savepoint handles are "lightweight" and thus don't require deallocation.

Returns:
handle to created savepoint

rollbackToSavepoint

public void rollbackToSavepoint(FennelSvptHandle fennelSvptHandle)
Rolls back to an existing savepoint.

Parameters:
fennelSvptHandle - handle to savepoint to rollback to

getFemSvptHandle

private FemSvptHandle getFemSvptHandle(FennelSvptHandle fennelSvptHandle)

newStreamGraph

public FennelStreamGraph newStreamGraph(FarragoAllocationOwner owner)
Wrapper for executeCmd in the case where cmd is a FemCmdCreateExecutionStreamGraph. This ensures that some object owns the returned stream graph.

Parameters:
owner - the object which will be made responsible for the stream graph's allocation as a result of this call
Returns:
opened FennelStreamGraph