- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
USING AOP WITHIN THE SAMPLE APPLICATION S BUSINESS TIER in Font
CHAPTER 11 USING AOP WITHIN THE SAMPLE APPLICATION S BUSINESS TIER Printing Data Matrix 2d Barcode In None Using Barcode creator for Font Control to generate, create Data Matrix ECC200 image in Font applications. www.OnBarcode.comUCC-128 Maker In None Using Barcode printer for Font Control to generate, create EAN128 image in Font applications. www.OnBarcode.comListing 11-9. The EJBGetter Class package aop.j2ee.business.util; import javax.rmi.PortableRemoteObject; import javax.naming.InitialContext; import javax.naming.NamingException; import aop.j2ee.commons.util.CodedNames; import aop.j2ee.business.entity.account.*; [...] // other imports public final class EJBGetter { public static AccountHome getAccountHome() throws NamingException { InitialContext initial = new InitialContext(); Object objref = initial.lookup(CodedNames.ACCOUNT_EJBHOME); return (AccountHome) PortableRemoteObject.narrow(objref, AccountHome.class); } [...] // other resolving methods } In the original Duke s Bank design, the account resolving and the transaction parameters testing are factorized within a single method. These two independent concerns are mixed because of the need to hide the use of the Home interface. This choice makes the transactional method code less explicit. Listing 11-10 is an example of a business service implementation that corresponds to an account withdrawal. Listing 11-10. A Withdrawal Business Service Implementation 01 public void withdraw(BigDecimal amount,String description, 02 String accountId) 03 throws InvalidParameterException, AccountNotFoundException, 04 IllegalAccountTypeException, InsufficientFundsException { 05 06 Account account = 07 checkAccountArgsAndResolve(amount, description, accountId); 08 try { 09 String type = account.getType(); 10 if (DomainUtil.isCreditAccount(type)) 11 throw new IllegalAccountTypeException(type); 12 BigDecimal newBalance = account.getBalance().subtract(amount); 13 if (newBalance.compareTo(bigZero) == -1) 14 throw new InsufficientFundsException(); 15 executeTx( 16 amount.negate(), 17 description, Generating QR-Code In None Using Barcode printer for Font Control to generate, create QR Code image in Font applications. www.OnBarcode.comCreate PDF 417 In None Using Barcode generator for Font Control to generate, create PDF-417 2d barcode image in Font applications. www.OnBarcode.comCHAPTER 11 USING AOP WITHIN THE SAMPLE APPLICATION S BUSINESS TIER
Printing USS Code 128 In None Using Barcode drawer for Font Control to generate, create Code 128 Code Set B image in Font applications. www.OnBarcode.comBarcode Creation In None Using Barcode drawer for Font Control to generate, create Barcode image in Font applications. www.OnBarcode.com18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 Draw UPC-A Supplement 5 In None Using Barcode generation for Font Control to generate, create UCC - 12 image in Font applications. www.OnBarcode.comDraw USPS Confirm Service Barcode In None Using Barcode generator for Font Control to generate, create USPS Confirm Service Barcode image in Font applications. www.OnBarcode.comaccountId, newBalance, account); } catch (RemoteException ex) { throw new EJBException("withdraw: " + ex.getMessage()); } } // withdraw private void executeTx(BigDecimal amount, String description, String accountId, BigDecimal newBalance, Account account) { try { makeConnection(); String txId = DBHelper.getNextTxId(con); account.setBalance(newBalance); Tx tx = txHome.create(txId,accountId,new java.util.Date(), amount,newBalance,description); } catch (Exception ex) { throw new EJBException("executeTx: " + ex.getMessage()); } finally { releaseConnection(); } } // executeTx Data Matrix Creator In None Using Barcode printer for Online Control to generate, create Data Matrix ECC200 image in Online applications. www.OnBarcode.comGenerating DataMatrix In Java Using Barcode maker for BIRT reports Control to generate, create Data Matrix image in BIRT reports applications. www.OnBarcode.comThe executedTx method of line 15 gathers two independent functions that would benefit from being explicitly coded within the functional implementation: the Tx EJB creation (line 33), and the invocation of setBalance (line 32) on an account. As shown in the code, the Tx EJB creation uses a database-related method: DBHelper. getNextTxId (line 31), which returns the next available transaction identifier. This operation is a low-level operation that should probably not be used within a business method. Conceptually speaking, we can classify all the presented operations Home interface resolving, account lookup from a primary key, and instantiation of the Tx EJB within a reference-managing concern. This concern depends highly on the J2EE infrastructure and on the EJB model. This is clearly a crosscutting concern for all EJB accessing or for the creation of EJBs, particularly the session EJBs. The use of design patterns such as the locator can make the code less dependent on the infrastructure and minimize the design efforts through reuse. However, it is then the use of the pattern that becomes a crosscutting concern. Furthermore, the use of a locator pattern still requires an indirect use of the EJB model. Barcode Printer In .NET Using Barcode generator for .NET framework Control to generate, create Barcode image in .NET applications. www.OnBarcode.comBarcode Recognizer In None Using Barcode scanner for Software Control to read, scan read, scan image in Software applications. www.OnBarcode.comUsing AOP
Scanning Barcode In Java Using Barcode reader for Java Control to read, scan read, scan image in Java applications. www.OnBarcode.comQuick Response Code Scanner In Visual Basic .NET Using Barcode recognizer for VS .NET Control to read, scan read, scan image in .NET applications. www.OnBarcode.comAOP, and more precisely the previously discussed implicit protocol technique, significantly simplifies the design and efficiently modularizes the reference-resolving crosscutting concern. First, we defined the reference accessing protocol in the EJB itself, as shown in Listing 11-11. In our program, it is a POJO since it automatically implements the javax.ejb.SessionBean interface through the POJOSession aspect. This POJO, named TxControllerPOJO, will be detailed in the rest of the chapter, once all the applied aspects have been presented. EAN / UCC - 14 Encoder In Java Using Barcode maker for Java Control to generate, create GS1 128 image in Java applications. www.OnBarcode.comPrint Code 39 In C# Using Barcode generator for .NET framework Control to generate, create USS Code 39 image in VS .NET applications. www.OnBarcode.comCHAPTER 11 USING AOP WITHIN THE SAMPLE APPLICATION S BUSINESS TIER
Barcode Generation In VS .NET Using Barcode drawer for Reporting Service Control to generate, create Barcode image in Reporting Service applications. www.OnBarcode.comGS1 128 Generator In None Using Barcode maker for Excel Control to generate, create GS1-128 image in Microsoft Excel applications. www.OnBarcode.comListing 11-11. The Implicit Protocol for EJB Resolving [...] // excerpt of the TxControllerPOJO implicit resolving protocol implementation private Collection findTxByAccountId(Date startDate, Date endDate,String accountId) throws Exception {return null;} private Tx findTxByPrimaryKey(String txId) throws Exception {return null;} private Account findAccountByPrimaryKey(String accountID) throws Exception {return null;} private Tx createTx(String accountId, Date date, BigDecimal amount, BigDecimal newBalance, String description) throws Exception {return null;} We now define the aspect implementing this protocol. In our study, this aspect is called the EJBResolver aspect, which is an abstract aspect extended by the POJOSession and POJOEntity concrete aspects. The purpose of the EJBResolver aspect is to implement common behaviors for reference-resolving implementation, as shown in Listing 11-12. Listing 11-12. The Aspect Implementation of the EJB Resolving Implicit Protocol 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 package aop.j2ee.business.aspect; import import import import import import import import java.util.Collection; java.util.Date; java.math.BigDecimal; aop.j2ee.business.entity.account.AccountHome; aop.j2ee.business.entity.account.Account; aop.j2ee.business.entity.tx.TxHome; aop.j2ee.business.entity.tx.Tx; aop.j2ee.business.aspect.sql.DBUtil; Generating EAN 128 In VS .NET Using Barcode creation for Reporting Service Control to generate, create GS1-128 image in Reporting Service applications. www.OnBarcode.comEAN-13 Maker In Objective-C Using Barcode creation for iPad Control to generate, create EAN 13 image in iPad applications. www.OnBarcode.compublic abstract aspect EJBResolver { static protected TxHome txHome; static protected AccountHome accountHome; [...] // Other homes... Account around(String accountID) throws Exception: execution( private Account *.findAccountByPrimaryKey(String) && args(accountID) { return accountHome.findByPrimaryKey(accountID); } Tx around(String txID) throws Exception: execution(private Tx *.findTxByPrimaryKey(String)) && args(txID) { return txHome.findByPrimaryKey(txID); }
|
|