|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP THREE LINKS YOU MUST CLICK ON Code Corner Transaction Rules Rule
Transaction Rules Rule
Mar. 12, 2002 12:00 AM
One of the primary uses of Enterprise JavaBeans (EJBs) is to free developers from routine infrastructure issues such as distribution, security, and persistence so they can concentrate on business logic. This recognizes that the truly valuable part of an application is the set of data and control flows that implement its business functions. The WebSphere Application Server (WAS) has supported EJBs since version 3.0. Placing the business logic of a WebSphere application into the EJB layer should allow the logic to be centralized, understood, reused, and maintained more easily. In theory at least, leveraging EJB container services should simplify development and greatly improve programmer productivity. The reality is usually very different. Many organizations have discovered that delivering systems with this layered architecture is a challenge. In their report, “Putting J2EE to Work,” Forrester Research concludes that most organizations will face a bumpy adoption road that won’t be fixed by advances in the J2EE specification. For EJBs, the difficulties include a steep learning curve, the complexity of designing for both flexibility and performance, and the relatively low-level Java language used to implement business functions. All this points to the need for another approach that specifically addresses the development and management of business logic in WebSphere applications. According to Forrester, this approach would automate away complexity, so developers “never have to know or care that EJBs require six different deployment files.” An approach using declarative logic, also known as rules, to specify transaction business logic is delivering a high degree of EJB automation for J2EE application servers such as WebSphere.
Automated Business Rules
To clarify our discussion, the rules used to automate EJBs are transaction-logic rules. Rules expert Barbara von Halle explains that such rules are data-change–oriented, which means that they execute when the data to which they are attached is touched. Specifying business logic through rules has many benefits. First, because a single rule can control the behavior of a whole set of objects, rules are much more productive than procedural or even object-oriented languages. Next, because they are centralized and easy to understand, rules can be located and changed quickly. Finally, because they are unambiguous and self-documenting, rules become a tool for communication between users, analysts, and developers. Rule-based specifications, of course, only begin the business logic automation process; for the specifications to be useful, they must be executable. That is, they must be turned into a set of business objects whose sophisticated interactions can be driven by changes to data values. This is done through a transaction logic “server” or “engine.” The engine is typically installed in an EJB container within the WebSphere application server. In addition to executing rule events, a transaction logic engine may also provide other services to improve the performance and manageability of rule-based logic. Ideally, these services would include:
P> The IBM Redbook, Application Development Using Versata Business Logic Automation for WebSphere, shows how transaction logic rules can be used to implement the business logic in a well-known application, IBM’s Trade 2 application performance benchmark. Trade 2 has a sophisticated Model-View-Controller architecture that simulates an online stock brokerage. Its functionality includes buying and selling stock “holdings.” By default, the business logic in Trade 2 is implemented in EJBs. Using Versata, the Trade 2 EJBs are automated using rules. In addition, the Trade 2 business logic is extended to include additional functions, such as controlling margin selling, selling partial holdings, and charging personalized commission rates. The model of the rules-extended Trade 2 application has five core business objects, described as:
Classification of Rules
Relationships typically imply a parent-child association between entities, although they can be used for more complex models. An example of a simple relationship is: “An Account Has Holdings.” Relationships are the foundation of many rules, and transaction logic servers can automate many operations between related entities. For instance, through the relationship described above an Account can automatically count and sum all of its related Holdings. Holdings can automatically check for sufficient funds in the related Account. Furthermore, as they are entered, Holdings can automatically check to ensure they are associated with valid Accounts.
Derivation Example
“QuantityOnHand = QuantityPurchased – QuantitySold” In addition, computational derivations can use the attribute values from several objects in computations. An example of this is a rule for selling a stock that says “The Transaction Amount is the Transaction Quantity multiplied by the Price (from the Quote object) navigated to through the related Holding object” Leveraging its relationship rules, the transaction logic server can automatically navigate to other objects to retrieve attribute values. A logic server will typically have a GUI for building rules.
Inference Example:
“AccountType is wholesale if the Balance is greater than $500K.” Like computational derivation, inference derivations can chain together evaluations and calculations from several entities. It’s possible, for instance, for a rule to say for an Account, “An AccountType is wholesale if the Account Balance is greater than $500K (Account object) AND the number of ActiveHoldings is greater than 20 (Holding object) AND the average TransactionSize is > $10K (Transaction object).”
Constraint Example
“Balance can’t be less than zero” Although it sounds simple, this constraint shows the power behind some logic servers. These servers can compile high-level, unordered rules into automatically sequenced chains of object interactions. For instance, in the Trade 2 example, the following “Buy” rule-chain is constrained by the margin-selling rule above. When buying a stock: 1. The Logic Server begins to create a new Holding for this Symbol, Date, and Quantity. 2. It gets the stock’s price from the associated Quote. 3. It begins to insert an initial “Buy” Transaction object . 4. It calculates the cost of the stock (multiply Price by Quantity). 5. It determines the Commission (by checking the Account entity to see whether the AccountType is a wholesale or retail account, checking the current CommissionRate for that Account Type and multiplying the CommissionRate by the Transaction Amount). 6. It calculates the total Transaction Amount. 7. It begins to update the Transaction Count for this Holding. 8. It begins to debit the Account Balance with the Transaction Amount. 9. Finally, it encounters the constraint. 10. If the constraint is violated (if the new Balance would be less than zero) 11. It unwinds the entire operation (rolls back changes to the Holding, Transaction, and Account objects). In addition, to optimizing performance, a logic server may be able to bring all the objects needed for a transaction chain into a transaction cache, so the entire chain can be processed with a single database I/O.
Action Example
“When adding a new Transaction, if the TransactionType is ‘sell,’ credit the related Holding’s related Account Balance.” Typically, a transaction logic server will implement this with a rule “listening service.” The logic server will receive the event when all other rules leading up to this event/condition have evaluated “true.”
Extending Rules with Java
While transaction logic rules are estimated to cover more than 90% of application business logic, any automation approach must address the remaining requirements. Extensibility can be provided in many ways: for instance, the rule system can:
Combined, these extensibility options should allow the developer to use a rule-based approach for almost any transactional application.
Application Use of Rules
To Automatically Sequence and Optimize Transactions
The Trade 2 application “Buy” function is a simple example. Given a UserID, stock Symbol, and Quantity, the Buy operation:
For Data Validation
Rules allow data validations to be attached to objects directly, as part of their metadata. Using rules to specify attribute validations has several benefits. First, validations, like all rules, will be applied consistently across all applications. This increases system integrity. In addition, validation metadata, like other rule-based metadata, can be accessed through object methods. This makes it possible for client components to derive their behavior from business entity metadata. This extends the use of the Model in the Model-View-Controller architecture and could allow client components to adapt automatically to changes in business logic.
For EJB Referential Integrity
In applications where all data is kept in the same relational database, enforcing referential integrity can be left to the database management system. If, however, there is the potential for data to come from more than one source, integrity must be assured through application code. In J2EE applications, the place for this code is in EJBs. (Whether it should be placed in the parent entity EJB, the child entity EJB, or in a third, session EBJ, is frequently debated.) Rules provide an easy and consistent way to enforce relationships and integrity, even between objects in different databases or legacy applications.
For Ad Hoc Object Queries
For instance, the Versata client library provides a JDBC-like API to submit ad hoc queries against objects, including objects that are joined from multiple entities. The libraries deliver optimized ResultSets of serialized “rows” of objects with client navigation (first, next, last) as well as buffered reads and saves. This simplifies client development and automatically provides the performance found in J2EE best-practice patterns such as value objects and value-object lists.
To Initiate Asynchronous Events
Rules watch data changes and can initiate synchronous transactions or asynchronous events based on those changes.
Beyond Transactions to Processes
A future article will examine the natural evolution of rule-based WebSphere applications into sophisticated process-driven systems.
Resources
WebSphere Performance Benchmark Sample (Trade 2 Application): www.ibm.com/software/webservers/appserv/wpbs_download.html Application Development Using Versata Business Logic Automation for WebSphere: www.redbooks.ibm.com Koetzle Laura, "Putting J2EE to Work," Forrester Research, July, 2001. WEBSPHERE LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING WEBSPHERE NEWS
|
||||||||||||||||||||||||||||