org.jboss.ejb.plugins.cmp.jdbc
Class JDBCUtil

java.lang.Object
  extended byorg.jboss.ejb.plugins.cmp.jdbc.JDBCUtil

public final class JDBCUtil
extends java.lang.Object

JDBCUtil takes care of some of the more anoying JDBC tasks. It hanles safe closing of jdbc resources, setting statement parameters and loading query results.


Constructor Summary
JDBCUtil()
           
 
Method Summary
static java.lang.Object coerceToSQLType(int jdbcType, java.lang.Object value)
          Coerces the input value into the correct type for the specified jdbcType.
static byte[] convertObjectToByteArray(java.lang.Object value)
          Coverts the value into a byte array.
static java.lang.Object convertToObject(byte[] input)
          Coverts the input into an object.
static java.lang.Object convertToObject(java.io.InputStream input)
          Coverts the input into an object.
static byte[] getByteArray(java.io.InputStream input)
          Read the entire input stream provided and return its content as a byte array.
static java.lang.String getJDBCTypeName(int jdbcType)
          Gets the JDBC type name corresponding to the given type code.
static java.lang.String getLongString(java.sql.ResultSet rs, int index)
          Get the indicated result set parameter as a character stream and return it's entire content as a String.
static java.lang.Object getParameter(Logger (src)  log, java.sql.CallableStatement cs, int index, int jdbcType, java.lang.Class destination)
          Used for all retrieval of parameters from CallableStatements.
static JDBCParameterSetter (src) getParameterSetter(int jdbcType, java.lang.Class javaType)
           
static JDBCResultSetReader (src) getResultReaderByType(java.lang.Class destination)
           
static JDBCResultSetReader (src) getResultSetReader(int jdbcType, java.lang.Class destination)
           
static void safeClose(java.sql.Connection con)
           
static void safeClose(java.io.InputStream in)
           
static void safeClose(java.io.OutputStream out)
           
static void safeClose(java.io.Reader reader)
           
static void safeClose(java.sql.ResultSet rs)
           
static void safeClose(java.sql.Statement statement)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCUtil

public JDBCUtil()
Method Detail

safeClose

public static void safeClose(java.sql.Connection con)

safeClose

public static void safeClose(java.sql.ResultSet rs)

safeClose

public static void safeClose(java.sql.Statement statement)

safeClose

public static void safeClose(java.io.InputStream in)

safeClose

public static void safeClose(java.io.OutputStream out)

safeClose

public static void safeClose(java.io.Reader reader)

coerceToSQLType

public static java.lang.Object coerceToSQLType(int jdbcType,
                                               java.lang.Object value)
Coerces the input value into the correct type for the specified jdbcType.

Parameters:
jdbcType - the jdbc type to which the value will be assigned
value - the value to coerce
Returns:
the corrected object

convertObjectToByteArray

public static byte[] convertObjectToByteArray(java.lang.Object value)
                                       throws java.sql.SQLException
Coverts the value into a byte array.

Parameters:
value - the value to convert into a byte array
Returns:
the byte representation of the value
Throws:
java.sql.SQLException - if a problem occures in the conversion

convertToObject

public static java.lang.Object convertToObject(byte[] input)
                                        throws java.sql.SQLException
Coverts the input into an object.

Parameters:
input - the bytes to convert
Returns:
the object repsentation of the input stream
Throws:
java.sql.SQLException - if a problem occures in the conversion

convertToObject

public static java.lang.Object convertToObject(java.io.InputStream input)
                                        throws java.sql.SQLException
Coverts the input into an object.

Parameters:
input - the bytes to convert
Returns:
the object repsentation of the input stream
Throws:
java.sql.SQLException - if a problem occures in the conversion

getLongString

public static java.lang.String getLongString(java.sql.ResultSet rs,
                                             int index)
                                      throws java.sql.SQLException
Get the indicated result set parameter as a character stream and return it's entire content as a String.

Parameters:
rs - the ResultSet from which a result is being retrieved.
index - index of the result column.
Returns:
a String containing the content of the result column
Throws:
java.sql.SQLException

getByteArray

public static byte[] getByteArray(java.io.InputStream input)
                           throws java.sql.SQLException
Read the entire input stream provided and return its content as a byte array.

Parameters:
input - the InputStream from which a result is being retrieved.
Returns:
a byte array containing the content of the input stream
Throws:
java.sql.SQLException

getResultSetReader

public static JDBCResultSetReader (src)  getResultSetReader(int jdbcType,
                                                     java.lang.Class destination)

getResultReaderByType

public static JDBCResultSetReader (src)  getResultReaderByType(java.lang.Class destination)

getParameterSetter

public static JDBCParameterSetter (src)  getParameterSetter(int jdbcType,
                                                     java.lang.Class javaType)

getJDBCTypeName

public static java.lang.String getJDBCTypeName(int jdbcType)
Gets the JDBC type name corresponding to the given type code. Only used in debug log messages.

Parameters:
jdbcType - the integer JDBC type code.
Returns:
the JDBC type name.
See Also:
Types

getParameter

public static java.lang.Object getParameter(Logger (src)  log,
                                            java.sql.CallableStatement cs,
                                            int index,
                                            int jdbcType,
                                            java.lang.Class destination)
                                     throws java.sql.SQLException
Used for all retrieval of parameters from CallableStatements. Implements tracing, and allows some tweaking of returned types.

Parameters:
log - where to log to
cs - the CallableStatement from which an out parameter is being retrieved
index - index of the result column.
jdbcType - a Types constant used to determine the most appropriate way to extract the data from rs.
destination - The class of the variable this is going into
Returns:
the value
Throws:
java.sql.SQLException