com.objectwave.transactionalSupport
Class Session

java.lang.Object
  |
  +--com.objectwave.transactionalSupport.Session

public class Session
extends java.lang.Object

A utility class to allow multiple threads share a single transaction context. All synchronization issues must explictly be handled by the developer. An easy way to use sessions is to use the static Session.createAndJoin(String name) method.

Version:
$Id: Session.java,v 2.2 2002/03/23 13:42:11 dave_hoag Exp $
Author:
dhoag
See Also:
createAndJoin(String)

Nested Class Summary
static class Session.Test
          Unit Tests
 
Field Summary
static int PARALLEL_IGNORE_SIBLINGS
          If one child session is rolled back, the other children will still commit.
static int PARALLEL_ROLLBACK_SIBLINGS
          If one child session is rolled back, all will be set to rollback only and will not commit.
 
Constructor Summary
protected Session()
          Session is not necessarily created via the constructor.
  Session(java.lang.String name)
          Session can have names.
 
Method Summary
 void addChildSession(Session s)
          Adds a child session explicitly to this session.
 void commit()
          Commit any changes made during this transaction.
static Session createAndJoin(java.lang.String name)
          A convience method for creating and joining a session in one step.
static Session createParallelChild(Session parentSession)
          This will create a parallel child with a name that is constructed from the parent name.
static Session createParallelChild(java.lang.String name, Session parentSession)
          Creates a child session for a parallel master with the given name and master session.
static Session createParallelMaster(java.lang.String name)
          This has been added simply for the uniformity of the API.
static Session createParallelMaster(java.lang.String name, int parallelPolicy)
          Creates a ParallelMaster session with the given name and the given parallelRollbackPolicy.
 int getChildSessionCount()
          Returns the number of child sessions currently associated to this session.
 TransactionLog getCurrentTransaction()
          It is probably better to use the commit(), rollback(), and startTransaction(String) methods rather than manually manipulating the transaction.
 java.lang.String getName()
          All of the threads in the current session.
 java.lang.Object getWrap()
           
 void join()
          Have the current thread join this session.
 void leave()
          Have the current thread leave a session.
 void removeChildSession(Session s)
          Removes a child session from this parent session.
 void rollback()
          Undo any changes that this transaction has made to the TransactionalObjects.
 void setChildRolledBack(Session childSession)
          This method notifies a parent session that a child has rolled back.
protected  void setCurrentTransaction(TransactionLog log)
          Only the transactionalSupport.TransactionLog should use this method.
 void setParentSession(Session parentSession)
          Sets the parent session of a session and adds the child to the parent in one step.
 void setRollbackOnly()
          Set a flag to cause this to be rollback only.
 void setWrap(java.lang.Object newValue)
           
 void startTransaction(java.lang.String transactionType)
          Start a root or subtransaction.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PARALLEL_IGNORE_SIBLINGS

public static final int PARALLEL_IGNORE_SIBLINGS
If one child session is rolled back, the other children will still commit.

See Also:
Constant Field Values

PARALLEL_ROLLBACK_SIBLINGS

public static final int PARALLEL_ROLLBACK_SIBLINGS
If one child session is rolled back, all will be set to rollback only and will not commit.

See Also:
Constant Field Values
Constructor Detail

Session

public Session(java.lang.String name)
Session can have names. The name is just an arbitraty data type that may help with debugging. Session is not necessarily created via the constructor. An easy way to use sessions is to use the static Session.createAndJoin(String name) method.

Parameters:
name -
See Also:
createAndJoin(String)

Session

protected Session()
Session is not necessarily created via the constructor. An easy way to use sessions is to use the static Session.createAndJoin(String name) method.

See Also:
createAndJoin(String)
Method Detail

createAndJoin

public static Session createAndJoin(java.lang.String name)
A convience method for creating and joining a session in one step. It is currently possible to create multiple sessions with the same name. Care should be taken by the developer to manage session instances. In the event a session instance is 'lost', the session for the current thread can be obtained via SessionManager.getSession();

Parameters:
name - java.lang.String
Returns:
com.objectwave.transactionalSupport.Session

createParallelMaster

public static Session createParallelMaster(java.lang.String name,
                                           int parallelPolicy)
Creates a ParallelMaster session with the given name and the given parallelRollbackPolicy. #see parallelRollbackPolicy #see createParallelMaster(String)

Parameters:
name -
parallelPolicy -
Returns:

createParallelMaster

public static Session createParallelMaster(java.lang.String name)
This has been added simply for the uniformity of the API.

Parameters:
name - The name of the session to create
Returns:
See Also:
createAndJoin(String)

createParallelChild

public static Session createParallelChild(Session parentSession)
This will create a parallel child with a name that is constructed from the parent name. This DOES NOT join this session to the thread. It is the responsiblity of the client code to properly associate it's child session to the thread it will run in.

Parameters:
parentSession -
Returns:
See Also:
createParallelChild(String, Session)

createParallelChild

public static Session createParallelChild(java.lang.String name,
                                          Session parentSession)
Creates a child session for a parallel master with the given name and master session.

Parameters:
name -
parentSession -
Returns:

setParentSession

public void setParentSession(Session parentSession)
Sets the parent session of a session and adds the child to the parent in one step.

Parameters:
parentSession - The parent session of the current session
See Also:
#parentSession, addChildSession(Session)

setChildRolledBack

public void setChildRolledBack(Session childSession)
This method notifies a parent session that a child has rolled back. It is then determined by the parallel transaction policy what is done with the other children of this transaction.

Parameters:
childSession - The new ChildRolledBack value
See Also:
parallelRollbackPolicy, setRollbackOnly()

setRollbackOnly

public void setRollbackOnly()
Set a flag to cause this to be rollback only. When this session is commited, the current transaction will rollback.


setWrap

public void setWrap(java.lang.Object newValue)
Parameters:
newValue - java.lang.Object

setCurrentTransaction

protected void setCurrentTransaction(TransactionLog log)
Only the transactionalSupport.TransactionLog should use this method. Don't use.

Parameters:
log - The new CurrentTransaction value

getChildSessionCount

public int getChildSessionCount()
Returns the number of child sessions currently associated to this session.

Returns:
The ChildSessionCount value

getCurrentTransaction

public TransactionLog getCurrentTransaction()
It is probably better to use the commit(), rollback(), and startTransaction(String) methods rather than manually manipulating the transaction. Used to obtain the transaction for the specified session.

Returns:
The CurrentTransaction value

getName

public java.lang.String getName()
All of the threads in the current session. This is merely a snapshot at the time the method is invoked. An additional thread may join, or an existing thread may leave, by the time the calling method does anything with the result set.

Returns:
java.util.Vector of Threads that have joined this session. No longer supported public java.util.Vector getMembers() { return SessionManager.getDefaultManager().getMembers(this); }

getWrap

public java.lang.Object getWrap()
Returns:
java.lang.Object

addChildSession

public void addChildSession(Session s)
Adds a child session explicitly to this session. This is done for you if you call childSession.setParent(parentSession); If a parent session has children, it's call to commit will block until all children have been removed. Via their commit() or rollback() calls

Parameters:
s - The child session to be added to this parent

removeChildSession

public void removeChildSession(Session s)
Removes a child session from this parent session. See addChildSession for information about blocking on the parent's commit() call

Parameters:
s - The child session to remove.

commit

public void commit()
            throws UpdateException
Commit any changes made during this transaction.

Throws:
UpdateException

join

public void join()
Have the current thread join this session. If the current thread was already in a session, it will leave that session.


leave

public void leave()
Have the current thread leave a session. This is not required, however, it is nice for garbage collection.


rollback

public void rollback()
Undo any changes that this transaction has made to the TransactionalObjects.


startTransaction

public void startTransaction(java.lang.String transactionType)
Start a root or subtransaction. This is not the same as a database begin. A transaction log will be created to capture changes made during this transaction. If a transaction is already in progress, the transaction started via this command will be a subtransaction.

Parameters:
transactionType -

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns: