/*
 * This is autogenerated and should not be modified.
 * Any changes should be made to the super class.
 * Copyright: (c) Reinders Posters
 * Modified:  $Date$
 */

package nl.reinders.bm.generated;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.beans.PropertyVetoException;
import java.beans.VetoableChangeListener;
import java.beans.VetoableChangeSupport;

import javax.persistence.EntityManager;
import javax.persistence.MappedSuperclass;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.SequenceGenerator;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.FetchType;
import javax.persistence.CascadeType;
import javax.persistence.JoinColumn;
import javax.persistence.Query;
import javax.persistence.Transient;

/**
 * A JPA entity class for relationstand.
 * @version    $Revision$
 * @author     $Author$
 */
@MappedSuperclass
abstract public class Relationstand extends nl.reinders.bm.AbstractBean
implements java.io.Serializable
         , java.lang.Cloneable
         , Comparable<nl.reinders.bm.Relationstand>
{
	static final long serialVersionUID = 0;
	static final String SOURCECODE_VERSION = "$Revision$";
	static org.apache.log4j.Logger log4j = org.apache.log4j.Logger.getLogger(Relationstand.class.getName());

	// ===============================================================================================
	// RELATIONS OneToMany


	// ===============================================================================================
	// RELATIONS ManyToOne

	/** Relation */
	public nl.reinders.bm.Relation getRelation() { return iRelation; }
	public void setRelation(nl.reinders.bm.Relation value)
	{
		if (value == iRelation) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Relation lValue = iRelation;
			fireVetoableChange(RELATION_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeRelationstandsWhereIAmRelation( (nl.reinders.bm.Relationstand)this );
			iRelation = value;
			if (value != null) value.addRelationstandsWhereIAmRelation( (nl.reinders.bm.Relationstand)this );
			firePropertyChange(RELATION_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@ManyToOne(fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Relation.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="relationnr") 
	private nl.reinders.bm.Relation iRelation;
	final static public String RELATION_PROPERTY_ID = "relation";
	final static public Class RELATION_PROPERTY_CLASS = nl.reinders.bm.Relation.class;
	final static public String RELATION_NAME = "Relation"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="relationnr", insertable=false, updatable=false)
	private java.math.BigDecimal iRelationnr = null;

	/** Stand */
	public nl.reinders.bm.Stand getStand() { return iStand; }
	public void setStand(nl.reinders.bm.Stand value)
	{
		if (value == iStand) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Stand lValue = iStand;
			fireVetoableChange(STAND_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeRelationstandsWhereIAmStand( (nl.reinders.bm.Relationstand)this );
			iStand = value;
			if (value != null) value.addRelationstandsWhereIAmStand( (nl.reinders.bm.Relationstand)this );
			firePropertyChange(STAND_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@ManyToOne(fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Stand.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="standnr") 
	private nl.reinders.bm.Stand iStand;
	final static public String STAND_PROPERTY_ID = "stand";
	final static public Class STAND_PROPERTY_CLASS = nl.reinders.bm.Stand.class;
	final static public String STAND_NAME = "Stand"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="standnr", insertable=false, updatable=false)
	private java.math.BigDecimal iStandnr = null;



	// ===============================================================================================
	// PROPERTIES

	/** Relationstandnr */
	public Integer getRelationstandnr() { return iRelationstandnr; }
	public void setRelationstandnr(Integer value)
	{
		try
		{
			Integer lValue = iRelationstandnr;
			if (log4j.isDebugEnabled()) log4j.debug("setRelationstandnr: " + lValue + " -> " + value);
			fireVetoableChange(RELATIONSTANDNR_PROPERTY_ID, lValue, value);
			iRelationstandnr = value;
			firePropertyChange(RELATIONSTANDNR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Id @GeneratedValue(generator="relationstand.relationstandnr", strategy=GenerationType.TABLE) @TableGenerator( name="relationstand.relationstandnr", pkColumnValue="relationstandnr", table="sequence", pkColumnName="seq_name", valueColumnName="seq_count", initialValue=1, allocationSize=1) @Column(name="relationstandnr")
	private Integer iRelationstandnr = null;
	final static public String RELATIONSTANDNR_PROPERTY_ID = "relationstandnr";
	final static public Class RELATIONSTANDNR_PROPERTY_CLASS = Integer.class;
	final static public String RELATIONSTANDNR_NAME = "Relationstandnr"; // with this ID you can access the internationalization

	/** Percentage */
	public java.math.BigDecimal getPercentage() { return iPercentage; }
	public void setPercentage(java.math.BigDecimal value)
	{
		try
		{
			java.math.BigDecimal lValue = iPercentage;
			if (log4j.isDebugEnabled()) log4j.debug("setPercentage: " + lValue + " -> " + value);
			fireVetoableChange(PERCENTAGE_PROPERTY_ID, lValue, value);
			iPercentage = value;
			firePropertyChange(PERCENTAGE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="percentage")
	private java.math.BigDecimal iPercentage = null;
	final static public String PERCENTAGE_PROPERTY_ID = "percentage";
	final static public Class PERCENTAGE_PROPERTY_CLASS = java.math.BigDecimal.class;
	final static public String PERCENTAGE_NAME = "Percentage"; // with this ID you can access the internationalization

	/** Lazylock */
	public Integer getLazylock() { return iLazylock; }
	public void setLazylock(Integer value)
	{
		try
		{
			Integer lValue = iLazylock;
			if (log4j.isDebugEnabled()) log4j.debug("setLazylock: " + lValue + " -> " + value);
			fireVetoableChange(LAZYLOCK_PROPERTY_ID, lValue, value);
			iLazylock = value;
			firePropertyChange(LAZYLOCK_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Version @Column(name="lazylock")
	private Integer iLazylock = 0;
	final static public String LAZYLOCK_PROPERTY_ID = "lazylock";
	final static public Class LAZYLOCK_PROPERTY_CLASS = Integer.class;
	final static public String LAZYLOCK_NAME = "Lazylock"; // with this ID you can access the internationalization

	/** Agreements */
	public String getAgreements() { return iAgreements; }
	public void setAgreements(String value)
	{
		try
		{
			String lValue = iAgreements;
			if (log4j.isDebugEnabled()) log4j.debug("setAgreements: " + lValue + " -> " + value);
			fireVetoableChange(AGREEMENTS_PROPERTY_ID, lValue, value);
			iAgreements = value;
			firePropertyChange(AGREEMENTS_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="agreements")
	private String iAgreements = null;
	final static public String AGREEMENTS_PROPERTY_ID = "agreements";
	final static public Class AGREEMENTS_PROPERTY_CLASS = String.class;
	final static public String AGREEMENTS_NAME = "Agreements"; // with this ID you can access the internationalization

	/** Startdate */
	public java.util.Calendar getStartdate() { return iStartdate; }
	public void setStartdate(java.util.Calendar value)
	{
		try
		{
			java.util.Calendar lValue = iStartdate;
			if (log4j.isDebugEnabled()) log4j.debug("setStartdate: " + lValue + " -> " + value);
			fireVetoableChange(STARTDATE_PROPERTY_ID, lValue, value);
			iStartdate = value;
			firePropertyChange(STARTDATE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Temporal(TemporalType.TIMESTAMP) @Column(name="startdate")
	private java.util.Calendar iStartdate = null;
	final static public String STARTDATE_PROPERTY_ID = "startdate";
	final static public Class STARTDATE_PROPERTY_CLASS = java.util.Calendar.class;
	final static public String STARTDATE_NAME = "Startdate"; // with this ID you can access the internationalization

	/** Enddate */
	public java.util.Calendar getEnddate() { return iEnddate; }
	public void setEnddate(java.util.Calendar value)
	{
		try
		{
			java.util.Calendar lValue = iEnddate;
			if (log4j.isDebugEnabled()) log4j.debug("setEnddate: " + lValue + " -> " + value);
			fireVetoableChange(ENDDATE_PROPERTY_ID, lValue, value);
			iEnddate = value;
			firePropertyChange(ENDDATE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Temporal(TemporalType.TIMESTAMP) @Column(name="enddate")
	private java.util.Calendar iEnddate = null;
	final static public String ENDDATE_PROPERTY_ID = "enddate";
	final static public Class ENDDATE_PROPERTY_CLASS = java.util.Calendar.class;
	final static public String ENDDATE_NAME = "Enddate"; // with this ID you can access the internationalization

	/** Dwhmodified */
	public java.util.Calendar getDwhmodified() { return iDwhmodified; }
	public void setDwhmodified(java.util.Calendar value)
	{
		try
		{
			java.util.Calendar lValue = iDwhmodified;
			if (log4j.isDebugEnabled()) log4j.debug("setDwhmodified: " + lValue + " -> " + value);
			fireVetoableChange(DWHMODIFIED_PROPERTY_ID, lValue, value);
			iDwhmodified = value;
			firePropertyChange(DWHMODIFIED_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Temporal(TemporalType.TIMESTAMP) @Column(name="dwhmodified")
	private java.util.Calendar iDwhmodified = new java.util.GregorianCalendar();
	final static public String DWHMODIFIED_PROPERTY_ID = "dwhmodified";
	final static public Class DWHMODIFIED_PROPERTY_CLASS = java.util.Calendar.class;
	final static public String DWHMODIFIED_NAME = "Dwhmodified"; // with this ID you can access the internationalization

	/** Dwhby */
	public Integer getDwhby() { return iDwhby; }
	public void setDwhby(Integer value)
	{
		try
		{
			Integer lValue = iDwhby;
			if (log4j.isDebugEnabled()) log4j.debug("setDwhby: " + lValue + " -> " + value);
			fireVetoableChange(DWHBY_PROPERTY_ID, lValue, value);
			iDwhby = value;
			firePropertyChange(DWHBY_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="dwhby")
	private Integer iDwhby = null;
	final static public String DWHBY_PROPERTY_ID = "dwhby";
	final static public Class DWHBY_PROPERTY_CLASS = Integer.class;
	final static public String DWHBY_NAME = "Dwhby"; // with this ID you can access the internationalization

	/** Inserted */
	public java.util.Calendar getInserted() { return iInserted; }
	public void setInserted(java.util.Calendar value)
	{
		try
		{
			java.util.Calendar lValue = iInserted;
			if (log4j.isDebugEnabled()) log4j.debug("setInserted: " + lValue + " -> " + value);
			fireVetoableChange(INSERTED_PROPERTY_ID, lValue, value);
			iInserted = value;
			firePropertyChange(INSERTED_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Temporal(TemporalType.TIMESTAMP) @Column(name="inserted")
	private java.util.Calendar iInserted = new java.util.GregorianCalendar();
	final static public String INSERTED_PROPERTY_ID = "inserted";
	final static public Class INSERTED_PROPERTY_CLASS = java.util.Calendar.class;
	final static public String INSERTED_NAME = "Inserted"; // with this ID you can access the internationalization


	// ===============================================================================================
	// Clone

	/** clone */
	public Object clone()
	{ 
		nl.reinders.bm.Relationstand lNew = new nl.reinders.bm.Relationstand();
		lNew.setRelation( getRelation() ); 
		lNew.setStand( getStand() ); 
		lNew.setPercentage( getPercentage() ); 
		lNew.setAgreements( getAgreements() ); 
		lNew.setStartdate( getStartdate() ); 
		lNew.setEnddate( getEnddate() ); 
		// not cloning this column: lNew.setDwhmodified( getDwhmodified() ); 
		// not cloning this column: lNew.setDwhby( getDwhby() ); 
		lNew.setInserted( getInserted() ); 
		return lNew;
	}
	public nl.reinders.bm.Relationstand cloneShallow() { return (nl.reinders.bm.Relationstand)clone();}


	// =========================================================================================
	// Comparable

	/**
	 * default compare on primary key
	 */
	public int compareTo(nl.reinders.bm.Relationstand o)
	{
		if (this.getRelationstandnr() == null) return -1;
		if (o == null) return 1;
		return this.getRelationstandnr().compareTo( o.getRelationstandnr() );
	}


	// =========================================================================================
	// DAO

	/**
	 * @param relationstandnr
	 */
	static public nl.reinders.bm.Relationstand findByPK(Integer relationstandnr)
	{
		EntityManager lEntityManager = org.tbee.util.jpa.EntityManagerFinder.findEntityManager();
		if (log4j.isDebugEnabled()) log4j.debug("Using EM #" + Integer.toHexString( lEntityManager.hashCode() ) );
		Query lQuery = lEntityManager.createQuery("select t from Relationstand t where t.iRelationstandnr=:relationstandnr");
		lQuery.setParameter("relationstandnr", relationstandnr);
		java.util.List<nl.reinders.bm.Relationstand> lList = lQuery.getResultList();
	    if (lList.size() == 0) return null;
	    return lList.get(0);
	}

	/**
	 * find all entities
	 */
	static public java.util.List<nl.reinders.bm.Relationstand> findAll()
	{
		return findAllOrderedBy(null);
	}

	/**
	 * find all entities ordered by
	 */
	static public java.util.List<nl.reinders.bm.Relationstand> findAllOrderedBy(String orderedBy)
	{
		EntityManager lEntityManager = org.tbee.util.jpa.EntityManagerFinder.findEntityManager();
		if (log4j.isDebugEnabled()) log4j.debug("Using EM #" + Integer.toHexString( lEntityManager.hashCode() ) );
		Query lQuery = lEntityManager.createQuery("select t from Relationstand t" + (orderedBy == null ? "" : " order by t." + orderedBy) + "");
		java.util.List<nl.reinders.bm.Relationstand> lList = lQuery.getResultList();
	    return lList;
	}


	// =========================================================================================
	// EQUALS

	/**
	 *
	 */
	public boolean equals(Object o)
	{
		if (o == null) return false;
		if (!(o instanceof nl.reinders.bm.Relationstand)) return false;
		nl.reinders.bm.Relationstand lOther = (nl.reinders.bm.Relationstand)o;
		if (
			this.getRelationstandnr() != null && lOther.getRelationstandnr() != null
		)
		{
			return
				   this.getRelationstandnr().equals( lOther.getRelationstandnr() )
			;
		}
		else
			return super.equals(o);
	}



	// =========================================================================================
	// CONVIENIENCE

	/**
	 *
	 */
	public String toString()
	{
		StringBuffer lStringBuffer = new StringBuffer();
		lStringBuffer.append(super.toString());
		lStringBuffer.append(", Relationstandnr="); lStringBuffer.append(getRelationstandnr());
		return lStringBuffer.toString();
	}


	/**
	 * Using the Internationalization class
	 */
	static public String translate(String id)
	{
		return org.tbee.util.Internationalization.getInternationalization().translate(nl.reinders.bm.Relationstand.class, id);
	}
}
