Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Building Java Enterprise Applications Volume I: Architecture phần 10 ppt
Nội dung xem thử
Mô tả chi tiết
Building Java™ Enterprise Applications Volume I: Architecture
239
public 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
package com.forethought.ejb.accountType;
import javax.ejb.CreateException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.forethought.ejb.sequence.SequenceException;
import com.forethought.ejb.sequence.SequenceLocal;
import com.forethought.ejb.sequence.SequenceLocalHome;
import com.forethought.ejb.util.EntityAdapter;
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( );
String accountTypeKey =
(String)context.lookup(
"java:comp/env/constants/AccountTypeKey");
Integer id = sequence.getNextValue(accountTypeKey);
// Set values
setId(id);
setType(type);
return null;
} catch (NamingException e) {
throw new CreateException("Could not obtain an " +
"InitialContext.");
} catch (SequenceException e) {
throw new CreateException("Error getting primary key value: " +
e.getMessage( ));
}
}
public void ejbPostCreate(String type) {
// Empty implementation
}
public abstract void setId(Integer id);
public abstract Integer getId( );
Building Java™ Enterprise Applications Volume I: Architecture
240
public 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)
throws RemoteException;
}
Example E-14 is the local interface for the Fund bean, and is used in container-managed
relationships.
Example E-14. The Fund Local Interface
package com.forethought.ejb.fund;
import javax.ejb.EJBException;
import javax.ejb.EJBLocalObject;
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.
Building Java™ Enterprise Applications Volume I: Architecture
241
Example 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) {
this.id = id;
this.name = name;
this.description = description;
}
public int getId( ) {
return id;
}
public String getName( ) {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription( ) {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
The home interface for the Fund entity bean is shown in Example E-16.
Example E-16. The FundHome Interface
package com.forethought.ejb.fund;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
import javax.ejb.FinderException;
public interface FundHome extends EJBHome {
public Fund create(String name, String description)
throws CreateException, RemoteException;
public Fund findByPrimaryKey(Integer fundID)
throws FinderException, RemoteException;