JdbcHelper Class

DEPRECATED Use com.bea.p13n.util.jdbc.JdbcHelper

com.beasys.commerce.util
JdbcHelper Class

public class JdbcHelper

    extends Object

Hierarchy
Object
  JdbcHelper

Field Summary

public static final boolean
shouldUseClobsForReads
Controls whether we should use the Clob object or the ResultSet.getString() method to retrieve CLOB columns.
public static final boolean
shouldUseClobsForWrites
Controls whether we should use the setCharacterStream() or the ResultSet.setString() method to set CLOB columns.
public static final Boolean
supportsLikeEscapeClause
Determine if the server configuration supports the LIKE ESCAPE clause.
 

Constructor Summary

JdbcHelper()

Helper constructor comment.
 

Method Summary

public static void
close(Connection con)
Close a connection, ignoring any errors.
public static void
close(Statement stmt)
Close a statement, ignoring any errors.
public static void
close(ResultSet rs)
Close a result set, ignoring any errors.
public static Object
deserialize(ResultSet rs, int index)
Convenience method for de-serializing an object from a JDBC source.
public static String
getClob(ResultSet rs, int index)
Get the value of a CLOB column as a string.
public static Reader
getClobReader(ResultSet rs, int index)
Get the value of a CLOB column as a reader.
public static Connection
getConnection(DataSource src, int maxRetries, long waitTime)
Get a connection from a DataSource with retry and timeout logic.
public static Connection
getConnection(DataSource src, int maxRetries)
Get a connection from a DataSource with retry logic.
public static double
getDouble(ResultSet rs, int index)
Retrieve a double value from the ResultSet at the given index.
public static double
getDouble(ResultSet rs, String colName)
Retrieve a double value from the ResultSet at the given column.
public static float
getFloat(ResultSet rs, int index)
Retrieve a float value from the ResultSet at the given index.
public static float
getFloat(ResultSet rs, String colName)
Retrieve a float value from the ResultSet at the given column.
public static int
getInt(ResultSet rs, int index)
Retrieve an int value from the ResultSet at the given index.
public static int
getInt(ResultSet rs, String colName)
Retrieve an int value from the ResultSet at the given column.
public static long
getLong(ResultSet rs, int index)
Retrieve a long value from the ResultSet at the given index.
public static long
getLong(ResultSet rs, String colName)
Retrieve a long value from the ResultSet at the given column.
public static boolean
isNoResourceException(SQLException ex)
Tell if a SQLException is telling that no resources/connections are available right now.
public static void
serialize(PreparedStatement ps, int index, Serializable obj)
Convenience method for serializing an object to a JDBC stream.
public static void
setClob(PreparedStatement stmt, int index, String str)
Set the value of a CLOB column with a string.
public static void
setClob(PreparedStatement stmt, int index, Reader in, int length)
Set the value of a CLOB column with an input reader.
public static boolean
supportsLikeEscapeClause(Connection con)
Determine if the given connection supports the LIKE ESCAPE clause.
 
Methods from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
   

Field Detail

shouldUseClobsForReads

public static final boolean shouldUseClobsForReads
Controls whether we should use the Clob object or the ResultSet.getString() method to retrieve CLOB columns.

This variable will initialized from the "commerce.jdbc.read.shouldUseClobs" property in weblogiccommerce.properties. Defaults to false


shouldUseClobsForWrites

public static final boolean shouldUseClobsForWrites
Controls whether we should use the setCharacterStream() or the ResultSet.setString() method to set CLOB columns.

This variable will initialized from the "commerce.jdbc.write.shouldUseClobs" property in weblogiccommerce.properties. Defaults to false


supportsLikeEscapeClause

public static final Boolean supportsLikeEscapeClause
Determine if the server configuration supports the LIKE ESCAPE clause.

This variable will initialized from the "commerce.jdbc.supportsLikeEscapeClause" property in weblogiccommerce.properties.

If this is null, then no configuration was specified and the JDBC connection should be queries. Otherwise, this will be true or false.

 

Constructor Detail

JdbcHelper

public JdbcHelper()
Helper constructor comment.
 

Method Detail

close(Connection) Method

DEPRECATED

public static void close(Connection con)
Close a connection, ignoring any errors.


close(Statement) Method

DEPRECATED

public static void close(Statement stmt)
Close a statement, ignoring any errors.


close(ResultSet) Method

DEPRECATED

public static void close(ResultSet rs)
Close a result set, ignoring any errors.


deserialize(ResultSet, int) Method

DEPRECATED

public static Object deserialize(ResultSet rs, 
                                 int index)
throws SQLException, IOException, StreamCorruptedException, ClassNotFoundException
Convenience method for de-serializing an object from a JDBC source. Note: This method may be able to use PipedOutputStream and PipedInputStream.

Parameters

rs
Result Set.
index
table column index.

Exceptions

SQLException
IOException
StreamCorruptedException
ClassNotFoundException

getClob(ResultSet, int) Method

DEPRECATED

public static String getClob(ResultSet rs, 
                             int index)
throws SQLException
Get the value of a CLOB column as a string.

This is controlled by the value of JdbcHelper.shouldUseClobsForReads.

Parameters

rs
the result set.
index
the column index in the result set.

Returns

the column as a string.

Exceptions

SQLException
thrown on an error.

getClobReader(ResultSet, int) Method

DEPRECATED

public static Reader getClobReader(ResultSet rs, 
                                   int index)
throws SQLException
Get the value of a CLOB column as a reader.

This is controlled by the value of JdbcHelper.shouldUseClobsForReads.

Parameters

rs
the result set.
index
the column index in the result set.

Returns

the column as a reader, null on null.

Exceptions

SQLException
thrown on an error.

getConnection(DataSource, int, long) Method

DEPRECATED

public static Connection getConnection(DataSource src, 
                                       int maxRetries, 
                                       long waitTime)
throws SQLException
Get a connection from a DataSource with retry and timeout logic.

This will retry upto maxRetries. Additionally, it will only retry for waitTime number of milliseconds (as best as possible -- it might be longer, but will not be less).

This will always try at least once to get a connection. Use maxRetries=0 for only a single attempt.

This works with both transactional and non-transaction DataSources tied to WLS connection pools. In WLS, transactional DataSources always internally wait 5 seconds for a new connection; non-transaction DataSources don't wait at all.

Parameters

src
the data source.
maxRetries
the maximum number of times to retry (less than 0 for infinite).
waitTime
the maximum number of milliseconds to try (less than 0 for infinite).

Returns

a connection from the data source on success.

Exceptions

SQLException
thrown on an error getting a connection.

Related Topics

JdbcHelper.isNoResourceException(SQLException)


getConnection(DataSource, int) Method

DEPRECATED

public static Connection getConnection(DataSource src, 
                                       int maxRetries)
throws SQLException
Get a connection from a DataSource with retry logic.

Parameters

src
the data source.
maxRetries
the maximum number of times to retry (less than 0 for infinite).

Returns

a connection from the data source on success.

Exceptions

SQLException
thrown on an error getting a connection.

getDouble(ResultSet, int) Method

DEPRECATED

public static double getDouble(ResultSet rs, 
                               int index)
throws SQLException
Retrieve a double value from the ResultSet at the given index.

This will validate if the underlying column was null.

Parameters

rs
the result set.
index
the column index.

Returns

the column value (0 for null column).

Exceptions

SQLException
from retrieving the column.

getDouble(ResultSet, String) Method

DEPRECATED

public static double getDouble(ResultSet rs, 
                               String colName)
throws SQLException
Retrieve a double value from the ResultSet at the given column.

This will validate if the underlying column was null.

Parameters

rs
the result set.
colName
the column name.

Returns

the column value (0 for null column).

Exceptions

SQLException
from retrieving the column.

getFloat(ResultSet, int) Method

DEPRECATED

public static float getFloat(ResultSet rs, 
                             int index)
throws SQLException
Retrieve a float value from the ResultSet at the given index.

This will validate if the underlying column was null.

Parameters

rs
the result set.
index
the column index.

Returns

the column value (0 for null column).

Exceptions

SQLException
from retrieving the column.

getFloat(ResultSet, String) Method

DEPRECATED

public static float getFloat(ResultSet rs, 
                             String colName)
throws SQLException
Retrieve a float value from the ResultSet at the given column.

This will validate if the underlying column was null.

Parameters

rs
the result set.
colName
the column name.

Returns

the column value (0 for null column).

Exceptions

SQLException
from retrieving the column.

getInt(ResultSet, int) Method

DEPRECATED

public static int getInt(ResultSet rs, 
                         int index)
throws SQLException
Retrieve an int value from the ResultSet at the given index.

This will validate if the underlying column was null.

Parameters

rs
the result set.
index
the column index.

Returns

the column value (0 for null column).

Exceptions

SQLException
from retrieving the column.

getInt(ResultSet, String) Method

DEPRECATED

public static int getInt(ResultSet rs, 
                         String colName)
throws SQLException
Retrieve an int value from the ResultSet at the given column.

This will validate if the underlying column was null.

Parameters

rs
the result set.
colName
the column name.

Returns

the column value (0 for null column).

Exceptions

SQLException
from retrieving the column.

getLong(ResultSet, int) Method

DEPRECATED

public static long getLong(ResultSet rs, 
                           int index)
throws SQLException
Retrieve a long value from the ResultSet at the given index.

This will validate if the underlying column was null.

Parameters

rs
the result set.
index
the column index.

Returns

the column value (0 for null column).

Exceptions

SQLException
from retrieving the column.

getLong(ResultSet, String) Method

DEPRECATED

public static long getLong(ResultSet rs, 
                           String colName)
throws SQLException
Retrieve a long value from the ResultSet at the given column.

This will validate if the underlying column was null.

Parameters

rs
the result set.
colName
the column name.

Returns

the column value (0 for null column).

Exceptions

SQLException
from retrieving the column.

isNoResourceException(SQLException) Method

DEPRECATED

public static boolean isNoResourceException(SQLException ex)
Tell if a SQLException is telling that no resources/connections are available right now.

When WLS doesn't have an available connection for a DataSource (either TX or non-TX), it will throw a SQLException with a message following this regular expression: "ResourceException.+[Nn]o.+available". That seems to the only way to tell if a connection wasn't availble from the underlying pool.


serialize(PreparedStatement, int, Serializable) Method

DEPRECATED

public static void serialize(PreparedStatement ps, 
                             int index, 
                             Serializable obj)
throws SQLException, IOException
Convenience method for serializing an object to a JDBC stream. Serializes the object and calls setBinaryStream() on the prepared statement. The data will be written out later when the statment is executed. Note: getBinaryStream() requires the size of the data bytes, so cannot use PipeInputStream, PipeOutputStream

Parameters

ps
PreparedStatement.
index
placeholder index of the serialized object.
obj
Object to be serialized.

Exceptions

SQLException
IOException

setClob(PreparedStatement, int, String) Method

DEPRECATED

public static void setClob(PreparedStatement stmt, 
                           int index, 
                           String str)
throws SQLException
Set the value of a CLOB column with a string.

This is controlled by the value of JdbcHelper.shouldUseClobsForWrites.

Parameters

stmt
the prepared statement.
index
the column index.
str
the CLOB string.

Exceptions

SQLException
thrown on an error.

setClob(PreparedStatement, int, Reader, int) Method

DEPRECATED

public static void setClob(PreparedStatement stmt, 
                           int index, 
                           Reader in, 
                           int length)
throws SQLException
Set the value of a CLOB column with an input reader.

This is controlled by the value of JdbcHelper.shouldUseClobsForWrites.

Parameters

stmt
the prepared statement.
index
the column index.
in
the CLOB input reader.

Exceptions

SQLException
thrown on an error.

supportsLikeEscapeClause(Connection) Method

DEPRECATED

public static boolean supportsLikeEscapeClause(Connection con)
Determine if the given connection supports the LIKE ESCAPE clause.

This first checks the JdbcHelper.supportsLikeEscapeClause varaible. It then checks with the Connection DatabaseMetaData.