com.sun.sgs.impl.util
Class TransactionContext

java.lang.Object
  extended by com.sun.sgs.impl.util.TransactionContext
Direct Known Subclasses:
ChannelServiceImpl.Context, ClientSessionServiceImpl.Context, Context

public abstract class TransactionContext
extends Object

A context to hold state associated with a transaction. A TransactionContext is created by the method TransactionContextFactory.createContext(com.sun.sgs.service.Transaction).


Field Summary
protected  boolean isCommitted
          true if the transaction is committed.
protected  boolean isPrepared
          true if the transaction is prepared.
protected  Transaction txn
          The transaction.
 
Constructor Summary
TransactionContext(Transaction txn)
          Constructs an instance of this class with the given transaction.
 
Method Summary
abstract  void abort(boolean retryable)
          Aborts this context's involvement with the transaction associated with this context.
abstract  void commit()
          Commits this context's state.
 Transaction getTransaction()
          Returns the transaction associated with this context.
 boolean isPrepared()
          Returns true if this context is prepared, otherwise returns false.
 boolean prepare()
          Prepares state for the transaction associated with this context, sets the isPrepared flag to true, and returns true if this context's state is read-only and returns false otherwise.
 void prepareAndCommit()
          Prepares state for the transaction associated with this context, sets the isPrepared flag to true, and if this context's state is not read-only, commits this context's state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

txn

protected final Transaction txn
The transaction.


isPrepared

protected boolean isPrepared
true if the transaction is prepared.


isCommitted

protected boolean isCommitted
true if the transaction is committed.

Constructor Detail

TransactionContext

public TransactionContext(Transaction txn)
Constructs an instance of this class with the given transaction.

Parameters:
txn - a transaction
Method Detail

prepare

public boolean prepare()
                throws Exception
Prepares state for the transaction associated with this context, sets the isPrepared flag to true, and returns true if this context's state is read-only and returns false otherwise. In the case that this method is overridden and returns true, that implementation should also set the isCommitted flag to true.

The default implementation of this method sets the isPrepared flag to true and returns false.

Returns:
true if this context's state is read-only, false otherwise
Throws:
Exception - if there is a problem preparing this context's state

prepareAndCommit

public void prepareAndCommit()
                      throws Exception
Prepares state for the transaction associated with this context, sets the isPrepared flag to true, and if this context's state is not read-only, commits this context's state. This method should also set the isCommitted flag to true.

The default implementation of this method invokes prepare to prepare state for the transaction associated with this context, and if prepare returns false, then invokes commit to commit this context's state.

Throws:
Exception - if there is a problem preparing this context's state

abort

public abstract void abort(boolean retryable)
Aborts this context's involvement with the transaction associated with this context.

Parameters:
retryable - if true, the transaction's abort cause is a retryable exception

commit

public abstract void commit()
Commits this context's state. The implementation of this method should set the isCommitted flag to true.


getTransaction

public Transaction getTransaction()
Returns the transaction associated with this context.

Returns:
the transaction associated with this context

isPrepared

public boolean isPrepared()
Returns true if this context is prepared, otherwise returns false.

Returns:
true if this context is prepared, otherwise returns false

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved