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

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


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

	/** Article */
	public nl.reinders.bm.Article getArticle() { return iArticle; }
	public void setArticle(nl.reinders.bm.Article value)
	{
		if (value == iArticle) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Article lValue = iArticle;
			fireVetoableChange(ARTICLE_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeLicenseArticlesWhereIAmArticle( (nl.reinders.bm.LicenseArticle)this );
			iArticle = value;
			if (value != null) value.addLicenseArticlesWhereIAmArticle( (nl.reinders.bm.LicenseArticle)this );
			firePropertyChange(ARTICLE_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.Article.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="articlenr") 
	private nl.reinders.bm.Article iArticle;
	final static public String ARTICLE_PROPERTY_ID = "article";
	final static public Class ARTICLE_PROPERTY_CLASS = nl.reinders.bm.Article.class;
	final static public String ARTICLE_NAME = "Article"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="articlenr", insertable=false, updatable=false)
	private java.math.BigDecimal iArticlenr = null;

	/** 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.removeLicenseArticlesWhereIAmLicense( (nl.reinders.bm.LicenseArticle)this );
			iLicense = value;
			if (value != null) value.addLicenseArticlesWhereIAmLicense( (nl.reinders.bm.LicenseArticle)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;



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

	/** LicenseArticleNr */
	public Integer getLicenseArticleNr() { return iLicenseArticleNr; }
	public void setLicenseArticleNr(Integer value)
	{
		try
		{
			Integer lValue = iLicenseArticleNr;
			if (log4j.isDebugEnabled()) log4j.debug("setLicenseArticleNr: " + lValue + " -> " + value);
			fireVetoableChange(LICENSEARTICLENR_PROPERTY_ID, lValue, value);
			iLicenseArticleNr = value;
			firePropertyChange(LICENSEARTICLENR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Id @GeneratedValue(generator="license_article.license_article_nr", strategy=GenerationType.TABLE) @TableGenerator( name="license_article.license_article_nr", pkColumnValue="license_article_nr", table="sequence", pkColumnName="seq_name", valueColumnName="seq_count", initialValue=1, allocationSize=1) @Column(name="license_article_nr")
	private Integer iLicenseArticleNr = null;
	final static public String LICENSEARTICLENR_PROPERTY_ID = "licenseArticleNr";
	final static public Class LICENSEARTICLENR_PROPERTY_CLASS = Integer.class;
	final static public String LICENSEARTICLENR_NAME = "LicenseArticleNr"; // with this ID you can access the internationalization


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

	/** clone */
	public Object clone()
	{ 
		nl.reinders.bm.LicenseArticle lNew = new nl.reinders.bm.LicenseArticle();
		lNew.setArticle( getArticle() ); 
		lNew.setLicense( getLicense() ); 
		return lNew;
	}
	public nl.reinders.bm.LicenseArticle cloneShallow() { return (nl.reinders.bm.LicenseArticle)clone();}


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

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


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

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

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

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


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

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



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

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


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