org.apache.ojb.broker.ant
Class DBUtility

java.lang.Object
  extended by org.apache.ojb.broker.ant.DBUtility

public class DBUtility
extends Object

DBUtility is a utility class for verifying that various Database objects exist in a specified database. This utility does not use the jdbc DatabaseMetaData object because not all jdbc drivers fully implement it (like org.hsqldb.jdbcDriver - suckers).

Version:
$Id: DBUtility.java,v 1.1 2007-08-24 22:17:41 ewestfal Exp $
Author:
Daren Drummond

Field Summary
private  Hashtable m_columnCache
           
private  Connection m_connection
           
private static String m_ORA_EXCEPTION_1000
           
private static String m_ORA_EXCEPTION_604
           
private  String m_pwd
           
private  String m_url
           
private  String m_user
           
 
Constructor Summary
DBUtility(String url, String user, String pwd)
          DBUtility connects to the database in this constructor.
 
Method Summary
private  Connection connect(String url, String user, String pwd)
           
 boolean exists(String tableName)
          Checks the database for the existence of this table.
 void exists(String tableName, String columnName, boolean ignoreCase)
          Checks the database for the existence of this table.column.
 void exists(String tableName, String columnName, String jdbcType, boolean ignoreCase)
          Checks the database for the existence of this table.column of the specified jdbc type.
 void existsUseWarnings(String tableName, String columnName, String jdbcType, boolean ignoreCase)
          Checks the database for the existence of this table.column of the specified jdbc type.
protected  void finalize()
           
private  ResultSet getColumns(String tableName)
           
 int getJdbcType(String ojbType)
          Determines the java.sql.Types constant value from an OJB FIELDDESCRIPTOR value.
private  void putColumns(String tableName, ResultSet columns)
           
 void release()
           
private  void resetConnection()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_connection

private Connection m_connection

m_url

private String m_url

m_user

private String m_user

m_pwd

private String m_pwd

m_ORA_EXCEPTION_1000

private static String m_ORA_EXCEPTION_1000

m_ORA_EXCEPTION_604

private static String m_ORA_EXCEPTION_604

m_columnCache

private Hashtable m_columnCache
Constructor Detail

DBUtility

public DBUtility(String url,
                 String user,
                 String pwd)
          throws SQLException
DBUtility connects to the database in this constructor.

Parameters:
url - String representing the jdbc connection url. For example, "jdbc:hsqldb:target/test/OJB".
user - The database user account to use for logging on.
pwd - The password for the user
Throws:
SQLException - Throws SQLException if there are problems connecting to the database.
ClassNotFoundException - Throws ClassNotFoundException if the jdbc driver class can not be found.
Method Detail

release

public void release()
             throws SQLException
Throws:
SQLException

resetConnection

private void resetConnection()

connect

private Connection connect(String url,
                           String user,
                           String pwd)
                    throws SQLException
Throws:
SQLException

exists

public boolean exists(String tableName)
Checks the database for the existence of this table. Returns true if it exists, false if it doesn't exist, and throws a SQLException if the connection is not established. NOTE: If a schema is required for your database, then it should have been provided in the connection url.

Parameters:
tableName - String name of the table that you want check for existence.
Returns:
boolean true if the table exists, false if it doesn't exist.

getColumns

private ResultSet getColumns(String tableName)

putColumns

private void putColumns(String tableName,
                        ResultSet columns)

exists

public void exists(String tableName,
                   String columnName,
                   String jdbcType,
                   boolean ignoreCase)
            throws SQLException
Checks the database for the existence of this table.column of the specified jdbc type. Returns true if it exists, false if it doesn't exist, and throws a SQLException if the connection is not established. NOTE: If a schema is required for your database, then it should have been provided in the connection url.

Parameters:
tableName - String name of the table to check.
columnName - String name of the table column to check.
jdbcType - Case insensitive String representation of the jdbc type of the column. Valid values are string representations of the types listed in java.sql.Types. For example, "bit", "float", "varchar", "clob", etc.
ignoreCase - boolean flag that determines if the utility should consider the column name case when searching for the database table.column.
Throws:
SQLException - if the Table doesn't exist, if the column doesn't exist, if the column type doesn't match the specified jdbcType.

existsUseWarnings

public void existsUseWarnings(String tableName,
                              String columnName,
                              String jdbcType,
                              boolean ignoreCase)
                       throws SQLException,
                              SQLWarning
Checks the database for the existence of this table.column of the specified jdbc type. Throws a SQLException if if the Table.Column can not be found, and throws a SQLWarning if the column type does not match the passed JDBC type. NOTE: If a schema is required for your database, then it should have been provided in the connection url.

Parameters:
tableName - String name of the table to check.
columnName - String name of the table column to check.
jdbcType - Case insensitive String representation of the jdbc type of the column. Valid values are string representations of the types listed in java.sql.Types. For example, "bit", "float", "varchar", "clob", etc.
ignoreCase - boolean flag that determines if the utility should consider the column name case when searching for the database table.column.
Throws:
SQLException - if the Table doesn't exist, if the column doesn't exist.
SQLWarning - if the column type doesn't match the specified jdbcType.

exists

public void exists(String tableName,
                   String columnName,
                   boolean ignoreCase)
            throws SQLException
Checks the database for the existence of this table.column. Throws a SQLException if if the Table.Column can not be found. NOTE: If a schema is required for your database, then it should have been provided in the connection url.

Parameters:
tableName - String name of the table to check.
columnName - String name of the table column to check.
ignoreCase - boolean flag that determines if the utility should consider the column name case when searching for the database table.column.
Throws:
SQLException - if the Table doesn't exist, if the column doesn't exist.

getJdbcType

public int getJdbcType(String ojbType)
                throws SQLException
Determines the java.sql.Types constant value from an OJB FIELDDESCRIPTOR value.

Parameters:
type - The FIELDDESCRIPTOR which JDBC type is to be determined.
Returns:
int the int value representing the Type according to
Throws:
SQLException - if the type is not a valid jdbc type. java.sql.Types

finalize

protected void finalize()
Overrides:
finalize in class Object


Copyright © 2007-2011 The Kuali Foundation. All Rights Reserved.