public class JDBCManager
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Field and Description |
---|---|
private static long |
serialVersionUID
The class' serialization version id.
|
Constructor and Description |
---|
JDBCManager() |
Modifier and Type | Method and Description |
---|---|
static void |
closeTransaction(java.sql.Connection conn,
boolean commit)
Closes a connection transaction and commits or rolls back any changes
made to the database.
|
static boolean |
createDatabase(java.lang.String poolName,
JDBCConnectionInfo cninf)
Creates the database tables and indexes and views using the definitions
found in the application's resource file.
|
private static boolean |
createDatabaseIndexes(JDBCConnectionInfo cninf)
Creates the database indexes using definitions in the application's
resource file.
|
private static boolean |
createDatabaseTables(JDBCConnectionInfo cninf)
Creates the database tables using definitions in the application's
resource file.
|
private static boolean |
createDatabaseViews(JDBCConnectionInfo cninf)
Creates the database views using definitions in the application's
resource file.
|
static boolean |
databaseExists(JDBCConnectionInfo cninf)
Determines if the database exists and if one or more tables are in the
database.
|
static boolean |
databaseRevised(JDBCConnectionInfo cninf)
Determines if the database has been revised by comparing the count of
tables and columns and views in the database to those defined in the
application's resource file.
|
static java.sql.DatabaseMetaData |
getDatabaseMetaData(java.sql.Connection conn)
Returns the
DatabaseMetaData object for the current JDBC
connection. |
static java.lang.String |
getDatabaseVersionInfo(java.sql.Connection conn)
Returns a formatted string of database and driver version information.
|
static java.sql.PreparedStatement |
getPreparedStatement(JDBCConnectionInfo cninf,
java.lang.String stmtkey)
Returns an SQL
PreparedStatement for the given statement
resource key. |
static java.sql.PreparedStatement |
getPreparedStatement(JDBCConnectionInfo cninf,
java.lang.String stmtkey,
java.lang.String stmtstr)
Returns an SQL
PreparedStatement for the given statement
resource key. |
static java.sql.PreparedStatement |
getPreparedStatementForUpdate(JDBCConnectionInfo cninf,
java.lang.String stmtkey,
java.lang.String stmtstr)
Returns an updatable SQL
PreparedStatement for the given
statement resource key. |
static java.sql.Statement |
getStatement(java.sql.Connection conn)
Returns an SQL
Statement object for the active JDBC
connection. |
static boolean |
isTransaction(java.sql.Connection conn)
Answers if a connection transaction is currently open (auto commit is off).
|
static void |
openTransaction(java.sql.Connection conn)
Opens a connection transaction (sets auto commit off).
|
static boolean |
optimizeDatabase()
Performs database optimization.
|
static boolean |
reviseDatabase(JDBCConnectionInfo cninf)
Revises the database tables and columns and views using the definitions
found in the application's resource file.
|
private static boolean |
reviseDatabaseColumns(JDBCConnectionInfo cninf,
java.lang.String tblname)
Adds or deletes columns in a database table.
|
private static boolean |
reviseDatabaseTables(JDBCConnectionInfo cninf,
int tblcount)
Adds or deletes tables in the database.
|
private static boolean |
reviseDatabaseViews(JDBCConnectionInfo cninf)
Adds or deletes views in the database.
|
private static final long serialVersionUID
public static void closeTransaction(java.sql.Connection conn, boolean commit)
conn
- (Connection) The JDBC connection to use.commit
- (boolean) true
if changes to the database
are to be committed, otherwise false
.public static boolean createDatabase(java.lang.String poolName, JDBCConnectionInfo cninf)
poolName
- (String) The JDBC pool name to use.cninf
- (JDBCConnectionInfo) The JDBC connection to use.true
if the database table and index and
view creates are successful, otherwise false
.private static boolean createDatabaseIndexes(JDBCConnectionInfo cninf)
cninf
- (JDBCConnectionInfo) The JDBC connection to use.true
if the database index creates
are successful, otherwise false
.private static boolean createDatabaseTables(JDBCConnectionInfo cninf)
cninf
- (JDBCConnectionInfo) The JDBC connection to use.true
if the database table creates
are successful, otherwise false
.private static boolean createDatabaseViews(JDBCConnectionInfo cninf)
cninf
- (JDBCConnectionInfo) The JDBC connection to use.true
if the database view creates
are successful, otherwise false
.public static boolean databaseExists(JDBCConnectionInfo cninf)
This method does not verify that every table and every column used by an
application exists. Applications that require a more complete verification
of the database should invoke databaseRevised if the result from
this method is true
.
cninf
- (JDBCConnectionInfo) The JDBC connection to use.true
if the database exists and tables
are found in the database, otherwise false
.public static boolean databaseRevised(JDBCConnectionInfo cninf)
Due to limitations in DB2e, this method does not verify indexes.
cninf
- (JDBCConnectionInfo) The JDBC connection to use.true
if the database table or column or
view counts differ from what is defined the application resource
file, otherwise false
.public static java.sql.DatabaseMetaData getDatabaseMetaData(java.sql.Connection conn) throws java.lang.Exception
DatabaseMetaData
object for the current JDBC
connection.conn
- (Connection) The JDBC connection to use.java.lang.Exception
- - if an error occurs when obtaining the meta data.public static java.lang.String getDatabaseVersionInfo(java.sql.Connection conn)
conn
- (Connection) The JDBC connection to use.public static java.sql.PreparedStatement getPreparedStatement(JDBCConnectionInfo cninf, java.lang.String stmtkey) throws java.sql.SQLException
PreparedStatement
for the given statement
resource key.cninf
- (JDBCConnectionInfo) The JDBC connection to use.stmtkey
- (String) The resource key for the prepared statement
to retrieve.PreparedStatement
object for the specified statement resource key.java.sql.SQLException
- - if an error occurs while processing the result
set.public static java.sql.PreparedStatement getPreparedStatement(JDBCConnectionInfo cninf, java.lang.String stmtkey, java.lang.String stmtstr) throws java.sql.SQLException
PreparedStatement
for the given statement
resource key.cninf
- (JDBCConnectionInfo) The JDBC connection to use.stmtkey
- (String) The resource key for the prepared statement
to retrieve.stmtstr
- (String) The sql statement string, if it is already
known; otherwise an empty string.PreparedStatement
object for the specified statement resource key.java.sql.SQLException
- - if an error occurs while processing the result
set.public static java.sql.PreparedStatement getPreparedStatementForUpdate(JDBCConnectionInfo cninf, java.lang.String stmtkey, java.lang.String stmtstr) throws java.sql.SQLException
PreparedStatement
for the given
statement resource key.cninf
- (JDBCConnectionInfo) The JDBC connection to use.stmtkey
- (String) The resource key for the prepared statement
to retrieve.stmtstr
- (String) The sql statement string, if it is already
known; otherwise an empty string.PreparedStatement
object for the specified statement resource key.java.sql.SQLException
- - if an error occurs while processing the result
set.public static java.sql.Statement getStatement(java.sql.Connection conn)
Statement
object for the active JDBC
connection. The invoker of this method is expected to close the statement
object when done using it.conn
- (Connection) The JDBC connection to use.Statement
object.public static boolean isTransaction(java.sql.Connection conn)
conn
- (Connection) The JDBC connection to use.true
if a connection transaction exists,
otherwise false
.public static void openTransaction(java.sql.Connection conn)
conn
- (Connection) The JDBC connection to use.public static boolean optimizeDatabase()
true
if the optimization is successful,
otherwise false
.public static boolean reviseDatabase(JDBCConnectionInfo cninf)
Due to limitations in DB2e, this method does not revise indexes.
cninf
- (JDBCConnectionInfo) The JDBC connection to use.true
if the database table and column
and view revisions are successful, otherwise false
.private static boolean reviseDatabaseColumns(JDBCConnectionInfo cninf, java.lang.String tblname)
cninf
- (JDBCConnectionInfo) The JDBC connection to use.tblname
- (String) The name of a database table.true
if the column adds or deletes are
successful, otherwise false
.private static boolean reviseDatabaseTables(JDBCConnectionInfo cninf, int tblcount)
cninf
- (JDBCConnectionInfo) The JDBC connection to use.tblcount
- (int) The number of tables defined in the application's
resource file.true
if the table adds and deletes are
successful, otherwise false
.private static boolean reviseDatabaseViews(JDBCConnectionInfo cninf)
cninf
- (JDBCConnectionInfo) The JDBC connection to use.true
if the view adds and deletes are
successful, otherwise false
.