net.sourceforge.orbroker
Class Executable

java.lang.Object
  extended bynet.sourceforge.orbroker.BrokerConnection
      extended bynet.sourceforge.orbroker.QueryableConnection
          extended bynet.sourceforge.orbroker.ExecutableConnection
              extended bynet.sourceforge.orbroker.Executable

public final class Executable
extends net.sourceforge.orbroker.ExecutableConnection

An Executable allows queries and execution of statements on an existing connection. It is up to the Connection supplier to manage all transactional properties, if any. This should generally only be used for container managed transactions and similar type external transaction management.

An Executable can also be passed to other methods that needs to take part in a transaction, but without exposing the commit and rollback capabilities of the Transaction object.

Author:
Nils Kilden-Pedersen
See Also:
Broker.obtainExecutable(Connection), Transaction.obtainExecutable()

Method Summary
 void addStatement(String id, String sql)
          Add temporary statement.
 void addStatement(String id, String sql, String resultObjectId)
          Add temporary statement.
 void closeIterator(Iterator iterator)
          Close iterator.
 int execute(String statementID)
          Execute statement.
 int executeBatch(String statementID, String batchParameterName, Collection batchParameters)
          Execute a collection of parameters as a batch.
 int[] executeBatch(String statementID, String batchParameterName, Object[] batchParameters)
          Execute an array of parameters as a batch.
 Object getParameter(String name)
          Get parameter.
 Iterator iterate(String statementID, int fetchSize)
          Return a live iterator.
 void releaseSavepoint(Savepoint savepoint)
          Release savepoint.
 void rollback(Savepoint savepoint)
          Roll back to savepoint.
 List selectMany(String statementID)
          Return a list of 0..n objects.
 int selectMany(String statementID, Collection resultCollection)
          Fill Collection with 0..n objects.
 int selectMany(String statementID, Collection resultCollection, int startRow, int rowCount)
          Fill Collection with 0..n objects.
 List selectMany(String statementID, int startRow, int rowCount)
          Return a list of 0..n objects.
 Object selectOne(String statementID)
          Return a single result object.
 boolean selectOne(String statementID, Object resultObject)
          Use supplied result object to apply values to.
 Object selectOneFromMany(String statementID, int fromRow)
          Return one result object from a query containing many.
 void setParameter(String name, Object value)
          Set named parameter.
 Savepoint setSavepoint()
          Set savepoint.
 Savepoint setSavepoint(String name)
          Set named savepoint.
 void setTextReplacement(String key, String value)
          Set a text replacement value.
 void setTextReplacements(Properties textReplacements)
          Set text replacement values.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

execute

public int execute(String statementID)
            throws BrokerException,
                   ConstraintException,
                   DeadlockException
Execute statement. This is used for statements such as

Parameters:
statementID - Statement id
Returns:
number of records affected.
Throws:
BrokerException
ConstraintException
DeadlockException

executeBatch

public int executeBatch(String statementID,
                        String batchParameterName,
                        Collection batchParameters)
                 throws BrokerException,
                        ConstraintException,
                        DeadlockException
Execute a collection of parameters as a batch.

Parameters:
statementID - Statement id
batchParameterName - The parameter name that will be repeated
batchParameters - The collection of batch parameter objects
Returns:
Total records affected, or a negative number if unknown
Throws:
BrokerException
ConstraintException
DeadlockException

executeBatch

public int[] executeBatch(String statementID,
                          String batchParameterName,
                          Object[] batchParameters)
                   throws BrokerException,
                          ConstraintException,
                          DeadlockException
Execute an array of parameters as a batch.

Parameters:
statementID - Statement id
batchParameterName - The parameter name that will be repeated
batchParameters - The array of batch objects
Returns:
Total records affected per parameter, or a negative number if unknown
Throws:
BrokerException
ConstraintException
DeadlockException

releaseSavepoint

public void releaseSavepoint(Savepoint savepoint)
Release savepoint.

Parameters:
savepoint - Savepoint
See Also:
Connection.releaseSavepoint(java.sql.Savepoint)

rollback

public void rollback(Savepoint savepoint)
Roll back to savepoint.

Parameters:
savepoint - Savepoint
See Also:
Connection.rollback(java.sql.Savepoint)

setSavepoint

public Savepoint setSavepoint()
Set savepoint.

Returns:
savepoint
See Also:
Connection.setSavepoint()

setSavepoint

public Savepoint setSavepoint(String name)
Set named savepoint.

Parameters:
name - Savepoint name
Returns:
savepoint
See Also:
Connection.setSavepoint(String)

selectMany

public final List selectMany(String statementID)
                      throws BrokerException
Return a list of 0..n objects. An empty List will be returned if result set is empty.

Parameters:
statementID - Statement id
Returns:
List of result objects
Throws:
BrokerException

selectMany

public final int selectMany(String statementID,
                            Collection resultCollection)
                     throws BrokerException
Fill Collection with 0..n objects. The supplied Collection does not have to be empty. Objects are added to Collection.

Parameters:
statementID - Statement id
resultCollection - The collection where the result will be added.
Returns:
Number of objects added to collection.
Throws:
BrokerException

iterate

public Iterator iterate(String statementID,
                        int fetchSize)
Return a live iterator. Very useful for large rows that, for memory concerns, need to be built a few at a time, controlled by the fetch size. The Iterator must be iterated with the source object active, i.e. a Query or Transaction must be open.

Parameters:
statementID - Statement id
fetchSize - Row buffer size
Returns:
Streamed Iterator of result objects.

closeIterator

public final void closeIterator(Iterator iterator)
Close iterator. Use this to close a live iterator returned by QueryableConnection.iterate(String, int). Only necessary if iterator has not been exhausted by hasNext() returning false

Parameters:
iterator - The not fully iterated iterator.
See Also:
QueryableConnection.iterate(String, int)

selectMany

public final int selectMany(String statementID,
                            Collection resultCollection,
                            int startRow,
                            int rowCount)
                     throws BrokerException
Fill Collection with 0..n objects. The supplied Collection does not have to be empty. Objects are added to Collection.

Parameters:
statementID - Statement id
resultCollection - The collection where the result will be added.
startRow - The start row to return. First row is 1.
rowCount - The number of rows to return
Returns:
Number of objects added to collection.
Throws:
BrokerException

selectMany

public final List selectMany(String statementID,
                             int startRow,
                             int rowCount)
                      throws BrokerException
Return a list of 0..n objects. An empty List will be returned if result set is empty or if startRow is greater than the result set size.

Parameters:
statementID - Statement id
startRow - The start row to return. First row is 1.
rowCount - The number of rows to return
Returns:
List of result objects
Throws:
BrokerException

selectOne

public final Object selectOne(String statementID)
                       throws BrokerException,
                              MoreThanOneRowException
Return a single result object.

Parameters:
statementID - Statement id
Returns:
the result object, or null if query returned 0 records.
Throws:
BrokerException
MoreThanOneRowException

selectOne

public final boolean selectOne(String statementID,
                               Object resultObject)
                        throws BrokerException,
                               MoreThanOneRowException
Use supplied result object to apply values to. Any constructor or factory method defined for mapping will be ignored.

Parameters:
statementID - Statement id
resultObject - result object to map to
Returns:
false if query didn't return a record.
Throws:
BrokerException
MoreThanOneRowException

selectOneFromMany

public Object selectOneFromMany(String statementID,
                                int fromRow)
                         throws BrokerException
Return one result object from a query containing many. Returns null if query is empty or returnRow is out of range.

Parameters:
statementID - Statement id
fromRow - Row to return. First row is 1.
Returns:
result object from row
Throws:
BrokerException

addStatement

public final void addStatement(String id,
                               String sql)
                        throws BrokerException,
                               ConfigurationException
Add temporary statement.

Parameters:
id - The statement id.
sql - The SQL statement
Throws:
BrokerException
ConfigurationException

addStatement

public final void addStatement(String id,
                               String sql,
                               String resultObjectId)
                        throws BrokerException,
                               ConfigurationException
Add temporary statement.

Parameters:
id - The statement id.
sql - The SQL statement
resultObjectId - The result-object id as defined in the XML configuration file.
Throws:
BrokerException
ConfigurationException

getParameter

public final Object getParameter(String name)
Get parameter. Used to retrieve OUT/INOUT parameters from stored procedures. Both input and output parameters are stored in the same context, so any parameter set using BrokerConnection.setParameter(String, Object) will be available with this method. Also if a stored procedure has an output parameter that needs to be used as input in another SQL statements, it's immediately available, i.e. there's no need to code like this: txn.setParameter("parm", txn.getParameter("parm"));

Parameters:
name - parameter name
Returns:
parameter value

setParameter

public final void setParameter(String name,
                               Object value)
Set named parameter.

Parameters:
name - parameter name
value - parameter value

setTextReplacement

public final void setTextReplacement(String key,
                                     String value)
Set a text replacement value. This will replace a {{key}} string with the value. This will override any value set on Broker.

Parameters:
key - Text replacement key
value - Text replacement value
See Also:
BrokerConnection.setTextReplacements(Properties)

setTextReplacements

public final void setTextReplacements(Properties textReplacements)
Set text replacement values. This will replace all {{key}} type properties in an sql-statement with the values. This will override any value set on Broker.

Parameters:
textReplacements - The replacement values to set.
See Also:
BrokerConnection.setTextReplacement(String, String)