package org.objectweb.jonas.jtests.beans.relation.tier;

import javax.ejb.EJBException;

public abstract class TierBean

implements javax.ejb.EntityBean {

    protected javax.ejb.EntityContext entityCtx = null;

    protected TierValue TierValue = null;

    /**
     * Returns the numinttie
     * @return the numinttie
     */
    public abstract java.lang.Integer getNuminttie();

    /**
     * Sets the numinttie
     * @param numinttie the new numinttie value
     */
    public abstract void setNuminttie(java.lang.Integer numinttie);

    /**
     * Returns the emailtie
     * @return the emailtie
     */
    public abstract java.lang.String getEmailtie();

    /**
     * Sets the emailtie
     * @param emailtie the new emailtie value
     */
    public abstract void setEmailtie(java.lang.String emailtie);


    /**
     * This is a bi-directional one-to-one relationship CMR method
     * @return the related TiephyLocal.
     */
    public abstract TiephyLocal getTiephy();

    /**
     * get method relation one
     */
    public TiephyValue getTiephyValue() {
        // return the value !
        return getTiephy().getTiephyValue();
    }

    /**
     * get method relation one
     */
    public void setTiephyValue(TiephyValue value) {
        getTiephy().update(value);
    }

    /**
     * Sets the related test.entity.tiephy.TiephyLocal
     */
    public abstract void setTiephy(TiephyLocal tiephy);

    /**
     * This is a bi-directional one-to-one relationship CMR method
     * @return the related TiemorLocal.
     */
    public abstract TiemorLocal getTiemor();

    /**
     * get method relation one
     */
    public TiemorValue getTiemorValue() {
        // return the value !
        return getTiemor().getTiemorValue();
    }

    /**
     * get method relation one
     */
    public void setTiemorValue(TiemorValue value) {
        getTiemor().update(value);
    }

    /**
     * Sets the related test.entity.tiemor.TiemorLocal
     * @param tiemor the related TiemorLocal
     */
    public abstract void setTiemor(TiemorLocal tiemor);

    /**
     * Return the value object version of this entity.
     */
    public TierValue getTierValue() {
        try {
            TierValue = new TierValue();
            TierValue = setColumns(TierValue);
            return TierValue;
        } catch (EJBException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;

    }

    /**
     * Update the value object version of this entity.
     * @ejb.interface-method view-type="local"
     */
    public void update(TierValue value) {
        if (value.emailtieHasBeenSet()) setEmailtie(value.getEmailtie());
    }

    /**
     * Creates an instance based on a value object When the client invokes a
     * create method, the EJB container invokes the ejbCreate method. Typically,
     * an ejbCreate method in an entity bean performs the following tasks:
     * <UL>
     * <LI>Inserts the entity state into the database.</LI>
     * <LI>Initializes the instance variables.</LI>
     * <LI>Returns the primary key.</LI>
     * </UL>
     * @param value the value object used to initialise the new instance
     * @return the primary key of the new instance
     * @ejb.create-method view-type="local"
     */
    public java.lang.Integer ejbCreate(TierValue value) throws javax.ejb.CreateException {
        // Use Middlegen's Sequence Block PK generator. Only works for numeric
        // fields
        try {
            SequenceSessionLocal sequenceGenerator = SequenceSessionUtil.getLocalHome().create();
            setNuminttie(new java.lang.Integer(Integer.toString(sequenceGenerator
                    .getNextSequenceNumber("CNEDI.TIERS.NUMINTTIE"))));
        } catch (javax.naming.NamingException e) {
            throw new javax.ejb.CreateException(e.getMessage());
        }
        // Use XDoclet's GUID generator. Only works for String fields
        // This requires <utilobject includeGUID="true"/> in ejbdoclet.

        setEmailtie(value.getEmailtie());
        // EJB 2.0 spec says return null for CMP ejbCreate methods.
        return null;
    }

    /**
     * The container invokes this method immediately after it calls ejbCreate.
     * @param value the value object used to initialise the new instance
     */
    public void ejbPostCreate(TierValue value) throws javax.ejb.CreateException {
    }


    public void setEntityContext(javax.ejb.EntityContext entityCtx) {
        this.entityCtx = entityCtx;
    }

    public void unsetEntityContext() {
        this.entityCtx = null;
    }

    private TierValue setColumns(TierValue value) {
        value.setNuminttie(getNuminttie());
        value.setEmailtie(getEmailtie());
        return value;
    }
}