Interface TransactionalExecutor


@PublicApi public interface TransactionalExecutor
Interface allowing the user to execute a callback with a Connection, in the context of a transaction.

Note that participation in an existing transaction i.e. requiresNew is merely a hint to the host application and not binding. Best effort will be attempted.

The following example will query an application's table using JDBC:

 
 final TransactionalExecutor transactionalExecutor = transactionalExecutorFactory
         .createExecutor()
         .readOnly()
         .newTransaction();

 final String summary = transactionalExecutor.execute(new ConnectionCallback<String>()
 {
     public String execute(final Connection connection)
     {
         try
         {
             final String schemaPrefix = transactionalExecutor.getSchemaName().map(s -> s + '.').getOrElse("");

             final PreparedStatement preparedStatement = connection.prepareStatement(""
                     + "select summary\n"
                     + "from " + schemaPrefix + "jiraissue\n"
                     + "order by id desc");

             final ResultSet resultSet = preparedStatement.executeQuery();

             return resultSet.next() ? resultSet.getString("summary") : "no issues";
         }
         catch (SQLException e)
         {
             throw new RuntimeException("oh noes!", e);
         }
     }
 });
 
 
Since:
3.0
See Also: