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

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

	/** EdifactordersitemssWhereIAmStandassign*/
	public void addEdifactordersitemssWhereIAmStandassign(nl.reinders.bm.Edifactordersitems value)
	{
		if (value != null && !iEdifactordersitemssWhereIAmStandassign.contains(value))
		{
			iEdifactordersitemssWhereIAmStandassign.add(value);
			value.setStandassign( (nl.reinders.bm.Standassign)this);
		}
	}
	public void removeEdifactordersitemssWhereIAmStandassign(nl.reinders.bm.Edifactordersitems value)
	{
		if (value != null && iEdifactordersitemssWhereIAmStandassign.contains(value))
		{
			iEdifactordersitemssWhereIAmStandassign.remove(value);
			value.setStandassign( (nl.reinders.bm.Standassign)null );
		}
	}
	public java.util.List<nl.reinders.bm.Edifactordersitems> getEdifactordersitemssWhereIAmStandassign() { return iEdifactordersitemssWhereIAmStandassign; }
	@OneToMany(mappedBy = "iStandassign", fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Edifactordersitems.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} )
	private java.util.List<nl.reinders.bm.Edifactordersitems> iEdifactordersitemssWhereIAmStandassign = new java.util.ArrayList<nl.reinders.bm.Edifactordersitems>();

	/** RelstandsalesWhereIAmStandassign*/
	public void addRelstandsalesWhereIAmStandassign(nl.reinders.bm.Relstandsale value)
	{
		if (value != null && !iRelstandsalesWhereIAmStandassign.contains(value))
		{
			iRelstandsalesWhereIAmStandassign.add(value);
			value.setStandassign( (nl.reinders.bm.Standassign)this);
		}
	}
	public void removeRelstandsalesWhereIAmStandassign(nl.reinders.bm.Relstandsale value)
	{
		if (value != null && iRelstandsalesWhereIAmStandassign.contains(value))
		{
			iRelstandsalesWhereIAmStandassign.remove(value);
			value.setStandassign( (nl.reinders.bm.Standassign)null );
		}
	}
	public java.util.List<nl.reinders.bm.Relstandsale> getRelstandsalesWhereIAmStandassign() { return iRelstandsalesWhereIAmStandassign; }
	@OneToMany(mappedBy = "iStandassign", fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Relstandsale.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} )
	private java.util.List<nl.reinders.bm.Relstandsale> iRelstandsalesWhereIAmStandassign = new java.util.ArrayList<nl.reinders.bm.Relstandsale>();

	/** RelstandstocksWhereIAmStandassign*/
	public void addRelstandstocksWhereIAmStandassign(nl.reinders.bm.Relstandstock value)
	{
		if (value != null && !iRelstandstocksWhereIAmStandassign.contains(value))
		{
			iRelstandstocksWhereIAmStandassign.add(value);
			value.setStandassign( (nl.reinders.bm.Standassign)this);
		}
	}
	public void removeRelstandstocksWhereIAmStandassign(nl.reinders.bm.Relstandstock value)
	{
		if (value != null && iRelstandstocksWhereIAmStandassign.contains(value))
		{
			iRelstandstocksWhereIAmStandassign.remove(value);
			value.setStandassign( (nl.reinders.bm.Standassign)null );
		}
	}
	public java.util.List<nl.reinders.bm.Relstandstock> getRelstandstocksWhereIAmStandassign() { return iRelstandstocksWhereIAmStandassign; }
	@OneToMany(mappedBy = "iStandassign", fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Relstandstock.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} )
	private java.util.List<nl.reinders.bm.Relstandstock> iRelstandstocksWhereIAmStandassign = new java.util.ArrayList<nl.reinders.bm.Relstandstock>();


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

	/** Article */
	public nl.reinders.bm.Article getArticle() { return iArticle; }
	public void setArticle(nl.reinders.bm.Article value)
	{
		if (value == iArticle) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Article lValue = iArticle;
			fireVetoableChange(ARTICLE_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeStandassignsWhereIAmArticle( (nl.reinders.bm.Standassign)this );
			iArticle = value;
			if (value != null) value.addStandassignsWhereIAmArticle( (nl.reinders.bm.Standassign)this );
			firePropertyChange(ARTICLE_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.Article.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="articlenr") 
	private nl.reinders.bm.Article iArticle;
	final static public String ARTICLE_PROPERTY_ID = "article";
	final static public Class ARTICLE_PROPERTY_CLASS = nl.reinders.bm.Article.class;
	final static public String ARTICLE_NAME = "Article"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="articlenr", insertable=false, updatable=false)
	private java.math.BigDecimal iArticlenr = null;

	/** Batchtype */
	public nl.reinders.bm.Batchtype getBatchtype() { return iBatchtype; }
	public void setBatchtype(nl.reinders.bm.Batchtype value)
	{
		if (value == iBatchtype) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Batchtype lValue = iBatchtype;
			fireVetoableChange(BATCHTYPE_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeStandassignsWhereIAmBatchtype( (nl.reinders.bm.Standassign)this );
			iBatchtype = value;
			if (value != null) value.addStandassignsWhereIAmBatchtype( (nl.reinders.bm.Standassign)this );
			firePropertyChange(BATCHTYPE_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.Batchtype.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="batchtype") 
	private nl.reinders.bm.Batchtype iBatchtype;
	final static public String BATCHTYPE_PROPERTY_ID = "batchtype";
	final static public Class BATCHTYPE_PROPERTY_CLASS = nl.reinders.bm.Batchtype.class;
	final static public String BATCHTYPE_NAME = "Batchtype"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="batchtype", insertable=false, updatable=false)
	private java.math.BigDecimal iBatchtypenr = null;

	/** Standversion */
	public nl.reinders.bm.Standversion getStandversion() { return iStandversion; }
	public void setStandversion(nl.reinders.bm.Standversion value)
	{
		if (value == iStandversion) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Standversion lValue = iStandversion;
			fireVetoableChange(STANDVERSION_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeStandassignsWhereIAmStandversion( (nl.reinders.bm.Standassign)this );
			iStandversion = value;
			if (value != null) value.addStandassignsWhereIAmStandversion( (nl.reinders.bm.Standassign)this );
			firePropertyChange(STANDVERSION_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.Standversion.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="standversionnr") 
	private nl.reinders.bm.Standversion iStandversion;
	final static public String STANDVERSION_PROPERTY_ID = "standversion";
	final static public Class STANDVERSION_PROPERTY_CLASS = nl.reinders.bm.Standversion.class;
	final static public String STANDVERSION_NAME = "Standversion"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="standversionnr", insertable=false, updatable=false)
	private java.math.BigDecimal iStandversionnr = null;



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

	/** Standassignnr */
	public Integer getStandassignnr() { return iStandassignnr; }
	public void setStandassignnr(Integer value)
	{
		try
		{
			Integer lValue = iStandassignnr;
			if (log4j.isDebugEnabled()) log4j.debug("setStandassignnr: " + lValue + " -> " + value);
			fireVetoableChange(STANDASSIGNNR_PROPERTY_ID, lValue, value);
			iStandassignnr = value;
			firePropertyChange(STANDASSIGNNR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Id @GeneratedValue(generator="standassign.standassignnr", strategy=GenerationType.TABLE) @TableGenerator( name="standassign.standassignnr", pkColumnValue="standassignnr", table="sequence", pkColumnName="seq_name", valueColumnName="seq_count", initialValue=1, allocationSize=10) @Column(name="standassignnr")
	private Integer iStandassignnr = null;
	final static public String STANDASSIGNNR_PROPERTY_ID = "standassignnr";
	final static public Class STANDASSIGNNR_PROPERTY_CLASS = Integer.class;
	final static public String STANDASSIGNNR_NAME = "Standassignnr"; // with this ID you can access the internationalization

	/** Code */
	public Integer getCode() { return iCode; }
	public void setCode(Integer value)
	{
		try
		{
			Integer lValue = iCode;
			if (log4j.isDebugEnabled()) log4j.debug("setCode: " + lValue + " -> " + value);
			fireVetoableChange(CODE_PROPERTY_ID, lValue, value);
			iCode = value;
			firePropertyChange(CODE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="code")
	private Integer iCode = null;
	final static public String CODE_PROPERTY_ID = "code";
	final static public Class CODE_PROPERTY_CLASS = Integer.class;
	final static public String CODE_NAME = "Code"; // with this ID you can access the internationalization

	/** ChangeIndicator */
	public Integer getChangeIndicator() { return iChangeIndicator; }
	public void setChangeIndicator(Integer value)
	{
		try
		{
			Integer lValue = iChangeIndicator;
			if (log4j.isDebugEnabled()) log4j.debug("setChangeIndicator: " + lValue + " -> " + value);
			fireVetoableChange(CHANGEINDICATOR_PROPERTY_ID, lValue, value);
			iChangeIndicator = value;
			firePropertyChange(CHANGEINDICATOR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="change_indicator")
	private Integer iChangeIndicator = null;
	final static public String CHANGEINDICATOR_PROPERTY_ID = "changeIndicator";
	final static public Class CHANGEINDICATOR_PROPERTY_CLASS = Integer.class;
	final static public String CHANGEINDICATOR_NAME = "ChangeIndicator"; // with this ID you can access the internationalization

	/** Ending */
	public Integer getEnding() { return iEnding; }
	public void setEnding(Integer value)
	{
		try
		{
			Integer lValue = iEnding;
			if (log4j.isDebugEnabled()) log4j.debug("setEnding: " + lValue + " -> " + value);
			fireVetoableChange(ENDING_PROPERTY_ID, lValue, value);
			iEnding = value;
			firePropertyChange(ENDING_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="ending")
	private Integer iEnding = null;
	final static public String ENDING_PROPERTY_ID = "ending";
	final static public Class ENDING_PROPERTY_CLASS = Integer.class;
	final static public String ENDING_NAME = "Ending"; // with this ID you can access the internationalization

	/** Ending2 */
	public Integer getEnding2() { return iEnding2; }
	public void setEnding2(Integer value)
	{
		try
		{
			Integer lValue = iEnding2;
			if (log4j.isDebugEnabled()) log4j.debug("setEnding2: " + lValue + " -> " + value);
			fireVetoableChange(ENDING2_PROPERTY_ID, lValue, value);
			iEnding2 = value;
			firePropertyChange(ENDING2_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="ending2")
	private Integer iEnding2 = null;
	final static public String ENDING2_PROPERTY_ID = "ending2";
	final static public Class ENDING2_PROPERTY_CLASS = Integer.class;
	final static public String ENDING2_NAME = "Ending2"; // with this ID you can access the internationalization

	/** Assignean */
	public java.math.BigDecimal getAssignean() { return iAssignean; }
	public void setAssignean(java.math.BigDecimal value)
	{
		try
		{
			java.math.BigDecimal lValue = iAssignean;
			if (log4j.isDebugEnabled()) log4j.debug("setAssignean: " + lValue + " -> " + value);
			fireVetoableChange(ASSIGNEAN_PROPERTY_ID, lValue, value);
			iAssignean = value;
			firePropertyChange(ASSIGNEAN_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="assignean")
	private java.math.BigDecimal iAssignean = null;
	final static public String ASSIGNEAN_PROPERTY_ID = "assignean";
	final static public Class ASSIGNEAN_PROPERTY_CLASS = java.math.BigDecimal.class;
	final static public String ASSIGNEAN_NAME = "Assignean"; // 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

	/** 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


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

	/** Does not clone Standversion because that will cause a conflict with no-duplcates check on code. */
	public Object clone()
	{ 
		nl.reinders.bm.Standassign lNew = new nl.reinders.bm.Standassign();
		lNew.setArticle( getArticle() ); 
		lNew.setBatchtype( getBatchtype() ); 
		// not cloning this property: lNew.setStandversion( getStandversion() ); 
		lNew.setCode( getCode() ); 
		lNew.setChangeIndicator( getChangeIndicator() ); 
		lNew.setEnding( getEnding() ); 
		lNew.setEnding2( getEnding2() ); 
		lNew.setAssignean( getAssignean() ); 
		// not cloning this column: lNew.setDwhmodified( getDwhmodified() ); 
		// not cloning this column: lNew.setDwhby( getDwhby() ); 
		return lNew;
	}
	public nl.reinders.bm.Standassign cloneShallow() { return (nl.reinders.bm.Standassign)clone();}


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

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


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

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

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

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


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

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



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

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


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