📄 tellersessionbean.java
字号:
/* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */package transaction.session;import java.rmi.RemoteException;import java.util.Collection;import javax.ejb.CreateException;import javax.ejb.EJBException;import javax.naming.InitialContext;import javax.naming.NamingException;import transaction.interfaces.AccountData;import transaction.interfaces.AccountSession;import transaction.interfaces.AccountSessionHome;import transaction.interfaces.Bank;import transaction.interfaces.BankException;import transaction.interfaces.BankHome;import transaction.interfaces.CustomerData;import transaction.interfaces.CustomerSession;import transaction.interfaces.CustomerSessionHome;/** * The Session bean represents a bank. * * @author Andreas Schaefer * @version $Revision: 1.1 $ * * @ejb:bean name="bank/TellerSession" * display-name="Teller Session" * type="Stateless" * view-type="remote" * jndi-name="ejb/bank/TellerSession" * * @ejb:interface extends="javax.ejb.EJBObject" * * @ejb:home extends="javax.ejb.EJBHome" * * @ejb:transaction type="Required" * * @ejb:ejb-ref ejb-name="bank/AccountSession" * * @ejb:ejb-ref ejb-name="bank/BankSession" * * @ejb:ejb-ref ejb-name="bank/CustomerSession" */public class TellerSessionBean extends SessionSupport{ // Constants ----------------------------------------------------- // Attributes ---------------------------------------------------- // Static -------------------------------------------------------- // Constructors -------------------------------------------------- // Public -------------------------------------------------------- /** * @ejb:interface-method view-type="remote" **/ public void deposit( String pToAccountId, float pAmount ) throws BankException { try { getAccountSession().deposit( pToAccountId, pAmount ); } catch( Exception e ) { sessionCtx.setRollbackOnly(); throw new BankException( "Could not deposit " + pAmount + " to " + pToAccountId, e ); } } /** * @ejb:interface-method view-type="remote" **/ public void transfer( String pFromAccountId, String pToAccountId, float pAmount ) throws BankException { try { getAccountSession().transfer( pFromAccountId, pToAccountId, pAmount ); } catch( Exception e ) { sessionCtx.setRollbackOnly(); throw new BankException( "Could not transfer " + pAmount + " from " + pFromAccountId + " to " + pToAccountId, e ); } } /** * @ejb:interface-method view-type="remote" **/ public void withdraw( String pFromAccountId, float pAmount ) throws BankException { try { getAccountSession().withdraw( pFromAccountId, pAmount ); } catch( Exception e ) { sessionCtx.setRollbackOnly(); throw new BankException( "Could not withdraw " + pAmount + " from " + pFromAccountId, e ); } } /** * @ejb:interface-method view-type="remote" **/ public AccountData createAccount( String pCustomerId, int pType, float pInitialDeposit ) throws BankException { try { return getAccountSession().createAccount( pCustomerId, pType, pInitialDeposit ); } catch( Exception e ) { sessionCtx.setRollbackOnly(); e.printStackTrace(); throw new BankException( "Could not create account", e ); } } /** * @ejb:interface-method view-type="remote" **/ public void removeAccount( String pAccountId ) throws BankException { try { getAccountSession().removeAccount( pAccountId ); } catch( Exception e ) { sessionCtx.setRollbackOnly(); e.printStackTrace(); throw new BankException( "Could not remove account", e ); } } /** * @ejb:interface-method view-type="remote" **/ public void removeAccount( String pCustomerId, int pType ) throws BankException { try { getAccountSession().removeAccount( pCustomerId, pType ); } catch( Exception e ) { sessionCtx.setRollbackOnly(); e.printStackTrace(); throw new BankException( "Could not remove account", e ); } } /** * @ejb:interface-method view-type="remote" **/ public Collection getAccounts( String pCustomerId ) throws BankException { try { return getAccountSession().getAccounts( pCustomerId ); } catch( Exception e ) { sessionCtx.setRollbackOnly(); e.printStackTrace(); throw new BankException( "Could not remove account", e ); } } /** * @ejb:interface-method view-type="remote" **/ public AccountData getAccount( String pCustomerId, int pType ) throws BankException { try { return getAccountSession().getAccount( pCustomerId, pType ); } catch( Exception e ) { sessionCtx.setRollbackOnly(); e.printStackTrace(); throw new BankException( "Could not remove account", e ); } } /** * @ejb:interface-method view-type="remote" **/ public AccountData getAccount( String pAccountId ) throws BankException { try { return getAccountSession().getAccount( pAccountId ); } catch( Exception e ) { sessionCtx.setRollbackOnly(); e.printStackTrace(); throw new BankException( "Could not remove account", e ); } } /** * @ejb:interface-method view-type="remote" **/ public CustomerData createCustomer( String pBankId, String pName, float pInitialDeposit ) throws BankException { try { return getCustomerSession().createCustomer( pBankId, pName, pInitialDeposit ); } catch( Exception e ) { sessionCtx.setRollbackOnly(); e.printStackTrace(); throw new BankException( "Could not create account", e ); } } /** * @ejb:interface-method view-type="remote" **/ public void removeCustomer( String pCustomerId ) throws BankException { try { getCustomerSession().removeCustomer( pCustomerId ); } catch( Exception e ) { sessionCtx.setRollbackOnly(); e.printStackTrace(); throw new BankException( "Could not remove account", e ); } } /** * @ejb:interface-method view-type="remote" **/ public CustomerData getCustomer( String pCustomerId ) throws BankException { try { CustomerSession lSession = getCustomerSession(); return lSession.getCustomer( pCustomerId ); } catch( Exception e ) { e.printStackTrace(); throw new BankException( "Could not get customer for " + pCustomerId, e ); } } /** * @ejb:interface-method view-type="remote" **/ public Collection getCustomers( String pBankId ) throws BankException { try { return getCustomerSession().getCustomers( pBankId ); } catch( Exception e ) { e.printStackTrace(); throw new BankException( "Could not get customers for bank " + pBankId, e ); } } private AccountSession getAccountSession() throws RemoteException { try { AccountSessionHome lHome = (AccountSessionHome) new InitialContext().lookup( AccountSessionHome.COMP_NAME ); return lHome.create(); } catch( NamingException ne ) { throw new EJBException( ne ); } catch( CreateException ce ) { throw new EJBException( ce ); } } private CustomerSession getCustomerSession() throws RemoteException { try { CustomerSessionHome lHome = (CustomerSessionHome) new InitialContext().lookup( CustomerSessionHome.COMP_NAME ); return lHome.create(); } catch( NamingException ne ) { throw new EJBException( ne ); } catch( CreateException ce ) { throw new EJBException( ce ); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -