com.massimo.tools.scriptrunner.utils
Class ConnectionFactory

java.lang.Object
  extended by com.massimo.tools.scriptrunner.utils.ConnectionFactory

public class ConnectionFactory
extends Object

Loads and configures DataSource instances, and uses them to get Connection objects.


Field Summary
protected static Map<String,DataSource> dataSources
          Map of connection names to DataSources
 
Method Summary
static void dump(PrintStream out)
          Dump some hopefully useful information.
static Element findConnectionElement(String dataSourceName, Element definition)
          
Look for the connection definition with matching dataSourceName.
static Connection getConnection(String dataSourceName, Element definition)
          Get a connection from the named data source.
static DatabaseType getDatabaseType(String dataSourceName, Element definition)
          Make a guess at the DBMS from the same information the DataSource is created from.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataSources

protected static Map<String,DataSource> dataSources
Map of connection names to DataSources

Method Detail

dump

public static void dump(PrintStream out)
Dump some hopefully useful information.
Used by DataSourcesTask

Parameters:
out -

findConnectionElement

public static Element findConnectionElement(String dataSourceName,
                                            Element definition)
                                     throws SRException

Look for the connection definition with matching dataSourceName.
If dataSourceName is empty, look for a single child connection definition that is not the audit connection. If none is found, look for a single ancestor connection definition that is not the audit connection. If none is found, assume that the dataSourceName is the default name, Constants.DATASOURCE_DEFAULT.

Parameters:
dataSourceName -
definition -
Returns:
The required connection Element
Throws:
SRException

getConnection

public static Connection getConnection(String dataSourceName,
                                       Element definition)
                                throws SRException
Get a connection from the named data source.

Look for the connection definition with a matching dataSourceName.
If dataSourceName is empty, look for a single child connection definition that is not the audit connection. If none is found, look for a single ancestor connection definition that is not the audit connection. If none is found, assume that the dataSourceName is the default name, Constants.DATASOURCE_DEFAULT.

Once the connection Element is determined, the DataSource class is found or created.
A Connection is had from the DataSource, with auto-commit set to false and transaction isolation set to TRANSACTION_SERIALIZABLE, i.e. dirty reads, non-repeatable reads and phantom reads are prevented.

Parameters:
dataSourceName - The dataSourceName of a connection element in definition or a parent.
definition - A Task definition Element
Returns:
Connection
Throws:
SRException

getDatabaseType

public static DatabaseType getDatabaseType(String dataSourceName,
                                           Element definition)
Make a guess at the DBMS from the same information the DataSource is created from.

Parameters:
dataSourceName - The dataSourceName of a connection element in definition or a parent.
definition - A Task definition Element
Returns:
DatabaseType