Business Logic Components
From grayeagle
Business Logic Components are Groovy/Java class files that declare Business Logic Rules for a Domain Object. Business Logic Components parallel the Java Domain Objects - you either place them in a standard location, or control their location.
This section explains how to create them.
Contents |
Create a Logic class
Follow the guidelines in the sub-sections below
Package Name
We recommend using name of your DomainClass, but replace the last node of the package name with
businesslogic, for example:
database.buslogicintro.businesslogiccontains the Business Logic Components fordatabase.buslogicintro.dataDomain Objects
Class Name
We recommend using the default name: <DomainObjectName>
Logic, for example
PurchaseorderLogicis the Business Logic Component forPurchaseorderLogicDomain Object
Logic Class Content
Instance Variables
Create Instance Variables for the current/old Domain Object instances. These will be initialized by the Business Logic Engine prior to calling your Business Logic Rule methods
- Create these with the tags shown
- The annotations are required
@CurrentBean@OldBean- We recommend the (rather obvious) names of
<DomainObjectName>and<DomainObjectName>_old- The Object Type must, of course, match your Domain Object
The old bean is optional. There is a slight performance penalty for initializing it if you don't need it.
Logic Methods for Business Logic Rules
Once you have created your Business Logic Component, build Logic Methods that declare your Business Logic Rules:
- Formula, and Parent Copy
- Sum
- Count
- Constraint, and Commit Constraint
- Action, and Commit Action
Other Methods
You can also build procedural methods - see Business Logic Components can invoke Java/Groovy Methods.
Execution
Execution
Unlike procedural programming where your methods are called explicitly, Business Logic Rule methods are invoked by Business Logic Runtime, in response to inserts/updates/deletes done by client applications. Important observations:
- You can set breakpoints in the Business Logic Rule methods
- But, such calls are not always made. The Business Logic Engine will not call a Formula if, for example, all its local attributes are unchanged.
- Business Logic Components can be invoked multiple times per transaction, on the same row.
- For example, saving n Lineitems for a Purchaseorder would execute your Business Logic Component n times. On call "i", the old values pertain to call "i-1".
