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

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

	/** EdifactordersitemssWhereIAmEdifactorders*/
	public void addEdifactordersitemssWhereIAmEdifactorders(nl.reinders.bm.Edifactordersitems value)
	{
		if (value != null && !iEdifactordersitemssWhereIAmEdifactorders.contains(value))
		{
			iEdifactordersitemssWhereIAmEdifactorders.add(value);
			value.setEdifactorders( (nl.reinders.bm.Edifactorders)this);
		}
	}
	public void removeEdifactordersitemssWhereIAmEdifactorders(nl.reinders.bm.Edifactordersitems value)
	{
		if (value != null && iEdifactordersitemssWhereIAmEdifactorders.contains(value))
		{
			iEdifactordersitemssWhereIAmEdifactorders.remove(value);
			value.setEdifactorders( (nl.reinders.bm.Edifactorders)null );
		}
	}
	public java.util.List<nl.reinders.bm.Edifactordersitems> getEdifactordersitemssWhereIAmEdifactorders() { return iEdifactordersitemssWhereIAmEdifactorders; }
	@OneToMany(mappedBy = "iEdifactorders", fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Edifactordersitems.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} )
	private java.util.List<nl.reinders.bm.Edifactordersitems> iEdifactordersitemssWhereIAmEdifactorders = new java.util.ArrayList<nl.reinders.bm.Edifactordersitems>();


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

	/** Sellorder */
	public nl.reinders.bm.Sellorder getSellorder() { return iSellorder; }
	public void setSellorder(nl.reinders.bm.Sellorder value)
	{
		if (value == iSellorder) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Sellorder lValue = iSellorder;
			fireVetoableChange(SELLORDER_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeEdifactorderssWhereIAmSellorder( (nl.reinders.bm.Edifactorders)this );
			iSellorder = value;
			if (value != null) value.addEdifactorderssWhereIAmSellorder( (nl.reinders.bm.Edifactorders)this );
			firePropertyChange(SELLORDER_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.Sellorder.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="sellordernr") 
	private nl.reinders.bm.Sellorder iSellorder;
	final static public String SELLORDER_PROPERTY_ID = "sellorder";
	final static public Class SELLORDER_PROPERTY_CLASS = nl.reinders.bm.Sellorder.class;
	final static public String SELLORDER_NAME = "Sellorder"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="sellordernr", insertable=false, updatable=false)
	private java.math.BigDecimal iSellordernr = null;



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

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

	/** Test */
	public Integer getTest() { return iTest; }
	public void setTest(Integer value)
	{
		try
		{
			Integer lValue = iTest;
			if (log4j.isDebugEnabled()) log4j.debug("setTest: " + lValue + " -> " + value);
			fireVetoableChange(TEST_PROPERTY_ID, lValue, value);
			iTest = value;
			firePropertyChange(TEST_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="test")
	private Integer iTest = 1;
	final static public String TEST_PROPERTY_ID = "test";
	final static public Class TEST_PROPERTY_CLASS = Integer.class;
	final static public String TEST_NAME = "Test"; // with this ID you can access the internationalization

	/** Ordernr */
	public String getOrdernr() { return iOrdernr; }
	public void setOrdernr(String value)
	{
		try
		{
			String lValue = iOrdernr;
			if (log4j.isDebugEnabled()) log4j.debug("setOrdernr: " + lValue + " -> " + value);
			fireVetoableChange(ORDERNR_PROPERTY_ID, lValue, value);
			iOrdernr = value;
			firePropertyChange(ORDERNR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="ordernr")
	private String iOrdernr = null;
	final static public String ORDERNR_PROPERTY_ID = "ordernr";
	final static public Class ORDERNR_PROPERTY_CLASS = String.class;
	final static public String ORDERNR_NAME = "Ordernr"; // with this ID you can access the internationalization

	/** Senderid */
	public String getSenderid() { return iSenderid; }
	public void setSenderid(String value)
	{
		try
		{
			String lValue = iSenderid;
			if (log4j.isDebugEnabled()) log4j.debug("setSenderid: " + lValue + " -> " + value);
			fireVetoableChange(SENDERID_PROPERTY_ID, lValue, value);
			iSenderid = value;
			firePropertyChange(SENDERID_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="senderid")
	private String iSenderid = null;
	final static public String SENDERID_PROPERTY_ID = "senderid";
	final static public Class SENDERID_PROPERTY_CLASS = String.class;
	final static public String SENDERID_NAME = "Senderid"; // with this ID you can access the internationalization

	/** Orderdate */
	public java.util.Calendar getOrderdate() { return iOrderdate; }
	public void setOrderdate(java.util.Calendar value)
	{
		try
		{
			java.util.Calendar lValue = iOrderdate;
			if (log4j.isDebugEnabled()) log4j.debug("setOrderdate: " + lValue + " -> " + value);
			fireVetoableChange(ORDERDATE_PROPERTY_ID, lValue, value);
			iOrderdate = value;
			firePropertyChange(ORDERDATE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Temporal(TemporalType.TIMESTAMP) @Column(name="orderdate")
	private java.util.Calendar iOrderdate = null;
	final static public String ORDERDATE_PROPERTY_ID = "orderdate";
	final static public Class ORDERDATE_PROPERTY_CLASS = java.util.Calendar.class;
	final static public String ORDERDATE_NAME = "Orderdate"; // with this ID you can access the internationalization

	/** Buyerean */
	public String getBuyerean() { return iBuyerean; }
	public void setBuyerean(String value)
	{
		try
		{
			String lValue = iBuyerean;
			if (log4j.isDebugEnabled()) log4j.debug("setBuyerean: " + lValue + " -> " + value);
			fireVetoableChange(BUYEREAN_PROPERTY_ID, lValue, value);
			iBuyerean = value;
			firePropertyChange(BUYEREAN_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="buyerean")
	private String iBuyerean = null;
	final static public String BUYEREAN_PROPERTY_ID = "buyerean";
	final static public Class BUYEREAN_PROPERTY_CLASS = String.class;
	final static public String BUYEREAN_NAME = "Buyerean"; // with this ID you can access the internationalization

	/** Deliverytoean */
	public String getDeliverytoean() { return iDeliverytoean; }
	public void setDeliverytoean(String value)
	{
		try
		{
			String lValue = iDeliverytoean;
			if (log4j.isDebugEnabled()) log4j.debug("setDeliverytoean: " + lValue + " -> " + value);
			fireVetoableChange(DELIVERYTOEAN_PROPERTY_ID, lValue, value);
			iDeliverytoean = value;
			firePropertyChange(DELIVERYTOEAN_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="deliverytoean")
	private String iDeliverytoean = null;
	final static public String DELIVERYTOEAN_PROPERTY_ID = "deliverytoean";
	final static public Class DELIVERYTOEAN_PROPERTY_CLASS = String.class;
	final static public String DELIVERYTOEAN_NAME = "Deliverytoean"; // with this ID you can access the internationalization

	/** Relationnr */
	public Integer getRelationnr() { return iRelationnr; }
	public void setRelationnr(Integer value)
	{
		try
		{
			Integer lValue = iRelationnr;
			if (log4j.isDebugEnabled()) log4j.debug("setRelationnr: " + lValue + " -> " + value);
			fireVetoableChange(RELATIONNR_PROPERTY_ID, lValue, value);
			iRelationnr = value;
			firePropertyChange(RELATIONNR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="relationnr")
	private Integer iRelationnr = null;
	final static public String RELATIONNR_PROPERTY_ID = "relationnr";
	final static public Class RELATIONNR_PROPERTY_CLASS = Integer.class;
	final static public String RELATIONNR_NAME = "Relationnr"; // 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

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


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

	/** clone */
	public Object clone()
	{ 
		nl.reinders.bm.Edifactorders lNew = new nl.reinders.bm.Edifactorders();
		lNew.setSellorder( getSellorder() ); 
		lNew.setTest( getTest() ); 
		lNew.setOrdernr( getOrdernr() ); 
		lNew.setSenderid( getSenderid() ); 
		lNew.setOrderdate( getOrderdate() ); 
		lNew.setBuyerean( getBuyerean() ); 
		lNew.setDeliverytoean( getDeliverytoean() ); 
		lNew.setRelationnr( getRelationnr() ); 
		// not cloning this column: lNew.setDwhmodified( getDwhmodified() ); 
		// not cloning this column: lNew.setDwhby( getDwhby() ); 
		return lNew;
	}
	public nl.reinders.bm.Edifactorders cloneShallow() { return (nl.reinders.bm.Edifactorders)clone();}


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

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


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

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

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

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


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

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



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

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


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