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

📄 orderbo.java

📁 一个netstore的完整代码,他使用了j2ee和webservice技术,并使用ojb o/r管理框架,很不错的
💻 JAVA
字号:
package netstore.businessobjects;

import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
import java.math.BigDecimal;
import java.sql.Timestamp;
/**
 * The Order Business Object, which represents a purchase order that a customer
 * has or is about to place.
 */
public class OrderBO extends BaseBusinessObject {
  // A list of line items for the order
  private List lineItems;
  // The customer who placed the order
  private CustomerBO customer;
  // The current price of the order
  private double totalPrice;
  // The id of the customer
  private Integer customerId;
  // Whether the order is inprocess, shipped, canceled, etc...
  private String orderStatus;
  // The date and time that the order was received
  private Timestamp submittedDate;

  /**
   * Default NoArg Constructor
   */
  public OrderBO() {
    super();
    // Initialize the line items as a linked list to keep them in order
    lineItems = new LinkedList();
  }
  /**
   * Additional constructor that takes the neccessary arguments to initialize
   */
  public OrderBO( Integer id, Integer custId, String orderStatus,
                  Timestamp submittedDate, double price ){
    this.setId(id);
    this.setCustomerId(custId);
    this.setOrderStatus(orderStatus);
    this.setSubmittedDate(submittedDate);
    this.setTotalPrice(price);
  }

  public void setCustomer( CustomerBO owner ){
    customer = owner;
  }

  public CustomerBO getCustomer(){
    return customer;
  }

  public double getTotalPrice(){
    return this.totalPrice;
  }

  private void setTotalPrice( double price ){
    this.totalPrice = price;
  }

  public void setLineItems( List lineItems ){
    this.lineItems = lineItems;
  }

  public List getLineItems(){
    return lineItems;
  }

  public void addLineItem( LineItemBO lineItem ){
    lineItems.add( lineItem );
  }

  public void removeLineItem( LineItemBO lineItem ){
    lineItems.remove( lineItem );
  }

  public void setCustomerId(Integer customerId) {
    this.customerId = customerId;
  }

  public Integer getCustomerId() {
    return customerId;
  }

  public void setOrderStatus(String orderStatus) {
    this.orderStatus = orderStatus;
  }

  public String getOrderStatus() {
    return orderStatus;
  }

  public void setSubmittedDate(Timestamp submittedDate) {
    this.submittedDate = submittedDate;
  }

  public Timestamp getSubmittedDate() {
    return submittedDate;
  }

  private void recalculatePrice(){
    double totalPrice = 0.0;

    if ( getLineItems() != null ){
      Iterator iter = getLineItems().iterator();
      while( iter.hasNext() ){
        // Get the price for the next line item and make sure it's not null
        Double lineItemPrice = ((LineItemBO)iter.next()).getUnitPrice();
        // Check for an invalid lineItem. If found, return null right here
        if (lineItemPrice != null){
          totalPrice += lineItemPrice.doubleValue();
        }
      }
      // Set the price for the order from the calcualted value
      setTotalPrice( totalPrice );
    }
  }
}

⌨️ 快捷键说明

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