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

import javax.ejb.EJBException;

public abstract class TiephyBean

implements javax.ejb.EntityBean {

    protected javax.ejb.EntityContext entityCtx = null;

    protected TiephyValue TiephyValue = 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 nomusatie
     * @return the nomusatie
     */
    public abstract java.lang.String getNomusatie();

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

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

    /**
     * get method relation one
     */
    public TierValue getTierValue() {
        // return the value !
        return getTier().getTierValue();
    }

    /**
     * get method relation one
     * @ejb.interface-method view-type="local"
     */
    public void setTierValue(TierValue value) {
        getTier().update(value);
    }

    /**
     * Sets the related TierLocal
     * @param tier the related TierLocal
     */
    public abstract void setTier(TierLocal tier);

    /**
     * Return the value object version of this entity.
     */
    public TiephyValue getTiephyValue() {
        try {
            TiephyValue = new TiephyValue();
            TiephyValue = setColumns(TiephyValue);
            return TiephyValue;
        } 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(TiephyValue value) {
        if (value.nomusatieHasBeenSet()) setNomusatie(value.getNomusatie());
    }

    /**
     * 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
     */
    public java.lang.Integer ejbCreate(TiephyValue value, TierLocal tier)
            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.TIEPHY.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.

        setNomusatie(value.getNomusatie());
        // 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(TiephyValue value, TierLocal tier)
            throws javax.ejb.CreateException {
        // Set CMR fields
        setTier(tier);
    }

    // No
    // D:\IBM\Eclipse3.0\eclipse\workspace\TestBugs\middlegen/src/middlegen/cmp20-tiephy-class-code.txt
    // found.

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

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

    private TiephyValue setColumns(TiephyValue value) {
        value.setNuminttie(getNuminttie());
        value.setNomusatie(getNomusatie());
        return value;
    }
}