|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.dbunit.util.SQLHelper
public class SQLHelper
Helper for SQL-related stuff.
TODO: testcases, also think about refactoring so that methods are not static anymore (for better extensibility)
| Field Summary | |
|---|---|
static java.lang.String |
DB_PRODUCT_SYBASE
The database product name reported by Sybase JDBC drivers. |
| Method Summary | |
|---|---|
static boolean |
areEqualIgnoreNull(java.lang.String value1,
java.lang.String value2,
boolean caseSensitive)
Compares the given values and returns true if they are equal. |
static void |
close(java.sql.ResultSet resultSet)
Closes the given result set in a null-safe way |
static void |
close(java.sql.ResultSet rs,
java.sql.Statement stmt)
Close a result set and a prepared statement, checking for null references. |
static void |
close(java.sql.Statement stmt)
Close a SQL statement, checking for null references. |
static java.lang.String |
correctCase(java.lang.String databaseIdentifier,
java.sql.Connection connection)
Corrects the case of the given String according to the way in which the database stores metadata. |
static java.lang.String |
correctCase(java.lang.String databaseIdentifier,
java.sql.DatabaseMetaData databaseMetaData)
Corrects the case of the given String according to the way in which the database stores metadata. |
static Column |
createColumn(java.sql.ResultSet resultSet,
IDataTypeFactory dataTypeFactory,
boolean datatypeWarning)
Utility method to create a Column object from a SQL ResultSet object. |
static java.lang.String |
getDatabaseInfo(java.sql.DatabaseMetaData metaData)
Returns the database and JDBC driver information as pretty formatted string |
static java.lang.String |
getPrimaryKeyColumn(java.sql.Connection conn,
java.lang.String table)
Gets the primary column for a table. |
static boolean |
isSybaseDb(java.sql.DatabaseMetaData metaData)
Detects whether or not the given metadata describes the connection to a Sybase database or not. |
static void |
logDebugIfValueChanged(java.lang.String oldValue,
java.lang.String newValue,
java.lang.String message,
java.lang.Class source)
Checks whether two given values are unequal and if so print a log message (level DEBUG) |
static void |
logInfoIfValueChanged(java.lang.String oldValue,
java.lang.String newValue,
java.lang.String message,
java.lang.Class source)
Checks whether two given values are unequal and if so print a log message (level DEBUG) |
static boolean |
matches(java.sql.ResultSet resultSet,
java.lang.String schema,
java.lang.String table,
boolean caseSensitive)
Deprecated. since 2.4.4 - use IMetadataHandler.matches(ResultSet, String, String, String, String, boolean) |
static boolean |
matches(java.sql.ResultSet resultSet,
java.lang.String catalog,
java.lang.String schema,
java.lang.String table,
java.lang.String column,
boolean caseSensitive)
Deprecated. since 2.4.4 - use IMetadataHandler.matches(ResultSet, String, String, String, String, boolean) |
static void |
printAllTables(java.sql.DatabaseMetaData metaData,
java.io.PrintStream outputStream)
Utility method for debugging to print all tables of the given metadata on the given stream |
static void |
printDatabaseInfo(java.sql.DatabaseMetaData metaData,
java.io.PrintStream outputStream)
Prints the database and JDBC driver information to the given output stream |
static boolean |
schemaExists(java.sql.Connection connection,
java.lang.String schema)
Returns true if the given schema exists for the given connection. |
static boolean |
tableExists(java.sql.DatabaseMetaData metaData,
java.lang.String schema,
java.lang.String tableName)
Deprecated. since 2.4.5 - use IMetadataHandler.tableExists(DatabaseMetaData, String, String) |
| 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 DB_PRODUCT_SYBASE
| Method Detail |
|---|
public static java.lang.String getPrimaryKeyColumn(java.sql.Connection conn,
java.lang.String table)
throws java.sql.SQLException
conn - connection with the databasetable - table name
java.sql.SQLException - raised while getting the meta data
public static void close(java.sql.ResultSet rs,
java.sql.Statement stmt)
throws java.sql.SQLException
rs - result set to be closedstmt - prepared statement to be closed
java.sql.SQLException - exception raised in either close() method
public static void close(java.sql.Statement stmt)
throws java.sql.SQLException
stmt - statement to be closed
java.sql.SQLException - exception raised while closing the statement
public static void close(java.sql.ResultSet resultSet)
throws java.sql.SQLException
resultSet -
java.sql.SQLException
public static boolean schemaExists(java.sql.Connection connection,
java.lang.String schema)
throws java.sql.SQLException
true if the given schema exists for the given connection.
connection - The connection to a databaseschema - The schema to be searched
true if the given schema exists for the given connection.
java.sql.SQLException
public static boolean tableExists(java.sql.DatabaseMetaData metaData,
java.lang.String schema,
java.lang.String tableName)
throws java.sql.SQLException
IMetadataHandler.tableExists(DatabaseMetaData, String, String)
metaData - The database meta dataschema - The schema in which the table should be searched. If null
the schema is not used to narrow the table name.tableName - The table name to be searched
true if the given table exists in the given schema.
Else returns false.
java.sql.SQLException
public static void printAllTables(java.sql.DatabaseMetaData metaData,
java.io.PrintStream outputStream)
throws java.sql.SQLException
metaData - outputStream -
java.sql.SQLExceptionpublic static java.lang.String getDatabaseInfo(java.sql.DatabaseMetaData metaData)
metaData - The JDBC database metadata needed to retrieve database information
public static void printDatabaseInfo(java.sql.DatabaseMetaData metaData,
java.io.PrintStream outputStream)
throws java.sql.SQLException
metaData - The JDBC database metadata needed to retrieve database informationoutputStream - The stream to which the information is printed
java.sql.SQLException
public static boolean isSybaseDb(java.sql.DatabaseMetaData metaData)
throws java.sql.SQLException
metaData - The metadata to be checked whether it is a Sybase connection
true if and only if the given metadata belongs to a Sybase database.
java.sql.SQLException
public static final Column createColumn(java.sql.ResultSet resultSet,
IDataTypeFactory dataTypeFactory,
boolean datatypeWarning)
throws java.sql.SQLException,
DataTypeException
Column object from a SQL ResultSet object.
resultSet - A result set produced via DatabaseMetaData.getColumns(String, String, String, String)dataTypeFactory - The factory used to lookup the DataType for this columndatatypeWarning - Whether or not a warning should be printed if the column could not
be created because of an unknown datatype.
Column or null if the column could not be initialized because of an
unknown datatype.
java.sql.SQLException
DataTypeException
public static boolean matches(java.sql.ResultSet resultSet,
java.lang.String schema,
java.lang.String table,
boolean caseSensitive)
throws java.sql.SQLException
IMetadataHandler.matches(ResultSet, String, String, String, String, boolean)
resultSet matches the given schema and table name.
The comparison is case sensitive.
resultSet - A result set produced via DatabaseMetaData.getColumns(String, String, String, String)schema - The name of the schema to check. If null it is ignored in the comparisontable - The name of the table to check. If null it is ignored in the comparisoncaseSensitive - Whether or not the comparison should be case sensitive or not
true if the column metadata of the given resultSet matches
the given schema and table parameters.
java.sql.SQLException
public static boolean matches(java.sql.ResultSet resultSet,
java.lang.String catalog,
java.lang.String schema,
java.lang.String table,
java.lang.String column,
boolean caseSensitive)
throws java.sql.SQLException
IMetadataHandler.matches(ResultSet, String, String, String, String, boolean)
resultSet matches the given schema and table name.
The comparison is case sensitive.
resultSet - A result set produced via DatabaseMetaData.getColumns(String, String, String, String)catalog - The name of the catalog to check. If null it is ignored in the comparisonschema - The name of the schema to check. If null it is ignored in the comparisontable - The name of the table to check. If null it is ignored in the comparisoncolumn - The name of the column to check. If null it is ignored in the comparisoncaseSensitive - Whether or not the comparison should be case sensitive or not
true if the column metadata of the given resultSet matches
the given schema and table parameters.
java.sql.SQLException
public static final boolean areEqualIgnoreNull(java.lang.String value1,
java.lang.String value2,
boolean caseSensitive)
null or empty String it always
returns true which is the way of ignoring nulls
for this specific case.
value1 - The first value to compare. Is ignored if null or empty Stringvalue2 - The second value to be compared
true if both values are equal or if the first value
is null or empty string.
public static final java.lang.String correctCase(java.lang.String databaseIdentifier,
java.sql.Connection connection)
databaseIdentifier - A database identifier such as a table name or a schema name for
which the case should be corrected.connection - The connection used to lookup the database metadata. This is needed to determine
the way in which the database stores its metadata.
public static final java.lang.String correctCase(java.lang.String databaseIdentifier,
java.sql.DatabaseMetaData databaseMetaData)
databaseIdentifier - A database identifier such as a table name or a schema name for
which the case should be corrected.databaseMetaData - The database metadata needed to determine the way in which the database stores
its metadata.
public static final void logInfoIfValueChanged(java.lang.String oldValue,
java.lang.String newValue,
java.lang.String message,
java.lang.Class source)
oldValue - The old value of a propertynewValue - The new value of a propertymessage - The message to be loggedsource - The class which invokes this method - used for enriching the log message
public static final void logDebugIfValueChanged(java.lang.String oldValue,
java.lang.String newValue,
java.lang.String message,
java.lang.Class source)
oldValue - The old value of a propertynewValue - The new value of a propertymessage - The message to be loggedsource - The class which invokes this method - used for enriching the log message
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||