org.lateralnz.common.util
Class DAOUtils

java.lang.Object
  extended by org.lateralnz.common.util.DAOUtils
All Implemented Interfaces:
Constants

public class DAOUtils
extends java.lang.Object
implements Constants

utility functions for use with Data Access Objects and for more general JDBC stuff


Field Summary
 
Fields inherited from interface org.lateralnz.common.util.Constants
AMPERSAND, AND, APPLICATION_X_WWW_FORM_URLENCODED, ASTERISK, AT, BACK_SLASH, CHAR_LEFT_CHEV, CHAR_RIGHT_CHEV, COLON, COMMA, CRLF, DASH, DELETE, DOLLAR, DOT, DOT_CLASS, DOT_JAVA, EIGHT, EMPTY, EQUALS, FALSE, FILE_SEPARATOR, FIVE, FORWARD_SLASH, FOUR, FULLSTOP, HASH, HAT, INSERT, LEFT_BRACE, LEFT_BRACKET, LEFT_CHEV, MAX_LEN_APPCODE, MAX_LEN_APPGROUP, MAX_LEN_MSGCODE, MAX_LEN_MSGTEXT, MINUS_ONE, N, NEWLINE, NINE, NO, NULL_STRING, OFF, ON, ONE, ONE_DAY, ONE_HOUR, ONE_MINUTE, ONE_WEEK, PATH_SEPARATOR, PERCENT, PIPE, PLUS, QUESTION_MARK, QUOTE, REQUIRED, REQUIRES_NEW, RETURN, RIGHT_BRACE, RIGHT_BRACKET, RIGHT_CHEV, SELECT, SEMICOLON, SEVEN, SINGLE_QUOTE, SIX, SPACE, SQ_LEFT_BRACKET, SQ_RIGHT_BRACKET, SUPPORTS, TEXT_HTML, TEXT_PLAIN, TEXT_XML, THREE, TRUE, TWO, UNDERSCORE, UPDATE, UTF_8, Y, YES, ZERO
 
Constructor Summary
DAOUtils()
           
 
Method Summary
static java.lang.String buildSQL(java.util.ResourceBundle sqlstatements, java.lang.String[] keys)
           
static boolean close(java.sql.Connection conn)
           
static boolean close(java.sql.ResultSet rs)
           
static boolean close(java.sql.Statement st)
           
static boolean commit(java.sql.Connection conn)
           
static java.lang.String createParameterPlaceholders(int count)
           
static java.lang.String createSQLArrayString(java.lang.String[] vals, int start, int len)
           
static java.lang.String dump(java.sql.ResultSet rs)
           
static java.lang.String dumpData(java.sql.ResultSet rs)
           
static boolean getCharAsBoolean(java.sql.ResultSet rs, java.lang.String column, boolean defaultValue)
          get a char(1) as a boolean value.
static ColumnMetaData getColumnMetaData(java.sql.Connection conn, java.lang.String schema, java.lang.String table, java.lang.String column)
          return column meta data for a particular column using the specified connection.
static java.sql.Connection getConnection(java.lang.String datasource)
          get a connection from a named datasource using JNDI
static java.util.Date getDate(java.sql.ResultSet rs, java.lang.String columnName)
          given a resultset and column name of a timestamp column, return the column as a java.util.Date
static boolean hasColumnMetaData(java.lang.String schema, java.lang.String table, java.lang.String column)
          a method for checking if column meta data has been cached for the specified schema, table and column name.
static boolean isDuplicateKeyException(java.sql.SQLException se)
           
static boolean isDuplicateKeyException(java.lang.Throwable t)
           
static java.lang.String parseInClause(java.lang.String sql, int numInList)
           
static void registerDriver(java.lang.String driverClass)
           
static void setParam(java.sql.PreparedStatement ps, int col, boolean value)
           
static void setParam(java.sql.PreparedStatement ps, int col, java.util.Date value)
          set a Date parameter on a prepared statement according to its index.
static void setParam(java.sql.PreparedStatement ps, int col, float value)
          set a float parameter on a prepared statement according to its index.
static void setParam(java.sql.PreparedStatement ps, int col, int value)
          set an int parameter on a prepared statement according to its index.
static void setParam(java.sql.PreparedStatement ps, int col, int value, boolean preserve)
          set an int parameter on a prepared statement according to its index.
static void setParam(java.sql.PreparedStatement ps, int col, java.lang.String value)
          set a String parameter on a prepared statement according to its index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DAOUtils

public DAOUtils()
Method Detail

buildSQL

public static final java.lang.String buildSQL(java.util.ResourceBundle sqlstatements,
                                              java.lang.String[] keys)

commit

public static boolean commit(java.sql.Connection conn)

close

public static boolean close(java.sql.Statement st)

close

public static boolean close(java.sql.ResultSet rs)

close

public static boolean close(java.sql.Connection conn)

createParameterPlaceholders

public static final java.lang.String createParameterPlaceholders(int count)

createSQLArrayString

public static final java.lang.String createSQLArrayString(java.lang.String[] vals,
                                                          int start,
                                                          int len)

dump

public static java.lang.String dump(java.sql.ResultSet rs)

dumpData

public static java.lang.String dumpData(java.sql.ResultSet rs)

getCharAsBoolean

public static boolean getCharAsBoolean(java.sql.ResultSet rs,
                                       java.lang.String column,
                                       boolean defaultValue)
                                throws java.sql.SQLException
get a char(1) as a boolean value. e.g. Y = true, N = false, an empty char = defaultvalue

Throws:
java.sql.SQLException

getDate

public static java.util.Date getDate(java.sql.ResultSet rs,
                                     java.lang.String columnName)
                              throws java.sql.SQLException
given a resultset and column name of a timestamp column, return the column as a java.util.Date

Throws:
java.sql.SQLException

hasColumnMetaData

public static boolean hasColumnMetaData(java.lang.String schema,
                                        java.lang.String table,
                                        java.lang.String column)
a method for checking if column meta data has been cached for the specified schema, table and column name. BEWARE: this method may need to change from database to database


getColumnMetaData

public static ColumnMetaData getColumnMetaData(java.sql.Connection conn,
                                               java.lang.String schema,
                                               java.lang.String table,
                                               java.lang.String column)
                                        throws java.sql.SQLException
return column meta data for a particular column using the specified connection. If the data is present in the cache, then the cached metadata is returned, otherwise the connection is used and the response is cached.

Throws:
java.sql.SQLException

getConnection

public static java.sql.Connection getConnection(java.lang.String datasource)
                                         throws java.sql.SQLException
get a connection from a named datasource using JNDI

Parameters:
datasource - the name of the data source to retrieve
Throws:
java.sql.SQLException

isDuplicateKeyException

public static boolean isDuplicateKeyException(java.lang.Throwable t)

isDuplicateKeyException

public static boolean isDuplicateKeyException(java.sql.SQLException se)

parseInClause

public static final java.lang.String parseInClause(java.lang.String sql,
                                                   int numInList)

registerDriver

public static final void registerDriver(java.lang.String driverClass)
                                 throws java.lang.Exception
Throws:
java.lang.Exception

setParam

public static void setParam(java.sql.PreparedStatement ps,
                            int col,
                            java.lang.String value)
                     throws java.sql.SQLException
set a String parameter on a prepared statement according to its index. Note: if the value is null, this will call setNull

Parameters:
ps - the PreparedStatement
col - the index of the parameter
value - the string to set
Throws:
java.sql.SQLException

setParam

public static void setParam(java.sql.PreparedStatement ps,
                            int col,
                            int value)
                     throws java.sql.SQLException
set an int parameter on a prepared statement according to its index. Note: if the value is less than 0, setNull will be called. If you want to set a negative integer, then you must call setParam with preserveNegative set to true.

Parameters:
ps - the PreparedStatement
col - the index of the parameter
value - the int value to set
Throws:
java.sql.SQLException

setParam

public static void setParam(java.sql.PreparedStatement ps,
                            int col,
                            int value,
                            boolean preserve)
                     throws java.sql.SQLException
set an int parameter on a prepared statement according to its index. Note: if the value is less than 0, setNull will be called unless preserve is set to true

Parameters:
ps - the PreparedStatement
col - the index of the parameter
value - the int value to set
preserveNegative - do not call setNull if this is true
Throws:
java.sql.SQLException

setParam

public static void setParam(java.sql.PreparedStatement ps,
                            int col,
                            float value)
                     throws java.sql.SQLException
set a float parameter on a prepared statement according to its index. Note: if the value is Float.NEGATIVE_INFINITY, setNull will be called

Parameters:
ps - the PreparedStatement
col - the index of the parameter
value - the float value to set
preserveNegative - do not call setNull if this is true
Throws:
java.sql.SQLException

setParam

public static void setParam(java.sql.PreparedStatement ps,
                            int col,
                            java.util.Date value)
                     throws java.sql.SQLException
set a Date parameter on a prepared statement according to its index. Note: if the value is null, this will call setNull

Parameters:
ps - the PreparedStatement
col - the index of the parameter
value - the date to set
Throws:
java.sql.SQLException

setParam

public static void setParam(java.sql.PreparedStatement ps,
                            int col,
                            boolean value)
                     throws java.sql.SQLException
Throws:
java.sql.SQLException