⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orderejb.java

📁 学生注册— 本模块允许新的学生创建和维护他们的帐户信息
💻 JAVA
字号:
package day21ex.order;
import java.util.*;
import java.io.*;
import java.rmi.*;
import javax.naming.*;
import javax.ejb.*;

import day21ex.student.*;
import day21ex.orderlineitem.*;

public abstract class OrderEJB implements EntityBean {
   protected EntityContext ctx;
   public abstract String getOrderId();
   public abstract void setOrderId(String id);
   public abstract Collection getLineItems();
   public abstract void setLineItems(Collection lineItems);
   public abstract StudentLocal getStudent();
   public abstract void setStudent(StudentLocal student);
   public abstract java.sql.Timestamp getOrderDate();
   public abstract void setOrderDate(java.sql.Timestamp timestamp);
   public abstract String getStatus();
   public abstract void setStatus(String status);
   public abstract double getAmount();
   public abstract void setAmount(double amount);
   public double getTotalPrice() {
      double totalPrice = 0;
      Iterator i = getLineItems().iterator();
      while (i.hasNext()) {
         OrderLineItemLocal item = (OrderLineItemLocal) i.next();
         totalPrice += item.getCourse().getFee();
      }
      return totalPrice;
   }
   public void setEntityContext(EntityContext ctx) {
      System.out.println("Order.setEntityContext called");
      this.ctx = ctx;
   }
   public void unsetEntityContext() {
      System.out.println("Order.unsetEntityContext called");
      this.ctx = null; 
   }
   public void ejbActivate() {
      System.out.println("Order.ejbActivate() called.");
   }
   public void ejbPassivate() {
      System.out.println("Order.ejbPassivate () called.");
   }
   public void ejbStore() {
      System.out.println("Order.ejbStore() called.");
   }
   public void ejbLoad() {
      System.out.println("Order.ejbLoad() called.");
   }
   public String ejbCreate(String orderID, StudentLocal student, 
                       Collection lineItems) throws CreateException {
      System.out.println("Order.ejbCreate(" + orderID + ") called");
      setOrderId(orderID);  
      setOrderDate(new java.sql.Timestamp(System.currentTimeMillis()));
      setStatus("submitted");
      return null;
   }
   public String ejbCreate(String orderID, StudentLocal student,
                 String status,double amount) throws CreateException {
      System.out.println("Order.ejbCreate(" + orderID + ") called");
      setOrderId(orderID);
      setOrderDate(new java.sql.Timestamp(System.currentTimeMillis()));
      setStatus(status);
      setAmount(amount);
      return null;
   }
   public String ejbCreate(String orderID, String studentID, 
                         Collection lineItems) throws CreateException {
      try {
         Context ctx = new InitialContext();
         StudentLocalHome home = (StudentLocalHome)
            javax.rmi.PortableRemoteObject.narrow(
               ctx.lookup("day21ex/Student"), StudentLocalHome.class);                
         StudentLocal c = home.findByPrimaryKey(studentID);
         return this.ejbCreate(orderID, c, lineItems);
      }catch (Exception e) {
         e.printStackTrace();
         throw new EJBException(e);
      }
   }
   public String ejbCreate(String orderID, String studentID,
              String status, double amount) throws CreateException {
      try {
         Context ctx = new InitialContext();
         StudentLocalHome home = (StudentLocalHome)
            javax.rmi.PortableRemoteObject.narrow(
               ctx.lookup("day21ex/Student"), StudentLocalHome.class);
         StudentLocal c = home.findByPrimaryKey(studentID);
         return this.ejbCreate(orderID, c,status,amount);
      } catch (Exception e) {
         e.printStackTrace();
         throw new EJBException(e);
      }
   }
   public void ejbPostCreate(String orderLineItemID, StudentLocal student, 
                          Collection lineItems) throws CreateException {
      System.out.println("Order.ejbPostCreate() 1  called");
      setStudent(student);           
   }
   public void ejbPostCreate(String orderLineItemID, 
     String studentID, Collection lineItems) throws CreateException {
      System.out.println("Order.ejbPostCreate() called");
      try{
         Context ctx = new InitialContext();
         StudentLocalHome home = (StudentLocalHome)
            javax.rmi.PortableRemoteObject.narrow(
               ctx.lookup("day21ex/Student"), StudentLocalHome.class);
         StudentLocal student = home.findByPrimaryKey(studentID);
         setStudent(student);
      }catch (Exception e) {
         e.printStackTrace();
         throw new EJBException(e);
      }   
   }
   public void ejbPostCreate(String orderLineItemID, StudentLocal student,
                                             String status,double amount) 
      throws CreateException {
      System.out.println("Order.ejbPostCreate() 1  called");
      setStudent(student);                
   }
   public void ejbPostCreate(String orderLineItemID, String studentID,
                                         String status,double amount) 
      throws CreateException {
      System.out.println("Order.ejbPostCreate() called");
      try{
         Context ctx = new InitialContext();
         StudentLocalHome home = (StudentLocalHome)
            javax.rmi.PortableRemoteObject.narrow(
               ctx.lookup("day21ex/Student"), StudentLocalHome.class);
         StudentLocal student = home.findByPrimaryKey(studentID);
         setStudent(student);
      }catch (Exception e) {
         e.printStackTrace();
         throw new EJBException(e);
      }
   }
   public void ejbRemove() throws RemoveException {
      System.out.println("Order.ejbRemove() called.");
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -