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

	/** Contact */
	public nl.reinders.bm.Contact getContact() { return iContact; }
	public void setContact(nl.reinders.bm.Contact value)
	{
		if (value == iContact) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Contact lValue = iContact;
			fireVetoableChange(CONTACT_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeWebimagedownloadsWhereIAmContact( (nl.reinders.bm.Webimagedownload)this );
			iContact = value;
			if (value != null) value.addWebimagedownloadsWhereIAmContact( (nl.reinders.bm.Webimagedownload)this );
			firePropertyChange(CONTACT_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.Contact.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="contactnr") 
	private nl.reinders.bm.Contact iContact;
	final static public String CONTACT_PROPERTY_ID = "contact";
	final static public Class CONTACT_PROPERTY_CLASS = nl.reinders.bm.Contact.class;
	final static public String CONTACT_NAME = "Contact"; // with this ID you can access the internationalization



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

	/** Contactnr */
	public Integer getContactnr() { return iContactnr; }
	public void setContactnr(Integer value)
	{
		try
		{
			Integer lValue = iContactnr;
			if (log4j.isDebugEnabled()) log4j.debug("setContactnr: " + lValue + " -> " + value);
			fireVetoableChange(CONTACTNR_PROPERTY_ID, lValue, value);
			iContactnr = value;
			firePropertyChange(CONTACTNR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Id @Column(name="contactnr", insertable=false, updatable=false)
	private Integer iContactnr = null;
	final static public String CONTACTNR_PROPERTY_ID = "contactnr";
	final static public Class CONTACTNR_PROPERTY_CLASS = Integer.class;
	final static public String CONTACTNR_NAME = "Contactnr"; // with this ID you can access the internationalization

	/** Articlenr */
	public Integer getArticlenr() { return iArticlenr; }
	public void setArticlenr(Integer value)
	{
		try
		{
			Integer lValue = iArticlenr;
			if (log4j.isDebugEnabled()) log4j.debug("setArticlenr: " + lValue + " -> " + value);
			fireVetoableChange(ARTICLENR_PROPERTY_ID, lValue, value);
			iArticlenr = value;
			firePropertyChange(ARTICLENR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Id @Column(name="articlenr", insertable=false, updatable=false)
	private Integer iArticlenr = null;
	final static public String ARTICLENR_PROPERTY_ID = "articlenr";
	final static public Class ARTICLENR_PROPERTY_CLASS = Integer.class;
	final static public String ARTICLENR_NAME = "Articlenr"; // with this ID you can access the internationalization

	/** Downloaddate */
	public java.util.Calendar getDownloaddate() { return iDownloaddate; }
	public void setDownloaddate(java.util.Calendar value)
	{
		try
		{
			java.util.Calendar lValue = iDownloaddate;
			if (log4j.isDebugEnabled()) log4j.debug("setDownloaddate: " + lValue + " -> " + value);
			fireVetoableChange(DOWNLOADDATE_PROPERTY_ID, lValue, value);
			iDownloaddate = value;
			firePropertyChange(DOWNLOADDATE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Id @Temporal(TemporalType.TIMESTAMP) @Column(name="downloaddate")
	private java.util.Calendar iDownloaddate = new java.util.GregorianCalendar();
	final static public String DOWNLOADDATE_PROPERTY_ID = "downloaddate";
	final static public Class DOWNLOADDATE_PROPERTY_CLASS = java.util.Calendar.class;
	final static public String DOWNLOADDATE_NAME = "Downloaddate"; // with this ID you can access the internationalization

	/** User */
	public String getUser() { return iUser; }
	public void setUser(String value)
	{
		try
		{
			String lValue = iUser;
			if (log4j.isDebugEnabled()) log4j.debug("setUser: " + lValue + " -> " + value);
			fireVetoableChange(USER_PROPERTY_ID, lValue, value);
			iUser = value;
			firePropertyChange(USER_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="user")
	private String iUser = null;
	final static public String USER_PROPERTY_ID = "user";
	final static public Class USER_PROPERTY_CLASS = String.class;
	final static public String USER_NAME = "User"; // with this ID you can access the internationalization


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

	/** clone */
	public Object clone()
	{ 
		nl.reinders.bm.Webimagedownload lNew = new nl.reinders.bm.Webimagedownload();
		lNew.setUser( getUser() ); 
		return lNew;
	}
	public nl.reinders.bm.Webimagedownload cloneShallow() { return (nl.reinders.bm.Webimagedownload)clone();}


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

	/**
	 * @param articlenr
	 * @param contactnr
	 * @param downloaddate
	 */
	static public nl.reinders.bm.Webimagedownload findByPK(Integer articlenr, Integer contactnr, java.util.Calendar downloaddate)
	{
		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 Webimagedownload t where t.iArticlenr=:articlenr and t.iContactnr=:contactnr and t.iDownloaddate=:downloaddate");
		lQuery.setParameter("articlenr", articlenr);
		lQuery.setParameter("contactnr", contactnr);
		lQuery.setParameter("downloaddate", downloaddate);
		java.util.List<nl.reinders.bm.Webimagedownload> lList = lQuery.getResultList();
	    if (lList.size() == 0) return null;
	    return lList.get(0);
	}

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

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


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

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



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

	/**
	 *
	 */
	public String toString()
	{
		StringBuffer lStringBuffer = new StringBuffer();
		lStringBuffer.append(super.toString());
		lStringBuffer.append(", Contactnr="); lStringBuffer.append(getContactnr());
		lStringBuffer.append(", Articlenr="); lStringBuffer.append(getArticlenr());
		lStringBuffer.append(", Downloaddate="); lStringBuffer.append(getDownloaddate());
		return lStringBuffer.toString();
	}


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