package oracle.fodemo.storefront.entities;

import java.sql.SQLException;

import oracle.jbo.AttributeList;
import oracle.jbo.Key;
import oracle.jbo.Row;
import oracle.jbo.RowIterator;
import oracle.jbo.RowSet;
import oracle.jbo.domain.DBSequence;
import oracle.jbo.domain.Date;
import oracle.jbo.domain.Number;
import oracle.jbo.server.AttributeDefImpl;
import oracle.jbo.server.EntityDefImpl;
import oracle.jbo.server.EntityImpl;
import oracle.jbo.server.TransactionEvent;
// ---------------------------------------------------------------------
// ---    File generated by Oracle ADF Business Components Design Time.
// ---    Custom code may be added to this class.
// ---    Warning: Do not modify method signatures of generated methods.
// ---------------------------------------------------------------------
public class OrderEOImpl extends EntityImpl {
    private static EntityDefImpl mDefinitionObject;

    /**
     * AttributesEnum: generated enum for identifying attributes and accessors. Do not modify.
     */
    public enum AttributesEnum {
        OrderId {
            public Object get(OrderEOImpl obj) {
                return obj.getOrderId();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setOrderId((DBSequence)value);
            }
        }
        ,
        OrderDate {
            public Object get(OrderEOImpl obj) {
                return obj.getOrderDate();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setOrderDate((Date)value);
            }
        }
        ,
        OrderShippedDate {
            public Object get(OrderEOImpl obj) {
                return obj.getOrderShippedDate();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setOrderShippedDate((Date)value);
            }
        }
        ,
        OrderStatusCode {
            public Object get(OrderEOImpl obj) {
                return obj.getOrderStatusCode();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setOrderStatusCode((String)value);
            }
        }
        ,
        OrderTotal {
            public Object get(OrderEOImpl obj) {
                return obj.getOrderTotal();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setOrderTotal((Number)value);
            }
        }
        ,
        CustomerId {
            public Object get(OrderEOImpl obj) {
                return obj.getCustomerId();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setCustomerId((Number)value);
            }
        }
        ,
        ShipToName {
            public Object get(OrderEOImpl obj) {
                return obj.getShipToName();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setShipToName((String)value);
            }
        }
        ,
        ShipToAddressId {
            public Object get(OrderEOImpl obj) {
                return obj.getShipToAddressId();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setShipToAddressId((Number)value);
            }
        }
        ,
        ShipToPhoneNumber {
            public Object get(OrderEOImpl obj) {
                return obj.getShipToPhoneNumber();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setShipToPhoneNumber((String)value);
            }
        }
        ,
        ShippingOptionId {
            public Object get(OrderEOImpl obj) {
                return obj.getShippingOptionId();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setShippingOptionId((Number)value);
            }
        }
        ,
        PaymentOptionId {
            public Object get(OrderEOImpl obj) {
                return obj.getPaymentOptionId();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setPaymentOptionId((Number)value);
            }
        }
        ,
        DiscountId {
            public Object get(OrderEOImpl obj) {
                return obj.getDiscountId();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setDiscountId((Number)value);
            }
        }
        ,
        CouponId {
            public Object get(OrderEOImpl obj) {
                return obj.getCouponId();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setCouponId((Number)value);
            }
        }
        ,
        FreeShippingFlag {
            public Object get(OrderEOImpl obj) {
                return obj.getFreeShippingFlag();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setFreeShippingFlag((String)value);
            }
        }
        ,
        CustomerCollectFlag {
            public Object get(OrderEOImpl obj) {
                return obj.getCustomerCollectFlag();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setCustomerCollectFlag((String)value);
            }
        }
        ,
        CollectionWarehouseId {
            public Object get(OrderEOImpl obj) {
                return obj.getCollectionWarehouseId();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setCollectionWarehouseId((Number)value);
            }
        }
        ,
        GiftwrapFlag {
            public Object get(OrderEOImpl obj) {
                return obj.getGiftwrapFlag();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setGiftwrapFlag((String)value);
            }
        }
        ,
        GiftwrapMessage {
            public Object get(OrderEOImpl obj) {
                return obj.getGiftwrapMessage();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setGiftwrapMessage((String)value);
            }
        }
        ,
        CreatedBy {
            public Object get(OrderEOImpl obj) {
                return obj.getCreatedBy();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setCreatedBy((String)value);
            }
        }
        ,
        CreationDate {
            public Object get(OrderEOImpl obj) {
                return obj.getCreationDate();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ,
        LastUpdatedBy {
            public Object get(OrderEOImpl obj) {
                return obj.getLastUpdatedBy();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setLastUpdatedBy((String)value);
            }
        }
        ,
        LastUpdateDate {
            public Object get(OrderEOImpl obj) {
                return obj.getLastUpdateDate();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ,
        ObjectVersionId {
            public Object get(OrderEOImpl obj) {
                return obj.getObjectVersionId();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ,
        CalculatedOrderTotal {
            public Object get(OrderEOImpl obj) {
                return obj.getCalculatedOrderTotal();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setCalculatedOrderTotal((Double)value);
            }
        }
        ,
        DiscountAmount {
            public Object get(OrderEOImpl obj) {
                return obj.getDiscountAmount();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setDiscountAmount((Double)value);
            }
        }
        ,
        TypedCouponCode {
            public Object get(OrderEOImpl obj) {
                return obj.getTypedCouponCode();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setTypedCouponCode((String)value);
            }
        }
        ,
        isCancelable {
            public Object get(OrderEOImpl obj) {
                return obj.getisCancelable();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setisCancelable((Boolean)value);
            }
        }
        ,
        Address {
            public Object get(OrderEOImpl obj) {
                return obj.getAddress();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setAddress((AddressEOImpl)value);
            }
        }
        ,
        DiscountBase {
            public Object get(OrderEOImpl obj) {
                return obj.getDiscountBase();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setDiscountBase((EntityImpl)value);
            }
        }
        ,
        DiscountBase1 {
            public Object get(OrderEOImpl obj) {
                return obj.getDiscountBase1();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setDiscountBase1((EntityImpl)value);
            }
        }
        ,
        CouponUsage {
            public Object get(OrderEOImpl obj) {
                return obj.getCouponUsage();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ,
        OrderItem {
            public Object get(OrderEOImpl obj) {
                return obj.getOrderItem();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ,
        PaymentOption {
            public Object get(OrderEOImpl obj) {
                return obj.getPaymentOption();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setPaymentOption((PaymentOptionEOImpl)value);
            }
        }
        ,
        Person {
            public Object get(OrderEOImpl obj) {
                return obj.getPerson();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setPerson((PersonEOImpl)value);
            }
        }
        ,
        ShippingOptionBase {
            public Object get(OrderEOImpl obj) {
                return obj.getShippingOptionBase();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setShippingOptionBase((EntityImpl)value);
            }
        }
        ,
        Warehouse {
            public Object get(OrderEOImpl obj) {
                return obj.getWarehouse();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setWarehouse((WarehouseEOImpl)value);
            }
        }
        ,
        OrdersVO {
            public Object get(OrderEOImpl obj) {
                return obj.getOrdersVO();
            }

            public void put(OrderEOImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ;
        private static AttributesEnum[] vals = null;
        private static int firstIndex = 0;

        public abstract Object get(OrderEOImpl object);

        public abstract void put(OrderEOImpl object, Object value);

        public int index() {
            return AttributesEnum.firstIndex() + ordinal();
        }

        public static int firstIndex() {
            return firstIndex;
        }

        public static int count() {
            return AttributesEnum.firstIndex() + AttributesEnum.staticValues().length;
        }

        public static AttributesEnum[] staticValues() {
            if (vals == null) {
                vals = AttributesEnum.values();
            }
            return vals;
        }
    }
    public static int ORDERID = AttributesEnum.OrderId.index();
    public static int ORDERDATE = AttributesEnum.OrderDate.index();
    public static int ORDERSHIPPEDDATE = AttributesEnum.OrderShippedDate.index();
    public static int ORDERSTATUSCODE = AttributesEnum.OrderStatusCode.index();
    public static int ORDERTOTAL = AttributesEnum.OrderTotal.index();
    public static int CUSTOMERID = AttributesEnum.CustomerId.index();
    public static int SHIPTONAME = AttributesEnum.ShipToName.index();
    public static int SHIPTOADDRESSID = AttributesEnum.ShipToAddressId.index();
    public static int SHIPTOPHONENUMBER = AttributesEnum.ShipToPhoneNumber.index();
    public static int SHIPPINGOPTIONID = AttributesEnum.ShippingOptionId.index();
    public static int PAYMENTOPTIONID = AttributesEnum.PaymentOptionId.index();
    public static int DISCOUNTID = AttributesEnum.DiscountId.index();
    public static int COUPONID = AttributesEnum.CouponId.index();
    public static int FREESHIPPINGFLAG = AttributesEnum.FreeShippingFlag.index();
    public static int CUSTOMERCOLLECTFLAG = AttributesEnum.CustomerCollectFlag.index();
    public static int COLLECTIONWAREHOUSEID = AttributesEnum.CollectionWarehouseId.index();
    public static int GIFTWRAPFLAG = AttributesEnum.GiftwrapFlag.index();
    public static int GIFTWRAPMESSAGE = AttributesEnum.GiftwrapMessage.index();
    public static int CREATEDBY = AttributesEnum.CreatedBy.index();
    public static int CREATIONDATE = AttributesEnum.CreationDate.index();
    public static int LASTUPDATEDBY = AttributesEnum.LastUpdatedBy.index();
    public static int LASTUPDATEDATE = AttributesEnum.LastUpdateDate.index();
    public static int OBJECTVERSIONID = AttributesEnum.ObjectVersionId.index();
    public static int CALCULATEDORDERTOTAL = AttributesEnum.CalculatedOrderTotal.index();
    public static int DISCOUNTAMOUNT = AttributesEnum.DiscountAmount.index();
    public static int TYPEDCOUPONCODE = AttributesEnum.TypedCouponCode.index();
    public static int ISCANCELABLE = AttributesEnum.isCancelable.index();
    public static int ADDRESS = AttributesEnum.Address.index();
    public static int DISCOUNTBASE = AttributesEnum.DiscountBase.index();
    public static int DISCOUNTBASE1 = AttributesEnum.DiscountBase1.index();
    public static int COUPONUSAGE = AttributesEnum.CouponUsage.index();
    public static int ORDERITEM = AttributesEnum.OrderItem.index();
    public static int PAYMENTOPTION = AttributesEnum.PaymentOption.index();
    public static int PERSON = AttributesEnum.Person.index();
    public static int SHIPPINGOPTIONBASE = AttributesEnum.ShippingOptionBase.index();
    public static int WAREHOUSE = AttributesEnum.Warehouse.index();


    public static final int ORDERSVO = AttributesEnum.OrdersVO.index();

    /**This is the default constructor (do not remove).
     */
    public OrderEOImpl() {
        
    }


    /**
     * @return the definition object for this instance class.
     */
    public static synchronized EntityDefImpl getDefinitionObject() {
        if (mDefinitionObject == null) {
            mDefinitionObject = EntityDefImpl.findDefObject("oracle.fodemo.storefront.entities.OrderEO");
        }
        return mDefinitionObject;
    }

    /** Begin Custom Code **/
    protected void create(AttributeList nameValuePair) {
       super.create(nameValuePair);
       this.setOrderDate(new Date());
    }

    protected void prepareForDML(int dml, TransactionEvent evt) {
            if (dml == DML_INSERT || dml == DML_UPDATE) {
                super.prepareForDML(dml,evt);
                init();
           }
    }

    public void init(){
        EntityImpl discountBase = this.getDiscountBase();
        if(discountBase != null){
            String flag = (String)discountBase.getAttribute("AddFreeShippingFlag");
            EntityImpl discountBase1 = this.getDiscountBase1();
            String flag1 = "N";
            if(discountBase1 != null){
                flag1 = (String)discountBase1.getAttribute("AddFreeShippingFlag");
                if(flag1 != null && (flag.equalsIgnoreCase("Y") || flag1.equalsIgnoreCase("Y"))){
                    this.setFreeShippingFlag("Y");
                } else {
                    this.setFreeShippingFlag("N");
                }
            }
            
            String message = this.getGiftwrapMessage();
            if(message != null && !message.equalsIgnoreCase("")){
                this.setGiftwrapFlag("Y");    
            }       
        }
    }
    
    public Number calculateDiscountAmount()throws SQLException{
        EntityImpl discount = this.getDiscountBase();    
        EntityImpl coupon = this.getDiscountBase1();
        Number discountAmount = processDiscount(discount);   
        Number couponAmount = processDiscount(coupon);
        return new Number(couponAmount.doubleValue() + discountAmount.doubleValue());
    }

    private  Number processDiscount(EntityImpl discount) throws SQLException {
        if(discount != null) {
            Number amount = (Number)discount.getAttribute("DiscountAmount");
            String isPercentage = (String)discount.getAttribute("ApplyAsPercentageFlag");
            if(isPercentage.equalsIgnoreCase("Y")){
                Double total = this.getCalculatedOrderTotal();
                amount = new Number(total*(amount.doubleValue()/100)); 
            }        
            return amount;
        } else {
            return new Number();
        }
    }

    /** End Custom Code **/

    /**Gets the attribute value for OrderId, using the alias name OrderId.
     */
    public DBSequence getOrderId() {
        return (DBSequence)getAttributeInternal(ORDERID);
    }

    /**Sets <code>value</code> as the attribute value for OrderId.
     */
    public void setOrderId(DBSequence value) {
        setAttributeInternal(ORDERID, value);
    }

    /**Gets the attribute value for OrderDate, using the alias name OrderDate.
     */
    public Date getOrderDate() {
        return (Date)getAttributeInternal(ORDERDATE);
    }

    /**Sets <code>value</code> as the attribute value for OrderDate.
     */
    public void setOrderDate(Date value) {
        setAttributeInternal(ORDERDATE, value);
    }

    /**Gets the attribute value for OrderShippedDate, using the alias name OrderShippedDate.
     */
    public Date getOrderShippedDate() {
        return (Date)getAttributeInternal(ORDERSHIPPEDDATE);
    }

    /**Sets <code>value</code> as the attribute value for OrderShippedDate.
     */
    public void setOrderShippedDate(Date value) {
        setAttributeInternal(ORDERSHIPPEDDATE, value);
    }

    /**Gets the attribute value for OrderStatusCode, using the alias name OrderStatusCode.
     */
    public String getOrderStatusCode() {
        return (String)getAttributeInternal(ORDERSTATUSCODE);
    }

    /**Sets <code>value</code> as the attribute value for OrderStatusCode.
     */
    public void setOrderStatusCode(String value) {
        setAttributeInternal(ORDERSTATUSCODE, value);
    }

    /**Gets the attribute value for OrderTotal, using the alias name OrderTotal.
     */
    public Number getOrderTotal() {
        return (Number)getAttributeInternal(ORDERTOTAL);
    }

    /**Sets <code>value</code> as the attribute value for OrderTotal.
     */
    public void setOrderTotal(Number value) {
        setAttributeInternal(ORDERTOTAL, value);
    }

    /**Gets the attribute value for CustomerId, using the alias name CustomerId.
     */
    public Number getCustomerId() {
        return (Number)getAttributeInternal(CUSTOMERID);
    }

    /**Sets <code>value</code> as the attribute value for CustomerId.
     */
    public void setCustomerId(Number value) {
        setAttributeInternal(CUSTOMERID, value);
    }

    /**Gets the attribute value for ShipToName, using the alias name ShipToName.
     */
    public String getShipToName() {
        return (String)getAttributeInternal(SHIPTONAME);
    }

    /**Sets <code>value</code> as the attribute value for ShipToName.
     */
    public void setShipToName(String value) {
        setAttributeInternal(SHIPTONAME, value);
    }

    /**Gets the attribute value for ShipToAddressId, using the alias name ShipToAddressId.
     */
    public Number getShipToAddressId() {
        return (Number)getAttributeInternal(SHIPTOADDRESSID);
    }

    /**Sets <code>value</code> as the attribute value for ShipToAddressId.
     */
    public void setShipToAddressId(Number value) {
        setAttributeInternal(SHIPTOADDRESSID, value);
    }

    /**Gets the attribute value for ShipToPhoneNumber, using the alias name ShipToPhoneNumber.
     */
    public String getShipToPhoneNumber() {
        return (String)getAttributeInternal(SHIPTOPHONENUMBER);
    }

    /**Sets <code>value</code> as the attribute value for ShipToPhoneNumber.
     */
    public void setShipToPhoneNumber(String value) {
        setAttributeInternal(SHIPTOPHONENUMBER, value);
    }

    /**Gets the attribute value for ShippingOptionId, using the alias name ShippingOptionId.
     */
    public Number getShippingOptionId() {
        return (Number)getAttributeInternal(SHIPPINGOPTIONID);
    }

    /**Sets <code>value</code> as the attribute value for ShippingOptionId.
     */
    public void setShippingOptionId(Number value) {
        setAttributeInternal(SHIPPINGOPTIONID, value);
    }

    /**Gets the attribute value for PaymentOptionId, using the alias name PaymentOptionId.
     */
    public Number getPaymentOptionId() {
        return (Number)getAttributeInternal(PAYMENTOPTIONID);
    }

    /**Sets <code>value</code> as the attribute value for PaymentOptionId.
     */
    public void setPaymentOptionId(Number value) {
        setAttributeInternal(PAYMENTOPTIONID, value);
    }

    /**Gets the attribute value for DiscountId, using the alias name DiscountId.
     */
    public Number getDiscountId() {
        return (Number)getAttributeInternal(DISCOUNTID);
    }

    /**Sets <code>value</code> as the attribute value for DiscountId.
     */
    public void setDiscountId(Number value) {
        setAttributeInternal(DISCOUNTID, value);
    }

    /**Gets the attribute value for CouponId, using the alias name CouponId.
     */
    public Number getCouponId() {
        return (Number)getAttributeInternal(COUPONID);
    }

    /**Sets <code>value</code> as the attribute value for CouponId.
     */
    public void setCouponId(Number value) {
        setAttributeInternal(COUPONID, value);
    }

    /**Gets the attribute value for FreeShippingFlag, using the alias name FreeShippingFlag.
     */
    public String getFreeShippingFlag() {
        return (String)getAttributeInternal(FREESHIPPINGFLAG);
    }

    /**Sets <code>value</code> as the attribute value for FreeShippingFlag.
     */
    public void setFreeShippingFlag(String value) {
        setAttributeInternal(FREESHIPPINGFLAG, value);
    }

    /**Gets the attribute value for CustomerCollectFlag, using the alias name CustomerCollectFlag.
     */
    public String getCustomerCollectFlag() {
        return (String)getAttributeInternal(CUSTOMERCOLLECTFLAG);
    }

    /**Sets <code>value</code> as the attribute value for CustomerCollectFlag.
     */
    public void setCustomerCollectFlag(String value) {
        setAttributeInternal(CUSTOMERCOLLECTFLAG, value);
    }

    /**Gets the attribute value for CollectionWarehouseId, using the alias name CollectionWarehouseId.
     */
    public Number getCollectionWarehouseId() {
        return (Number)getAttributeInternal(COLLECTIONWAREHOUSEID);
    }

    /**Sets <code>value</code> as the attribute value for CollectionWarehouseId.
     */
    public void setCollectionWarehouseId(Number value) {
        setAttributeInternal(COLLECTIONWAREHOUSEID, value);
    }

    /**Gets the attribute value for GiftwrapFlag, using the alias name GiftwrapFlag.
     */
    public String getGiftwrapFlag() {
        return (String)getAttributeInternal(GIFTWRAPFLAG);
    }

    /**Sets <code>value</code> as the attribute value for GiftwrapFlag.
     */
    public void setGiftwrapFlag(String value) {
        setAttributeInternal(GIFTWRAPFLAG, value);
    }

    /**Gets the attribute value for GiftwrapMessage, using the alias name GiftwrapMessage.
     */
    public String getGiftwrapMessage() {
        return (String)getAttributeInternal(GIFTWRAPMESSAGE);
    }

    /**Sets <code>value</code> as the attribute value for GiftwrapMessage.
     */
    public void setGiftwrapMessage(String value) {
        setAttributeInternal(GIFTWRAPMESSAGE, value);
    }

    /**Gets the attribute value for CreatedBy, using the alias name CreatedBy.
     */
    public String getCreatedBy() {
        return (String)getAttributeInternal(CREATEDBY);
    }

    /**Sets <code>value</code> as the attribute value for CreatedBy.
     */
    public void setCreatedBy(String value) {
        setAttributeInternal(CREATEDBY, value);
    }

    /**Gets the attribute value for CreationDate, using the alias name CreationDate.
     */
    public Date getCreationDate() {
        return (Date)getAttributeInternal(CREATIONDATE);
    }

    /**Gets the attribute value for LastUpdatedBy, using the alias name LastUpdatedBy.
     */
    public String getLastUpdatedBy() {
        return (String)getAttributeInternal(LASTUPDATEDBY);
    }

    /**Sets <code>value</code> as the attribute value for LastUpdatedBy.
     */
    public void setLastUpdatedBy(String value) {
        setAttributeInternal(LASTUPDATEDBY, value);
    }

    /**Gets the attribute value for LastUpdateDate, using the alias name LastUpdateDate.
     */
    public Date getLastUpdateDate() {
        return (Date)getAttributeInternal(LASTUPDATEDATE);
    }

    /**Gets the attribute value for ObjectVersionId, using the alias name ObjectVersionId.
     */
    public Number getObjectVersionId() {
        return (Number)getAttributeInternal(OBJECTVERSIONID);
    }

    /**Gets the attribute value for CalculatedOrderTotal, using the alias name CalculatedOrderTotal.
     */
    public Double getCalculatedOrderTotal() {
        RowIterator rowItr = this.getOrderItem();
        Double total = 0.0;
        while(rowItr.hasNext()){
            Row row = rowItr.next();
            Number unitPrice = (Number)row.getAttribute("ListPrice");
            Integer quantity = (Integer)row.getAttribute("Quantity");
            total += (unitPrice.doubleValue() * quantity.intValue());   
        }
        return total;
    }

    /**
     * Sets <code>value</code> as the attribute value for CalculatedOrderTotal.
     */
    public void setCalculatedOrderTotal(Double value) {
        setAttributeInternal(CALCULATEDORDERTOTAL, value);
    }

    /**Gets the attribute value for DiscountAmount, using the alias name DiscountAmount.
     */
    public Double getDiscountAmount() {
        try {
            Number amount = calculateDiscountAmount();
            return amount.doubleValue();
        } catch (SQLException e){
            System.out.println("SQLException error");
        }
        return (Double)getAttributeInternal(DISCOUNTAMOUNT);
    }

    /**Sets <code>value</code> as the attribute value for DiscountAmount.
     */
    public void setDiscountAmount(Double value) {
        try {
            Number amount = calculateDiscountAmount();
            value = amount.doubleValue();
        } catch (SQLException e){
            System.out.println("SQLException error");
        }
        setAttributeInternal(DISCOUNTAMOUNT, value);
    }

    /**Gets the attribute value for TypedCouponCode, using the alias name TypedCouponCode.
     */
    public String getTypedCouponCode() {
        return (String)getAttributeInternal(TYPEDCOUPONCODE);
    }

    /**Sets <code>value</code> as the attribute value for TypedCouponCode.
     */
    public void setTypedCouponCode(String value) {
        setAttributeInternal(TYPEDCOUPONCODE, value);
    }

    /**getAttrInvokeAccessor: generated method. Do not modify.
     */
    protected Object getAttrInvokeAccessor(int index, 
                                           AttributeDefImpl attrDef) throws Exception {
        if ((index >= AttributesEnum.firstIndex()) && (index < AttributesEnum.count())) {
            return AttributesEnum.staticValues()[index - AttributesEnum.firstIndex()].get(this);
        }
        return super.getAttrInvokeAccessor(index, attrDef);
    }

    /**setAttrInvokeAccessor: generated method. Do not modify.
     */
    protected void setAttrInvokeAccessor(int index, Object value, 
                                         AttributeDefImpl attrDef) throws Exception {
        if ((index >= AttributesEnum.firstIndex()) && (index < AttributesEnum.count())) {
            AttributesEnum.staticValues()[index - AttributesEnum.firstIndex()].put(this, value);
            return;
        }
        super.setAttrInvokeAccessor(index, value, attrDef);
    }

    /**Gets the associated entity AddressEOImpl.
     */
    public AddressEOImpl getAddress() {
        return (AddressEOImpl)getAttributeInternal(ADDRESS);
    }

    /**Sets <code>value</code> as the associated entity AddressEOImpl.
     */
    public void setAddress(AddressEOImpl value) {
        setAttributeInternal(ADDRESS, value);
    }

    /**Gets the associated entity oracle.jbo.server.EntityImpl.
     */
    public EntityImpl getDiscountBase() {
        return (EntityImpl)getAttributeInternal(DISCOUNTBASE);
    }

    /**Sets <code>value</code> as the associated entity oracle.jbo.server.EntityImpl.
     */
    public void setDiscountBase(EntityImpl value) {
        setAttributeInternal(DISCOUNTBASE, value);
    }

    /**Gets the associated entity oracle.jbo.server.EntityImpl.
     */
    public EntityImpl getDiscountBase1() {
        return (EntityImpl)getAttributeInternal(DISCOUNTBASE1);
    }

    /**Sets <code>value</code> as the associated entity oracle.jbo.server.EntityImpl.
     */
    public void setDiscountBase1(EntityImpl value) {
        setAttributeInternal(DISCOUNTBASE1, value);
    }

    /**Gets the associated entity oracle.jbo.RowIterator.
     */
    public RowIterator getCouponUsage() {
        return (RowIterator)getAttributeInternal(COUPONUSAGE);
    }

    /**Gets the associated entity oracle.jbo.RowIterator.
     */
    public RowIterator getOrderItem() {
        return (RowIterator)getAttributeInternal(ORDERITEM);
    }

    /**Gets the associated entity oracle.jbo.server.EntityImpl.
     */
    public PaymentOptionEOImpl getPaymentOption() {
        return (PaymentOptionEOImpl)getAttributeInternal(PAYMENTOPTION);
    }

    /**Sets <code>value</code> as the associated entity oracle.jbo.server.EntityImpl.
     */
    public void setPaymentOption(PaymentOptionEOImpl value) {
        setAttributeInternal(PAYMENTOPTION, value);
    }

    /**Gets the associated entity PersonEOImpl.
     */
    public PersonEOImpl getPerson() {
        return (PersonEOImpl)getAttributeInternal(PERSON);
    }

    /**Sets <code>value</code> as the associated entity PersonEOImpl.
     */
    public void setPerson(PersonEOImpl value) {
        setAttributeInternal(PERSON, value);
    }

    /**Gets the associated entity oracle.jbo.server.EntityImpl.
     */
    public EntityImpl getShippingOptionBase() {
        return (EntityImpl)getAttributeInternal(SHIPPINGOPTIONBASE);
    }

    /**Sets <code>value</code> as the associated entity oracle.jbo.server.EntityImpl.
     */
    public void setShippingOptionBase(EntityImpl value) {
        setAttributeInternal(SHIPPINGOPTIONBASE, value);
    }

    /**Gets the associated entity oracle.jbo.server.EntityImpl.
     */
    public WarehouseEOImpl getWarehouse() {
        return (WarehouseEOImpl)getAttributeInternal(WAREHOUSE);
    }

    /**Sets <code>value</code> as the associated entity oracle.jbo.server.EntityImpl.
     */
    public void setWarehouse(WarehouseEOImpl value) {
        setAttributeInternal(WAREHOUSE, value);
    }

    /**Gets the view accessor <code>RowSet</code> OrdersVO
     */
    public RowSet getOrdersVO() {
        return (RowSet)getAttributeInternal(ORDERSVO);
    }


    /**
     * @param orderId key constituent

     * @return a Key object based on given key constituents.
     */
    public static Key createPrimaryKey(DBSequence orderId) {
        return new Key(new Object[]{orderId});
    }

    /**Gets the attribute value for isCancelable, using the alias name isCancelable.
     */
    public Boolean getisCancelable() {
        return (Boolean)getAttributeInternal(ISCANCELABLE);
    }

    /**Sets <code>value</code> as the attribute value for isCancelable.
     */
    public void setisCancelable(Boolean value) {
        setAttributeInternal(ISCANCELABLE, value);
    }

}
