OrderEJB.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:6k
源码类别:
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.");
- }
- }