net.sourceforge.sqlunit
Class ConnectionRegistry

java.lang.Object
  extended by net.sourceforge.sqlunit.ConnectionRegistry

public final class ConnectionRegistry
extends java.lang.Object

A Singelton object which stores database Connection objects in a HashMap and returns them to the application on demand. The properties are kept in a backup HashMap so they can be regenerated on demand.

Version:
$Revision: 1.22 $
Author:
Sujit Pal (spal@users.sourceforge.net)

Method Summary
static java.sql.Connection getConnection(java.lang.String id)
          Returns the Connection object associated with a given connection-id.
static java.lang.String getServerName()
          Returns the server name (supplied explicitly as an attribute to the Connection element or implicitly derived from the DatabaseMetaData) for the current thread.
static boolean hasTransactionSupport(java.lang.String id)
          Checks to see if the transaction-support feature is enabled for the specified connection id parameter.
static void invalidate(java.lang.String id)
          Invalidates the Connection at connection-id attribute in the Connection registry in case of an exception.
static boolean isTransactionSupportImplicit(java.lang.String id)
          Checks to see if the transaction support feature is set to implicit.
static boolean reconnectOnFailure(java.lang.String id)
          Checks to see if the reconnect-on-failure is enabled for the specified connection id parameter.
static void releaseConnections()
          Closes all the connections in the registry and marks the registry as ready for garbage collection.
static void safelyCommit(java.lang.String id, java.sql.Connection conn)
          Issues a COMMIT on the specified connection only if transaction-support is turned on for the connection.
static void safelyRollback(java.lang.String id, java.sql.Connection conn)
          Issues a ROLLBACK on the specified connection only if transaction-support is turned on for the connection.
static void setConnection(java.sql.Connection conn)
          Sets the default connection object by specifying an actual Connection object.
static void setConnection(java.lang.String id, java.util.Map props)
          Sets a Connection keyed by a Map of connection properties supplied in the connection element for the given Connection id.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getConnection

public static java.sql.Connection getConnection(java.lang.String id)
                                         throws SQLUnitException
Returns the Connection object associated with a given connection-id.

Parameters:
id - the value of the connection-id attribute.
Returns:
the Connection object stored at this id.
Throws:
SQLUnitException - if there was a problem getting the connection.

getServerName

public static java.lang.String getServerName()
Returns the server name (supplied explicitly as an attribute to the Connection element or implicitly derived from the DatabaseMetaData) for the current thread.

Returns:
the server name for the current thread.

setConnection

public static void setConnection(java.sql.Connection conn)
Sets the default connection object by specifying an actual Connection object. Note that if the connection is specified in this manner, then SQLUnit will not be able to recreate the Connection once it is invalidated. This method is generally used by external clients who do not use the connection tag to specify the Connection to use for the test.

Parameters:
conn - the Connection object to use.

setConnection

public static void setConnection(java.lang.String id,
                                 java.util.Map props)
                          throws java.lang.Exception
Sets a Connection keyed by a Map of connection properties supplied in the connection element for the given Connection id.

Parameters:
id - the value of the connection-id attribute.
props - the Connection properties for the Connection object.
Throws:
java.lang.Exception - if there was a problem setting the connection.

reconnectOnFailure

public static boolean reconnectOnFailure(java.lang.String id)
Checks to see if the reconnect-on-failure is enabled for the specified connection id parameter.

Parameters:
id - the connection id.
Returns:
true if reconnect-on-failure is enabled for this connection.

hasTransactionSupport

public static boolean hasTransactionSupport(java.lang.String id)
Checks to see if the transaction-support feature is enabled for the specified connection id parameter.

Parameters:
id - the connection id.
Returns:
true if transaction-support is on.

isTransactionSupportImplicit

public static boolean isTransactionSupportImplicit(java.lang.String id)
Checks to see if the transaction support feature is set to implicit.

Parameters:
id - the connection id.
Returns:
true if the transaction-support is implicit.

invalidate

public static void invalidate(java.lang.String id)
Invalidates the Connection at connection-id attribute in the Connection registry in case of an exception. The invalidation will only happen if the Connection has reconnect-on-failure enabled.

Parameters:
id - the value of the connection-id attribute.

releaseConnections

public static void releaseConnections()
Closes all the connections in the registry and marks the registry as ready for garbage collection.


safelyCommit

public static void safelyCommit(java.lang.String id,
                                java.sql.Connection conn)
Issues a COMMIT on the specified connection only if transaction-support is turned on for the connection.

Parameters:
id - the Connection id.
conn - the Connection.

safelyRollback

public static void safelyRollback(java.lang.String id,
                                  java.sql.Connection conn)
Issues a ROLLBACK on the specified connection only if transaction-support is turned on for the connection.

Parameters:
id - the Connection id.
conn - the Connection.