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

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

	/** SellexpectlinesWhereIAmSellexpect*/
	public void addSellexpectlinesWhereIAmSellexpect(nl.reinders.bm.Sellexpectline value)
	{
		if (value != null && !iSellexpectlinesWhereIAmSellexpect.contains(value))
		{
			iSellexpectlinesWhereIAmSellexpect.add(value);
			value.setSellexpect( (nl.reinders.bm.Sellexpect)this);
		}
	}
	public void removeSellexpectlinesWhereIAmSellexpect(nl.reinders.bm.Sellexpectline value)
	{
		if (value != null && iSellexpectlinesWhereIAmSellexpect.contains(value))
		{
			iSellexpectlinesWhereIAmSellexpect.remove(value);
			value.setSellexpect( (nl.reinders.bm.Sellexpect)null );
		}
	}
	public java.util.List<nl.reinders.bm.Sellexpectline> getSellexpectlinesWhereIAmSellexpect() { return iSellexpectlinesWhereIAmSellexpect; }
	@OneToMany(mappedBy = "iSellexpect", fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Sellexpectline.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} )
	private java.util.List<nl.reinders.bm.Sellexpectline> iSellexpectlinesWhereIAmSellexpect = new java.util.ArrayList<nl.reinders.bm.Sellexpectline>();


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



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

	/** Sellexpectnr */
	public Integer getSellexpectnr() { return iSellexpectnr; }
	public void setSellexpectnr(Integer value)
	{
		try
		{
			Integer lValue = iSellexpectnr;
			if (log4j.isDebugEnabled()) log4j.debug("setSellexpectnr: " + lValue + " -> " + value);
			fireVetoableChange(SELLEXPECTNR_PROPERTY_ID, lValue, value);
			iSellexpectnr = value;
			firePropertyChange(SELLEXPECTNR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Id @GeneratedValue(generator="sellexpect.sellexpectnr", strategy=GenerationType.TABLE) @TableGenerator( name="sellexpect.sellexpectnr", pkColumnValue="sellexpectnr", table="sequence", pkColumnName="seq_name", valueColumnName="seq_count", initialValue=1, allocationSize=1) @Column(name="sellexpectnr")
	private Integer iSellexpectnr = null;
	final static public String SELLEXPECTNR_PROPERTY_ID = "sellexpectnr";
	final static public Class SELLEXPECTNR_PROPERTY_CLASS = Integer.class;
	final static public String SELLEXPECTNR_NAME = "Sellexpectnr"; // 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 = null;
	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.Sellexpect lNew = new nl.reinders.bm.Sellexpect();
		// not cloning this column: lNew.setDwhmodified( getDwhmodified() ); 
		// not cloning this column: lNew.setDwhby( getDwhby() ); 
		return lNew;
	}
	public nl.reinders.bm.Sellexpect cloneShallow() { return (nl.reinders.bm.Sellexpect)clone();}


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

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


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

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

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

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


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

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



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

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


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