|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.orbroker.BrokerConnection
net.sourceforge.orbroker.QueryableConnection
net.sourceforge.orbroker.ExecutableConnection
net.sourceforge.orbroker.Transaction
Any database modifications (INSERT, UPDATE, DELETE) must be done through
the Transaction object. It wraps a Connection
object, and like a Query
instance, close()
must be called after
use (in a finally
block), to avoid connection pool leaks.
A transaction using an isolation level of
Connection.TRANSACTION_NONE
is considered non-transactional and will have auto-commit enabled. This makes
it illegal to call either commit()
or rollback()
. All other isolation
levels require a call to commit()
method for the transaction to commit.
Broker.startTransaction()
,
Broker.startTransaction(int)
Method Summary | |
void |
addStatement(String id,
String sql)
Add temporary statement. |
void |
addStatement(String id,
String sql,
String resultObjectId)
Add temporary statement. |
void |
close()
Close transaction. |
void |
closeIterator(Iterator iterator)
Close iterator. |
void |
commit()
Commit the transaction. |
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. |
Executable |
obtainExecutable()
Obtain an Executable that uses this Transaction's connection. |
void |
releaseSavepoint(Savepoint savepoint)
Release savepoint. |
void |
rollback()
Roll back the transaction. |
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 |
public void close()
Transaction txn = broker.startTransaction(); try { txn.setParameter("account", account); txn.execute("updateAccount"); txn.commit(); ] finally { txn.close(); }There is no need to issue a rollback. If commit() is not called due to an exception, rollback is done automatically. This is assuming that the transaction is in isolation level other than
Connection.TRANSACTION_NONE
.
public void commit() throws BrokerException, ConstraintException, DeadlockException
This method cannot be called if isolation level
is Connection.TRANSACTION_NONE
.
BrokerException
ConstraintException
DeadlockException
rollback()
public Executable obtainExecutable()
close()
,
Broker.obtainExecutable(Connection)
public void rollback() throws BrokerException
close()
(provided that close()
method is called in a
finally
block as it always should).
This method cannot be called if isolation level
is Connection.TRANSACTION_NONE
.
BrokerException
commit()
public int execute(String statementID) throws BrokerException, ConstraintException, DeadlockException
statementID
- Statement id
BrokerException
ConstraintException
DeadlockException
public int executeBatch(String statementID, String batchParameterName, Collection batchParameters) throws BrokerException, ConstraintException, DeadlockException
statementID
- Statement idbatchParameterName
- The parameter name that will be repeatedbatchParameters
- The collection of batch parameter objects
BrokerException
ConstraintException
DeadlockException
public int[] executeBatch(String statementID, String batchParameterName, Object[] batchParameters) throws BrokerException, ConstraintException, DeadlockException
statementID
- Statement idbatchParameterName
- The parameter name that will be repeatedbatchParameters
- The array of batch objects
BrokerException
ConstraintException
DeadlockException
public void releaseSavepoint(Savepoint savepoint)
savepoint
- SavepointConnection.releaseSavepoint(java.sql.Savepoint)
public void rollback(Savepoint savepoint)
savepoint
- SavepointConnection.rollback(java.sql.Savepoint)
public Savepoint setSavepoint()
Connection.setSavepoint()
public Savepoint setSavepoint(String name)
name
- Savepoint name
Connection.setSavepoint(String)
public final List selectMany(String statementID) throws BrokerException
List
will be returned if
result set is empty.
statementID
- Statement id
BrokerException
public final int selectMany(String statementID, Collection resultCollection) throws BrokerException
statementID
- Statement idresultCollection
- The collection where the result will be added.
BrokerException
public Iterator iterate(String statementID, int fetchSize)
Query
or Transaction
must be open.
statementID
- Statement idfetchSize
- Row buffer size
Iterator
of result objects.public final void closeIterator(Iterator iterator)
QueryableConnection.iterate(String, int)
. Only necessary if iterator has
not been exhausted by hasNext()
returning false
iterator
- The not fully iterated iterator.QueryableConnection.iterate(String, int)
public final int selectMany(String statementID, Collection resultCollection, int startRow, int rowCount) throws BrokerException
statementID
- Statement idresultCollection
- 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
BrokerException
public final List selectMany(String statementID, int startRow, int rowCount) throws BrokerException
List
will be returned if
result set is empty or if startRow
is greater than
the result set size.
statementID
- Statement idstartRow
- The start row to return. First row is 1.rowCount
- The number of rows to return
BrokerException
public final Object selectOne(String statementID) throws BrokerException, MoreThanOneRowException
statementID
- Statement id
null
if query returned 0
records.
BrokerException
MoreThanOneRowException
public final boolean selectOne(String statementID, Object resultObject) throws BrokerException, MoreThanOneRowException
statementID
- Statement idresultObject
- result object to map to
false
if query didn't return a record.
BrokerException
MoreThanOneRowException
public Object selectOneFromMany(String statementID, int fromRow) throws BrokerException
null
if query is empty or returnRow is out of range.
statementID
- Statement idfromRow
- Row to return. First row is 1.
BrokerException
public final void addStatement(String id, String sql) throws BrokerException, ConfigurationException
id
- The statement id.sql
- The SQL statement
BrokerException
ConfigurationException
public final void addStatement(String id, String sql, String resultObjectId) throws BrokerException, ConfigurationException
id
- The statement id.sql
- The SQL statementresultObjectId
- The result-object
id as
defined in the XML configuration file.
BrokerException
ConfigurationException
public final Object getParameter(String name)
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"));
name
- parameter name
public final void setParameter(String name, Object value)
name
- parameter namevalue
- parameter valuepublic final void setTextReplacement(String key, String value)
{{key}}
string with the value.
This will override any value set on Broker.
key
- Text replacement keyvalue
- Text replacement valueBrokerConnection.setTextReplacements(Properties)
public final void setTextReplacements(Properties textReplacements)
{{key}}
type properties in an sql-statement with the values.
This will override any value set on Broker.
textReplacements
- The replacement values to set.BrokerConnection.setTextReplacement(String, String)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |