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

Constructor Summary
DBUtility(String url, String user, String pwd)
          DBUtility connects to the database in this constructor.
 
Method Summary
 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()
           
 int getJdbcType(String ojbType)
          Determines the java.sql.Types constant value from an OJB FIELDDESCRIPTOR value.
 void release()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

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.

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 © 2004-2012 The Kuali Foundation. All Rights Reserved.