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

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


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

	/** License */
	public nl.reinders.bm.License getLicense() { return iLicense; }
	public void setLicense(nl.reinders.bm.License value)
	{
		if (value == iLicense) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.License lValue = iLicense;
			fireVetoableChange(LICENSE_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeLicensePaymentsWhereIAmLicense( (nl.reinders.bm.LicensePayment)this );
			iLicense = value;
			if (value != null) value.addLicensePaymentsWhereIAmLicense( (nl.reinders.bm.LicensePayment)this );
			firePropertyChange(LICENSE_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.License.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="licensenr") 
	private nl.reinders.bm.License iLicense;
	final static public String LICENSE_PROPERTY_ID = "license";
	final static public Class LICENSE_PROPERTY_CLASS = nl.reinders.bm.License.class;
	final static public String LICENSE_NAME = "License"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="licensenr", insertable=false, updatable=false)
	private java.math.BigDecimal iLicensenr = null;

	/** LicensePaymentType */
	public nl.reinders.bm.LicensePaymentType getLicensePaymentType() { return iLicensePaymentType; }
	public void setLicensePaymentType(nl.reinders.bm.LicensePaymentType value)
	{
		if (value == iLicensePaymentType) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.LicensePaymentType lValue = iLicensePaymentType;
			fireVetoableChange(LICENSEPAYMENTTYPE_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeLicensePaymentsWhereIAmLicensePaymentType( (nl.reinders.bm.LicensePayment)this );
			iLicensePaymentType = value;
			if (value != null) value.addLicensePaymentsWhereIAmLicensePaymentType( (nl.reinders.bm.LicensePayment)this );
			firePropertyChange(LICENSEPAYMENTTYPE_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.LicensePaymentType.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="license_payment_typenr") 
	private nl.reinders.bm.LicensePaymentType iLicensePaymentType;
	final static public String LICENSEPAYMENTTYPE_PROPERTY_ID = "licensePaymentType";
	final static public Class LICENSEPAYMENTTYPE_PROPERTY_CLASS = nl.reinders.bm.LicensePaymentType.class;
	final static public String LICENSEPAYMENTTYPE_NAME = "LicensePaymentType"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="license_payment_typenr", insertable=false, updatable=false)
	private java.math.BigDecimal iLicensePaymentTypenr = null;



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

	/** LicensePaymentnr */
	public Integer getLicensePaymentnr() { return iLicensePaymentnr; }
	public void setLicensePaymentnr(Integer value)
	{
		try
		{
			Integer lValue = iLicensePaymentnr;
			if (log4j.isDebugEnabled()) log4j.debug("setLicensePaymentnr: " + lValue + " -> " + value);
			fireVetoableChange(LICENSEPAYMENTNR_PROPERTY_ID, lValue, value);
			iLicensePaymentnr = value;
			firePropertyChange(LICENSEPAYMENTNR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Id @GeneratedValue(generator="license_payment.license_paymentnr", strategy=GenerationType.TABLE) @TableGenerator( name="license_payment.license_paymentnr", pkColumnValue="license_paymentnr", table="sequence", pkColumnName="seq_name", valueColumnName="seq_count", initialValue=1, allocationSize=1) @Column(name="license_paymentnr")
	private Integer iLicensePaymentnr = null;
	final static public String LICENSEPAYMENTNR_PROPERTY_ID = "licensePaymentnr";
	final static public Class LICENSEPAYMENTNR_PROPERTY_CLASS = Integer.class;
	final static public String LICENSEPAYMENTNR_NAME = "LicensePaymentnr"; // with this ID you can access the internationalization

	/** Amount */
	public java.math.BigDecimal getAmount() { return iAmount; }
	public void setAmount(java.math.BigDecimal value)
	{
		try
		{
			java.math.BigDecimal lValue = iAmount;
			if (log4j.isDebugEnabled()) log4j.debug("setAmount: " + lValue + " -> " + value);
			fireVetoableChange(AMOUNT_PROPERTY_ID, lValue, value);
			iAmount = value;
			firePropertyChange(AMOUNT_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="amount")
	private java.math.BigDecimal iAmount = null;
	final static public String AMOUNT_PROPERTY_ID = "amount";
	final static public Class AMOUNT_PROPERTY_CLASS = java.math.BigDecimal.class;
	final static public String AMOUNT_NAME = "Amount"; // with this ID you can access the internationalization

	/** PaymentDate */
	public java.util.Calendar getPaymentDate() { return iPaymentDate; }
	public void setPaymentDate(java.util.Calendar value)
	{
		try
		{
			java.util.Calendar lValue = iPaymentDate;
			if (log4j.isDebugEnabled()) log4j.debug("setPaymentDate: " + lValue + " -> " + value);
			fireVetoableChange(PAYMENTDATE_PROPERTY_ID, lValue, value);
			iPaymentDate = value;
			firePropertyChange(PAYMENTDATE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Temporal(TemporalType.TIMESTAMP) @Column(name="payment_date")
	private java.util.Calendar iPaymentDate = null;
	final static public String PAYMENTDATE_PROPERTY_ID = "paymentDate";
	final static public Class PAYMENTDATE_PROPERTY_CLASS = java.util.Calendar.class;
	final static public String PAYMENTDATE_NAME = "PaymentDate"; // with this ID you can access the internationalization

	/** Description */
	public String getDescription() { return iDescription; }
	public void setDescription(String value)
	{
		try
		{
			String lValue = iDescription;
			if (log4j.isDebugEnabled()) log4j.debug("setDescription: " + lValue + " -> " + value);
			fireVetoableChange(DESCRIPTION_PROPERTY_ID, lValue, value);
			iDescription = value;
			firePropertyChange(DESCRIPTION_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="description")
	private String iDescription = null;
	final static public String DESCRIPTION_PROPERTY_ID = "description";
	final static public Class DESCRIPTION_PROPERTY_CLASS = String.class;
	final static public String DESCRIPTION_NAME = "Description"; // 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

	/** ToForeign */
	public java.math.BigDecimal getToForeign() { return iToForeign; }
	public void setToForeign(java.math.BigDecimal value)
	{
		try
		{
			java.math.BigDecimal lValue = iToForeign;
			if (log4j.isDebugEnabled()) log4j.debug("setToForeign: " + lValue + " -> " + value);
			fireVetoableChange(TOFOREIGN_PROPERTY_ID, lValue, value);
			iToForeign = value;
			firePropertyChange(TOFOREIGN_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="to_foreign")
	private java.math.BigDecimal iToForeign = null;
	final static public String TOFOREIGN_PROPERTY_ID = "toForeign";
	final static public Class TOFOREIGN_PROPERTY_CLASS = java.math.BigDecimal.class;
	final static public String TOFOREIGN_NAME = "ToForeign"; // with this ID you can access the internationalization


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

	/** clone */
	public Object clone()
	{ 
		nl.reinders.bm.LicensePayment lNew = new nl.reinders.bm.LicensePayment();
		lNew.setLicense( getLicense() ); 
		lNew.setLicensePaymentType( getLicensePaymentType() ); 
		lNew.setAmount( getAmount() ); 
		lNew.setPaymentDate( getPaymentDate() ); 
		lNew.setDescription( getDescription() ); 
		// not cloning this column: lNew.setDwhmodified( getDwhmodified() ); 
		// not cloning this column: lNew.setDwhby( getDwhby() ); 
		lNew.setToForeign( getToForeign() ); 
		return lNew;
	}
	public nl.reinders.bm.LicensePayment cloneShallow() { return (nl.reinders.bm.LicensePayment)clone();}


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

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


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

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

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

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


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

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



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

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


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