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 calling commit() or rollback().

    Asynchronous Queries

    The procedure to send transactional asynchronous queries is:

    1. create the activity using the DatabaseQueryProvider.createTransactionalActivity() method
    2. get an ActivityContextInterface object for the activity
    3. attach the SBB local object to the ACI
    4. create a QueryInfo object that contains a copy of the values to set as parameters on the statement
    5. send the query using the sendQuery(QueryInfo) method on the activity
    6. handle the result in an event handler for the DatabaseResultEvent event
    7. handle failures in an event handler for the DatabaseQueryFailureEvent event
    8. repeat steps 4-7 as needed
    9. call commit() or rollback()
    Example Asynchronous Query
         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

      • 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, a DatabaseResultEvent will be fired on this activity. Failed commits will be fired as a DatabaseQueryFailureEvent.

      • 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, a DatabaseResultEvent will be fired on this activity. Failed rollbacks will be fired as a DatabaseQueryFailureEvent.

      • setTransactionIsolation

        void setTransactionIsolation​(int level)
        Set a transaction isolation level. The given level will be passed to Connection.setTransactionIsolation(int) when a connection is first retrieved for this transaction. The constants defined in the interface Connection are the possible transaction isolation levels.

        Parameters:
        level - one of the following Connection constants: Connection.TRANSACTION_READ_UNCOMMITTED, Connection.TRANSACTION_READ_COMMITTED, Connection.TRANSACTION_REPEATABLE_READ, or Connection.TRANSACTION_SERIALIZABLE. (Note that Connection.TRANSACTION_NONE cannot be used because it specifies that transactions are not supported.)