Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1)

E13403-03

oracle.javatools.db.execute
Class StatementWrapper

java.lang.Object
  extended by oracle.javatools.db.execute.StatementWrapper
Direct Known Subclasses:
QueryWrapper

public class StatementWrapper
extends java.lang.Object

Wrapper for executing statements against a database. It provides:

Example usage:
   final Database db = ...
   final String stmt = ...
   final StatementWrapper wrap = new StatementWrapper( db, stmt );
   boolean success = false;
   try
   {
     success = wrap.execute();
   }
   catch( DBException dbe )
   {
     // process exception
   }
 

Since:
11

Nested Class Summary
static class StatementWrapper.ExecutionProxy
          Allows a proxy to be registered against all queries to wrap the execution of any sql against the database.
 class StatementWrapper.ExecutionRunnable<T>
          Runnable implementation that wraps the execution of a statement or query.
static interface StatementWrapper.Listener
          Listner interface to be implemented by anything interested in knowing when the API is talking to a database.
 
Constructor Summary
StatementWrapper(Database db, java.lang.String... statements)
           
StatementWrapper(java.lang.String connName, java.sql.Connection connection, java.lang.String... statements)
           
 
Method Summary
static void addListener(StatementWrapper.Listener l)
          Adds a query listener to be notified whenever the db is queried.
 void close()
          Closes the statement and result set if we got that far.
protected  java.sql.Statement createStatment()
          Creates the Statement object to use.
protected
<T> T
doExecute(StatementWrapper.ExecutionRunnable<T> r)
           
 boolean execute()
          Executes the statment against the database.
protected  boolean executeImpl(java.lang.String stmt)
           
protected  java.sql.Connection getConnection()
           
protected  java.lang.String getConnectionName()
           
protected  Database getDatabase()
          Returns the Database that this wrapper is executing on.
static StatementWrapper.ExecutionProxy getExecutionProxy()
          Gets the execution proxy for statement execution (if one is set).
 java.lang.String getIdentifier()
          Gets the identifier for this statement wrapper.
protected  java.sql.Statement getStatement()
          Gets the Statement object for this wrapper.
protected  java.lang.String[] getStatementStrings()
          Returns all the statement strings to be executed.
protected  java.lang.String getStatementTextForLog()
          For logging and exception handling.
protected  boolean hasCancelled(java.sql.SQLException sqe)
           
protected  boolean isIgnoreErrors()
           
protected  void queryFinished()
           
protected  void queryStarted()
           
static boolean removeListener(StatementWrapper.Listener l)
          Removes a query listener.
 void setBypassExecutionProxy(boolean doNotThread)
          Explicitly disables the threading of this query using an execution proxy.
protected  void setDatabase(Database db)
          Sets the wrappers database.
protected  void setExecuting(boolean executing)
          Indicates that this wrapper is in the process of executing.
static void setExecutionProxy(StatementWrapper.ExecutionProxy ep)
          Sets the execution proxy for all queries in the API.
 void setIdentifier(java.lang.String i)
          Sets the identifier for this query wrapper.
 void setIgnoreErrors(boolean ignore)
           
 void setStatement(java.lang.String... statements)
          Only works after construction for simple statements, not queries (i.e.
protected  void sqlTrace(java.lang.String dbName, java.lang.String query, java.lang.Object... params)
          Sets up the query log which will be output when the query has finished (complete with timing information).
 void throwDBException(DBObject obj, java.sql.SQLException sqe)
          If a SQLException is caught during the processing of this query, or its Difference then it can be wrapped in a DBException which can then be displayed to the user.
protected  void throwDBException(DBObject obj, java.lang.String text, java.sql.SQLException sqe)
           
 void throwDBException(java.sql.SQLException sqe)
          If a SQLException is caught during the processing of this query, or its Difference then it can be wrapped in a DBException which can then be displayed to the user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StatementWrapper

public StatementWrapper(java.lang.String connName,
                        java.sql.Connection connection,
                        java.lang.String... statements)

StatementWrapper

public StatementWrapper(Database db,
                        java.lang.String... statements)
Method Detail

setStatement

public void setStatement(java.lang.String... statements)
Only works after construction for simple statements, not queries (i.e. prepared statements).


getStatementStrings

protected final java.lang.String[] getStatementStrings()
Returns all the statement strings to be executed.


getStatementTextForLog

protected java.lang.String getStatementTextForLog()
For logging and exception handling. Returns the statement text by default, sublcasses should override as appropriate.


getStatement

protected final java.sql.Statement getStatement()
                                         throws java.sql.SQLException
Gets the Statement object for this wrapper. If required settings can be set on the Statement, but execute should happen through this wrapper to ensure proper logging.

Throws:
java.sql.SQLException

createStatment

protected java.sql.Statement createStatment()
                                     throws java.sql.SQLException
Creates the Statement object to use. By default this creates a simple Statement, subclasses can override to create a Prepared or Callable statement.

Throws:
java.sql.SQLException

setBypassExecutionProxy

public void setBypassExecutionProxy(boolean doNotThread)
Explicitly disables the threading of this query using an execution proxy. This is necessary for "state" queries (e.g. isAlive() ) that will lock if used on a thread.

Parameters:
doNotThread - don't use an execution proxy for this wrapper, even if one exists.

setExecuting

protected final void setExecuting(boolean executing)
Indicates that this wrapper is in the process of executing.


execute

public boolean execute()
                throws DBException
Executes the statment against the database. Returns true if the execution succeeded (i.e. java.sql.Statement.execute() returned true). If multiple statements are included, true is returned if any succeed. If an error occurs (SQLException) execution halts at that statement.

Throws:
DBException
See Also:
Statement.execute(java.lang.String)

executeImpl

protected boolean executeImpl(java.lang.String stmt)
                       throws java.sql.SQLException
Throws:
java.sql.SQLException

doExecute

protected final <T> T doExecute(StatementWrapper.ExecutionRunnable<T> r)
                     throws DBException
Throws:
DBException

close

public void close()
Closes the statement and result set if we got that far. Call in a finally{ ... } block. When finished the timing is traced for the query time.


getIdentifier

public final java.lang.String getIdentifier()
Gets the identifier for this statement wrapper. The identifier has nothing to do with the statement, it is used so that a passed wrapper can be seperately identified if necessary.


setIdentifier

public final void setIdentifier(java.lang.String i)
Sets the identifier for this query wrapper. The identifier has nothing to do with the statement, it is used so that a passed wrapper can be seperately identified if necessary.


getDatabase

protected final Database getDatabase()
Returns the Database that this wrapper is executing on.


setDatabase

protected final void setDatabase(Database db)
Sets the wrappers database. Should have been done in the constructor.


getConnectionName

protected final java.lang.String getConnectionName()

getConnection

protected final java.sql.Connection getConnection()

isIgnoreErrors

protected boolean isIgnoreErrors()

setIgnoreErrors

public void setIgnoreErrors(boolean ignore)

throwDBException

protected final void throwDBException(DBObject obj,
                                      java.lang.String text,
                                      java.sql.SQLException sqe)
                               throws DBException
Throws:
DBException

throwDBException

public final void throwDBException(java.sql.SQLException sqe)
                            throws DBException
If a SQLException is caught during the processing of this query, or its Difference then it can be wrapped in a DBException which can then be displayed to the user.

Throws:
DBException

throwDBException

public final void throwDBException(DBObject obj,
                                   java.sql.SQLException sqe)
                            throws DBException
If a SQLException is caught during the processing of this query, or its Difference then it can be wrapped in a DBException which can then be displayed to the user.

Throws:
DBException

hasCancelled

protected boolean hasCancelled(java.sql.SQLException sqe)

sqlTrace

protected final void sqlTrace(java.lang.String dbName,
                              java.lang.String query,
                              java.lang.Object... params)
Sets up the query log which will be output when the query has finished (complete with timing information).


queryStarted

protected final void queryStarted()

queryFinished

protected final void queryFinished()

addListener

public static final void addListener(StatementWrapper.Listener l)
Adds a query listener to be notified whenever the db is queried.


removeListener

public static final boolean removeListener(StatementWrapper.Listener l)
Removes a query listener.

See Also:
addListener(oracle.javatools.db.execute.StatementWrapper.Listener)

setExecutionProxy

public static void setExecutionProxy(StatementWrapper.ExecutionProxy ep)
Sets the execution proxy for all queries in the API.


getExecutionProxy

public static StatementWrapper.ExecutionProxy getExecutionProxy()
Gets the execution proxy for statement execution (if one is set).


Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1)

E13403-03

Copyright © 1997, 2009, Oracle. All rights reserved.