com.im.commons.db 5.9.2

com.im.commons.db.util
Class DBUtils

java.lang.Object
  extended by com.im.commons.db.util.DBUtils

public class DBUtils
extends Object

Class collecting a few generic static utility methods mostly related to SQL generation


Field Summary
static String PROP_LOG_SQL_STATEMENTS
          Property for option triggering SQL statements logging
static String UNDERSCORE
           
 
Constructor Summary
DBUtils()
           
 
Method Summary
static PreparedStatementCreator createPreparedStatementCreator(String sql, DBType dbType)
          Create a PreparedStatementCreator with maximum optimal fetch size for given dbType.
static PreparedStatementCreator createPreparedStatementCreator(String sql, int fetchSize)
          Create a PreparedStatementCreator, specifying some options for how the PreparedStatement should be created
static DBDatabaseInfo.ColumnSQLType findColumnType(String nativeType)
          Find the ColumnSQLType enum for this native type.
static String findStringNotPresent(List<String> values)
          Helper method for JChem cartridge functions to find a String (character) that is not present in any of the specified values
static String[] getColumnNamesAsArray(List<DBColInfo> cols)
           
static List<String> getColumnNamesAsList(List<DBColInfo> cols)
           
static String[] getColumnNamesFor(DBTableInfo info, String[] exceptThese)
           
static String join(Collection terms, String sep)
          Join a List of values with the specified separator
static String join(int[] terms, String sep)
          Substitute an array of ids into a statement separated with the specified separator
static String join(Object[] terms, String sep)
          Join the array of values with the specified separator
static String join(Object[] terms, String sep, String identifierQuoteString)
          Join the array of values with the specified separator and quote char
static void join(StringBuffer buf, Collection terms, String sep, int jdbcType)
          Join a List of values with the specified separator and append to the specified StringBuffer
static void join(StringBuffer buf, Object[] terms, String sep)
          Join the array of values with the specified separator and append to the specified StringBuffer
static String repeat(String val, String sep, int count)
           
static String schemaNameNoTable(String tableName)
          Parses schema name from schema qualified table name.
static String sqlEscapeString(Object o)
           
static String[] sqlEscapeString(Object[] o)
           
static String sqlQuoteAndEscapeString(Object o)
           
static String[] sqlQuoteAndEscapeString(Object[] o)
           
static String sqlQuoteString(Object o)
           
static String[] sqlQuoteString(Object[] o)
           
static String stripQuotes(String txt)
          Strips the quotes (') from a string.
static String tableNameNoSchema(String name)
          Get the table name component of a table that might have a schema specified.
static void verifySchemaQualifiedTableName(String tableName)
          Verifies that table name contains '.', ie.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_LOG_SQL_STATEMENTS

public static final String PROP_LOG_SQL_STATEMENTS
Property for option triggering SQL statements logging

See Also:
Constant Field Values

UNDERSCORE

public static final String UNDERSCORE
See Also:
Constant Field Values
Constructor Detail

DBUtils

public DBUtils()
Method Detail

repeat

public static String repeat(String val,
                            String sep,
                            int count)

join

public static String join(int[] terms,
                          String sep)
Substitute an array of ids into a statement separated with the specified separator

Parameters:
terms - The values to join
sep - The separator
Returns:
The joined values

join

public static String join(Collection terms,
                          String sep)
Join a List of values with the specified separator

Parameters:
terms - A Collection of values whose values (according to the toString() method) are joined together
sep - The separator to use

join

public static void join(StringBuffer buf,
                        Collection terms,
                        String sep,
                        int jdbcType)
Join a List of values with the specified separator and append to the specified StringBuffer

Parameters:
buf - The buffer to append the results to
terms - A Collection of values whose values (according to the toString() method) are joined together
sep - The separator to use
jdbcType - THe JDBC type which is used to determine if the values need quoting and escaping

join

public static void join(StringBuffer buf,
                        Object[] terms,
                        String sep)
Join the array of values with the specified separator and append to the specified StringBuffer

Parameters:
buf - The buffer to append the results to
terms - An array of values whose values (according to the toString() method) are joined together
sep - The separator to use

join

public static String join(Object[] terms,
                          String sep)
Join the array of values with the specified separator

Parameters:
terms - An array of values whose values (according to the toString() method) are joined together
sep - The separator to use
Returns:
The joined values

join

public static String join(Object[] terms,
                          String sep,
                          String identifierQuoteString)
Join the array of values with the specified separator and quote char

Parameters:
terms - An array of values whose values (according to the toString() method) are joined together
sep - The separator to use
identifierQuoteString - quote char surrounding each term
Returns:
The joined values

sqlEscapeString

public static String sqlEscapeString(Object o)

sqlQuoteString

public static String sqlQuoteString(Object o)

sqlQuoteAndEscapeString

public static String sqlQuoteAndEscapeString(Object o)

sqlEscapeString

public static String[] sqlEscapeString(Object[] o)

sqlQuoteString

public static String[] sqlQuoteString(Object[] o)

sqlQuoteAndEscapeString

public static String[] sqlQuoteAndEscapeString(Object[] o)

stripQuotes

public static String stripQuotes(String txt)
Strips the quotes (') from a string. e.g converts 'hello' to hello


getColumnNamesFor

public static String[] getColumnNamesFor(DBTableInfo info,
                                         String[] exceptThese)

getColumnNamesAsList

public static List<String> getColumnNamesAsList(List<DBColInfo> cols)

getColumnNamesAsArray

public static String[] getColumnNamesAsArray(List<DBColInfo> cols)

findColumnType

public static DBDatabaseInfo.ColumnSQLType findColumnType(String nativeType)
Find the ColumnSQLType enum for this native type. If not found then returns null.

Parameters:
nativeType - The column type as a String. e.g. VARCHAR
Returns:
The ColumnSQLType enum corresponding to the nativeType.

tableNameNoSchema

public static String tableNameNoSchema(String name)
Get the table name component of a table that might have a schema specified. e.g. if a table is given as SOME_SCHEMA.SOME_TABLE return SOME_TABLE


verifySchemaQualifiedTableName

public static void verifySchemaQualifiedTableName(String tableName)
Verifies that table name contains '.', ie. is a schema qualified name

Parameters:
tableName - The t ableName to check

schemaNameNoTable

public static String schemaNameNoTable(String tableName)
Parses schema name from schema qualified table name.

Parameters:
tableName -
Returns:
The schemaName or null if tableName not qualified by schema

findStringNotPresent

public static String findStringNotPresent(List<String> values)
Helper method for JChem cartridge functions to find a String (character) that is not present in any of the specified values


createPreparedStatementCreator

public static PreparedStatementCreator createPreparedStatementCreator(String sql,
                                                                      int fetchSize)
Create a PreparedStatementCreator, specifying some options for how the PreparedStatement should be created

Parameters:
sql - The sql to use
fetchSize - The JDBC fetch size. See Statement.setFetchSize(int)
Returns:
The PreparedStatementCreator

createPreparedStatementCreator

public static PreparedStatementCreator createPreparedStatementCreator(String sql,
                                                                      DBType dbType)
Create a PreparedStatementCreator with maximum optimal fetch size for given dbType. See Statement.setFetchSize(int)

Parameters:
sql - The sql to use
dbType - given dbType.
Returns:
The PreparedStatementCreator

com.im.commons.db 5.9.2