⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 banksessionbean.java

📁 Jboss s J2EE Sample
💻 JAVA
字号:
/* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */package transaction.session;import java.util.ArrayList;import java.util.Collection;import java.util.Iterator;import java.rmi.RemoteException;import javax.ejb.EJBException;import javax.ejb.CreateException;import javax.ejb.FinderException;import javax.ejb.RemoveException;import javax.ejb.SessionContext;import javax.naming.Context;import javax.naming.InitialContext;import javax.naming.NamingException;import transaction.interfaces.Bank;import transaction.interfaces.BankData;import transaction.interfaces.BankPK;import transaction.interfaces.BankHome;import transaction.interfaces.Customer;import transaction.interfaces.CustomerData;import transaction.interfaces.CustomerSession;import transaction.interfaces.CustomerSessionHome;/** * The Session bean represents a bank's business interface. * * @author Andreas Schaefer * @version $Revision: 1.1 $ * * @ejb:bean name="bank/BankSession" *           display-name="Bank Session" *           type="Stateless" *           view-type="remote" *           jndi-name="ejb/bank/BankSession" * * @ejb:interface extends="javax.ejb.EJBObject" * * @ejb:home extends="javax.ejb.EJBHome" * * @ejb:pk extends="java.lang.Object" * * @ejb:transaction type="Required" * * @ejb:ejb-ref ejb-name="bank/Bank" * * @ejb:ejb-ref ejb-name="bank/CustomerSession" */public class BankSessionBean   extends SessionSupport{      // Constants -----------------------------------------------------      // Attributes ----------------------------------------------------      // Static --------------------------------------------------------      // Constructors --------------------------------------------------      // Public --------------------------------------------------------      /**    * @ejb:interface-method view-type="remote"    **/   public BankData createBank( String pName, String pAddress )      throws CreateException, RemoteException   {      Bank lBank = getBankHome().create( pName, pAddress );      return lBank.getData();   }      /**    * @ejb:interface-method view-type="remote"    **/   public void removeBank( String pBankId )      throws RemoveException, RemoteException   {      try {         getBankHome().findByPrimaryKey(            new BankPK( pBankId )         ).remove();      }      catch( FinderException fe ) {      }   }      /**    * @ejb:interface-method view-type="remote"    **/   public Collection getBanks()      throws FinderException, RemoteException   {      Collection lBanks = getBankHome().findAll();      Collection lList = new ArrayList( lBanks.size() );      Iterator i = lBanks.iterator();      while( i.hasNext() ) {         lList.add( ( (Bank) i.next() ).getData() );      }      return lList;   }      /**    * @ejb:interface-method view-type="remote"    **/   public CustomerData getCustomer( String pCustomerId )      throws FinderException, RemoteException   {      return getCustomerSession().getCustomer( pCustomerId );   }      /**    * @ejb:interface-method view-type="remote"    **/   public Collection getCustomers( String pBankId )      throws FinderException, RemoteException   {      return getCustomerSession().getCustomers( pBankId );   }      /**    * @ejb:interface-method view-type="remote"    **/   public CustomerData createCustomer( String pBankId, String pName, float pInitialDeposit )      throws CreateException, RemoteException   {      return getCustomerSession().createCustomer(         pBankId,         pName,         pInitialDeposit      );   }      /**    * @ejb:interface-method view-type="remote"    **/   public void removeCustomer( String pCustomerId )      throws RemoveException, RemoteException   {      getCustomerSession().removeCustomer(         pCustomerId      );   }      private BankHome getBankHome() {      try {         return (BankHome) new InitialContext().lookup( BankHome.COMP_NAME );      }      catch( NamingException ne ) {         throw new EJBException( ne );      }   }      private CustomerSession getCustomerSession()      throws RemoteException   {      try {         return ( (CustomerSessionHome) new InitialContext().lookup( CustomerSessionHome.COMP_NAME ) ).create();      }      catch( NamingException ne ) {         throw new EJBException( ne );      }      catch( CreateException ce ) {         throw new EJBException( ce );      }   }      // SessionBean implementation ------------------------------------   public void setSessionContext(SessionContext context)    {      super.setSessionContext(context);   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -