com.ibm.commerce.base.helpers
Class BaseJDBCHelper

java.lang.Object
  |
  +--com.ibm.commerce.base.helpers.BaseJDBCHelper

public abstract class BaseJDBCHelper
extends java.lang.Object

JDBC helper class which provides interactation to the database. For example, initializing the datasource and executing the query.


Field Summary
static boolean autoFlush
          The default value of the auto flush parameter.
static java.lang.String COPYRIGHT
          IBM copyright notice field.
protected static java.lang.String DATASOURCE
           
protected static java.util.HashMap dataSourceConfigData
           
static java.lang.String DB_DB2
          The default value of the constant of DB2 database.
static java.lang.String DB_DB2_390
          The default value of the constant of a DB2 database running on a 390 system.
static java.lang.String DB_DB2J
          The default value of the constant of DB Cloudscape database.
static java.lang.String DB_ORACLE
          The default value of the constant of Oracle database.
protected static java.lang.String DBTYPE
           
protected  javax.ejb.SessionContext mySessionCtx
           
 
Constructor Summary
BaseJDBCHelper()
          Constructor for BaseJDBCHelper.
 
Method Summary
static java.lang.String buildCommaSeparatedWhereClause(int length)
          Builds comma separated where clause by length
protected  void closeConnection()
          Closes the database connection.
protected static java.util.Hashtable convertFirstRowToHashtable(java.sql.ResultSet aResultSet)
          Converts the first row of the input result set to a Hashtable.
static java.util.Vector convertResultSetToTable(java.sql.ResultSet rs)
          Converts the input result set to a table.
protected static java.lang.String convertRowFromHashtable(java.util.Hashtable aHashtable)
          Converts the row in Hashtable to a SQL statment.
protected  void debugInitConnection(java.lang.String dataSourceName, java.lang.String userId, java.lang.String pswd)
          Debugs the initial data source connection.
protected  java.sql.ResultSet executeQuery(java.sql.PreparedStatement stmt, boolean flush)
          Executes the database query.
protected  int executeUpdate(java.sql.PreparedStatement stmt, boolean flush)
          Executes the database update statement.
 void flush()
          Flush the session context.
protected  java.sql.CallableStatement getCallableStatement(java.lang.String sqlStatement)
          Gets the CallableStatement from SQL statement.
static java.lang.String getCharacterStreamFromResultSet(java.sql.ResultSet rs, int nColumn)
          Gets the characters stream from the result set
protected  java.sql.Connection getConnection()
          Gets the data source connection.
static javax.sql.DataSource getDataSource()
          Gets the default data source.
protected  java.sql.PreparedStatement getPreparedStatement(java.lang.String sqlStatement)
          Gets the prepared statement.
protected  java.sql.PreparedStatement getPreparedStatement(java.lang.String sqlStatement, int resultSetType, int resultSetConcurrency)
          Gets the prepared statement.
abstract  javax.ejb.SessionContext getSessionContext()
          Gets the session context.
static void init(ConfigProperties parameters)
          Deprecated. Initialization of the JDBC Session bean helper has been replaced with parameters specified in the deployment descriptor. Replaced by com.ibm.commerce.base.objects.ConfiguratorBean#initDataSourceInfo().
static void init(java.lang.String ds, java.lang.String dt, java.lang.String uid, java.lang.String pw)
          Deprecated. Initialization of the JDBC Session bean helper has been replaced with parameters specified in the deployment descriptor. Replaced by com.ibm.commerce.base.objects.ConfiguratorBean#initDataSourceInfo().
protected  void makeConnection()
          Creates connection to data source.
static boolean useCloudscape()
          Checks if Cloudscape is used as database.
static boolean useDB2_390()
          Checks if DB 390 is used as database
static boolean useDB2()
          Checks if DB2 is used as database
static boolean useOracle()
          Checks if Oracle is used as database
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail
public static final java.lang.String COPYRIGHT
IBM copyright notice field.

DB_DB2

public static final java.lang.String DB_DB2
The default value of the constant of DB2 database.
See Also:
Constant Field Values

DB_ORACLE

public static final java.lang.String DB_ORACLE
The default value of the constant of Oracle database.
See Also:
Constant Field Values

DB_DB2_390

public static final java.lang.String DB_DB2_390
The default value of the constant of a DB2 database running on a 390 system.
See Also:
Constant Field Values

DB_DB2J

public static final java.lang.String DB_DB2J
The default value of the constant of DB Cloudscape database.
See Also:
Constant Field Values

autoFlush

public static final boolean autoFlush
The default value of the auto flush parameter.
See Also:
Constant Field Values

mySessionCtx

protected transient javax.ejb.SessionContext mySessionCtx

dataSourceConfigData

protected static final java.util.HashMap dataSourceConfigData

DATASOURCE

protected static final java.lang.String DATASOURCE
See Also:
Constant Field Values

DBTYPE

protected static final java.lang.String DBTYPE
See Also:
Constant Field Values
Constructor Detail

BaseJDBCHelper

public BaseJDBCHelper()
Constructor for BaseJDBCHelper.
Method Detail

closeConnection

protected void closeConnection()
                        throws java.sql.SQLException
Closes the database connection.
Throws:
java.sql.SQLException

convertFirstRowToHashtable

protected static java.util.Hashtable convertFirstRowToHashtable(java.sql.ResultSet aResultSet)
                                                         throws java.sql.SQLException
Converts the first row of the input result set to a Hashtable.
Parameters:
aResultSet - result set object
Returns:
the Hashtable containing the first row of data from the result set
Throws:
java.sql.SQLException

convertResultSetToTable

public static java.util.Vector convertResultSetToTable(java.sql.ResultSet rs)
                                                throws java.sql.SQLException
Converts the input result set to a table.
Parameters:
rs - result set object
Returns:
the Vector containing the result set data
Throws:
java.sql.SQLException

convertRowFromHashtable

protected static java.lang.String convertRowFromHashtable(java.util.Hashtable aHashtable)
                                                   throws java.sql.SQLException
Converts the row in Hashtable to a SQL statment.
Parameters:
aHashtable - The result set object
Returns:
A SQL statement string
Throws:
java.sql.SQLException

debugInitConnection

protected void debugInitConnection(java.lang.String dataSourceName,
                                   java.lang.String userId,
                                   java.lang.String pswd)
                            throws javax.naming.NamingException,
                                   java.sql.SQLException
Debugs the initial data source connection.
Parameters:
dataSourceName - data source name
userId - user id to connect to data source
pswd - user password
Throws:
javax.naming.NamingException
java.sql.SQLException

executeQuery

protected java.sql.ResultSet executeQuery(java.sql.PreparedStatement stmt,
                                          boolean flush)
                                   throws java.sql.SQLException
Executes the database query.
Parameters:
stmt - prepare statment to be executed
flush - true if the flush is required; false otherwise
Returns:
the result set after executing the input prepared statment
Throws:
java.sql.SQLException

executeUpdate

protected int executeUpdate(java.sql.PreparedStatement stmt,
                            boolean flush)
                     throws java.sql.SQLException
Executes the database update statement.
Parameters:
stmt - prepare statment to be executed
flush - true if the flush is required; false otherwise
Returns:
the row count for the INSERT, UPDATE or DELETE statements or 0 for SQL statements that return nothing
Throws:
java.sql.SQLException

flush

public void flush()
Flush the session context.

getCallableStatement

protected java.sql.CallableStatement getCallableStatement(java.lang.String sqlStatement)
                                                   throws java.sql.SQLException
Gets the CallableStatement from SQL statement.
Parameters:
sqlStatement - SQL statement
Returns:
a CallableStatement object containing the SQL statement
Throws:
java.sql.SQLException

getConnection

protected java.sql.Connection getConnection()
                                     throws javax.naming.NamingException,
                                            java.sql.SQLException
Gets the data source connection.
Returns:
the data source Connection object
Throws:
javax.naming.NamingException
java.sql.SQLException

getDataSource

public static javax.sql.DataSource getDataSource()
                                          throws javax.naming.NamingException
Gets the default data source.
Returns:
the default data source
Throws:
javax.naming.NamingException

getPreparedStatement

protected java.sql.PreparedStatement getPreparedStatement(java.lang.String sqlStatement)
                                                   throws java.sql.SQLException
Gets the prepared statement.
Parameters:
sqlStatement - SQL statement
Returns:
the PreparedStatement
Throws:
java.sql.SQLException

getPreparedStatement

protected java.sql.PreparedStatement getPreparedStatement(java.lang.String sqlStatement,
                                                          int resultSetType,
                                                          int resultSetConcurrency)
                                                   throws java.sql.SQLException
Gets the prepared statement.
Parameters:
sqlStatement - SQL statement
resultSetType - result set type
resultSetConcurrency - concurrency type of result set
Returns:
the PreparedStatement
Throws:
java.sql.SQLException

getSessionContext

public abstract javax.ejb.SessionContext getSessionContext()
Gets the session context.
Returns:
the SessionContext

init

public static void init(ConfigProperties parameters)
                 throws javax.naming.NamingException
Deprecated. Initialization of the JDBC Session bean helper has been replaced with parameters specified in the deployment descriptor. Replaced by com.ibm.commerce.base.objects.ConfiguratorBean#initDataSourceInfo().
Initializes the data source information.
Parameters:
parameters - configuration properties.
Throws:
javax.naming.NamingException - a naming exception.

init

public static void init(java.lang.String ds,
                        java.lang.String dt,
                        java.lang.String uid,
                        java.lang.String pw)
                 throws javax.naming.NamingException
Deprecated. Initialization of the JDBC Session bean helper has been replaced with parameters specified in the deployment descriptor. Replaced by com.ibm.commerce.base.objects.ConfiguratorBean#initDataSourceInfo().
Initializes the data source information.
Parameters:
dt - database type
uid - user Id
pw - password
Throws:
javax.naming.NamingException - a naming exception.

makeConnection

protected void makeConnection()
                       throws javax.naming.NamingException,
                              java.sql.SQLException
Creates connection to data source.
Throws:
javax.naming.NamingException
java.sql.SQLException

useDB2

public static boolean useDB2()
Checks if DB2 is used as database
Returns:
true if DB2 is used as the database.

useDB2_390

public static boolean useDB2_390()
Checks if DB 390 is used as database
Returns:
true if DB 390 is used as the database.

useOracle

public static boolean useOracle()
Checks if Oracle is used as database
Returns:
true if Oracle is used as the database.

useCloudscape

public static boolean useCloudscape()
Checks if Cloudscape is used as database. Note that Cloudscape is not a supported production environment database.
Returns:
true if Cloudscape is used as the database.

getCharacterStreamFromResultSet

public static java.lang.String getCharacterStreamFromResultSet(java.sql.ResultSet rs,
                                                               int nColumn)
                                                        throws java.sql.SQLException
Gets the characters stream from the result set
Parameters:
rs - Result set
nColumn - column index
Returns:
String of character stream from result set
Throws:
java.sql.SQLException

buildCommaSeparatedWhereClause

public static java.lang.String buildCommaSeparatedWhereClause(int length)
Builds comma separated where clause by length
Parameters:
length - The length used to separate the where clause
Returns:
SQL statmenet string