| 
Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference 11g Release 1 (11.1.1.4.0) E13403-05  | 
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectoracle.javatools.db.execute.ConnectionWrapper
public class ConnectionWrapper
Class to wrap a process that uses a Database connection and can execute that process while recovering from a closed connection (by reconnecting). This is automatically used by the StatementWrapper and QueryWrapper so does not need to be used in addition to them.
Example usage 1: Retrieving the user name for the Connection
 final Database db = ...
 try
 {
   final ConnectionWrapper wrapper =
     new ConnectionWrapper( db, "Query username from connection metadata" ); // description should be translated
   final String userName = wrapper.call(
     wrapper.new SQLCallable()
     {
       public String call() throws SQLException
       {
         return getConnection().getMetaData().getUserName();
       }
     } );
 }
 catch( SQLException sqe )
 {
   // process the exception
 }
  
 Example usage 2: Setting the autocommit flag on the connection
 
 final Database db = ...
 try
 {
   final ConnectionWrapper wrapper =
     new ConnectionWrapper( db, "Set the auto commit flag on the Connection" ); // description should be translated
   final String userName = wrapper.run(
     wrapper.new SQLRunnable()
     {
       public String run() throws SQLException
       {
         getConnection().setAutoCommit( true );
       }
     } );
 }
 catch( SQLException sqe )
 {
   // process the exception
 }
 
| Nested Class Summary | |
|---|---|
 class | 
ConnectionWrapper.SQLCallable<T>
Callable class that can throw a SQLException from its call method.  | 
 class | 
ConnectionWrapper.SQLRunnable
Runnable class that can throw a SQLException from its run method.  | 
| Constructor Summary | |
|---|---|
ConnectionWrapper(Database db,
                  java.lang.String desc)
Creates a ConnectionWrapper using the given Database.  | 
|
| Method Summary | ||
|---|---|---|
 | 
call(ConnectionWrapper.SQLCallable<T> c)
Calls the given SQLCallable.  | 
|
 void | 
run(ConnectionWrapper.SQLRunnable r)
Runs the given SQLRunnable.  | 
|
| Methods inherited from class java.lang.Object | 
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
public ConnectionWrapper(Database db,
                         java.lang.String desc)
db - the database to use the Connection fromdesc - a translatable description of the nature of the process being
 executed. This will be wrapped into any DBException thrown if the process
 fails to indicate to the user what failed.| Method Detail | 
|---|
public void run(ConnectionWrapper.SQLRunnable r)
         throws DBException
r - the runnable to run as a unit of work on the Connection
DBException - if an error with the database occurs
public <T> T call(ConnectionWrapper.SQLCallable<T> c)
       throws DBException
c - the callable to run as a unit of work on the Connection
DBException - if an error with the database occurs
  | 
Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference 11g Release 1 (11.1.1.4.0) E13403-05  | 
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||