Guide‎ > ‎Logic Design Patterns‎ > ‎

Direct Logic Invocation

In nearly all cases, business logic is transactional - it operates in response to inserts, updates and delete of Domain Objects.  ABL also provides support for Direct Logic Invocation, so that clients can invoke Logic Class Methods without requiring attribute changes, for example:
  • print a row

  • sending mail regarding a row

  • encapsulating update logic, such as putOnHold (which might set the onHold flag and issue an update), or giveRaise (which adjusts a salary by a supplied percentage)

  • complex query execution

  • recomputeNow - recompute an attribute

LogicContext provides services to address these requirements as described below, illustrated in BusLogicIntro in the delivered jUnit test:



Invocation via LogicContext

Invoke the desired Logic Class Method using the invokeAction as shown on the highlit line.  Note the first argument designates the name of the Logic Method to invoke.

Getting Logic Method Results

Queued Execution

Important: your Logic Class Method (and any listeners) execute only when the commit is executing, not when you issue the invokeMethod.

It is important to understand that a transaction is in progress with all the associated database locks, so long-duration operations such as user interactions are strongly discouraged.
You can register a listener for obtaining the return object as shown by the comment Logic Class Method return object.

Passing arguments to Logic Methods

You can pass arguments to the Logic Method by supplying an Object array as shown by the comment Logic Class Method parameters.  An exception will be raised if the number and types do not match the target method.

Determining changes made in Logic Methods

Your Logic Class Method can make updates, which are subjected to the usual business logic.  Your client code can determine what changes occurred using the transaction by registering a listener as shown below:

GlobalLogicEventHandler.getGlobalTransactionSummaryListenerHandler().addListener(

new TransactionSummaryListener() {

public void transactionCommitted(TransactionSummary summary) {
   System.out.println("\n\nTransaction Summary: " + summary);
   System.out.println("\n.. " + summary.getObjectEvents()) ;
   System.out.println("\n..end of transactionSummary");
   }

}

);


Defining Logic Class Methods for Direct Execution

Direct Invocation is for methods in your Logic Class, as shown here for PurchaseorderLogic.  Observe you must provide the @Invocable annotation.  Also observe your Logic Method has the usual context beans (here purchaseorder).

@Invocable
public String getMailTextWithArgs(String arg1, String arg2) {
   String info = "no sales rep assigned"
   if (purchaseorder.salesrep != null)
      info = purchaseorder.salesrep.name
   String rtn = "email text for salesRep: $info, with args: $arg1, $arg2"
   if (_logger.isDebugEnabled() ) _logger.debug("++++ $rtn")
   return rtn
}

Comments