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

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

	/** BatchbuyorderlinesWhereIAmBuyorderline*/
	public void addBatchbuyorderlinesWhereIAmBuyorderline(nl.reinders.bm.Batchbuyorderline value)
	{
		if (value != null && !iBatchbuyorderlinesWhereIAmBuyorderline.contains(value))
		{
			iBatchbuyorderlinesWhereIAmBuyorderline.add(value);
			value.setBuyorderline( (nl.reinders.bm.Buyorderline)this);
		}
	}
	public void removeBatchbuyorderlinesWhereIAmBuyorderline(nl.reinders.bm.Batchbuyorderline value)
	{
		if (value != null && iBatchbuyorderlinesWhereIAmBuyorderline.contains(value))
		{
			iBatchbuyorderlinesWhereIAmBuyorderline.remove(value);
			value.setBuyorderline( (nl.reinders.bm.Buyorderline)null );
		}
	}
	public java.util.List<nl.reinders.bm.Batchbuyorderline> getBatchbuyorderlinesWhereIAmBuyorderline() { return iBatchbuyorderlinesWhereIAmBuyorderline; }
	@OneToMany(mappedBy = "iBuyorderline", fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Batchbuyorderline.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} )
	private java.util.List<nl.reinders.bm.Batchbuyorderline> iBatchbuyorderlinesWhereIAmBuyorderline = new java.util.ArrayList<nl.reinders.bm.Batchbuyorderline>();

	/** BuyorderlinesWhereIAmSubBuyorderline*/
	public void addBuyorderlinesWhereIAmSubBuyorderline(nl.reinders.bm.Buyorderline value)
	{
		if (value != null && !iBuyorderlinesWhereIAmSubBuyorderline.contains(value))
		{
			iBuyorderlinesWhereIAmSubBuyorderline.add(value);
			value.setSubBuyorderline( (nl.reinders.bm.Buyorderline)this);
		}
	}
	public void removeBuyorderlinesWhereIAmSubBuyorderline(nl.reinders.bm.Buyorderline value)
	{
		if (value != null && iBuyorderlinesWhereIAmSubBuyorderline.contains(value))
		{
			iBuyorderlinesWhereIAmSubBuyorderline.remove(value);
			value.setSubBuyorderline( (nl.reinders.bm.Buyorderline)null );
		}
	}
	public java.util.List<nl.reinders.bm.Buyorderline> getBuyorderlinesWhereIAmSubBuyorderline() { return iBuyorderlinesWhereIAmSubBuyorderline; }
	@OneToMany(mappedBy = "iSubBuyorderline", fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Buyorderline.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} )
	private java.util.List<nl.reinders.bm.Buyorderline> iBuyorderlinesWhereIAmSubBuyorderline = new java.util.ArrayList<nl.reinders.bm.Buyorderline>();

	/** ReservationsWhereIAmBuyorderline*/
	public void addReservationsWhereIAmBuyorderline(nl.reinders.bm.Reservation value)
	{
		if (value != null && !iReservationsWhereIAmBuyorderline.contains(value))
		{
			iReservationsWhereIAmBuyorderline.add(value);
			value.setBuyorderline( (nl.reinders.bm.Buyorderline)this);
		}
	}
	public void removeReservationsWhereIAmBuyorderline(nl.reinders.bm.Reservation value)
	{
		if (value != null && iReservationsWhereIAmBuyorderline.contains(value))
		{
			iReservationsWhereIAmBuyorderline.remove(value);
			value.setBuyorderline( (nl.reinders.bm.Buyorderline)null );
		}
	}
	public java.util.List<nl.reinders.bm.Reservation> getReservationsWhereIAmBuyorderline() { return iReservationsWhereIAmBuyorderline; }
	@OneToMany(mappedBy = "iBuyorderline", fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Reservation.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} )
	private java.util.List<nl.reinders.bm.Reservation> iReservationsWhereIAmBuyorderline = new java.util.ArrayList<nl.reinders.bm.Reservation>();


	// ===============================================================================================
	// 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.removeBuyorderlinesWhereIAmArticle( (nl.reinders.bm.Buyorderline)this );
			iArticle = value;
			if (value != null) value.addBuyorderlinesWhereIAmArticle( (nl.reinders.bm.Buyorderline)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;

	/** Buyorder */
	public nl.reinders.bm.Buyorder getBuyorder() { return iBuyorder; }
	public void setBuyorder(nl.reinders.bm.Buyorder value)
	{
		if (value == iBuyorder) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Buyorder lValue = iBuyorder;
			fireVetoableChange(BUYORDER_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeBuyorderlinesWhereIAmBuyorder( (nl.reinders.bm.Buyorderline)this );
			iBuyorder = value;
			if (value != null) value.addBuyorderlinesWhereIAmBuyorder( (nl.reinders.bm.Buyorderline)this );
			firePropertyChange(BUYORDER_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.Buyorder.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="buyordernr") 
	private nl.reinders.bm.Buyorder iBuyorder;
	final static public String BUYORDER_PROPERTY_ID = "buyorder";
	final static public Class BUYORDER_PROPERTY_CLASS = nl.reinders.bm.Buyorder.class;
	final static public String BUYORDER_NAME = "Buyorder"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="buyordernr", insertable=false, updatable=false)
	private java.math.BigDecimal iBuyordernr = null;

	/** SubBuyorderline */
	public nl.reinders.bm.Buyorderline getSubBuyorderline() { return iSubBuyorderline; }
	public void setSubBuyorderline(nl.reinders.bm.Buyorderline value)
	{
		if (value == iSubBuyorderline) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Buyorderline lValue = iSubBuyorderline;
			fireVetoableChange(SUBBUYORDERLINE_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeBuyorderlinesWhereIAmSubBuyorderline( (nl.reinders.bm.Buyorderline)this );
			iSubBuyorderline = value;
			if (value != null) value.addBuyorderlinesWhereIAmSubBuyorderline( (nl.reinders.bm.Buyorderline)this );
			firePropertyChange(SUBBUYORDERLINE_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.Buyorderline.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="sub_buyorderlinenr") 
	private nl.reinders.bm.Buyorderline iSubBuyorderline;
	final static public String SUBBUYORDERLINE_PROPERTY_ID = "subBuyorderline";
	final static public Class SUBBUYORDERLINE_PROPERTY_CLASS = nl.reinders.bm.Buyorderline.class;
	final static public String SUBBUYORDERLINE_NAME = "SubBuyorderline"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="sub_buyorderlinenr", insertable=false, updatable=false)
	private java.math.BigDecimal iSubBuyorderlinenr = null;



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

	/** Buyorderlinenr */
	public Integer getBuyorderlinenr() { return iBuyorderlinenr; }
	public void setBuyorderlinenr(Integer value)
	{
		try
		{
			Integer lValue = iBuyorderlinenr;
			if (log4j.isDebugEnabled()) log4j.debug("setBuyorderlinenr: " + lValue + " -> " + value);
			fireVetoableChange(BUYORDERLINENR_PROPERTY_ID, lValue, value);
			iBuyorderlinenr = value;
			firePropertyChange(BUYORDERLINENR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Id @GeneratedValue(generator="buyorderline.buyorderlinenr", strategy=GenerationType.TABLE) @TableGenerator( name="buyorderline.buyorderlinenr", pkColumnValue="buyorderlinenr", table="sequence", pkColumnName="seq_name", valueColumnName="seq_count", initialValue=1, allocationSize=1) @Column(name="buyorderlinenr")
	private Integer iBuyorderlinenr = null;
	final static public String BUYORDERLINENR_PROPERTY_ID = "buyorderlinenr";
	final static public Class BUYORDERLINENR_PROPERTY_CLASS = Integer.class;
	final static public String BUYORDERLINENR_NAME = "Buyorderlinenr"; // 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

	/** BuyPrice */
	public java.math.BigDecimal getBuyPrice() { return iBuyPrice; }
	public void setBuyPrice(java.math.BigDecimal value)
	{
		try
		{
			java.math.BigDecimal lValue = iBuyPrice;
			if (log4j.isDebugEnabled()) log4j.debug("setBuyPrice: " + lValue + " -> " + value);
			fireVetoableChange(BUYPRICE_PROPERTY_ID, lValue, value);
			iBuyPrice = value;
			firePropertyChange(BUYPRICE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="buy_price")
	private java.math.BigDecimal iBuyPrice = null;
	final static public String BUYPRICE_PROPERTY_ID = "buyPrice";
	final static public Class BUYPRICE_PROPERTY_CLASS = java.math.BigDecimal.class;
	final static public String BUYPRICE_NAME = "BuyPrice"; // with this ID you can access the internationalization

	/** Amount */
	public Integer getAmount() { return iAmount; }
	public void setAmount(Integer value)
	{
		try
		{
			Integer lValue = iAmount;
			if (log4j.isDebugEnabled()) log4j.debug("setAmount: " + lValue + " -> " + value);
			fireVetoableChange(AMOUNT_PROPERTY_ID, lValue, value);
			iAmount = value;
			firePropertyChange(AMOUNT_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="amount")
	private Integer iAmount = null;
	final static public String AMOUNT_PROPERTY_ID = "amount";
	final static public Class AMOUNT_PROPERTY_CLASS = Integer.class;
	final static public String AMOUNT_NAME = "Amount"; // with this ID you can access the internationalization

	/** OrderReason */
	public String getOrderReason() { return iOrderReason; }
	public void setOrderReason(String value)
	{
		try
		{
			String lValue = iOrderReason;
			if (log4j.isDebugEnabled()) log4j.debug("setOrderReason: " + lValue + " -> " + value);
			fireVetoableChange(ORDERREASON_PROPERTY_ID, lValue, value);
			iOrderReason = value;
			firePropertyChange(ORDERREASON_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="order_reason")
	private String iOrderReason = null;
	final static public String ORDERREASON_PROPERTY_ID = "orderReason";
	final static public Class ORDERREASON_PROPERTY_CLASS = String.class;
	final static public String ORDERREASON_NAME = "OrderReason"; // 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

	/** clone */
	public Object clone()
	{ 
		nl.reinders.bm.Buyorderline lNew = new nl.reinders.bm.Buyorderline();
		lNew.setArticle( getArticle() ); 
		lNew.setBuyorder( getBuyorder() ); 
		lNew.setSubBuyorderline( getSubBuyorderline() ); 
		lNew.setSeqnr( getSeqnr() ); 
		lNew.setBuyPrice( getBuyPrice() ); 
		lNew.setAmount( getAmount() ); 
		lNew.setOrderReason( getOrderReason() ); 
		// not cloning this column: lNew.setDwhmodified( getDwhmodified() ); 
		// not cloning this column: lNew.setDwhby( getDwhby() ); 
		return lNew;
	}
	public nl.reinders.bm.Buyorderline cloneShallow() { return (nl.reinders.bm.Buyorderline)clone();}


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

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


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

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

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

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


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

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



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

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


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