com.webmethods.portal.service.sql
Class DataManager

java.lang.Object
  extended by com.webmethods.portal.service.sql.DataManager

public class DataManager
extends Object

DataManager works as a factory class to create SqlWorker instances.

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, ConnectionManager

Field Summary
static String DATA_SERVICE
           
static String DATA_SERVICE_ALIAS_PREFIX
           
static String DATA_SERVICE_FOLDER
           
static boolean DEBUG_ON
          Switch for internal SQL debug logging
static Category logCategory
          Log4J category for SqlOutput
static Object perf_Database_Exec
          perfstat objects
static Object perf_Get_Conn
          perfstat objects
static String THREAD_LOCAL_TRANSACTION
          Thread local key for SQL transaction
 
Constructor Summary
DataManager()
           
 
Method Summary
static void beginTran()
          Starts sql transaction for default database connection on the current thread.
static void commitTran()
          Commits any outstanding transaction on the current thread.
static ISqlWorker createSafeWorker(String datasourceName)
          Get worker object to perform some database work.
static ISqlWorker createWorker()
          Get worker object to perform some database work for the default portal datasource.
static ISqlWorker createWorker(String datasourceName)
          Get worker object to perform some database work
protected static void executeSqlScriptDsn(Reader script, com.webmethods.portal.service.sql.DataManager.ScriptExecuteContext context)
          Executes SQL script from passed reader against specified DSN
static void executeSqlScriptFile(String fileName)
           
static void executeSqlScriptFile(String fileName, PrintStream terminalWriter, PrintStream spoolWriter, boolean ignoreErrors, Map args)
           
static void executeSqlScriptString(String script, String datasource)
          Execute Sql script file against default DSN
static void executeSqlScriptString(String script, String datasource, boolean ignoreErrors, Map args)
          Execute Sql script file against default DSN
static Connection getConnection()
          Returns connection to a default database
static Connection getConnection(String datasource)
          Returns connection to a specific datasource
static IDatabaseRuntime getDatabaseRuntime()
          Returns current database runtime which is setup for active portal database connection
static int getDefaultServerType()
          Returns name of the default database server type: mssql, oracle, mysql
static void init()
          Called automatically by the portal runtime to initialize the DataMangager.
 void init(IComponentData data, String phase)
          Called automatically by the portal runtime to initialize the DataMangager.
static boolean isInitialized()
          Check to see if the DataManger has been initialized.
static void release()
          Release all connection resources
static void releaseConnection(Connection conn)
          Releases connection back to the pool
static void rollbackTran()
          Rollsback any outstanding transaction on the current thread.
 void shutdown()
          Called automatically by the portal runtime when the VM is closing down.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATA_SERVICE

public static final String DATA_SERVICE
See Also:
Constant Field Values

DATA_SERVICE_FOLDER

public static final String DATA_SERVICE_FOLDER
See Also:
Constant Field Values

DATA_SERVICE_ALIAS_PREFIX

public static final String DATA_SERVICE_ALIAS_PREFIX
See Also:
Constant Field Values

THREAD_LOCAL_TRANSACTION

public static final String THREAD_LOCAL_TRANSACTION
Thread local key for SQL transaction

See Also:
Constant Field Values

logCategory

public static Category logCategory
Log4J category for SqlOutput


DEBUG_ON

public static boolean DEBUG_ON
Switch for internal SQL debug logging


perf_Database_Exec

public static Object perf_Database_Exec
perfstat objects


perf_Get_Conn

public static Object perf_Get_Conn
perfstat objects

Constructor Detail

DataManager

public DataManager()
Method Detail

init

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

Parameters:
data - the IComponentData contains the configuration data for the data manager.
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()
Called automatically by the portal runtime to initialize the DataMangager. A typical portal developer should never need to call this method.


isInitialized

public static boolean isInitialized()
Check to see if the DataManger has been initialized. A typical portal developer should never need to call this method.

Returns:
true if the DataManager has been initialized, false otherwise

getDefaultServerType

public static int getDefaultServerType()
Returns name of the default database server type: mssql, oracle, mysql

Returns:
ISqlWorker.SERVERTYPE_ORACLE for oracle or ISqlWorker.SERVERTYPE_MSSQL otherwise

createWorker

public static ISqlWorker createWorker()
                               throws SQLException
Get worker object to perform some database work for the default portal datasource.

Throws:
SQLException

beginTran

public static void beginTran()
                      throws SQLException
Starts sql transaction for default database connection on the current thread. See corresponding ISqlWorker.beginTran() method.

Throws:
SQLException

commitTran

public static void commitTran()
                       throws SQLException
Commits any outstanding transaction on the current thread. See corresponding ISqlWorker.commitTran() method

Throws:
SQLException

rollbackTran

public static void rollbackTran()
                         throws SQLException
Rollsback any outstanding transaction on the current thread. See corresponding ISqlWorker.rollbackTran() method

Throws:
SQLException

createWorker

public static ISqlWorker createWorker(String datasourceName)
                               throws SQLException
Get worker object to perform some database work

Parameters:
datasourceName - name of the datasource to create a worker for
Throws:
SQLException

createSafeWorker

public static ISqlWorker createSafeWorker(String datasourceName)
                                   throws SQLException
Get worker object to perform some database work. If configuration doesn't have a datasource with the given name, then the default datasource is used

Parameters:
datasourceName - name of the datasource to use
Throws:
SQLException

getDatabaseRuntime

public static IDatabaseRuntime getDatabaseRuntime()
Returns current database runtime which is setup for active portal database connection


getConnection

public static Connection getConnection()
Returns connection to a default database


getConnection

public static Connection getConnection(String datasource)
Returns connection to a specific datasource

Parameters:
datasource - name of the datasource

release

public static void release()
Release all connection resources


releaseConnection

public static void releaseConnection(Connection conn)
Releases connection back to the pool


executeSqlScriptFile

public static void executeSqlScriptFile(String fileName)
                                 throws SQLException,
                                        ServerBusyException,
                                        DeadlockException
Throws:
SQLException
ServerBusyException
DeadlockException

executeSqlScriptFile

public static void executeSqlScriptFile(String fileName,
                                        PrintStream terminalWriter,
                                        PrintStream spoolWriter,
                                        boolean ignoreErrors,
                                        Map args)
                                 throws SQLException,
                                        ServerBusyException,
                                        DeadlockException
Throws:
SQLException
ServerBusyException
DeadlockException

executeSqlScriptString

public static void executeSqlScriptString(String script,
                                          String datasource)
                                   throws SQLException,
                                          ServerBusyException,
                                          DeadlockException
Execute Sql script file against default DSN

Throws:
SQLException
ServerBusyException
DeadlockException

executeSqlScriptString

public static void executeSqlScriptString(String script,
                                          String datasource,
                                          boolean ignoreErrors,
                                          Map args)
                                   throws SQLException,
                                          ServerBusyException,
                                          DeadlockException
Execute Sql script file against default DSN

Throws:
SQLException
ServerBusyException
DeadlockException

executeSqlScriptDsn

protected static void executeSqlScriptDsn(Reader script,
                                          com.webmethods.portal.service.sql.DataManager.ScriptExecuteContext context)
                                   throws SQLException,
                                          ServerBusyException,
                                          DeadlockException
Executes SQL script from passed reader against specified DSN

Throws:
SQLException
ServerBusyException
DeadlockException