EnrollmentEJB.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- package day21ex.enrollment;
- import java.util.*;
- import java.io.*;
- import java.rmi.*;
- import javax.naming.*;
- import javax.ejb.*;
- import day21ex.student.*;
- import day21ex.course.*;
- public abstract class EnrollmentEJB implements EntityBean {
- protected EntityContext ctx;
- /* get and set methods for cmp fields */
- public abstract String getEnrollmentId();
- public abstract void setEnrollmentId(String id);
- /* get and set methods for relationship fields */
- public abstract StudentLocal getStudent();
- public abstract void setStudent(StudentLocal student);
- public abstract CourseLocal getCourse();
- public abstract void setCourse(CourseLocal course);
- /* Callback methods */
- public void setEntityContext(EntityContext ctx) {}
- public void unsetEntityContext() {
- this.ctx = null;
- }
- public void ejbActivate() {}
- public void ejbPassivate() {}
- public void ejbStore() {}
- public void ejbLoad() {}
- public void ejbRemove() throws RemoveException {}
- public String ejbCreate(String studentId, String courseId)
- throws CreateException {
- setEnrollmentId(getUniqueId());
- return null;
- }
- public void ejbPostCreate(String studentId, String courseId)
- throws CreateException {
- System.out.println("Order.ejbPostCreate() called");
- try{
- Context ctx = new InitialContext();
- StudentLocalHome studentHome = (StudentLocalHome)
- javax.rmi.PortableRemoteObject.narrow(
- ctx.lookup("day21ex/Student"), StudentLocalHome.class);
- StudentLocal student = studentHome.findByPrimaryKey(studentId);
- setStudent(student);
- CourseLocalHome courseHome = (CourseLocalHome)
- javax.rmi.PortableRemoteObject.narrow(
- ctx.lookup("day21ex/Course"), CourseLocalHome.class);
- CourseLocal course = courseHome.findByPrimaryKey(courseId);
- setCourse(course);
- }catch (Exception e) {
- e.printStackTrace();
- throw new EJBException(e);
- }
- }
- String getUniqueId(){
- return new Long(System.currentTimeMillis()).toString();
- }
- }