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

	/** Catalog */
	public nl.reinders.bm.Catalog getCatalog() { return iCatalog; }
	public void setCatalog(nl.reinders.bm.Catalog value)
	{
		if (value == iCatalog) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Catalog lValue = iCatalog;
			fireVetoableChange(CATALOG_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeCatalogentrysWhereIAmCatalog( (nl.reinders.bm.Catalogentry)this );
			iCatalog = value;
			if (value != null) value.addCatalogentrysWhereIAmCatalog( (nl.reinders.bm.Catalogentry)this );
			firePropertyChange(CATALOG_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.Catalog.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="catalognr") 
	private nl.reinders.bm.Catalog iCatalog;
	final static public String CATALOG_PROPERTY_ID = "catalog";
	final static public Class CATALOG_PROPERTY_CLASS = nl.reinders.bm.Catalog.class;
	final static public String CATALOG_NAME = "Catalog"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="catalognr", insertable=false, updatable=false)
	private java.math.BigDecimal iCatalognr = null;



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

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

	/** Pagenr */
	public Integer getPagenr() { return iPagenr; }
	public void setPagenr(Integer value)
	{
		try
		{
			Integer lValue = iPagenr;
			if (log4j.isDebugEnabled()) log4j.debug("setPagenr: " + lValue + " -> " + value);
			fireVetoableChange(PAGENR_PROPERTY_ID, lValue, value);
			iPagenr = value;
			firePropertyChange(PAGENR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="pagenr")
	private Integer iPagenr = null;
	final static public String PAGENR_PROPERTY_ID = "pagenr";
	final static public Class PAGENR_PROPERTY_CLASS = Integer.class;
	final static public String PAGENR_NAME = "Pagenr"; // with this ID you can access the internationalization

	/** Pagepos */
	public Integer getPagepos() { return iPagepos; }
	public void setPagepos(Integer value)
	{
		try
		{
			Integer lValue = iPagepos;
			if (log4j.isDebugEnabled()) log4j.debug("setPagepos: " + lValue + " -> " + value);
			fireVetoableChange(PAGEPOS_PROPERTY_ID, lValue, value);
			iPagepos = value;
			firePropertyChange(PAGEPOS_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="pagepos")
	private Integer iPagepos = null;
	final static public String PAGEPOS_PROPERTY_ID = "pagepos";
	final static public Class PAGEPOS_PROPERTY_CLASS = Integer.class;
	final static public String PAGEPOS_NAME = "Pagepos"; // with this ID you can access the internationalization

	/** AddedInRelease */
	public Integer getAddedInRelease() { return iAddedInRelease; }
	public void setAddedInRelease(Integer value)
	{
		try
		{
			Integer lValue = iAddedInRelease;
			if (log4j.isDebugEnabled()) log4j.debug("setAddedInRelease: " + lValue + " -> " + value);
			fireVetoableChange(ADDEDINRELEASE_PROPERTY_ID, lValue, value);
			iAddedInRelease = value;
			firePropertyChange(ADDEDINRELEASE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="added_in_release")
	private Integer iAddedInRelease = null;
	final static public String ADDEDINRELEASE_PROPERTY_ID = "addedInRelease";
	final static public Class ADDEDINRELEASE_PROPERTY_CLASS = Integer.class;
	final static public String ADDEDINRELEASE_NAME = "AddedInRelease"; // 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.Catalogentry lNew = new nl.reinders.bm.Catalogentry();
		lNew.setArticle( getArticle() ); 
		lNew.setCatalog( getCatalog() ); 
		lNew.setPagenr( getPagenr() ); 
		lNew.setPagepos( getPagepos() ); 
		lNew.setAddedInRelease( getAddedInRelease() ); 
		// not cloning this column: lNew.setDwhmodified( getDwhmodified() ); 
		// not cloning this column: lNew.setDwhby( getDwhby() ); 
		return lNew;
	}
	public nl.reinders.bm.Catalogentry cloneShallow() { return (nl.reinders.bm.Catalogentry)clone();}


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

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


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

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

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

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


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

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



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

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


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