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

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

	/** ContractpaymentlinesWhereIAmContractpayment*/
	public void addContractpaymentlinesWhereIAmContractpayment(nl.reinders.bm.Contractpaymentline value)
	{
		if (value != null && !iContractpaymentlinesWhereIAmContractpayment.contains(value))
		{
			iContractpaymentlinesWhereIAmContractpayment.add(value);
			value.setContractpayment( (nl.reinders.bm.Contractpayment)this);
		}
	}
	public void removeContractpaymentlinesWhereIAmContractpayment(nl.reinders.bm.Contractpaymentline value)
	{
		if (value != null && iContractpaymentlinesWhereIAmContractpayment.contains(value))
		{
			iContractpaymentlinesWhereIAmContractpayment.remove(value);
			value.setContractpayment( (nl.reinders.bm.Contractpayment)null );
		}
	}
	public java.util.List<nl.reinders.bm.Contractpaymentline> getContractpaymentlinesWhereIAmContractpayment() { return iContractpaymentlinesWhereIAmContractpayment; }
	@OneToMany(mappedBy = "iContractpayment", fetch = FetchType.LAZY, targetEntity = nl.reinders.bm.Contractpaymentline.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} )
	private java.util.List<nl.reinders.bm.Contractpaymentline> iContractpaymentlinesWhereIAmContractpayment = new java.util.ArrayList<nl.reinders.bm.Contractpaymentline>();


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

	/** Contract */
	public nl.reinders.bm.Contract getContract() { return iContract; }
	public void setContract(nl.reinders.bm.Contract value)
	{
		if (value == iContract) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Contract lValue = iContract;
			fireVetoableChange(CONTRACT_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeContractpaymentsWhereIAmContract( (nl.reinders.bm.Contractpayment)this );
			iContract = value;
			if (value != null) value.addContractpaymentsWhereIAmContract( (nl.reinders.bm.Contractpayment)this );
			firePropertyChange(CONTRACT_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.Contract.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="contractnr") 
	private nl.reinders.bm.Contract iContract;
	final static public String CONTRACT_PROPERTY_ID = "contract";
	final static public Class CONTRACT_PROPERTY_CLASS = nl.reinders.bm.Contract.class;
	final static public String CONTRACT_NAME = "Contract"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="contractnr", insertable=false, updatable=false)
	private java.math.BigDecimal iContractnr = 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.removeContractpaymentsWhereIAmTimeframe( (nl.reinders.bm.Contractpayment)this );
			iTimeframe = value;
			if (value != null) value.addContractpaymentsWhereIAmTimeframe( (nl.reinders.bm.Contractpayment)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

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

	/** Year */
	public Integer getYear() { return iYear; }
	public void setYear(Integer value)
	{
		try
		{
			Integer lValue = iYear;
			if (log4j.isDebugEnabled()) log4j.debug("setYear: " + lValue + " -> " + value);
			fireVetoableChange(YEAR_PROPERTY_ID, lValue, value);
			iYear = value;
			firePropertyChange(YEAR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="year")
	private Integer iYear = null;
	final static public String YEAR_PROPERTY_ID = "year";
	final static public Class YEAR_PROPERTY_CLASS = Integer.class;
	final static public String YEAR_NAME = "Year"; // with this ID you can access the internationalization

	/** Date */
	public java.util.Calendar getDate() { return iDate; }
	public void setDate(java.util.Calendar value)
	{
		try
		{
			java.util.Calendar lValue = iDate;
			if (log4j.isDebugEnabled()) log4j.debug("setDate: " + lValue + " -> " + value);
			fireVetoableChange(DATE_PROPERTY_ID, lValue, value);
			iDate = value;
			firePropertyChange(DATE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Temporal(TemporalType.TIMESTAMP) @Column(name="date")
	private java.util.Calendar iDate = null;
	final static public String DATE_PROPERTY_ID = "date";
	final static public Class DATE_PROPERTY_CLASS = java.util.Calendar.class;
	final static public String DATE_NAME = "Date"; // with this ID you can access the internationalization

	/** Conversion */
	public java.math.BigDecimal getConversion() { return iConversion; }
	public void setConversion(java.math.BigDecimal value)
	{
		try
		{
			java.math.BigDecimal lValue = iConversion;
			if (log4j.isDebugEnabled()) log4j.debug("setConversion: " + lValue + " -> " + value);
			fireVetoableChange(CONVERSION_PROPERTY_ID, lValue, value);
			iConversion = value;
			firePropertyChange(CONVERSION_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="conversion")
	private java.math.BigDecimal iConversion = null;
	final static public String CONVERSION_PROPERTY_ID = "conversion";
	final static public Class CONVERSION_PROPERTY_CLASS = java.math.BigDecimal.class;
	final static public String CONVERSION_NAME = "Conversion"; // 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.Contractpayment lNew = new nl.reinders.bm.Contractpayment();
		lNew.setContract( getContract() ); 
		lNew.setTimeframe( getTimeframe() ); 
		lNew.setYear( getYear() ); 
		lNew.setDate( getDate() ); 
		lNew.setConversion( getConversion() ); 
		// not cloning this column: lNew.setDwhmodified( getDwhmodified() ); 
		// not cloning this column: lNew.setDwhby( getDwhby() ); 
		return lNew;
	}
	public nl.reinders.bm.Contractpayment cloneShallow() { return (nl.reinders.bm.Contractpayment)clone();}


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

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


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

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

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

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


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

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



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

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


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