Class DBAction

java.lang.Object
org.eclnt.ccee.db.DBAction
All Implemented Interfaces:
ICCEEConstants
Direct Known Subclasses:
DBIsolatedAction

public abstract class DBAction extends Object implements ICCEEConstants
Environment for executing (transactional) operations against database.

The typical way of calling is:
  new DBAction()
  {
      protected void run() throws Exception
      {
          ...your code...
      }
  };
 
By placing your code into the run method it is automatically embedded into corresponding database context management.

DBActions can be nested - i.e. within one DBAction.run()-processing you can invoke any other DBAction.run()-processing. All the code will be executed using the same connection to the database and being embedded in one transaction to the database.
  • Constructor Details

    • DBAction

      public DBAction()
      Opens up a DBAction within the standard context.
    • DBAction

      public DBAction(String contextName)
      Opens up a DBAction with a special context associated.
  • Method Details

    • noWarning

      public void noWarning()
      This method does... ...nothing! The only purpose is to suppress warnings that may be reported by your Java compiler - dependent on your compiler configuration.
      The following code may be marked with "The allocated object is never used":
       new DBAction()
       {
           protected void run() throws Exception
      { ... } };
      By appending "noWarning()" the compiler will not mark this code, because now it is used by the "noWarning()" method:
       new DBAction()
       {
           protected void run() throws Exception
      { ... } }.noWarning();
    • process

      protected final void process(String contextName)
    • run

      protected abstract void run() throws Exception
      Implementation of database operation. This is the method you need to override.
      Throws:
      Exception
    • addCommitRunnable

      protected final void addCommitRunnable(Runnable r)
      Allows to add an action that is executed as part of the commit processing. The execution is only performed on successful termination of the DB-transaction.
      Example: you may write some logging information into some file system. Or you might send some notification messages to other systems.
      Pay attention: there is no transactional context that guarantees your operations to be executed!
    • withSchema

      public final String withSchema(String tableName)
      In case of using an explicit schema then this method returns the table name with some schema prefix. You may use this method if implementinng the SQL statement on your own.
      Parameters:
      Name - of table
    • withSchema

      public final String withSchema(DOFWEntity entity)
      In case of using an explicit schema then this method returns the table name with some schema prefix. You may use this method if implementing the SQL statement on your own.
    • createStatement

      public final PreparedStatement createStatement(String query)
      Creates a PreparedStatement - this method can be called within the run() implementation in order to create a prepared statement. The statemnt is automatically closed at the end of the DBAction-processing.
      Parameters:
      query - SQL query that is passed into the PreparedStatement.
      Returns:
    • createStatement

      public final PreparedStatement createStatement(String query, int autoGeneratedKeys)
      Same as createStatement(String) but now with additional int-indicator that is passed into the original prepareStatement(...) method.
    • createBatchStatement

      public final PreparedStatement createBatchStatement(String query)
      Creates a prepared statement for the query. If the same query is requested again then the already created statement is returned.