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

import javax.ejb.EJBException;


/**
 * 
 *
 */
public abstract class TiemorBean 


    implements javax.ejb.EntityBean {
    
   protected javax.ejb.EntityContext entityCtx = null;
   protected TiemorValue TiemorValue = 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 raisoctie
    * @return the raisoctie
    */
   public abstract java.lang.String getRaisoctie();

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


   /**
    * 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
    */   
   	public void setTierValue(TierValue value) {
		getTier().update(value);
	}
   /**
    * Sets the related test.entity.tiers.TierLocal
    * @param tier the related test.entity.tiers.TierLocal
    *
    */
   public abstract void setTier(TierLocal tier);
  




   /**
    * Return the value object version of this entity.
    */
   public TiemorValue getTiemorValue() {
		try {
			TiemorValue = new TiemorValue();
			TiemorValue = setColumns(TiemorValue);
			return TiemorValue;		    
		} 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.
    */
   public void update(TiemorValue value) {
		if (value.raisoctieHasBeenSet())
	      setRaisoctie(value.getRaisoctie());
   }
   
   /**
    * 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(TiemorValue 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.TIEMOR.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.


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

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

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

   private TiemorValue setColumns(TiemorValue value) {
      value.setNuminttie(getNuminttie());
      value.setRaisoctie(getRaisoctie());
	  return value;
   }
}
