package oracle.fodemo.storefront.entities;

import oracle.jbo.AttributeList;
import oracle.jbo.Key;
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 AddressUsageEOImpl extends EntityImpl {
    public static final int SHAREDADDRESSUSAGETYPES = 14;
    public static final int SHAREDADDRESSOWNERTYPES = 15;
    private static EntityDefImpl mDefinitionObject;

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

            public void put(AddressUsageEOImpl obj, Object value) {
                obj.setAddressUsagesId((DBSequence)value);
            }
        }
        ,
        AssociatedOwnerId {
            public Object get(AddressUsageEOImpl obj) {
                return obj.getAssociatedOwnerId();
            }

            public void put(AddressUsageEOImpl obj, Object value) {
                obj.setAssociatedOwnerId((Number)value);
            }
        }
        ,
        OwnerTypeCode {
            public Object get(AddressUsageEOImpl obj) {
                return obj.getOwnerTypeCode();
            }

            public void put(AddressUsageEOImpl obj, Object value) {
                obj.setOwnerTypeCode((String)value);
            }
        }
        ,
        AddressId {
            public Object get(AddressUsageEOImpl obj) {
                return obj.getAddressId();
            }

            public void put(AddressUsageEOImpl obj, Object value) {
                obj.setAddressId((Number)value);
            }
        }
        ,
        UsageTypeCode {
            public Object get(AddressUsageEOImpl obj) {
                return obj.getUsageTypeCode();
            }

            public void put(AddressUsageEOImpl obj, Object value) {
                obj.setUsageTypeCode((String)value);
            }
        }
        ,
        ExpiredFlag {
            public Object get(AddressUsageEOImpl obj) {
                return obj.getExpiredFlag();
            }

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

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

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

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

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

            public void put(AddressUsageEOImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ,
        Address {
            public Object get(AddressUsageEOImpl obj) {
                return obj.getAddress();
            }

            public void put(AddressUsageEOImpl obj, Object value) {
                obj.setAddress((AddressEOImpl)value);
            }
        }
        ,
        Person {
            public Object get(AddressUsageEOImpl obj) {
                return obj.getPerson();
            }

            public void put(AddressUsageEOImpl obj, Object value) {
                obj.setPerson((PersonEOImpl)value);
            }
        }
        ,
        Supplier {
            public Object get(AddressUsageEOImpl obj) {
                return obj.getSupplier();
            }

            public void put(AddressUsageEOImpl obj, Object value) {
                obj.setSupplier((EntityImpl)value);
            }
        }
        ,
        LookupCodeEO {
            public Object get(AddressUsageEOImpl obj) {
                return obj.getLookupCodeEO();
            }

            public void put(AddressUsageEOImpl obj, Object value) {
                obj.setLookupCodeEO((EntityImpl)value);
            }
        }
        ,
        AddressOwnerTypesVA {
            public Object get(AddressUsageEOImpl obj) {
                return obj.getAddressOwnerTypesVA();
            }

            public void put(AddressUsageEOImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ,
        AddressUsageTypesVA {
            public Object get(AddressUsageEOImpl obj) {
                return obj.getAddressUsageTypesVA();
            }

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

        public abstract Object get(AddressUsageEOImpl object);

        public abstract void put(AddressUsageEOImpl 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 final int ADDRESSUSAGESID = AttributesEnum.AddressUsagesId.index();
    public static final int ASSOCIATEDOWNERID = AttributesEnum.AssociatedOwnerId.index();
    public static final int OWNERTYPECODE = AttributesEnum.OwnerTypeCode.index();
    public static final int ADDRESSID = AttributesEnum.AddressId.index();
    public static final int USAGETYPECODE = AttributesEnum.UsageTypeCode.index();
    public static final int EXPIREDFLAG = AttributesEnum.ExpiredFlag.index();
    public static final int CREATEDBY = AttributesEnum.CreatedBy.index();
    public static final int CREATIONDATE = AttributesEnum.CreationDate.index();
    public static final int LASTUPDATEDBY = AttributesEnum.LastUpdatedBy.index();
    public static final int LASTUPDATEDATE = AttributesEnum.LastUpdateDate.index();
    public static final int OBJECTVERSIONID = AttributesEnum.ObjectVersionId.index();
    public static final int ADDRESS = AttributesEnum.Address.index();
    public static final int PERSON = AttributesEnum.Person.index();
    public static final int SUPPLIER = AttributesEnum.Supplier.index();
    public static final int LOOKUPCODEEO = AttributesEnum.LookupCodeEO.index();
    public static final int ADDRESSOWNERTYPESVA = AttributesEnum.AddressOwnerTypesVA.index();
    public static final int ADDRESSUSAGETYPESVA = AttributesEnum.AddressUsageTypesVA.index();

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


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

    /**Gets the attribute value for AddressUsagesId, using the alias name AddressUsagesId.
     */
    public DBSequence getAddressUsagesId() {
        return (DBSequence)getAttributeInternal(ADDRESSUSAGESID);
    }

    /**Sets <code>value</code> as the attribute value for AddressUsagesId.
     */
    public void setAddressUsagesId(DBSequence value) {
        setAttributeInternal(ADDRESSUSAGESID, value);
    }

    /**Gets the attribute value for AssociatedOwnerId, using the alias name AssociatedOwnerId.
     */
    public Number getAssociatedOwnerId() {
        return (Number)getAttributeInternal(ASSOCIATEDOWNERID);
    }

    /**Sets <code>value</code> as the attribute value for AssociatedOwnerId.
     */
    public void setAssociatedOwnerId(Number value) {
        setAttributeInternal(ASSOCIATEDOWNERID, value);
    }

    /**Gets the attribute value for OwnerTypeCode, using the alias name OwnerTypeCode.
     */
    public String getOwnerTypeCode() {
        return (String)getAttributeInternal(OWNERTYPECODE);
    }

    /**Sets <code>value</code> as the attribute value for OwnerTypeCode.
     */
    public void setOwnerTypeCode(String value) {
        setAttributeInternal(OWNERTYPECODE, value);
    }

    /**Gets the attribute value for AddressId, using the alias name AddressId.
     */
    public Number getAddressId() {
        return (Number)getAttributeInternal(ADDRESSID);
    }

    /**Sets <code>value</code> as the attribute value for AddressId.
     */
    public void setAddressId(Number value) {
        setAttributeInternal(ADDRESSID, value);
    }

    /**Gets the attribute value for UsageTypeCode, using the alias name UsageTypeCode.
     */
    public String getUsageTypeCode() {
        return (String)getAttributeInternal(USAGETYPECODE);
    }

    /**Sets <code>value</code> as the attribute value for UsageTypeCode.
     */
    public void setUsageTypeCode(String value) {
        setAttributeInternal(USAGETYPECODE, value);
    }

    /**Gets the attribute value for ExpiredFlag, using the alias name ExpiredFlag.
     */
    public String getExpiredFlag() {
        return (String)getAttributeInternal(EXPIREDFLAG);
    }

    /**Sets <code>value</code> as the attribute value for ExpiredFlag.
     */
    public void setExpiredFlag(String value) {
        setAttributeInternal(EXPIREDFLAG, 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);
    }


    /**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);
    }


    @Override
    public void postChanges(TransactionEvent transactionEvent) {
        /* If current entity is new or modified */
       if (getPostState() == STATUS_NEW || 
            getPostState() == STATUS_MODIFIED) {
            /* Get the associated Address for the Address Usage */
            AddressEOImpl address = getAddress();
            PersonEOImpl person = getPerson();

            /* If there is an associated product */
            if (address != null) {
                /* And if it's post-status is NEW */
                byte addressPostState = address.getPostState();
            
                String status = this.getStatusName(addressPostState);
                
                if (addressPostState == STATUS_NEW) {
                    /*
                     * Post the Address first, before posting this
                     * entity by calling super below
                     */
                    address.postChanges(transactionEvent);
                }
            }
            if (person != null) {
                if (person.getPostState() == STATUS_NEW){
                    /*
                    * Post the person first, before posting this
                    * entity by calling super below
                    */
                    person.postChanges(transactionEvent);
                }
            }
        }
        super.postChanges(transactionEvent);
    }
    

    private String getStatusName(byte pStatus){
        switch(pStatus){
        case STATUS_INITIALIZED:
            return "INITIALIZED";
        case STATUS_NEW:
            return "NEW";
        case STATUS_MODIFIED:
            return "MODIFIED";
        case STATUS_UNMODIFIED:
            return "UNMODIFIED";
        case STATUS_DEAD:
            return "DEAD";
        case STATUS_DELETED:
            return "DELETED";
        default:
            return Byte.toString(pStatus);

        }
    }
    /**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 PersonEOImpl getPerson() {
        return (PersonEOImpl)getAttributeInternal(PERSON);
    }

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

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

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

    /**Gets the view accessor <code>RowSet</code> SharedAddressUsageTypes
     */
    public RowSet getSharedAddressUsageTypes() {
        return (RowSet)getAttributeInternal(SHAREDADDRESSUSAGETYPES);
    }

    /**Gets the view accessor <code>RowSet</code> SharedAddressOwnerTypes
     */
    public RowSet getSharedAddressOwnerTypes() {
        return (RowSet)getAttributeInternal(SHAREDADDRESSOWNERTYPES);
    }


    @Override
    public void create(AttributeList attributeList) {
        super.create(attributeList);
    }

    /**Gets the view accessor <code>RowSet</code> AddressOwnerTypesVA
     */
    public RowSet getAddressOwnerTypesVA() {
        return (RowSet)getAttributeInternal(ADDRESSOWNERTYPESVA);
    }

    /**Gets the view accessor <code>RowSet</code> AddressUsageTypesVA
     */
    public RowSet getAddressUsageTypesVA() {
        return (RowSet)getAttributeInternal(ADDRESSUSAGETYPESVA);
    }


    /**
     * @param addressUsagesId key constituent

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

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

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

}
