Class DbWorker<T extends DataManager>

java.lang.Object
org.conical.common.bbl.jpa.DbWorker<T>
Type Parameters:
T - An implementation of DataManager (likely a subclass of JpaDataManager)

public abstract class DbWorker<T extends DataManager> extends Object
Performs database tasks using a given the operations available on the passed DataManager. Typical usage is to subclass a child of DbWorker inline and perform the required operations inside an overridden doDbTasks method. For example, if you have:
  • interface AppDataManager extends DataManager
  • class AppDataManagerImpl implements AppDataManager extends JpaDataManager
  • class AppDbWorker extends DbWorker<AppDataManager>
Then you can do the following in your code to perform DB tasks within a transaction:
   
   new AppDbWorker() {
     public void doDbTasks(AppDataManager dataMgr) {
     
       // perform desired database operations using your custom DataManager
     
     }
   }.doWork();
 
Author:
rdoherty
  • Constructor Details

    • DbWorker

      public DbWorker()
  • Method Details

    • doWork

      public final void doWork() throws Exception
      Performs work defined in doDbTasks. What operations are performed are implementation dependent.
      Throws:
      Exception - if an error occurs
    • getDataManager

      public abstract T getDataManager()
      Returns an instance of the subclass's implementation of DataManager
      Returns:
      DataManager instance
    • doDbTasks

      public abstract void doDbTasks(T dataManager)
      Must be overridden. Performs desired database operations.
      Parameters:
      dataManager - DataManager subclass that can perform desired operations