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

java.lang.Object
  extended by com.softwareag.tamino.db.api.connection.TConnectionImpl
All Implemented Interfaces:
TConnection, TDarkConnection

public class TConnectionImpl
extends java.lang.Object
implements TDarkConnection

TConnectionImpl is the implementation class for TConnection/TDarkConnection.

Version:
$Revision: 1.61 $
Author:
Marcus Schreyer

Field Summary
 
Fields inherited from interface com.softwareag.tamino.db.api.connection.TConnection
DEFAULT_TIMEOUT
 
Constructor Summary
protected TConnectionImpl(TInvocation invocation)
          Protected Constructor.
protected TConnectionImpl(TInvocation invocation, java.util.Locale locale)
           
 
Method Summary
 void close()
          Closes the connection to Tamino.
 java.lang.String getDatabaseURI()
          Return the database URI as a string.
 TInvocation getInvocation()
          Return the invocation.
 TIsolationDegree getIsolationDegree()
          Gets the current isolation degree.
 boolean getKeepAlive()
          Get the keep alive property.
 java.util.Locale getLocale()
          Gets the locale.
 TLockMode getLockMode()
          Gets the current lock mode
 TLockwaitMode getLockwaitMode()
          Gets the current lockwait mode
 long getMaximumTransactionDuration()
          Gets the maximum transaction duration in seconds.

Note:
This method retrieves the servers default value, when this duration has not been set to a specific value (unequal to TConnection.DEFAULT_TIMEOUT)!
 long getNonActivityTimeout()
          Gets the nonActivity timeout in seconds.

Note:
This method retrieves the servers default value, when this timeout has not been set to a specific value (unequal to TConnection.DEFAULT_TIMEOUT)!
 int getSocketTimeout()
           
 TTransaction getTransaction()
          Gets the current active transaction instance.
 boolean isActive()
          Indicates whether the session associated with the TConnection instance is active
 boolean isClosed()
          Indicates if the connection is closed.
 boolean isFirstCallPending()
          Check whether th efirst call in a new transaction is pending.
 boolean isHealthy()
          Indicates whether the connection is still healthy.
 boolean isInDangerToBeStale()
          Indicates whether the undelyign physical Tamino connection might have been timed out due to the nonActivityTimeout.
 TAdministrationAccessor newAdministrationAccessor()
          Creates a TAdministrationAccessor instance that is bound to this connection.
 TNonXMLObjectAccessor newNonXMLObjectAccessor(TAccessLocation accessLocation)
          Creates a new TNonXMLObjectAccessor object that is bound to this connection.
 TSchemaDefinition2Accessor newSchemaDefinition2Accessor(java.lang.Object xmlObjectModel)
          Creates a new TSchemaDefinition2Accessor object that is bound to this connection.
 TSchemaDefinition3Accessor newSchemaDefinition3Accessor(java.lang.Object xmlObjectModel)
          Creates a new TSchemaDefinition3Accessor object that is bound to this connection.
 TStreamAccessor newStreamAccessor(TAccessLocation accessLocation)
          Creates a new TStreamAccessor instance that is bound to this connection.
 TSystemAccessor newSystemAccessor()
          Creates a new TSystemAccessor object that is bound to this connection.
 TXMLObjectAccessor newXMLObjectAccessor(TAccessLocation accessLocation, java.lang.Object xmlObjectModel)
          Creates a new TXMLObjectAccessor objects that is bound to this connection.
 TPreparedXQuery prepareQuery(java.lang.String expression)
          Creates a TPreparedXQuery instance that is bound to this connection.
 void reset()
          Resets the connection to its initial state.
 void resetTransactionParameters()
          Resets the transactional parameters to represent the Tamino defaults.
 void resetTransactionTimeoutParameters()
          Resets the timeout parameters to represent the Tamino defaults.
 void setFirstCallPending(boolean b)
          Sets the indicator to indicate that the first call in a new transaction is pending.
 void setGroups(java.lang.String groups)
          Sets the groups for the current user.
 void setIsolationDegree(TIsolationDegree isolationDegree)
          Sets the isolation degree for a local or global transaction.
 void setKeepAlive(boolean keepAlive)
          Set the keep alive feature of the connection.
Setting keepAlive to true will cause this connection to schedule a task that periodically will try to refresh the databases nonActivityTimeout.
Otherwise it will stop the keep alive task.
 void setLockMode(TLockMode lockMode)
          Sets the lock mode for a local or global transaction.
 void setLockwaitMode(TLockwaitMode lockwaitMode)
          Sets the lockwait mode for a local or global transaction.
 void setMaximumTransactionDuration(long maximumTransactionDuration)
          Sets the maximum transaction duration in seconds.
 void setNonActivityTimeout(long nonActivityTimeout)
          Sets the nonActivity timeout in seconds.
 void setSocketTimeout(int timeout)
           
 void useAutoCommitMode()
          Tells the connection to use autocommit mode.
 TGlobalTransaction useGlobalTransactionMode(TGlobalTransactionSpecifier globalTransactionSpecifier)
          Tells the connection to use and participate in a global transaction with the given isolation level and lockwait mode.
 TLocalTransaction useLocalTransactionMode()
          Tells the connection to use a local transaction with the given isolation level and lockwait mode.
 boolean usesAutoCommitMode()
          Indicates if currently an autocommit transaction mode is used.
 boolean usesGlobalTransactionMode()
          Indicates if currently a global transaction mode is used.
 boolean usesLocalTransactionMode()
          Indicates if currently a local transaction mode is used.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TConnectionImpl

protected TConnectionImpl(TInvocation invocation)
                   throws TCommunicationException
Protected Constructor.

Parameters:
invocation -
Throws:
TCommunicationException

TConnectionImpl

protected TConnectionImpl(TInvocation invocation,
                          java.util.Locale locale)
                   throws TCommunicationException
Throws:
TCommunicationException
Method Detail

newStreamAccessor

public TStreamAccessor newStreamAccessor(TAccessLocation accessLocation)
Creates a new TStreamAccessor instance that is bound to this connection. A TStreamAccessor can be used for low level stream access on Tamino.

Specified by:
newStreamAccessor in interface TConnection
Parameters:
accessLocation - the TAccessLocation instance specifying the location for the accessor.
Returns:
TStreamAccessor object that is associated with this conneciton.

newNonXMLObjectAccessor

public TNonXMLObjectAccessor newNonXMLObjectAccessor(TAccessLocation accessLocation)
Creates a new TNonXMLObjectAccessor object that is bound to this connection.

Specified by:
newNonXMLObjectAccessor in interface TConnection
Parameters:
accessLocation - the TAccessLocation instance specifying the location for the accessor.
Returns:
TNonXMLObjectAccessor object that is associated with this conneciton connection.

newXMLObjectAccessor

public TXMLObjectAccessor newXMLObjectAccessor(TAccessLocation accessLocation,
                                               java.lang.Object xmlObjectModel)
Creates a new TXMLObjectAccessor objects that is bound to this connection. The instantiated TXMLObjectAccessor is parametrized with the given xmlObjectModel which has to implement the operations defined within TXMLObjectModel.

Specified by:
newXMLObjectAccessor in interface TConnection
Parameters:
accessLocation - the TAccessLocation instance specifying the location for the accessor.
xmlObjectModel - an instance of TXMLObjectModel indicating the object model to be used for the accessor.
Returns:
TNativeXmlAccessor object that is associated with this conneciton connection.

newSchemaDefinition2Accessor

public TSchemaDefinition2Accessor newSchemaDefinition2Accessor(java.lang.Object xmlObjectModel)
Creates a new TSchemaDefinition2Accessor object that is bound to this connection. The instantiated TSchemaDefinition2Accessor is parametrized with the given xmlObjectModel which has to implement the operations defined within TXMLObjectModel.

Specified by:
newSchemaDefinition2Accessor in interface TConnection
Parameters:
xmlObjectModel - an instance of TXMLObjectModel indicating the object model to be used for the accessor.
Returns:
TSchemaDefinition2Accessor which is associated with this conneciton. Can be used to access meta data based on Tamino Schema Definition 2.

newSchemaDefinition3Accessor

public TSchemaDefinition3Accessor newSchemaDefinition3Accessor(java.lang.Object xmlObjectModel)
Creates a new TSchemaDefinition3Accessor object that is bound to this connection. The instantiated TSchemaDefinition3Accessor is parametrized with the given xmlObjectModel which has to implement the operations defined within TXMLObjectModel.

Specified by:
newSchemaDefinition3Accessor in interface TConnection
Parameters:
xmlObjectModel - an instance of TXMLObjectModel indicating the object model to be used for the accessor.
Returns:
TXMLMetaDataAccessor the object that is associated with this conneciton.

newSystemAccessor

public TSystemAccessor newSystemAccessor()
Creates a new TSystemAccessor object that is bound to this connection.

Specified by:
newSystemAccessor in interface TConnection
Returns:
TSystemAccessor the object that is associated with this conneciton.

newAdministrationAccessor

public TAdministrationAccessor newAdministrationAccessor()
Creates a TAdministrationAccessor instance that is bound to this connection. You can use a TAdministrationAccessor instance for executing administrative commands on Tamino.

Specified by:
newAdministrationAccessor in interface TConnection
Returns:
TSystemAccessor a system accessor bound to this connection.

setKeepAlive

public void setKeepAlive(boolean keepAlive)
Set the keep alive feature of the connection.
Setting keepAlive to true will cause this connection to schedule a task that periodically will try to refresh the databases nonActivityTimeout.
Otherwise it will stop the keep alive task.

Specified by:
setKeepAlive in interface TDarkConnection
Parameters:
keepAlive - on true this connection tries to refresh the timeout; otherwise not.

getKeepAlive

public boolean getKeepAlive()
Get the keep alive property.

Returns:
the keep alive property

useAutoCommitMode

public void useAutoCommitMode()
                       throws TTransactionModeChangeException
Tells the connection to use autocommit mode. If a connection is in autocommit mode, then all access operations performed on associated TAccessor instances will be executed and committed as individual transactions. If the connection is currently in the local transactin mode, then the current local transaction is rolled back and the relevant TLocalTransaction instance is released and cannot be used any longer.

Specified by:
useAutoCommitMode in interface TConnection
Throws:
TTransactionModeChangeException - due to a problem during changing the transaction mode (e.g. from local to autocommit).

usesAutoCommitMode

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

Specified by:
usesAutoCommitMode in interface TConnection
Returns:
true if an autocommit transaction mode is currently in use, false otherwise.

useLocalTransactionMode

public TLocalTransaction useLocalTransactionMode()
                                          throws TTransactionModeChangeException
Tells the connection to use a local transaction with the given isolation level and lockwait mode. A TLocalTransaction instance is handed back so that the client can perform commit/rollback on the local transaction. The connection resides in the local transaction mode until the TLocalTransaction instance is released on the connection. The default isolation level is shared and the default lockwait being used is set to no.

Specified by:
useLocalTransactionMode in interface TConnection
Returns:
a TLocalTransaction instance that can be used for commit/rollback.
Throws:
TTransactionModeChangeException - due to a problem during changing the transaction mode (e.g. from autocommit to local).

usesLocalTransactionMode

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

Specified by:
usesLocalTransactionMode in interface TConnection
Returns:
true if a local transaction is currently in use, false otherwise.

useGlobalTransactionMode

public TGlobalTransaction useGlobalTransactionMode(TGlobalTransactionSpecifier globalTransactionSpecifier)
                                            throws TTransactionModeChangeException
Tells the connection to use and participate in a global transaction with the given isolation level and lockwait mode.

Specified by:
useGlobalTransactionMode in interface TConnection
Parameters:
globalTransactionSpecifier - the global transaction identifier. Should be originated by transaction controller.
Returns:
a TGlobalTransaction instance that can be used for the global transaction.
Throws:
TTransactionModeChangeException

usesGlobalTransactionMode

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

Specified by:
usesGlobalTransactionMode in interface TConnection
Returns:
true if a global transaction 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.

Specified by:
getTransaction in interface TConnection
Returns:
the current transaction instance, or null if no transaction instance is required for this mode.

reset

public void reset()
           throws TTransactionModeChangeException
Resets the connection to its initial state. When the connection is in auto commit mode the connection sets the lockwait mode and isolation level to the Tamino defaults. When the connection is in local transaction mode the current transaction is rolled back and the connection is switched to auto commit mode.

Specified by:
reset in interface TConnection
Throws:
TTransactionModeChangeException - due to a problem during reseting the transaction mode to auto commit.

setLockwaitMode

public void setLockwaitMode(TLockwaitMode lockwaitMode)
Sets the lockwait mode for a local or global transaction. Setting the lockwait mode is only possible in the autocommit mode.

Specified by:
setLockwaitMode in interface TConnection
Parameters:
lockwaitMode - for a local or global transaction.

getLockwaitMode

public TLockwaitMode getLockwaitMode()
Gets the current lockwait mode

Specified by:
getLockwaitMode in interface TConnection
Returns:
The lockwait mode level.

setIsolationDegree

public void setIsolationDegree(TIsolationDegree isolationDegree)
Sets the isolation degree for a local or global transaction. Setting the isolation degree is only possible in the autocommit mode.

Specified by:
setIsolationDegree in interface TConnection
Parameters:
isolationDegree - for a local or global transaction.

getIsolationDegree

public TIsolationDegree getIsolationDegree()
Gets the current isolation degree.

Specified by:
getIsolationDegree in interface TConnection
Returns:
The isolation degree.

setLockMode

public void setLockMode(TLockMode lockMode)
Sets the lock mode for a local or global transaction. Setting the lock mode is only possible in the autocommit mode.

Specified by:
setLockMode in interface TConnection
Parameters:
lockwaitMode - for a local or global transaction.

getLockMode

public TLockMode getLockMode()
Gets the current lock mode

Specified by:
getLockMode in interface TConnection
Returns:
The lock mode.

setNonActivityTimeout

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

Specified by:
setNonActivityTimeout in interface TConnection
Parameters:
nonActivityTimeout - the transaction nonActivity timeout in seconds be set, TConnection.DEFAULT_TIMEOUT for Tamino default.

getNonActivityTimeout

public long getNonActivityTimeout()
Gets the nonActivity timeout in seconds.

Note:
This method retrieves the servers default value, when this timeout has not been set to a specific value (unequal to TConnection.DEFAULT_TIMEOUT)!

Specified by:
getNonActivityTimeout in interface TConnection
Returns:
the transaction nonActivity timeout in seconds.

setMaximumTransactionDuration

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

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

getLocale

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

Specified by:
getLocale in interface TConnection
Returns:
the locale.

getMaximumTransactionDuration

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

Note:
This method retrieves the servers default value, when this duration has not been set to a specific value (unequal to TConnection.DEFAULT_TIMEOUT)!

Specified by:
getMaximumTransactionDuration in interface TConnection
Returns:
the maximum transaction duration in seconds.

setGroups

public void setGroups(java.lang.String groups)
Sets the groups for the current user. This has to be set before invoking useLocalTransactionMode().

Specified by:
setGroups in interface TConnection
Parameters:
groups - the groups for the current user

close

public void close()
           throws TConnectionCloseException
Closes the connection to Tamino. As a result any internal resources needed for the connections with Tamino are closed. This connection instance can afterwards not be used any longer. Before closing the connection, the connection first comes back to the autocommit mode thus a local transaction that might be given is first rolled back.

Specified by:
close in interface TConnection
Throws:
TConnectionCloseException - due to problems (such as database access) during the the closure of the connection.

isClosed

public boolean isClosed()
Indicates if the connection is closed.

Specified by:
isClosed in interface TConnection
Returns:
true if the TConnection instance is closed, false otherwise.

isHealthy

public boolean isHealthy()
Indicates whether the connection is still healthy. A connection can become sick (unhealthy) if for some reason the session id/key information returned by Tamino is no longer valid. This may happen due to some failure in the underlying protocol stacks or if Tamino returns with an "invalid session state". In that case, the connection is no longer usable. If JCA is involved, this situation needs to be recognized. That is the reason that this method was introduced.

Specified by:
isHealthy in interface TDarkConnection
Returns:
boolean indicating whether the connection is healthy or not.

resetTransactionParameters

public void resetTransactionParameters()
Resets the transactional parameters to represent the Tamino defaults.

Specified by:
resetTransactionParameters in interface TDarkConnection

resetTransactionTimeoutParameters

public void resetTransactionTimeoutParameters()
Resets the timeout parameters to represent the Tamino defaults.

Specified by:
resetTransactionTimeoutParameters in interface TDarkConnection

getInvocation

public TInvocation getInvocation()
Return the invocation.

Specified by:
getInvocation in interface TDarkConnection
Returns:
the invocation

getDatabaseURI

public java.lang.String getDatabaseURI()
Return the database URI as a string.

Returns:
the database URI.

isInDangerToBeStale

public boolean isInDangerToBeStale()
Description copied from interface: TDarkConnection
Indicates whether the undelyign physical Tamino connection might have been timed out due to the nonActivityTimeout. This method is used to enable an automatic reconnect for the connection pool.

Specified by:
isInDangerToBeStale in interface TDarkConnection
Returns:
boolean indicating whether the connection may have been timed out already.

isFirstCallPending

public boolean isFirstCallPending()
Check whether th efirst call in a new transaction is pending.

Specified by:
isFirstCallPending in interface TDarkConnection
Returns:
true - if the first call is pending otherwise false

setFirstCallPending

public void setFirstCallPending(boolean b)
Sets the indicator to indicate that the first call in a new transaction is pending.

Specified by:
setFirstCallPending in interface TDarkConnection
See Also:
com.softwareag.tamino.db.api.connection.TDarkConnection.isFirstCallPending()

prepareQuery

public TPreparedXQuery prepareQuery(java.lang.String expression)
Creates a TPreparedXQuery instance that is bound to this connection. You can use a TPreparedXQuery instance for seperate compilation and execution of XQueries.

Specified by:
prepareQuery in interface TConnection
Returns:
TPreparedXQuery a prepared XQuery bound to this connection.

isActive

public boolean isActive()
Indicates whether the session associated with the TConnection instance is active

Specified by:
isActive in interface TConnection
Returns:
true if the session is valid, false otherwise

getSocketTimeout

public int getSocketTimeout()
Specified by:
getSocketTimeout in interface TConnection

setSocketTimeout

public void setSocketTimeout(int timeout)
Specified by:
setSocketTimeout in interface TConnection


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