com.softwareag.tamino.db.api.connection
Class TTransactionModeCoordinator

java.lang.Object
  extended by com.softwareag.tamino.db.api.connection.TTransactionModeCoordinator

public class TTransactionModeCoordinator
extends java.lang.Object

TTransactionModeCoordinator is responsible for the coordination of the concrete transaction modes that can take place during the lifetime of a database session with Tamino. As this, the coordinator defines the rules for the transition between the transaction mode. It also defines the operation that can be invoked by a client to initiate a transaction mode transition. Where the coordinator defines the rules and the initiations for mode transitions, each concrete mode defines how to update its mode for a Tamino response and how to write its mode to a command statement instance.

Version:
$Revision: 1.28 $
Author:
Marcus Schreyer

Constructor Summary
TTransactionModeCoordinator(TGenericAccessor genericAccessor, java.util.Locale locale)
          Initializes the coordinator with the given TGenericAccessor instance.
 
Method Summary
 TIsolationDegree getIsolationDegree()
          Gets the isolation degree.
 java.util.Locale getLocale()
          Gets the locale.
 TLockMode getLockMode()
          Gets the lock mode.
 TLockwaitMode getLockwaitMode()
          Gets the current lockwait mode A 'null' value represents the Tamino default.
 long getMaximumTransactionDuration()
          Gets the maximum transaction duration in seconds.
 long getNonActivityTimeout()
          Gets the nonActivity timeout.
 TTransaction getTransaction()
          Gets the current active transaction instance.
 boolean isHealthy()
          Indicates whether the transaction mode coordinator is healthy or not.
 boolean needsSessionState(TCommand command)
          Test whether the given command statement needs session state updating, i.e.
 void resetSessionState()
          Resets the session state.
 void resetTransactionParameters()
          Resets the transaction parameters.
 void resetTransactionTimeoutParameters()
          Resets the timeout parameters.
 void setGroups(java.lang.String groups)
          Sets the groups for the current user.
 void setIsolationDegree(TIsolationDegree isolationDegree)
          Sets the isolation degree.
 void setLocale(java.util.Locale locale)
          Sets the locale.
 void setLockMode(TLockMode lockMode)
          Sets the lock mode.
 void setLockwaitMode(TLockwaitMode lockwaitMode)
          Sets the lockwait mode for a transaction.
 void setMaximumTransactionDuration(long maximumTransactionDuration)
          Sets the maximum transaction duration in seconds.
 void setNonActivityTimeout(long nonActivityTimeout)
          Sets the nonActivity timeout.
 boolean supports(TCommand command)
          Indicates if the given command is supported within the current transaction mode of this transaction mode coordinator.
 java.lang.String toString()
          Writes the current TransactionModeCoordinator state into a String.
 void updateModeFrom(TInputStream inputStream)
          Updates the transaction state according to the transaction specific content of the input stream.
 void useAutoCommitMode()
          Tells the coordinator to use an autocommit transaction mode.
 TGlobalTransaction useGlobalTransactionMode(TGlobalTransactionSpecifier globalTransactionSpecifier)
          Tells the coordinator to use a global transacion mode.
 TLocalTransaction useLocalTransactionMode()
          Tells the coordinator to use a local transaction mode.
 boolean usesAutoCommitMode()
          Indicates if currently an autocommit transaction mode is used and coordinated.
 boolean usesGlobalTransactionMode()
          Indicates if currently a global transaction mode is used and coordinated.
 boolean usesLocalTransactionMode()
          Indicates if currently a local transaction mode is used and coordinated.
 void writeModeTo(TCommandStatement commandStatement)
          Writes the current transaction mode to the given commandStatement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TTransactionModeCoordinator

public TTransactionModeCoordinator(TGenericAccessor genericAccessor,
                                   java.util.Locale locale)
Initializes the coordinator with the given TGenericAccessor instance. At the beginning the coordinator always uses a autocommit state.

Method Detail

useAutoCommitMode

public void useAutoCommitMode()
                       throws TTransactionModeChangeException
Tells the coordinator to use an autocommit transaction mode.

Throws:
TTransactionModeChangeException - for the case of mode change problems.

usesAutoCommitMode

public boolean usesAutoCommitMode()
Indicates if currently an autocommit transaction mode is used and coordinated.

Returns:
true if an autocommit transaction mode is currently in use, false otherwise.

useLocalTransactionMode

public TLocalTransaction useLocalTransactionMode()
                                          throws TTransactionModeChangeException
Tells the coordinator to use a local transaction mode.

Throws:
TTransactionModeChangeException - for the case of state change problems.

usesLocalTransactionMode

public boolean usesLocalTransactionMode()
Indicates if currently a local transaction mode is used and coordinated.

Returns:
true if a local transaction mode is currently in use, false otherwise.

useGlobalTransactionMode

public TGlobalTransaction useGlobalTransactionMode(TGlobalTransactionSpecifier globalTransactionSpecifier)
                                            throws TTransactionModeChangeException
Tells the coordinator to use a global transacion mode.

Parameters:
globalTransactionSpecifier - specifies the properties of the global transaction.
Throws:
TTransactionModeChangeException - for the case of state change problems.

usesGlobalTransactionMode

public boolean usesGlobalTransactionMode()
Indicates if currently a global transaction mode is used and coordinated.

Returns:
true if an autocommit transaction mode is currently in use, false otherwise.

getTransaction

public TTransaction getTransaction()
Gets the current active transaction instance. Since not every transaction mode has a transaction instance (e.g. TAutoCommitMode), this method may return null.

Returns:
the current transaction instance, or null if no transaction instance is required for this mode.

resetTransactionParameters

public void resetTransactionParameters()
Resets the transaction parameters.


resetTransactionTimeoutParameters

public void resetTransactionTimeoutParameters()
Resets the timeout parameters.


resetSessionState

public void resetSessionState()
Resets the session state.


setLockwaitMode

public void setLockwaitMode(TLockwaitMode lockwaitMode)
Sets the lockwait mode for a transaction.

Parameters:
lockwaitMode - the lockwait mode to be set, 'null' for Tamino default.

getLockwaitMode

public TLockwaitMode getLockwaitMode()
Gets the current lockwait mode A 'null' value represents the Tamino default.

Returns:
the lockwait mode. Returns 'null' if no lockwait mode is specified.

setIsolationDegree

public void setIsolationDegree(TIsolationDegree isolationDegree)
Sets the isolation degree.

Parameters:
isolationDegree - the isolation degree to be set, 'null' for Tamino default.

getIsolationDegree

public TIsolationDegree getIsolationDegree()
Gets the isolation degree. A 'null' value represents the Tamino default.

Returns:
the isolation degree. Returns 'null' if no isolation degree is specified.

setLockMode

public void setLockMode(TLockMode lockMode)
Sets the lock mode.

Parameters:
lockMode - the lock mode to be set, 'null' for Tamino default.

getLockMode

public TLockMode getLockMode()
Gets the lock mode. A 'null' value represents the Tamino default.

Returns:
the lock mode. Returns 'null' if no lock mode is specified.

setNonActivityTimeout

public void setNonActivityTimeout(long nonActivityTimeout)
Sets the nonActivity timeout.

Parameters:
nonActivityTimeout - the transaction nonActivity timeout be set, TConnection.DEFAULT_TIMEOUT for Tamino default.

getNonActivityTimeout

public long getNonActivityTimeout()
Gets the nonActivity timeout.

Returns:
the transaction nonActivity timeout. Returns TConnection.DEFAULT_TIMEOUT, if no transaction nonActivity timeout is specified.

setMaximumTransactionDuration

public void setMaximumTransactionDuration(long maximumTransactionDuration)
Sets the maximum transaction duration in seconds.

Parameters:
maximumTransactionDuration - the maximum transaction duration in seconds in seconds be set, TConnection.DEFAULT_TIMEOUT for Tamino default.

getMaximumTransactionDuration

public long getMaximumTransactionDuration()
Gets the maximum transaction duration in seconds.

Returns:
the maximum transaction duration. Returns TConnection.DEFAULT_TIMEOUT, if no transaction timeout is specified.

setGroups

public void setGroups(java.lang.String groups)
Sets the groups for the current user.

Parameters:
groups - the groups for the current user

writeModeTo

public void writeModeTo(TCommandStatement commandStatement)
Writes the current transaction mode to the given commandStatement.

Parameters:
commandStatement - gets the current transaction state.

updateModeFrom

public void updateModeFrom(TInputStream inputStream)
                    throws TTransactionModeUpdateException
Updates the transaction state according to the transaction specific content of the input stream. This method is a template method according the GOF template method design pattern. It defines the skeletal implementation for the state update. All abstract update methods within this class are plug in methods.

Parameters:
inputStream - represents a Tamino response stream containing a Tamino response XML document.
Throws:
TTransactionModeUpdateException - if transactions mode cannot be updated.

supports

public boolean supports(TCommand command)
Indicates if the given command is supported within the current transaction mode of this transaction mode coordinator. This is needed because there might be commands (currently only cursor specific commands) that cannot be used in a specific transaction mode.

Parameters:
command - is checked wheter it can be use with the current transaction mode.
Returns:
true if the given commandStatement can be used, false otherwise.

needsSessionState

public boolean needsSessionState(TCommand command)
Test whether the given command statement needs session state updating, i.e. sending sessionId/Key and updating.

Parameters:
command - test for this command.
Returns:
true -> session state update is needed, otherwise false.

isHealthy

public boolean isHealthy()
Indicates whether the transaction mode coordinator is healthy or not. It is not healthy when no valid session id/key are available. Once this happens no commands can be sent successfully to Tamino anymore.

Returns:
boolean indicating whether the transaction mode coordinator is healthy or not.

setLocale

public void setLocale(java.util.Locale locale)
Sets the locale.


getLocale

public java.util.Locale getLocale()
Gets the locale.

Returns:
the locale.

toString

public java.lang.String toString()
Writes the current TransactionModeCoordinator state into a String.

Overrides:
toString in class java.lang.Object
Returns:
the TransactionModeCoordinator state as a String.


Copyright (c) 2013 Software AG. All Rights Reserved.