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

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


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

	/** Contractpayment */
	public nl.reinders.bm.Contractpayment getContractpayment() { return iContractpayment; }
	public void setContractpayment(nl.reinders.bm.Contractpayment value)
	{
		if (value == iContractpayment) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Contractpayment lValue = iContractpayment;
			fireVetoableChange(CONTRACTPAYMENT_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeContractpaymentlinesWhereIAmContractpayment( (nl.reinders.bm.Contractpaymentline)this );
			iContractpayment = value;
			if (value != null) value.addContractpaymentlinesWhereIAmContractpayment( (nl.reinders.bm.Contractpaymentline)this );
			firePropertyChange(CONTRACTPAYMENT_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.Contractpayment.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="contractpaymentnr") 
	private nl.reinders.bm.Contractpayment iContractpayment;
	final static public String CONTRACTPAYMENT_PROPERTY_ID = "contractpayment";
	final static public Class CONTRACTPAYMENT_PROPERTY_CLASS = nl.reinders.bm.Contractpayment.class;
	final static public String CONTRACTPAYMENT_NAME = "Contractpayment"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="contractpaymentnr", insertable=false, updatable=false)
	private java.math.BigDecimal iContractpaymentnr = null;

	/** Timeframe */
	public nl.reinders.bm.Timeframe getTimeframe() { return iTimeframe; }
	public void setTimeframe(nl.reinders.bm.Timeframe value)
	{
		if (value == iTimeframe) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Timeframe lValue = iTimeframe;
			fireVetoableChange(TIMEFRAME_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeContractpaymentlinesWhereIAmTimeframe( (nl.reinders.bm.Contractpaymentline)this );
			iTimeframe = value;
			if (value != null) value.addContractpaymentlinesWhereIAmTimeframe( (nl.reinders.bm.Contractpaymentline)this );
			firePropertyChange(TIMEFRAME_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.Timeframe.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="timeframenr") 
	private nl.reinders.bm.Timeframe iTimeframe;
	final static public String TIMEFRAME_PROPERTY_ID = "timeframe";
	final static public Class TIMEFRAME_PROPERTY_CLASS = nl.reinders.bm.Timeframe.class;
	final static public String TIMEFRAME_NAME = "Timeframe"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="timeframenr", insertable=false, updatable=false)
	private java.math.BigDecimal iTimeframenr = null;



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

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

	/** Unitsold */
	public Integer getUnitsold() { return iUnitsold; }
	public void setUnitsold(Integer value)
	{
		try
		{
			Integer lValue = iUnitsold;
			if (log4j.isDebugEnabled()) log4j.debug("setUnitsold: " + lValue + " -> " + value);
			fireVetoableChange(UNITSOLD_PROPERTY_ID, lValue, value);
			iUnitsold = value;
			firePropertyChange(UNITSOLD_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="unitsold")
	private Integer iUnitsold = null;
	final static public String UNITSOLD_PROPERTY_ID = "unitsold";
	final static public Class UNITSOLD_PROPERTY_CLASS = Integer.class;
	final static public String UNITSOLD_NAME = "Unitsold"; // with this ID you can access the internationalization

	/** Price */
	public String getPrice() { return iPrice; }
	public void setPrice(String value)
	{
		try
		{
			String lValue = iPrice;
			if (log4j.isDebugEnabled()) log4j.debug("setPrice: " + lValue + " -> " + value);
			fireVetoableChange(PRICE_PROPERTY_ID, lValue, value);
			iPrice = value;
			firePropertyChange(PRICE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="price")
	private String iPrice = null;
	final static public String PRICE_PROPERTY_ID = "price";
	final static public Class PRICE_PROPERTY_CLASS = String.class;
	final static public String PRICE_NAME = "Price"; // with this ID you can access the internationalization

	/** Unitreturned */
	public String getUnitreturned() { return iUnitreturned; }
	public void setUnitreturned(String value)
	{
		try
		{
			String lValue = iUnitreturned;
			if (log4j.isDebugEnabled()) log4j.debug("setUnitreturned: " + lValue + " -> " + value);
			fireVetoableChange(UNITRETURNED_PROPERTY_ID, lValue, value);
			iUnitreturned = value;
			firePropertyChange(UNITRETURNED_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="unitreturned")
	private String iUnitreturned = null;
	final static public String UNITRETURNED_PROPERTY_ID = "unitreturned";
	final static public Class UNITRETURNED_PROPERTY_CLASS = String.class;
	final static public String UNITRETURNED_NAME = "Unitreturned"; // with this ID you can access the internationalization

	/** Turnover */
	public Integer getTurnover() { return iTurnover; }
	public void setTurnover(Integer value)
	{
		try
		{
			Integer lValue = iTurnover;
			if (log4j.isDebugEnabled()) log4j.debug("setTurnover: " + lValue + " -> " + value);
			fireVetoableChange(TURNOVER_PROPERTY_ID, lValue, value);
			iTurnover = value;
			firePropertyChange(TURNOVER_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="turnover")
	private Integer iTurnover = null;
	final static public String TURNOVER_PROPERTY_ID = "turnover";
	final static public Class TURNOVER_PROPERTY_CLASS = Integer.class;
	final static public String TURNOVER_NAME = "Turnover"; // with this ID you can access the internationalization

	/** Rate */
	public java.math.BigDecimal getRate() { return iRate; }
	public void setRate(java.math.BigDecimal value)
	{
		try
		{
			java.math.BigDecimal lValue = iRate;
			if (log4j.isDebugEnabled()) log4j.debug("setRate: " + lValue + " -> " + value);
			fireVetoableChange(RATE_PROPERTY_ID, lValue, value);
			iRate = value;
			firePropertyChange(RATE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="rate")
	private java.math.BigDecimal iRate = null;
	final static public String RATE_PROPERTY_ID = "rate";
	final static public Class RATE_PROPERTY_CLASS = java.math.BigDecimal.class;
	final static public String RATE_NAME = "Rate"; // 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.Contractpaymentline lNew = new nl.reinders.bm.Contractpaymentline();
		lNew.setContractpayment( getContractpayment() ); 
		lNew.setTimeframe( getTimeframe() ); 
		lNew.setUnitsold( getUnitsold() ); 
		lNew.setPrice( getPrice() ); 
		lNew.setUnitreturned( getUnitreturned() ); 
		lNew.setTurnover( getTurnover() ); 
		lNew.setRate( getRate() ); 
		// not cloning this column: lNew.setDwhmodified( getDwhmodified() ); 
		// not cloning this column: lNew.setDwhby( getDwhby() ); 
		return lNew;
	}
	public nl.reinders.bm.Contractpaymentline cloneShallow() { return (nl.reinders.bm.Contractpaymentline)clone();}


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

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


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

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

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

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


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

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



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

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


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