org.apache.ojb.broker.ant
Class DBUtility

java.lang.Object
  extended byorg.apache.ojb.broker.ant.DBUtility

public class DBUtility
extends java.lang.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: $
Author:
Daren Drummond

Constructor Summary
DBUtility(java.lang.String url, java.lang.String user, java.lang.String pwd)
          DBUtility connects to the database in this constructor.
 
Method Summary
 boolean exists(java.lang.String tableName)
          Checks the database for the existence of this table.
 void exists(java.lang.String tableName, java.lang.String columnName, boolean ignoreCase)
          Checks the database for the existence of this table.column.
 void exists(java.lang.String tableName, java.lang.String columnName, java.lang.String jdbcType, boolean ignoreCase)
          Checks the database for the existence of this table.column of the specified jdbc type.
 void existsUseWarnings(java.lang.String tableName, java.lang.String columnName, java.lang.String jdbcType, boolean ignoreCase)
          Checks the database for the existence of this table.column of the specified jdbc type.
protected  void finalize()
           
 int getJdbcType(java.lang.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(java.lang.String url,
                 java.lang.String user,
                 java.lang.String pwd)
          throws java.sql.SQLException,
                 java.lang.ClassNotFoundException
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:
java.sql.SQLException - Throws SQLException if there are problems connecting to the database.
java.lang.ClassNotFoundException - Throws ClassNotFoundException if the jdbc driver class can not be found.
Method Detail

release

public void release()
             throws java.sql.SQLException
Throws:
java.sql.SQLException

exists

public boolean exists(java.lang.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(java.lang.String tableName,
                   java.lang.String columnName,
                   java.lang.String jdbcType,
                   boolean ignoreCase)
            throws java.sql.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:
java.sql.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(java.lang.String tableName,
                              java.lang.String columnName,
                              java.lang.String jdbcType,
                              boolean ignoreCase)
                       throws java.sql.SQLException,
                              java.sql.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:
java.sql.SQLException - if the Table doesn't exist, if the column doesn't exist.
java.sql.SQLWarning - if the column type doesn't match the specified jdbcType.

exists

public void exists(java.lang.String tableName,
                   java.lang.String columnName,
                   boolean ignoreCase)
            throws java.sql.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:
java.sql.SQLException - if the Table doesn't exist, if the column doesn't exist.

getJdbcType

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

Returns:
int the int value representing the Type according to
Throws:
java.sql.SQLException - if the type is not a valid jdbc type. java.sql.Types

finalize

protected void finalize()


Authors: Thomas Mahler and others. (C) 2000 - 2003 Apache Software Foundation
All rights reserved. Published under the Apache License.
http://db.apache.org/ojb
Version: 1.0.rc5, 2003-12-14