[ Pobierz całość w formacie PDF ] .getMessage( ));}}public void setOffice(Office office) {try {// Handle case where no office suppliedif (office == null) {setOfficeLocal(null);return;}// Construct primary key for this officeInteger officeID = office.getId( );// Find the local interface for this officeContext context = new InitialContext( );OfficeLocalHome officeLocalHome =(OfficeLocalHome)context.lookup("java:comp/env/ejb/OfficeLocalHome");OfficeLocal officeLocal =officeLocalHome.findByPrimaryKey(officeID);setOfficeLocal(officeLocal);} catch (NamingException e) {throw new EJBException("Error looking up Office bean: " +e.getMessage( ));} catch (RemoteException e) {throw new EJBException("Error looking up Office bean: " +e.getMessage( ));} catch (FinderException shouldNeverHappen) {// This should never happen; the ID from an office's remote// interface should match an office's ID in a local interfacethrow new EJBException("Error matching remote Office to " +"local Office: " + shouldNeverHappen.getMessage( ));}}public abstract Integer getId( );public abstract void setId(Integer id);public abstract String getUserDn( );public abstract void setUserDn(String userDn);public abstract UserTypeLocal getUserTypeLocal( );public abstract void setUserTypeLocal(UserTypeLocal userTypeLocal);public abstract OfficeLocal getOfficeLocal( );public abstract void setOfficeLocal(OfficeLocal officeLocal);public abstract String getFirstName( );public abstract void setFirstName(String firstName);public abstract String getLastName( );public abstract void setLastName(String lastName);}237Building Java"! Enterprise Applications Volume I: ArchitectureThe User bean is the first bean to use CMP relationships so far.CMPrelationships are well documented in various EJB books, and turn out tobe simple to understand.Several other beans in this appendix use theserelationships as well, so you should be able to pick things up byfollowing the examples.You should also note that for the first time in this book, theejbPostCreate( ) method is used in this bean.The EJB 2.0specification dictates that CMP relationships cannot be dealt with in theejbCreate( ) method; instead, they must be handled by theejbPostCreate( ) method.This allows the container to make someassumptions about what classes and resources must be available foreach method invocation.As a result, the two relationship-basedmethods, (setOffice( ) and setUserType( ), are invoked bythe ejbPostCreate( ) method in this bean.E.1.3 The AccountType BeanExample E-10 is the AccountType entity bean's local interface.Like the UserType bean, italso has only local interfaces exposed.Example E-10.The AccountTypeLocal Interfacepackage com.forethought.ejb.accountType;import javax.ejb.EJBException;import javax.ejb.EJBLocalObject;public interface AccountTypeLocal extends EJBLocalObject {public Integer getId( ) throws EJBException;public String getType( ) throws EJBException;public void setType(String type) throws EJBException;}The local home interface for the AccountType bean is shown in Example E-11.Example E-11.The AccountTypeLocalHome Interfacepackage com.forethought.ejb.accountType;import javax.ejb.CreateException;import javax.ejb.EJBException;import javax.ejb.EJBLocalHome;import javax.ejb.FinderException;public interface AccountTypeLocalHome extends EJBLocalHome {public AccountTypeLocal create(String type)throws CreateException, EJBException;238Building Java"! Enterprise Applications Volume I: Architecturepublic 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 Classpackage 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
[ Pobierz całość w formacie PDF ] zanotowane.pldoc.pisz.plpdf.pisz.plmikr.xlx.pl
|