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

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

	/** BuyordersWhereIAmEnteredbyEmp*/
	public void addBuyordersWhereIAmEnteredbyEmp(nl.reinders.bm.Buyorder value)
	{
		if (value != null && !iBuyordersWhereIAmEnteredbyEmp.contains(value))
		{
			iBuyordersWhereIAmEnteredbyEmp.add(value);
			value.setEnteredbyEmp( (nl.reinders.bm.Employee)this);
		}
	}
	public void removeBuyordersWhereIAmEnteredbyEmp(nl.reinders.bm.Buyorder value)
	{
		if (value != null && iBuyordersWhereIAmEnteredbyEmp.contains(value))
		{
			iBuyordersWhereIAmEnteredbyEmp.remove(value);
			value.setEnteredbyEmp( (nl.reinders.bm.Employee)null );
		}
	}
	public java.util.List<nl.reinders.bm.Buyorder> getBuyordersWhereIAmEnteredbyEmp() { return iBuyordersWhereIAmEnteredbyEmp; }
	@OneToMany(mappedBy = "iEnteredbyEmp", fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Buyorder.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} )
	private java.util.List<nl.reinders.bm.Buyorder> iBuyordersWhereIAmEnteredbyEmp = new java.util.ArrayList<nl.reinders.bm.Buyorder>();

	/** CalendarsWhereIAmEmployee*/
	public void addCalendarsWhereIAmEmployee(nl.reinders.bm.Calendar value)
	{
		if (value != null && !iCalendarsWhereIAmEmployee.contains(value))
		{
			iCalendarsWhereIAmEmployee.add(value);
			value.setEmployee( (nl.reinders.bm.Employee)this);
		}
	}
	public void removeCalendarsWhereIAmEmployee(nl.reinders.bm.Calendar value)
	{
		if (value != null && iCalendarsWhereIAmEmployee.contains(value))
		{
			iCalendarsWhereIAmEmployee.remove(value);
			value.setEmployee( (nl.reinders.bm.Employee)null );
		}
	}
	public java.util.List<nl.reinders.bm.Calendar> getCalendarsWhereIAmEmployee() { return iCalendarsWhereIAmEmployee; }
	@OneToMany(mappedBy = "iEmployee", fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Calendar.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} )
	private java.util.List<nl.reinders.bm.Calendar> iCalendarsWhereIAmEmployee = new java.util.ArrayList<nl.reinders.bm.Calendar>();

	/** Employee2GroupsWhereIAmEmployee*/
	public void addEmployee2GroupsWhereIAmEmployee(nl.reinders.bm.Employee2Group value)
	{
		if (value != null && !iEmployee2GroupsWhereIAmEmployee.contains(value))
		{
			iEmployee2GroupsWhereIAmEmployee.add(value);
			value.setEmployee( (nl.reinders.bm.Employee)this);
		}
	}
	public void removeEmployee2GroupsWhereIAmEmployee(nl.reinders.bm.Employee2Group value)
	{
		if (value != null && iEmployee2GroupsWhereIAmEmployee.contains(value))
		{
			iEmployee2GroupsWhereIAmEmployee.remove(value);
			value.setEmployee( (nl.reinders.bm.Employee)null );
		}
	}
	public java.util.List<nl.reinders.bm.Employee2Group> getEmployee2GroupsWhereIAmEmployee() { return iEmployee2GroupsWhereIAmEmployee; }
	@OneToMany(mappedBy = "iEmployee", fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Employee2Group.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} )
	private java.util.List<nl.reinders.bm.Employee2Group> iEmployee2GroupsWhereIAmEmployee = new java.util.ArrayList<nl.reinders.bm.Employee2Group>();

	/** PdaordersWhereIAmEmployee*/
	public void addPdaordersWhereIAmEmployee(nl.reinders.bm.Pdaorder value)
	{
		if (value != null && !iPdaordersWhereIAmEmployee.contains(value))
		{
			iPdaordersWhereIAmEmployee.add(value);
			value.setEmployee( (nl.reinders.bm.Employee)this);
		}
	}
	public void removePdaordersWhereIAmEmployee(nl.reinders.bm.Pdaorder value)
	{
		if (value != null && iPdaordersWhereIAmEmployee.contains(value))
		{
			iPdaordersWhereIAmEmployee.remove(value);
			value.setEmployee( (nl.reinders.bm.Employee)null );
		}
	}
	public java.util.List<nl.reinders.bm.Pdaorder> getPdaordersWhereIAmEmployee() { return iPdaordersWhereIAmEmployee; }
	@OneToMany(mappedBy = "iEmployee", fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Pdaorder.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} )
	private java.util.List<nl.reinders.bm.Pdaorder> iPdaordersWhereIAmEmployee = new java.util.ArrayList<nl.reinders.bm.Pdaorder>();

	/** SellordersWhereIAmEnteredbyEmp*/
	public void addSellordersWhereIAmEnteredbyEmp(nl.reinders.bm.Sellorder value)
	{
		if (value != null && !iSellordersWhereIAmEnteredbyEmp.contains(value))
		{
			iSellordersWhereIAmEnteredbyEmp.add(value);
			value.setEnteredbyEmp( (nl.reinders.bm.Employee)this);
		}
	}
	public void removeSellordersWhereIAmEnteredbyEmp(nl.reinders.bm.Sellorder value)
	{
		if (value != null && iSellordersWhereIAmEnteredbyEmp.contains(value))
		{
			iSellordersWhereIAmEnteredbyEmp.remove(value);
			value.setEnteredbyEmp( (nl.reinders.bm.Employee)null );
		}
	}
	public java.util.List<nl.reinders.bm.Sellorder> getSellordersWhereIAmEnteredbyEmp() { return iSellordersWhereIAmEnteredbyEmp; }
	@OneToMany(mappedBy = "iEnteredbyEmp", fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Sellorder.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} )
	private java.util.List<nl.reinders.bm.Sellorder> iSellordersWhereIAmEnteredbyEmp = new java.util.ArrayList<nl.reinders.bm.Sellorder>();


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



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

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

	/** Name */
	public String getName() { return iName; }
	public void setName(String value)
	{
		try
		{
			String lValue = iName;
			if (log4j.isDebugEnabled()) log4j.debug("setName: " + lValue + " -> " + value);
			fireVetoableChange(NAME_PROPERTY_ID, lValue, value);
			iName = value;
			firePropertyChange(NAME_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="name")
	private String iName = null;
	final static public String NAME_PROPERTY_ID = "name";
	final static public Class NAME_PROPERTY_CLASS = String.class;
	final static public String NAME_NAME = "Name"; // 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.Employee lNew = new nl.reinders.bm.Employee();
		lNew.setName( getName() ); 
		// not cloning this column: lNew.setDwhmodified( getDwhmodified() ); 
		// not cloning this column: lNew.setDwhby( getDwhby() ); 
		return lNew;
	}
	public nl.reinders.bm.Employee cloneShallow() { return (nl.reinders.bm.Employee)clone();}


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

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


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

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

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

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


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

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



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

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


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