The Fund Remote Interface package com.forethought.ejb.fund; import java.rmi.RemoteException; import javax.ejb.EJBObject; public interface Fund extends EJBObject { public FundInfo getIn
Trang 1public AccountTypeLocal findByPrimaryKey(Integer accountTypeID)
throws FinderException, EJBException;
public AccountTypeLocal findByType(String type)
throws FinderException, EJBException;
}
Example E-12 is the implementation class for the AccountType bean
Example E-12 The AccountTypeBean Implementation Class
public abstract class AccountTypeBean extends EntityAdapter {
public Integer ejbCreate(String type) throws CreateException {
// Get the next primary key value
try {
Context context = new InitialContext( );
// Note that RMI-IIOP narrowing is not required
SequenceLocalHome home = (SequenceLocalHome)
context.lookup("java:comp/env/ejb/SequenceLocalHome"); SequenceLocal sequence = home.create( );
public abstract void setId(Integer id);
public abstract Integer getId( );
Trang 2public abstract String getType( );
public abstract void setType(String type);
}
E.1.4 The Fund Bean
Example E-13 is the remote interface for the Fund entity bean
Example E-13 The Fund Remote Interface
package com.forethought.ejb.fund;
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
public interface Fund extends EJBObject {
public FundInfo getInfo( ) throws RemoteException;
public void setInfo(FundInfo fundInfo) throws RemoteException;
public Integer getId( ) throws RemoteException;
public String getName( ) throws RemoteException;
public void setName(String name) throws RemoteException;
public String getDescription( ) throws RemoteException;
public void setDescription(String description)
public interface FundLocal extends EJBLocalObject {
public Integer getId( ) throws EJBException;
public String getName( ) throws EJBException;
public void setName(String name) throws EJBException;
public String getDescription( ) throws EJBException;
public void setDescription(String description)
throws EJBException;
}
Example E-15 shows the information class (FundInfo) for the Fund entity bean
Trang 3Example E-15 The FundInfo Class
package com.forethought.ejb.fund;
import java.io.Serializable;
public class FundInfo implements Serializable {
private int id;
private String name;
private String description;
protected FundInfo(int id, String name, String description) {
The home interface for the Fund entity bean is shown in Example E-16
Example E-16 The FundHome Interface
public interface FundHome extends EJBHome {
public Fund create(String name, String description)
throws CreateException, RemoteException;
public Fund findByPrimaryKey(Integer fundID)
throws FinderException, RemoteException;
Trang 4public Fund findByName(String name)
throws FinderException, RemoteException;
}
The local home interface for the Fund bean is shown in Example E-17
Example E-17 The FundLocalHome Interface
public interface FundLocalHome extends EJBLocalHome {
public FundLocal create(String name, String description)
throws CreateException, EJBException;
public FundLocal findByPrimaryKey(Integer fundID)
throws FinderException, EJBException;
public FundLocal findByName(String name)
throws FinderException, EJBException;
}
Example E-18 is the Fund bean's implementation class
Example E-18 The FundBean Implementation Class
public abstract class FundBean extends EntityAdapter {
public Integer ejbCreate(String name, String description)
// Note that RMI-IIOP narrowing is not required
SequenceLocalHome home = (SequenceLocalHome)
context.lookup("java:comp/env/ejb/SequenceLocalHome"); SequenceLocal sequence = home.create( );
String fundKey =
(String)context.lookup(
"java:comp/env/constants/FundKey");
Integer id = sequence.getNextValue(fundKey);
Trang 5public abstract Integer getId( );
public abstract void setId(Integer id);
public abstract String getName( );
public abstract void setName(String name);
public abstract String getDescription( );
public abstract void setDescription(String description);
}
E.1.5 The Account Bean
Example E-19 is the Account bean's remote interface
Example E-19 The Account Remote Interface
Trang 6public void setInfo(AccountInfo accountInfo)
throws RemoteException, UnknownAccountTypeException;
public Integer getId( ) throws RemoteException;
public User getUser( ) throws RemoteException;
public void setUser(User user) throws RemoteException;
public String getType( ) throws RemoteException;
public void setType(String type)
throws RemoteException, UnknownAccountTypeException;
public float getBalance( ) throws RemoteException;
public void setBalance(float balance) throws RemoteException;
}
Example E-20 is the local interface for the Account bean, used in CMP relationships
Example E-20 The AccountLocal Interface
public interface AccountLocal extends EJBLocalObject {
public Integer getId( ) throws EJBException;
public UserLocal getUserLocal( ) throws EJBException;
public void setUserLocal(UserLocal userLocal) throws EJBException; public String getType( ) throws EJBException;
public void setType(String type)
throws EJBException, UnknownAccountTypeException;
public float getBalance( ) throws EJBException;
public void setBalance(float balance) throws EJBException;
}
The information map for the Account bean is shown in Example E-21
Example E-21 The AccountInfo Class
package com.forethought.ejb.account;
import java.io.Serializable;
// User bean
import com.forethought.ejb.user.UserInfo;
Trang 7public class AccountInfo implements Serializable {
private int id;
private UserInfo userInfo;
private String type;
private float balance;
AccountInfo(int id, String type, float balance, UserInfo userInfo) {
The home interface for the Account bean is shown in Example E-22
Example E-22 The AccountHome Interface
Trang 8// User bean
import com.forethought.ejb.user.User;
public interface AccountHome extends EJBHome {
public Account create(String type, float balance, User user)
throws CreateException, RemoteException,
UnknownAccountTypeException;
public Account findByPrimaryKey(Integer accountID)
throws FinderException, RemoteException;
public Collection findByBalance(float minBalance, float maxBalance) throws FinderException, RemoteException;
}
Example E-23 shows the Account bean's local home interface
Example E-23 The AccountLocalHome Interface
public interface AccountLocalHome extends EJBLocalHome {
public AccountLocal create(String type, float balance, User user)
throws CreateException, EJBException, UnknownAccountTypeException; public AccountLocal findByPrimaryKey(Integer accountID)
throws FinderException, EJBException;
public Collection findByBalance(float minBalance, float maxBalance) throws FinderException, EJBException;
}
Example E-24 is the implementation class for the Account bean
Example E-24 The AccountBean Implementation Class
Trang 9public abstract class AccountBean extends EntityAdapter {
public Integer ejbCreate(String type, float balance, User user)
throws CreateException, UnknownAccountTypeException {
// Get the next primary key value
try {
Context context = new InitialContext( );
// Note that RMI-IIOP narrowing is not required
SequenceLocalHome home = (SequenceLocalHome)
context.lookup("java:comp/env/ejb/SequenceLocalHome"); SequenceLocal sequence = home.create( );
String accountKey =
(String)context.lookup("java:comp/env/constants/AccountKey"); Integer id = sequence.getNextValue(accountKey);
Trang 10public AccountInfo getInfo( ) throws RemoteException {
AccountInfo accountInfo =
new AccountInfo(getId().intValue(),
getAccountTypeLocal().getType( ), getBalance(), getUser().getInfo( ));
// Couldn't find supplied type
throw new UnknownAccountTypeException(type);
// Construct primary key for this user
Integer userID = user.getId( );
// Find the local interface for this office
Context context = new InitialContext( );
Trang 11} catch (FinderException shouldNeverHappen) {
// This should never happen; the ID from an office's remote // interface should match an office's ID in a local interface throw new EJBException("Error matching remote User to " +
"local User: " + shouldNeverHappen.getMessage( ));
// Construct primary key for this user
Integer userID = new Integer(userInfo.getId( ));
// Find the local interface for this office
Context context = new InitialContext( );
} catch (FinderException shouldNeverHappen) {
// This should never happen; the ID from an office's remote // interface should match an office's ID in a local interface throw new EJBException("Error matching remote User to " +
"local User: " + shouldNeverHappen.getMessage( ));
}
}
public User getUser( ) {
// Construct primary key for this office
Integer userID = getUserLocal().getId( );
try {
// Find the remote interface for this office
Context context = new InitialContext( );
} catch (FinderException shouldNeverHappen) {
// This should never happen; the ID from a user's remote
// interface should match a user's ID in a local interface throw new EJBException("Error matching remote User to " +
"local User: " + shouldNeverHappen.getMessage( ));
}
}
public abstract Integer getId( );
public abstract void setId(Integer id);
Trang 12
public abstract UserLocal getUserLocal( );
public abstract void setUserLocal(UserLocal userLocal);
public abstract AccountTypeLocal getAccountTypeLocal( );
public abstract void setAccountTypeLocal(AccountTypeLocal
accountTypeLocal);
public abstract float getBalance( );
public abstract void setBalance(float balance);
}
E.1.6 The Transaction Bean
The remote interface for the Transaction bean is shown in Example E-25
Example E-25 The Transaction Remote Interface
public interface Transaction extends EJBObject {
public TransactionInfo getInfo( ) throws RemoteException;
public void setInfo(TransactionInfo transactionInfo)
throws RemoteException;
public Integer getId( ) throws RemoteException;
public Account getAccount( ) throws RemoteException;
public void setAccount(Account account) throws RemoteException;
public float getAmount( ) throws RemoteException;
public void setAmount(float amount) throws RemoteException;
public Date getDateTime( ) throws RemoteException;
public void setDateTime(Date dateTime) throws RemoteException;
}
Example E-26 is the Transaction bean's information/value class
Example E-26 The TransactionInfo Class
Trang 13public class TransactionInfo implements Serializable {
private int id;
private AccountInfo accountInfo;
private float amount;
private Date dateTime;
TransactionInfo(int id, float amount, Date dateTime,
Example E-27 shows the home interface for the Transaction bean
Example E-27 The TransactionHome Interface
Trang 14public interface TransactionHome extends EJBHome {
public Transaction create(float amount, Date dateTime, Account account) throws CreateException, RemoteException;
public Transaction findByPrimaryKey(Integer transactionID)
throws FinderException, RemoteException;
public Collection findByAmount(float minAmount, float maxAmount)
throws FinderException, RemoteException;
}
Example E-28 is the Transaction bean's implementation class
Example E-28 The TransactionBean Implementation Class
public abstract class TransactionBean extends EntityAdapter {
public Integer ejbCreate(float amount, Date dateTime, Account account) throws CreateException {
// Get the next primary key value
try {
Context context = new InitialContext( );
// Note that RMI-IIOP narrowing is not required
SequenceLocalHome home = (SequenceLocalHome)
context.lookup("java:comp/env/ejb/SequenceLocalHome"); SequenceLocal sequence = home.create( );
Trang 15public Account getAccount( ) throws RemoteException {
// Construct primary key for this account
Integer accountID = getAccountLocal().getId( );
try {
// Find the remote interface for this account
Context context = new InitialContext( );
} catch (FinderException shouldNeverHappen) {
// This should never happen; the ID from an account's remote // interface should match an account's ID in a local interface throw new EJBException("Error matching remote Account to " + "local Account: " + shouldNeverHappen.getMessage( )); }
}
Trang 16
public void setAccount(Account account) {
try {
// Construct primary key for this account
Integer accountID = account.getId( );
// Find the local interface for this account
Context context = new InitialContext( );
} catch (FinderException shouldNeverHappen) {
// This should never happen; the ID from an account's remote // interface should match an account's ID in a local interface throw new EJBException("Error matching remote Account to " + "local Account: " + shouldNeverHappen.getMessage( )); }
}
public void setAccount(AccountInfo accountInfo) {
try {
// Construct primary key for this account
Integer accountID = new Integer(accountInfo.getId( ));
// Find the local interface for this account
Context context = new InitialContext( );
} catch (FinderException shouldNeverHappen) {
// This should never happen; the ID from an account's remote // interface should match an account's ID in a local interface throw new EJBException("Error matching remote Account to " + "local Account: " + shouldNeverHappen.getMessage( )); }
}
public abstract Integer getId( );
public abstract void setId(Integer id);
public abstract AccountLocal getAccountLocal( );
public abstract void setAccountLocal(AccountLocal accountLocal);
public abstract float getAmount( );
public abstract void setAmount(float amount);
Trang 17public abstract Date getDateTime( );
public abstract void setDateTime(Date dateTime);
}
E.1.7 The Investment Bean
Example E-29 is the Investment bean's remote interface
Example E-29 The Investment Remote Interface
public interface Investment extends EJBObject {
public InvestmentInfo getInfo( ) throws RemoteException;
public void setInfo(InvestmentInfo investmentInfo)
public Integer getId( ) throws RemoteException;
public Fund getFund( ) throws RemoteException;
public void setFund(Fund fund) throws RemoteException;
public Account getAccount( ) throws RemoteException;
public void setAccount(Account account)
throws RemoteException;
public float getInitialAmount( ) throws RemoteException;
public void setInitialAmount(float initialAmount)
throws RemoteException;
public float getYield( ) throws RemoteException;
public void setYield(float yield) throws RemoteException;
}
Example E-30 is the Investment bean's information class
Example E-30 The InvestmentInfo Class