// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package javadb;

import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name="orderline")
public class OrderLine {
    private int orderLineId;
    private int orderId;
    private String itemName;
    private BigDecimal itemPrice;
    private int quantity;
    public OrderLine() {
        this(0, 0, "", BigDecimal.ZERO, 0);
    }
    public OrderLine(int orderLineId, int orderId, String itemName, BigDecimal itemPrice, int quantity) {
        this.orderLineId = orderLineId;
        this.orderId = orderId;
        this.itemName = itemName;
        this.itemPrice = itemPrice;
        this.quantity = quantity;
    }
    @Id
    @Column(name="orderlineid")
    public int getOrderLineId() {
        return orderLineId;
    }
    public void setOrderLineId(int orderLineId) {
        this.orderLineId = orderLineId;
    }
    @Column(name="orderid")
    public int getOrderId() {
        return orderId;
    }
    public void setOrderId(int orderId) {
        this.orderId = orderId;
    }
    @Column(name="itemname")
    public String getItemName() {
        return itemName;
    }
    public void setItemName(String itemName) {
        this.itemName = itemName;
    }
    @Column(name="itemprice")
    public BigDecimal getItemPrice() {
        return itemPrice;
    }
    public void setItemPrice(BigDecimal itemPrice) {
        this.itemPrice = itemPrice;
    }
    @Column(name="quantity")
    public int getQuantity() {
        return quantity;
    }
    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }
    @Transient
    public BigDecimal getItemCost() {
        return itemPrice.multiply(new BigDecimal(quantity));
    }
}
