Interface DatabaseQueryActivity
-
public interface DatabaseQueryActivity
The query activity on which result and failure events are fired. This activity does not support transactions.Asynchronous Queries
The procedure to send asynchronous queries is:
- create the activity using the DatabaseQueryProvider.createActivity() 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
private void asyncRequest(String shortCode) { try { DatabaseQueryActivity queryActivity = dbProvider.createActivity(); 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) { aci.detach(getSbbLocalObject()); ResultSet rs = result.getResultSet(); // ... handle result ... } public void onDatabaseQueryFailure(DatabaseQueryFailureEvent failure, ActivityContextInterface aci) { aci.detach(getSbbLocalObject()); // ... handle failure ... }
- Author:
- OpenCloud
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
sendQuery(QueryInfo queryInfo)
Send the database query asynchronously.
-
-
-
Method Detail
-
sendQuery
void sendQuery(QueryInfo queryInfo) throws NoDataSourcesAvailableException
Send the database query asynchronously. The result will be fired as aDatabaseResultEvent
event on this activity. Failed queries will be fired as aDatabaseQueryFailureEvent
. The activity will end when the result event is fired and it cannot be used again.- 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
-
-