public class ConnectionManager extends Object implements com.webmethods.portal.system.init.IInitializable
Typically, the only method from this class that a portlet developer would need to use would be the
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(); } }
ISqlWorker
,
DataManager
Constructor and Description |
---|
ConnectionManager()
Default Constructor needed for reflection.
|
Modifier and Type | Method and Description |
---|---|
protected static void |
addDatasource(com.webmethods.portal.service.sql.core.ConnectionInfo connInfo)
Adds new datasource.
|
protected static com.webmethods.portal.service.sql.core.IConnectionProvider |
createConnProvider(com.webmethods.portal.service.sql.core.ConnectionInfo connInfo)
Creates and caches connection provider for a given connection info
|
static com.webmethods.portal.service.sql.core.ConnectionInfo |
getConnInfo(String datasourceName)
Returns
ConnectionInfo for given datasource name. |
static com.webmethods.portal.service.sql.core.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(com.webmethods.portal.system.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(com.webmethods.portal.service.sql.core.ConnectionInfo connInfo)
Registers new sql datasource and persists the updated configuration.
|
static void |
registerNewDatasource(com.webmethods.portal.service.sql.core.ConnectionInfo connInfo,
boolean persist)
Registers new sql datasource and persists the updated configuration.
|
protected static com.webmethods.portal.service.sql.core.ConnectionInfo |
replaceSAGProxyDriversWithMWS(com.webmethods.portal.service.sql.core.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(com.webmethods.portal.service.sql.core.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,
com.webmethods.portal.service.sql.core.ConnectionInfo connInfo)
Updates existing datasource and persists the updated configuration.
|
protected static void |
validateDatasource() |
public static final String CONNECTION_CONFIG_NAME
public static final String CONFIG_BAK_EXTENSION
public static String ORACLE_THIN_URL_TEMPLATE
public static String ORACLE_THIN_DRIVER
public static String ORACLE_THIN_URL_PARSER_EXPRESSION
public static final String SAG_BASE_PROXY_DRIVER_PATH
public static final String ORACLE_SAG_PROXY_DRIVER
public static final String MSSQL_SAG_PROXY_DRIVER
public static final String DB2_SAG_PROXY_DRIVER
public static final String INFORMIX_SAG_PROXY_DRIVER
public static final String SYBASE_SAG_PROXY_DRIVER
public static final String MYSQL_SAG_PROXY_DRIVER
public static final String DRIVER_PARAMETER
public static String ORACLE_URL_TEMPLATE
public static String ORACLE_DRIVER
public static String ORACLE_URL_PARSER_EXPRESSION
public static String MSSQL_URL_TEMPLATE
public static String MSSQL_DRIVER
public static String MSSQL_URL_PARSER_EXPRESSION
public static String DB2_URL_TEMPLATE
public static String DB2_DRIVER
public static String DB2_URL_PARSER_EXPRESSION
public static String INFORMIX_URL_TEMPLATE
public static String INFORMIX_DRIVER
public static String INFORMIX_URL_PARSER_EXPRESSION
public static String SYBASE_URL_TEMPLATE
public static String SYBASE_DRIVER
public static String SYBASE_URL_PARSER_EXPRESSION
public static String DERBY_URL_TEMPLATE
public static String DERBY_DRIVER
public static String DERBY_URL_PARSER_EXPRESSION
public static String DERBY_SERVER_URL_PARSER_EXPRESSION
public static String MYSQL_URL_TEMPLATE
public static String MYSQL_DRIVER
public static String MYSQL_URL_PARSER_EXPRESSION
public static String MYSQL_SERVER_URL_PARSER_EXPRESSION
public static String SERVER_ORACLE
public static String SERVER_MSSQL
public static String SERVER_DERBY
public static String SERVER_DB2
public static String SERVER_MYSQL
protected static final String CONNECTION_NODE_QUERY
protected static Document m_rootConfig
protected static Collection m_connProviderList
protected static HashMap m_connProviderMap
protected static HashMap<String,com.webmethods.portal.service.sql.core.ConnectionInfo> m_connInfoMap
protected static com.webmethods.portal.service.sql.core.ConnectionInfo m_defConnInfo
public ConnectionManager()
public static void init(String serverType, String hostName, String database, String user, String password) throws Exception
serverType
- ISqlWorker
server typehostName
- database host and port. For example myserver:1521database
- database name. For Oracle database this is a SIDuser
- password
- PortalException
Exception
public void init(com.webmethods.portal.system.IComponentData data, String phase) throws com.webmethods.portal.system.init.InitializationException
init
in interface com.webmethods.portal.system.init.IInitializable
data
- the IComponentData
contains the configuration data for the registered data sources.phase
- the name of the startup phase that is currently executingcom.webmethods.portal.system.init.InitializationException
IInitializable
public void shutdown()
shutdown
in interface com.webmethods.portal.system.init.IInitializable
IInitializable
public static void init() throws com.webmethods.portal.system.init.InitializationException
com.webmethods.portal.system.init.InitializationException
public static void postInit() throws com.webmethods.portal.system.init.InitializationException
Initializes connection info service information. This needs to be done after the MetadataSystem has initialized.
com.webmethods.portal.system.init.InitializationException
public static void init(Element config) throws com.webmethods.portal.system.init.InitializationException
Initializes ConnectionManager from an XML configuration element
com.webmethods.portal.system.init.InitializationException
public static com.webmethods.portal.service.sql.core.IConnectionProvider getConnProvider(String datasourceName)
datasourceName
- the datasource name to retrive the IConnectionProvider
instance forpublic static com.webmethods.portal.service.sql.core.ConnectionInfo getConnInfo(String datasourceName)
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.datasourceName
- the datasource name to retrive the ConnectionInfo
forConnectionInfo
instance for the given datasourceNamepublic static List getDatasources()
List
will
be ConnectionInfo
objects. A typical portal developer would rarely need to
call this method.List
of the currently registered sql datasourcespublic static Collection getConnProviders()
IConnectionProvider
implementations.
The contents of the List
will be IConnectionProvider
objects.
A typical portal developer would rarely need to call this method.Collection
of currently registered connection providerspublic static void saveConfig() throws com.webmethods.portal.service.meta2.MetaException
com.webmethods.portal.service.meta2.MetaException
public static void registerDatasource(String datasourceName, String serverType, String hostName, String database, String user, String password) throws com.webmethods.portal.service.meta2.MetaException
com.webmethods.portal.service.meta2.MetaException
public static void unregisterDatasource(String datasourceName) throws com.webmethods.portal.service.meta2.MetaException
dsnname
- the name of the datasource to unregistercom.webmethods.portal.service.meta2.MetaException
public static void registerNewDatasource(com.webmethods.portal.service.sql.core.ConnectionInfo connInfo) throws com.webmethods.portal.service.meta2.MetaException
connInfo
- the connection info for the new datasourcecom.webmethods.portal.service.meta2.MetaException
public static void registerNewDatasource(com.webmethods.portal.service.sql.core.ConnectionInfo connInfo, boolean persist) throws com.webmethods.portal.service.meta2.MetaException
connInfo
- the connection info for the new datasourcepersist
- whether new configuration should be persisted back to the config filecom.webmethods.portal.service.meta2.MetaException
protected static com.webmethods.portal.service.sql.core.ConnectionInfo replaceSAGProxyDriversWithMWS(com.webmethods.portal.service.sql.core.ConnectionInfo connInfo)
public static void updateDatasource(String origName, com.webmethods.portal.service.sql.core.ConnectionInfo connInfo) throws com.webmethods.portal.service.meta2.MetaException
origName
- the name of the datasource that is being updatedconnInfo
- the new connection info for datasourcecom.webmethods.portal.service.meta2.MetaException
public static void testConnection(com.webmethods.portal.service.sql.core.ConnectionInfo connInfo) throws com.webmethods.portal.service.meta2.MetaException
connInfo
- the ConnectionInfo
instance for the datasource to testcom.webmethods.portal.service.meta2.MetaException
- if there was an error testing the connection.protected static void addDatasource(com.webmethods.portal.service.sql.core.ConnectionInfo connInfo)
protected static void validateDatasource() throws com.webmethods.portal.system.init.InitializationException
com.webmethods.portal.system.init.InitializationException
protected static void persistConfigFile(Document configDoc, boolean makeBackup) throws IOException
configDoc
- the XML Document containing all the configuration information for
the current directory servicesmakeBackup
- is whether or not to create a backup before storing the configIOException
protected static com.webmethods.portal.service.sql.core.IConnectionProvider createConnProvider(com.webmethods.portal.service.sql.core.ConnectionInfo connInfo)