© 2005 BEA Systems, Inc.

com.bea.p13n.util.jdbc
Interface Database

All Known Implementing Classes:
GenericDatabase

public interface Database

Provides various BLOB and CLOB handling methods, as well as validity-checking for database drivers. Sub-classed by GenericDatabase.

See Also:
GenericDatabase

Method Summary
 boolean accept(Connection connection)
          Check to see if the Database can bind to the supplied connection.
 void close()
          Close the Connection associated with this Database.
 void close(InputStream is)
          Closes an InputStream.
 void close(OutputStream os)
          Closes an OutputStream.
 void close(PreparedStatement ps)
          Closes a PreparedStatement.
 void close(Reader reader)
          Closes a Reader stream.
 void close(ResultSet rs)
          Closes a ResultSet.
 void close(ResultSet rs, Statement stmt)
          Closes a ResultSet and its associated Statement.
 void close(Statement stmt)
          Closes a Statement.
 void close(Writer writer)
          Closes a Writer stream.
 boolean commitConnection(Connection connection)
           
 void endBlob()
          Call Connection.commit().
 void endClob()
          Call Connection.commit().
 String getApplicationName()
          Get the name of the current WebLogic J2EE application or return null if not running within a WebLogic J2EE context.
 byte[] getBlob(ResultSet rs, int index)
          Get the value of a Blob column as an InputStream.
 OutputStream getBlobLocator(Connection con, String tableName, String blobColumnName, String whereClause)
           
 String getClob(ResultSet rs, int index)
          Get the value of a CLOB column as a string.
 Clob getClobLocator(Connection con, String tableName, String clobColumnName, String whereClause)
           
 Connection getConnection()
          Return Connection for the current Database instance.
 String getEmptyBlobInitializer()
           
 String getEmptyClobInitializer()
           
 String getName()
          Gets the name of the database instance.
 String readFromClob(Clob clob)
          Reads the contents of a Clob and returns as a String.
 boolean setClob(PreparedStatement stmt, int index, Clob clob, String str)
          If there is a delegate, this method uses JdbcHelperDelegate.writeClobData() If this is done, then the PreparedStatement does not need to be used and the return value, executeRequired, is false.
 void setClob(PreparedStatement stmt, int index, String str)
          Set the value of a CLOB column with a string.
 void startBlob()
          setAutoCommit( false ) on the Connection.
 void startClob()
          setAutoCommit( false ) on the Connection.
 void writeToClob(Clob clob, String data)
          Writes the data from a String into a Clob.
 

Method Detail

accept

public boolean accept(Connection connection)
Check to see if the Database can bind to the supplied connection.

Parameters:
connection - The Connection object that contains the URL.
Returns:
Returns boolean after checking if this Database can bind to the supplied connection. Typically the Database will examine the Connection MetaData to determine suitability.

close

public void close()
Close the Connection associated with this Database.


close

public void close(InputStream is)
Closes an InputStream.

Parameters:
is - The InputStream object to be closed.

close

public void close(OutputStream os)
Closes an OutputStream.

Parameters:
os - The OutputStream object to be closed.

close

public void close(PreparedStatement ps)
Closes a PreparedStatement.

Parameters:
ps - The PreparedStatement object to be closed.

close

public void close(Reader reader)
Closes a Reader stream.

Parameters:
reader - The Reader object to be closed.

close

public void close(ResultSet rs)
Closes a ResultSet.

Parameters:
rs - The ResultSet object to be closed.

close

public void close(ResultSet rs,
                  Statement stmt)
Closes a ResultSet and its associated Statement.

Parameters:
rs - The ResultSet object to be closed.
stmt - The Statement object to be closed.

close

public void close(Statement stmt)
Closes a Statement.

Parameters:
stmt - The Statement object to be closed.

close

public void close(Writer writer)
Closes a Writer stream.

Parameters:
writer - The Writer object to be closed.

commitConnection

public boolean commitConnection(Connection connection)
                         throws SQLException
Throws:
SQLException

endBlob

public void endBlob()
             throws SQLException
Call Connection.commit().

Throws:
SQLException - Thrown when error occurs while persisting Blob.

endClob

public void endClob()
             throws SQLException
Call Connection.commit().

Throws:
SQLException - Thrown when error occurs while persisting Clob.

getApplicationName

public String getApplicationName()
Get the name of the current WebLogic J2EE application or return null if not running within a WebLogic J2EE context.

Returns:
The name of the current WebLogic J2EE application.

getBlob

public byte[] getBlob(ResultSet rs,
                      int index)
               throws SQLException
Get the value of a Blob column as an InputStream.

This method will only return the value of the Blob in the current row of the ResultSet. This method does not increment the ResultSet cursor. You must use ResultSet.next() to increment the cursor before calling this method. This allows the method to be used to process multi-row ResultSets.

Parameters:
rs - The result set.
index - The column index in the ResultSet.
Returns:
An InputStream representing the column Blob.
Throws:
SQLException - thrown on an error.

getBlobLocator

public OutputStream getBlobLocator(Connection con,
                                   String tableName,
                                   String blobColumnName,
                                   String whereClause)
                            throws SQLException
Throws:
SQLException

getClob

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

This method will only return the value of the CLOB in the current row of the ResultSet. This method does not increment the ResultSet cursor. You must use ResultSet.next() to increment the cursor before calling this method. This allows the method to be used to process multi-row ResultSets.

If no JdbcHelperDelegate is specified in the console (configured via JdbcHelperMBean) then this method will return a string obtained using the default method that was used before a delegate model was implemented for this class. That method uses Clob.getCharacterStream() to construct a BufferedReader that is read in with the readLine() method.

Parameters:
rs - the result set.
index - the column index in the result set.
Returns:
the column as a string.
Throws:
SQLException - thrown on an error.

getClobLocator

public Clob getClobLocator(Connection con,
                           String tableName,
                           String clobColumnName,
                           String whereClause)
                    throws SQLException
Throws:
SQLException

getConnection

public Connection getConnection()
Return Connection for the current Database instance.

Returns:
The Connection of the current Database instance.

getEmptyBlobInitializer

public String getEmptyBlobInitializer()
                               throws SQLException
Throws:
SQLException

getEmptyClobInitializer

public String getEmptyClobInitializer()
                               throws SQLException
Throws:
SQLException

getName

public String getName()
Gets the name of the database instance.

Returns:
The name of the database instance.

readFromClob

public String readFromClob(Clob clob)
                    throws SQLException
Reads the contents of a Clob and returns as a String.

Throws:
SQLException - Thrown when error occurs while reading Clob.

setClob

public boolean setClob(PreparedStatement stmt,
                       int index,
                       Clob clob,
                       String str)
                throws SQLException
If there is a delegate, this method uses JdbcHelperDelegate.writeClobData() If this is done, then the PreparedStatement does not need to be used and the return value, executeRequired, is false. The CLOB should be first located with getClobLocator() If there is no delegate, then this method ignores the Clob argument and sets the value of the String into the CLOB placeholder in the PreparedStatement with setClob(PreparedStatement stmt, int index, String str) and returns executeRequired = true.

WARNING: if using a delegate to stream data to a CLOB, then you should have used Connection.setAutoCommit(false) before calling the CLOB locator method that provided the Clob you are using in this method call. This will make the CLOB available across multiple SQL statements.

Parameters:
stmt - the prepared statement.
index - the column index.
clob - the CLOB locator (ignored if no delegate).
str - the String to be set in the CLOB (if delegate) or in the PreparedStatement (if no delegate)
Returns:
boolean executeRequired. If false then a delegate was used to directly set the CLOB in the database without using the PreparedStatement. If true then no delegate was used, or the delegate set the Clob value on the statement and the PreparedStatement must be executed to update the database.
Throws:
SQLException - thrown on an error.

setClob

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

Parameters:
stmt - the prepared statement.
index - the column index.
str - the CLOB string.
Throws:
SQLException - thrown on an error.

startBlob

public void startBlob()
               throws SQLException
setAutoCommit( false ) on the Connection.

Throws:
SQLException - Thrown when trying to set auto-commit to false.

startClob

public void startClob()
               throws SQLException
setAutoCommit( false ) on the Connection.

Throws:
SQLException - Thrown when trying to set auto-commit to false.

writeToClob

public void writeToClob(Clob clob,
                        String data)
                 throws SQLException
Writes the data from a String into a Clob.

Throws:
SQLException - Thrown when error occurs while writing to Clob.

© 2005 BEA Systems, Inc.

Copyright © 2005 BEA Systems, Inc. All Rights Reserved