com.webmethods.portal.service.sql.core
Class ConnectionManager

java.lang.Object
  extended by com.webmethods.portal.service.sql.core.ConnectionManager

public class ConnectionManager
extends Object

ConnectionManager manages connection pools for each of the sql data sources registered with the portal.

Typically, the only method from this class that a portlet developer would need to use would be the ConnectionManager.getConnInfo(java.lang.String) method that returns the information needed to establish a connection to a registered sql datasource.


Here is an example of opening a connection to a sql datasource:

    String dataSource = "dataSourceName";
    ISqlWorker worker = null;
    try {
        // get the connection information for the datasource
        ConnectionInfo conninfo = ConnectionManager.getConnInfo(dataSource);

        //get a worker instance from the data manager
        worker = DataManager.createWorker(dataSource);

        //TODO use one of the execute methods from the worker to
        // perform the query or update

    } catch (SQLException e) {
        //log and report the exception
        Debug.fatal(e, m_logCategory);
        throw new PortalException(e);
    } finally {
        if (worker != null) {
            //release the worker so the sql resources can be reclaimed
            worker.release();
        }
    }
 

See Also:
ISqlWorker, DataManager

Field Summary
static String CONFIG_BAK_EXTENSION
          backup file extension
static String CONNECTION_CONFIG_NAME
          entry in portal.properties storing location for db config file
protected static String CONNECTION_NODE_QUERY
           
static String DB2_DRIVER
           
static String DB2_SAG_PROXY_DRIVER
           
static String DB2_URL_PARSER_EXPRESSION
           
static String DB2_URL_TEMPLATE
           
static String DERBY_DRIVER
           
static String DERBY_SERVER_URL_PARSER_EXPRESSION
           
static String DERBY_URL_PARSER_EXPRESSION
           
static String DERBY_URL_TEMPLATE
           
static String DRIVER_PARAMETER
           
static String INFORMIX_DRIVER
           
static String INFORMIX_SAG_PROXY_DRIVER
           
static String INFORMIX_URL_PARSER_EXPRESSION
           
static String INFORMIX_URL_TEMPLATE
           
protected static HashMap m_connInfoMap
           
protected static Collection m_connProviderList
           
protected static HashMap m_connProviderMap
           
protected static ConnectionInfo m_defConnInfo
           
protected static Document m_rootConfig
           
static String MSSQL_DRIVER
           
static String MSSQL_SAG_PROXY_DRIVER
           
static String MSSQL_URL_PARSER_EXPRESSION
           
static String MSSQL_URL_TEMPLATE
           
static String MYSQL_DRIVER
           
static String MYSQL_SAG_PROXY_DRIVER
           
static String MYSQL_SERVER_URL_PARSER_EXPRESSION
           
static String MYSQL_URL_PARSER_EXPRESSION
           
static String MYSQL_URL_TEMPLATE
           
static String ORACLE_DRIVER
           
static String ORACLE_SAG_PROXY_DRIVER
           
static String ORACLE_THIN_DRIVER
           
static String ORACLE_THIN_URL_PARSER_EXPRESSION
           
static String ORACLE_THIN_URL_TEMPLATE
           
static String ORACLE_URL_PARSER_EXPRESSION
           
static String ORACLE_URL_TEMPLATE
           
static String SAG_BASE_PROXY_DRIVER_PATH
           
static String SERVER_DB2
           
static String SERVER_DERBY
           
static String SERVER_MSSQL
           
static String SERVER_ORACLE
           
static String SYBASE_DRIVER
           
static String SYBASE_SAG_PROXY_DRIVER
           
static String SYBASE_URL_PARSER_EXPRESSION
           
static String SYBASE_URL_TEMPLATE
           
 
Constructor Summary
ConnectionManager()
          Default Constructor needed for reflection.
 
Method Summary
protected static void addDatasource(ConnectionInfo connInfo)
          Adds new datasource.
protected static IConnectionProvider createConnProvider(ConnectionInfo connInfo)
          Creates and caches connection provider for a given connection info
static ConnectionInfo getConnInfo(String datasourceName)
          Returns ConnectionInfo for given datasource name.
static IConnectionProvider getConnProvider(String datasourceName)
          Returns connection provider implementation instance for the given datasource name.
static Collection getConnProviders()
          Returns list of all registered IConnectionProvider implementations.
static List getDatasources()
          Returns list of all registered data sources.
static void init()
          Called automatically by the portal runtime to initialize the ConnectionMangager.
static void init(Element config)
          Called automatically by the portal runtime to initialize the ConnectionMangager.
 void init(IComponentData data, String phase)
          Called automatically by the portal runtime to initialize the ConnectionMangager.
static void init(String serverType, String hostName, String database, String user, String password)
          Initializes ConnectionManager when not part of the PortalSystem.
protected static void persistConfigFile(Document configDoc, boolean makeBackup)
          This will persist the database config file.
static void postInit()
          Called automatically by the portal runtime to initialize the ConnectionMangager.
static void registerDatasource(String datasourceName, String serverType, String hostName, String database, String user, String password)
           
static void registerNewDatasource(ConnectionInfo connInfo)
          Registers new sql datasource and persists the updated configuration.
static void registerNewDatasource(ConnectionInfo connInfo, boolean persist)
          Registers new sql datasource and persists the updated configuration.
protected static ConnectionInfo replaceSAGProxyDriversWithMWS(ConnectionInfo connInfo)
           
static void saveConfig()
          Persists the database configuration into Registry.
 void shutdown()
          Called automatically by the portal runtime when the VM is closing down.
static void testConnection(ConnectionInfo connInfo)
          Tests opening a connection to the given datasource.
static void unregisterDatasource(String datasourceName)
          Unregisters the datasource by given name and persists the updated configuration.
static void updateDatasource(String origName, ConnectionInfo connInfo)
          Updates existing datasource and persists the updated configuration.
protected static void validateDatasource()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONNECTION_CONFIG_NAME

public static final String CONNECTION_CONFIG_NAME
entry in portal.properties storing location for db config file

See Also:
Constant Field Values

CONFIG_BAK_EXTENSION

public static final String CONFIG_BAK_EXTENSION
backup file extension

See Also:
Constant Field Values

ORACLE_THIN_URL_TEMPLATE

public static String ORACLE_THIN_URL_TEMPLATE

ORACLE_THIN_DRIVER

public static String ORACLE_THIN_DRIVER

ORACLE_THIN_URL_PARSER_EXPRESSION

public static String ORACLE_THIN_URL_PARSER_EXPRESSION

SAG_BASE_PROXY_DRIVER_PATH

public static final String SAG_BASE_PROXY_DRIVER_PATH
See Also:
Constant Field Values

ORACLE_SAG_PROXY_DRIVER

public static final String ORACLE_SAG_PROXY_DRIVER
See Also:
Constant Field Values

MSSQL_SAG_PROXY_DRIVER

public static final String MSSQL_SAG_PROXY_DRIVER
See Also:
Constant Field Values

DB2_SAG_PROXY_DRIVER

public static final String DB2_SAG_PROXY_DRIVER
See Also:
Constant Field Values

INFORMIX_SAG_PROXY_DRIVER

public static final String INFORMIX_SAG_PROXY_DRIVER
See Also:
Constant Field Values

SYBASE_SAG_PROXY_DRIVER

public static final String SYBASE_SAG_PROXY_DRIVER
See Also:
Constant Field Values

MYSQL_SAG_PROXY_DRIVER

public static final String MYSQL_SAG_PROXY_DRIVER
See Also:
Constant Field Values

DRIVER_PARAMETER

public static final String DRIVER_PARAMETER
See Also:
Constant Field Values

ORACLE_URL_TEMPLATE

public static String ORACLE_URL_TEMPLATE

ORACLE_DRIVER

public static String ORACLE_DRIVER

ORACLE_URL_PARSER_EXPRESSION

public static String ORACLE_URL_PARSER_EXPRESSION

MSSQL_URL_TEMPLATE

public static String MSSQL_URL_TEMPLATE

MSSQL_DRIVER

public static String MSSQL_DRIVER

MSSQL_URL_PARSER_EXPRESSION

public static String MSSQL_URL_PARSER_EXPRESSION

DB2_URL_TEMPLATE

public static String DB2_URL_TEMPLATE

DB2_DRIVER

public static String DB2_DRIVER

DB2_URL_PARSER_EXPRESSION

public static String DB2_URL_PARSER_EXPRESSION

INFORMIX_URL_TEMPLATE

public static String INFORMIX_URL_TEMPLATE

INFORMIX_DRIVER

public static String INFORMIX_DRIVER

INFORMIX_URL_PARSER_EXPRESSION

public static String INFORMIX_URL_PARSER_EXPRESSION

SYBASE_URL_TEMPLATE

public static String SYBASE_URL_TEMPLATE

SYBASE_DRIVER

public static String SYBASE_DRIVER

SYBASE_URL_PARSER_EXPRESSION

public static String SYBASE_URL_PARSER_EXPRESSION

DERBY_URL_TEMPLATE

public static String DERBY_URL_TEMPLATE

DERBY_DRIVER

public static String DERBY_DRIVER

DERBY_URL_PARSER_EXPRESSION

public static String DERBY_URL_PARSER_EXPRESSION

DERBY_SERVER_URL_PARSER_EXPRESSION

public static String DERBY_SERVER_URL_PARSER_EXPRESSION

MYSQL_URL_TEMPLATE

public static String MYSQL_URL_TEMPLATE

MYSQL_DRIVER

public static String MYSQL_DRIVER

MYSQL_URL_PARSER_EXPRESSION

public static String MYSQL_URL_PARSER_EXPRESSION

MYSQL_SERVER_URL_PARSER_EXPRESSION

public static String MYSQL_SERVER_URL_PARSER_EXPRESSION

SERVER_ORACLE

public static String SERVER_ORACLE

SERVER_MSSQL

public static String SERVER_MSSQL

SERVER_DERBY

public static String SERVER_DERBY

SERVER_DB2

public static String SERVER_DB2

CONNECTION_NODE_QUERY

protected static final String CONNECTION_NODE_QUERY
See Also:
Constant Field Values

m_rootConfig

protected static Document m_rootConfig

m_connProviderList

protected static Collection m_connProviderList

m_connProviderMap

protected static HashMap m_connProviderMap

m_connInfoMap

protected static HashMap m_connInfoMap

m_defConnInfo

protected static ConnectionInfo m_defConnInfo
Constructor Detail

ConnectionManager

public ConnectionManager()
Default Constructor needed for reflection. Portal developers should never need to create a new ConnectionManager object. The exposed static methods should have all the information you would need.

Method Detail

init

public static void init(String serverType,
                        String hostName,
                        String database,
                        String user,
                        String password)
                 throws Exception
Initializes ConnectionManager when not part of the PortalSystem. This functions creates connection pool to the specified database server. After connection manager initializaton, DataManager class could be used to obtain instance of ISqlWorker

Parameters:
serverType - ISqlWorker server type
hostName - database host and port. For example myserver:1521
database - database name. For Oracle database this is a SID
user -
password -
Throws:
PortalException
Exception

init

public void init(IComponentData data,
                 String phase)
          throws InitializationException
Called automatically by the portal runtime to initialize the ConnectionMangager. A typical portal developer should never need to call this method.

Parameters:
data - the IComponentData contains the configuration data for the registered data sources.
phase - the name of the startup phase that is currently executing
Throws:
com.webmethods.portal.system.init.InitializationException
InitializationException
See Also:
IInitializable

shutdown

public void shutdown()
Called automatically by the portal runtime when the VM is closing down. A typical portal developer should never need to call this method.

See Also:
IInitializable

init

public static void init()
                 throws InitializationException
Called automatically by the portal runtime to initialize the ConnectionMangager. A typical portal developer should never need to call this method.

Throws:
InitializationException

postInit

public static void postInit()
                     throws InitializationException
Called automatically by the portal runtime to initialize the ConnectionMangager. A typical portal developer should never need to call this method.

Initializes connection info service information. This needs to be done after the MetadataSystem has initialized.

Throws:
InitializationException

init

public static void init(Element config)
                 throws InitializationException
Called automatically by the portal runtime to initialize the ConnectionMangager. A typical portal developer should never need to call this method.

Initializes ConnectionManager from an XML configuration element

Throws:
InitializationException

getConnProvider

public static IConnectionProvider getConnProvider(String datasourceName)
Returns connection provider implementation instance for the given datasource name. A typical portal developer would rarely need to call this method.

Parameters:
datasourceName - the datasource name to retrive the IConnectionProvider instance for
Returns:
the connection provider instance for the given datasourceName

getConnInfo

public static ConnectionInfo getConnInfo(String datasourceName)
Returns ConnectionInfo for given datasource name. A typical portal developer would call this method to retrieve the connection information needed to open a connection to a registered sql datasource.

Parameters:
datasourceName - the datasource name to retrive the ConnectionInfo for
Returns:
the ConnectionInfo instance for the given datasourceName

getDatasources

public static List getDatasources()
Returns list of all registered data sources. The contents of the List will be ConnectionInfo objects. A typical portal developer would rarely need to call this method.

Returns:
a List of the currently registered sql datasources

getConnProviders

public static Collection getConnProviders()
Returns list of all registered IConnectionProvider implementations. The contents of the List will be IConnectionProvider objects. A typical portal developer would rarely need to call this method.

Returns:
a Collection of currently registered connection providers

saveConfig

public static void saveConfig()
                       throws MetaException
Persists the database configuration into Registry. Is called automatically upon any configuration modification. Configuration is saved under CONNECTION_CONFIG_NAME entry. A typical portal developer should never need to call this method.

Throws:
MetaException

registerDatasource

public static void registerDatasource(String datasourceName,
                                      String serverType,
                                      String hostName,
                                      String database,
                                      String user,
                                      String password)
                               throws MetaException
Throws:
MetaException

unregisterDatasource

public static void unregisterDatasource(String datasourceName)
                                 throws MetaException
Unregisters the datasource by given name and persists the updated configuration. A typical portal developer should never need to call this method. Un-registration of datasources should be done via the DataSource Administation portlet.

Parameters:
dsnname - the name of the datasource to unregister
Throws:
MetaException

registerNewDatasource

public static void registerNewDatasource(ConnectionInfo connInfo)
                                  throws MetaException
Registers new sql datasource and persists the updated configuration. A typical portal developer should never need to call this method. Registration of datasources should be done via the DataSource Administation portlet.

Parameters:
connInfo - the connection info for the new datasource
Throws:
MetaException

registerNewDatasource

public static void registerNewDatasource(ConnectionInfo connInfo,
                                         boolean persist)
                                  throws MetaException
Registers new sql datasource and persists the updated configuration. A typical portal developer should never need to call this method. Registration of datasources should be done via the DataSource Administation portlet.

Parameters:
connInfo - the connection info for the new datasource
persist - whether new configuration should be persisted back to the config file
Throws:
MetaException

replaceSAGProxyDriversWithMWS

protected static ConnectionInfo replaceSAGProxyDriversWithMWS(ConnectionInfo connInfo)

updateDatasource

public static void updateDatasource(String origName,
                                    ConnectionInfo connInfo)
                             throws MetaException
Updates existing datasource and persists the updated configuration. A typical portal developer should never need to call this method. Updating datasources should be done via the DataSource Administation portlet.

Parameters:
origName - the name of the datasource that is being updated
connInfo - the new connection info for datasource
Throws:
MetaException

testConnection

public static void testConnection(ConnectionInfo connInfo)
                           throws MetaException
Tests opening a connection to the given datasource.

Parameters:
connInfo - the ConnectionInfo instance for the datasource to test
Throws:
MetaException - if there was an error testing the connection.

addDatasource

protected static void addDatasource(ConnectionInfo connInfo)
Adds new datasource. If datasource exists - updates it.


validateDatasource

protected static void validateDatasource()
                                  throws InitializationException
Throws:
InitializationException

persistConfigFile

protected static void persistConfigFile(Document configDoc,
                                        boolean makeBackup)
                                 throws IOException
This will persist the database config file. If backing up, just stream the original into a backup, otherwise persist the given XML Document to the config file

Parameters:
configDoc - the XML Document containing all the configuration information for the current directory services
makeBackup - is whether or not to create a backup before storing the config
Throws:
IOException

createConnProvider

protected static IConnectionProvider createConnProvider(ConnectionInfo connInfo)
Creates and caches connection provider for a given connection info