/*
 * 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 stand.
 * @version    $Revision$
 * @author     $Author$
 */
@MappedSuperclass
abstract public class Stand extends nl.reinders.bm.AbstractBean
implements java.io.Serializable
         , java.lang.Cloneable
         , Comparable<nl.reinders.bm.Stand>
{
	static final long serialVersionUID = 0;
	static final String SOURCECODE_VERSION = "$Revision$";
	static org.apache.log4j.Logger log4j = org.apache.log4j.Logger.getLogger(Stand.class.getName());

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


	/** StandsWhereIAmDerrivedfromstand*/
	public void addStandsWhereIAmDerrivedfromstand(nl.reinders.bm.Stand value)
	{
		if (value != null && !iStandsWhereIAmDerrivedfromstand.contains(value))
		{
			iStandsWhereIAmDerrivedfromstand.add(value);
			value.setDerrivedfromstand( (nl.reinders.bm.Stand)this);
		}
	}
	public void removeStandsWhereIAmDerrivedfromstand(nl.reinders.bm.Stand value)
	{
		if (value != null && iStandsWhereIAmDerrivedfromstand.contains(value))
		{
			iStandsWhereIAmDerrivedfromstand.remove(value);
			value.setDerrivedfromstand( (nl.reinders.bm.Stand)null );
		}
	}
	public java.util.List<nl.reinders.bm.Stand> getStandsWhereIAmDerrivedfromstand() { return iStandsWhereIAmDerrivedfromstand; }
	@OneToMany(mappedBy = "iDerrivedfromstand", fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Stand.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} )
	private java.util.List<nl.reinders.bm.Stand> iStandsWhereIAmDerrivedfromstand = new java.util.ArrayList<nl.reinders.bm.Stand>();

	/** StandversionsWhereIAmStand*/
	public void addStandversionsWhereIAmStand(nl.reinders.bm.Standversion value)
	{
		if (value != null && !iStandversionsWhereIAmStand.contains(value))
		{
			iStandversionsWhereIAmStand.add(value);
			value.setStand( (nl.reinders.bm.Stand)this);
		}
	}
	public void removeStandversionsWhereIAmStand(nl.reinders.bm.Standversion value)
	{
		if (value != null && iStandversionsWhereIAmStand.contains(value))
		{
			iStandversionsWhereIAmStand.remove(value);
			value.setStand( (nl.reinders.bm.Stand)null );
		}
	}
	public java.util.List<nl.reinders.bm.Standversion> getStandversionsWhereIAmStand() { return iStandversionsWhereIAmStand; }
	@OneToMany(mappedBy = "iStand", fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Standversion.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} )
	private java.util.List<nl.reinders.bm.Standversion> iStandversionsWhereIAmStand = new java.util.ArrayList<nl.reinders.bm.Standversion>();


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

	/** Derrivedfromstand */
	public nl.reinders.bm.Stand getDerrivedfromstand() { return iDerrivedfromstand; }
	public void setDerrivedfromstand(nl.reinders.bm.Stand value)
	{
		if (value == iDerrivedfromstand) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Stand lValue = iDerrivedfromstand;
			fireVetoableChange(DERRIVEDFROMSTAND_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeStandsWhereIAmDerrivedfromstand( (nl.reinders.bm.Stand)this );
			iDerrivedfromstand = value;
			if (value != null) value.addStandsWhereIAmDerrivedfromstand( (nl.reinders.bm.Stand)this );
			firePropertyChange(DERRIVEDFROMSTAND_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="derrivedfromstandnr") 
	private nl.reinders.bm.Stand iDerrivedfromstand;
	final static public String DERRIVEDFROMSTAND_PROPERTY_ID = "derrivedfromstand";
	final static public Class DERRIVEDFROMSTAND_PROPERTY_CLASS = nl.reinders.bm.Stand.class;
	final static public String DERRIVEDFROMSTAND_NAME = "Derrivedfromstand"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="derrivedfromstandnr", insertable=false, updatable=false)
	private java.math.BigDecimal iDerrivedfromstandnr = null;



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

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

	/** Standid */
	public String getStandid() { return iStandid; }
	public void setStandid(String value)
	{
		try
		{
			String lValue = iStandid;
			if (log4j.isDebugEnabled()) log4j.debug("setStandid: " + lValue + " -> " + value);
			fireVetoableChange(STANDID_PROPERTY_ID, lValue, value);
			iStandid = value;
			firePropertyChange(STANDID_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="standid")
	private String iStandid = null;
	final static public String STANDID_PROPERTY_ID = "standid";
	final static public Class STANDID_PROPERTY_CLASS = String.class;
	final static public String STANDID_NAME = "Standid"; // with this ID you can access the internationalization

	/** Oldid */
	public String getOldid() { return iOldid; }
	public void setOldid(String value)
	{
		try
		{
			String lValue = iOldid;
			if (log4j.isDebugEnabled()) log4j.debug("setOldid: " + lValue + " -> " + value);
			fireVetoableChange(OLDID_PROPERTY_ID, lValue, value);
			iOldid = value;
			firePropertyChange(OLDID_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="oldid")
	private String iOldid = null;
	final static public String OLDID_PROPERTY_ID = "oldid";
	final static public Class OLDID_PROPERTY_CLASS = String.class;
	final static public String OLDID_NAME = "Oldid"; // with this ID you can access the internationalization

	/** Size */
	public Integer getSize() { return iSize; }
	public void setSize(Integer value)
	{
		try
		{
			Integer lValue = iSize;
			if (log4j.isDebugEnabled()) log4j.debug("setSize: " + lValue + " -> " + value);
			fireVetoableChange(SIZE_PROPERTY_ID, lValue, value);
			iSize = value;
			firePropertyChange(SIZE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="size")
	private Integer iSize = null;
	final static public String SIZE_PROPERTY_ID = "size";
	final static public Class SIZE_PROPERTY_CLASS = Integer.class;
	final static public String SIZE_NAME = "Size"; // 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

	/** Seqnr */
	public Integer getSeqnr() { return iSeqnr; }
	public void setSeqnr(Integer value)
	{
		try
		{
			Integer lValue = iSeqnr;
			if (log4j.isDebugEnabled()) log4j.debug("setSeqnr: " + lValue + " -> " + value);
			fireVetoableChange(SEQNR_PROPERTY_ID, lValue, value);
			iSeqnr = value;
			firePropertyChange(SEQNR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="seqnr")
	private Integer iSeqnr = null;
	final static public String SEQNR_PROPERTY_ID = "seqnr";
	final static public Class SEQNR_PROPERTY_CLASS = Integer.class;
	final static public String SEQNR_NAME = "Seqnr"; // with this ID you can access the internationalization

	/** Inifillsize */
	public Integer getInifillsize() { return iInifillsize; }
	public void setInifillsize(Integer value)
	{
		try
		{
			Integer lValue = iInifillsize;
			if (log4j.isDebugEnabled()) log4j.debug("setInifillsize: " + lValue + " -> " + value);
			fireVetoableChange(INIFILLSIZE_PROPERTY_ID, lValue, value);
			iInifillsize = value;
			firePropertyChange(INIFILLSIZE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="inifillsize")
	private Integer iInifillsize = null;
	final static public String INIFILLSIZE_PROPERTY_ID = "inifillsize";
	final static public Class INIFILLSIZE_PROPERTY_CLASS = Integer.class;
	final static public String INIFILLSIZE_NAME = "Inifillsize"; // with this ID you can access the internationalization

	/** Description */
	public String getDescription() { return iDescription; }
	public void setDescription(String value)
	{
		try
		{
			String lValue = iDescription;
			if (log4j.isDebugEnabled()) log4j.debug("setDescription: " + lValue + " -> " + value);
			fireVetoableChange(DESCRIPTION_PROPERTY_ID, lValue, value);
			iDescription = value;
			firePropertyChange(DESCRIPTION_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="description")
	private String iDescription = null;
	final static public String DESCRIPTION_PROPERTY_ID = "description";
	final static public Class DESCRIPTION_PROPERTY_CLASS = String.class;
	final static public String DESCRIPTION_NAME = "Description"; // 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

	/** Derrivedreason */
	public String getDerrivedreason() { return iDerrivedreason; }
	public void setDerrivedreason(String value)
	{
		try
		{
			String lValue = iDerrivedreason;
			if (log4j.isDebugEnabled()) log4j.debug("setDerrivedreason: " + lValue + " -> " + value);
			fireVetoableChange(DERRIVEDREASON_PROPERTY_ID, lValue, value);
			iDerrivedreason = value;
			firePropertyChange(DERRIVEDREASON_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="derrivedreason")
	private String iDerrivedreason = null;
	final static public String DERRIVEDREASON_PROPERTY_ID = "derrivedreason";
	final static public Class DERRIVEDREASON_PROPERTY_CLASS = String.class;
	final static public String DERRIVEDREASON_NAME = "Derrivedreason"; // with this ID you can access the internationalization


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

	/** clone */
	public Object clone()
	{ 
		nl.reinders.bm.Stand lNew = new nl.reinders.bm.Stand();
		lNew.setDerrivedfromstand( getDerrivedfromstand() ); 
		lNew.setStandid( getStandid() ); 
		lNew.setOldid( getOldid() ); 
		lNew.setSize( getSize() ); 
		lNew.setSeqnr( getSeqnr() ); 
		lNew.setInifillsize( getInifillsize() ); 
		lNew.setDescription( getDescription() ); 
		// not cloning this column: lNew.setDwhmodified( getDwhmodified() ); 
		// not cloning this column: lNew.setDwhby( getDwhby() ); 
		lNew.setDerrivedreason( getDerrivedreason() ); 
		return lNew;
	}
	public nl.reinders.bm.Stand cloneShallow() { return (nl.reinders.bm.Stand)clone();}


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

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


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

	/**
	 * @param standnr
	 */
	static public nl.reinders.bm.Stand findByPK(Integer standnr)
	{
		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 Stand t where t.iStandnr=:standnr");
		lQuery.setParameter("standnr", standnr);
		java.util.List<nl.reinders.bm.Stand> lList = lQuery.getResultList();
	    if (lList.size() == 0) return null;
	    return lList.get(0);
	}

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

	/**
	 * find all entities ordered by
	 */
	static public java.util.List<nl.reinders.bm.Stand> 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 Stand t" + (orderedBy == null ? "" : " order by t." + orderedBy) + "");
		java.util.List<nl.reinders.bm.Stand> lList = lQuery.getResultList();
	    return lList;
	}


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

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



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

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


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