Interface DatabaseQueryTransactionalActivity
-
public interface DatabaseQueryTransactionalActivity
The query activity on which result and failure events are fired. This activity supports transactions. Transactions MUST be committed or rolled back, by callingcommit()
orrollback()
.Asynchronous Queries
The procedure to send transactional asynchronous queries is:
- create the activity using the DatabaseQueryProvider.createTransactionalActivity() method
- get an ActivityContextInterface object for the activity
- attach the SBB local object to the ACI
- create a QueryInfo object that contains a copy of the values to set as parameters on the statement
- send the query using the sendQuery(QueryInfo) method on the activity
- handle the result in an event handler for the
DatabaseResultEvent
event - handle failures in an event handler for the
DatabaseQueryFailureEvent
event - repeat steps 4-7 as needed
- call
commit()
orrollback()
private void asyncRequest(String shortCode) { try { DatabaseQueryTransactionalActivity queryActivity = dbProvider.createTransactionalActivity(); ActivityContextInterface dbAci = dbACIFactory.getActivityContextInterface(queryActivity); dbAci.attach(getSbbLocalObject()); queryActivity.sendQuery(new SelectLongCodeQueryInfo(shortCode)); } catch (StartActivityException e) { // ... handle exception ... } catch (NoDataSourcesAvailableException e) { // ... handle exception ... } } public void onDatabaseResult(DatabaseResultEvent result, ActivityContextInterface aci) { ResultSet rs = result.getResultSet(); // ... handle result ... } public void onDatabaseQueryFailure(DatabaseQueryFailureEvent failure, ActivityContextInterface aci) { aci.detach(getSbbLocalObject()); // ... handle failure ... } private void commit() { DatabaseQueryTransactionalActivity queryActivity = retrieveActivity(); if(queryActivity != null) { queryActivity.commit(); } }
- Since:
- 1.2
- Author:
- OpenCloud
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
commit()
Call commit on the connection in use by the transaction associated with this result.void
rollback()
Call rollback on the connection in use by the transaction associated with this result.void
sendQuery(QueryInfo queryInfo)
Send a query asynchronously.void
setTransactionIsolation(int level)
Set a transaction isolation level.
-
-
-
Method Detail
-
sendQuery
void sendQuery(QueryInfo queryInfo) throws NoDataSourcesAvailableException
Send a query asynchronously. The result will be fired as aDatabaseResultEvent
event on this activity. Failed queries will be fired as aDatabaseQueryFailureEvent
.- Parameters:
queryInfo
- a callback object to get the query string and set parameters for the SQL statement- Throws:
NoDataSourcesAvailableException
- if there are no configured data sources currently marked as available when trying to get a connection for the first query
-
commit
void commit()
Call commit on the connection in use by the transaction associated with this result. This will also close all resources associated with the connection. If the commit is successful, aDatabaseResultEvent
will be fired on this activity. Failed commits will be fired as aDatabaseQueryFailureEvent
.
-
rollback
void rollback()
Call rollback on the connection in use by the transaction associated with this result. This will also close all resources associated with the connection. If the rollback is successful, aDatabaseResultEvent
will be fired on this activity. Failed rollbacks will be fired as aDatabaseQueryFailureEvent
.
-
setTransactionIsolation
void setTransactionIsolation(int level)
Set a transaction isolation level. The given level will be passed toConnection.setTransactionIsolation(int)
when a connection is first retrieved for this transaction. The constants defined in the interfaceConnection
are the possible transaction isolation levels.- Parameters:
level
- one of the followingConnection
constants:Connection.TRANSACTION_READ_UNCOMMITTED
,Connection.TRANSACTION_READ_COMMITTED
,Connection.TRANSACTION_REPEATABLE_READ
, orConnection.TRANSACTION_SERIALIZABLE
. (Note thatConnection.TRANSACTION_NONE
cannot be used because it specifies that transactions are not supported.)
-
-