?? customersessionbean.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.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.ejb.EJBException;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.ejb.RemoveException;
import javax.ejb.SessionContext;
import transaction.interfaces.Account;
import transaction.interfaces.AccountData;
import transaction.interfaces.AccountSession;
import transaction.interfaces.AccountSessionHome;
// import transaction.interfaces.AccountPK;
import transaction.interfaces.Constants;
import transaction.interfaces.Customer;
import transaction.interfaces.CustomerData;
import transaction.interfaces.CustomerHome;
import transaction.interfaces.CustomerPK;
/**
* The Session bean represents the customer's business interface
*
* @author Andreas Schaefer
* @version $Revision: 1.1 $
*
* @ejb:bean name="bank/CustomerSession"
* display-name="Customer Session"
* type="Stateless"
* view-type="remote"
* jndi-name="ejb/bank/CustomerSession"
*
* @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/AccountSession"
*
* @ejb:ejb-ref ejb-name="bank/Customer"
*/
public class CustomerSessionBean
extends SessionSupport
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
/**
* @ejb:interface-method view-type="remote"
*
* @--ejb:transaction type="RequiresNew"
**/
public CustomerData createCustomer( String pBankId, String pName, float pInitialDeposit )
throws CreateException, RemoteException
{
Customer lCustomer = getCustomerHome().create(
pBankId,
pName
);
CustomerData lNew = lCustomer.getData();
getAccountHome().create().createAccount(
lNew.getId(),
Constants.CHECKING,
pInitialDeposit
);
return lNew;
}
/**
* @ejb:interface-method view-type="remote"
**/
public void removeCustomer( String pCustomerId )
throws RemoveException, RemoteException
{
try {
getCustomerHome().findByPrimaryKey(
new CustomerPK( pCustomerId )
).remove();
}
catch( FinderException fe ) {
// When not found then ignore it because customer is already removed
}
}
/**
* @ejb:interface-method view-type="remote"
**/
public CustomerData getCustomer( String pCustomerId )
throws FinderException, RemoteException
{
Customer lCustomer = getCustomerHome().findByPrimaryKey(
new CustomerPK( pCustomerId )
);
return lCustomer.getData();
}
/**
* @ejb:interface-method view-type="remote"
**/
public Collection getCustomers( String pBankId )
throws FinderException, RemoteException
{
Collection lCustomers = getCustomerHome().findByBank(
pBankId
);
Collection lList = new ArrayList( lCustomers.size() );
Iterator i = lCustomers.iterator();
while( i.hasNext() ) {
lList.add( ( (Customer) i.next() ).getData() );
}
return lList;
}
/**
* @ejb:interface-method view-type="remote"
**/
public Collection getAccounts( String pCustomerId )
throws FinderException, RemoteException
{
try {
return getAccountHome().create().getAccounts( pCustomerId );
}
catch( CreateException ce ) {
throw new EJBException( ce );
}
}
/**
* @ejb:interface-method view-type="remote"
**/
public AccountData createAccount( String pCustomerId, int pType, float pInitialDeposit )
throws CreateException, RemoteException
{
return getAccountHome().create().createAccount(
pCustomerId,
pType,
pInitialDeposit
);
}
/**
* @ejb:interface-method view-type="remote"
**/
public void removeAccount( String pCustomerId, int pType )
throws RemoveException, RemoteException
{
try {
getAccountHome().create().removeAccount( pCustomerId, pType );
}
catch( CreateException ce ) {
// When not found then ignore it because account is already removed
}
}
private AccountSessionHome getAccountHome() {
try {
return (AccountSessionHome) new InitialContext().lookup( AccountSessionHome.COMP_NAME );
}
catch( NamingException ne ) {
throw new EJBException( ne );
}
}
private CustomerHome getCustomerHome() {
try {
return (CustomerHome) new InitialContext().lookup( CustomerHome.COMP_NAME );
}
catch( NamingException ne ) {
throw new EJBException( ne );
}
}
// SessionBean implementation ------------------------------------
public void setSessionContext(SessionContext context)
{
super.setSessionContext(context);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -