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

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


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



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

	/** Guid */
	public String getGuid() { return iGuid; }
	public void setGuid(String value)
	{
		try
		{
			String lValue = iGuid;
			if (log4j.isDebugEnabled()) log4j.debug("setGuid: " + lValue + " -> " + value);
			fireVetoableChange(GUID_PROPERTY_ID, lValue, value);
			iGuid = value;
			firePropertyChange(GUID_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Id @GeneratedValue(generator="docuware.guid", strategy=GenerationType.TABLE) @TableGenerator( name="docuware.guid", pkColumnValue="guid", table="sequence", pkColumnName="seq_name", valueColumnName="seq_count", initialValue=1, allocationSize=1) @Column(name="guid")
	private String iGuid = null;
	final static public String GUID_PROPERTY_ID = "guid";
	final static public Class GUID_PROPERTY_CLASS = String.class;
	final static public String GUID_NAME = "Guid"; // with this ID you can access the internationalization

	/** Relationnr */
	public Integer getRelationnr() { return iRelationnr; }
	public void setRelationnr(Integer value)
	{
		try
		{
			Integer lValue = iRelationnr;
			if (log4j.isDebugEnabled()) log4j.debug("setRelationnr: " + lValue + " -> " + value);
			fireVetoableChange(RELATIONNR_PROPERTY_ID, lValue, value);
			iRelationnr = value;
			firePropertyChange(RELATIONNR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="relationnr")
	private Integer iRelationnr = null;
	final static public String RELATIONNR_PROPERTY_ID = "relationnr";
	final static public Class RELATIONNR_PROPERTY_CLASS = Integer.class;
	final static public String RELATIONNR_NAME = "Relationnr"; // with this ID you can access the internationalization

	/** Relationname */
	public String getRelationname() { return iRelationname; }
	public void setRelationname(String value)
	{
		try
		{
			String lValue = iRelationname;
			if (log4j.isDebugEnabled()) log4j.debug("setRelationname: " + lValue + " -> " + value);
			fireVetoableChange(RELATIONNAME_PROPERTY_ID, lValue, value);
			iRelationname = value;
			firePropertyChange(RELATIONNAME_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="relationname")
	private String iRelationname = null;
	final static public String RELATIONNAME_PROPERTY_ID = "relationname";
	final static public Class RELATIONNAME_PROPERTY_CLASS = String.class;
	final static public String RELATIONNAME_NAME = "Relationname"; // with this ID you can access the internationalization

	/** Sellordernr */
	public Integer getSellordernr() { return iSellordernr; }
	public void setSellordernr(Integer value)
	{
		try
		{
			Integer lValue = iSellordernr;
			if (log4j.isDebugEnabled()) log4j.debug("setSellordernr: " + lValue + " -> " + value);
			fireVetoableChange(SELLORDERNR_PROPERTY_ID, lValue, value);
			iSellordernr = value;
			firePropertyChange(SELLORDERNR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="sellordernr")
	private Integer iSellordernr = null;
	final static public String SELLORDERNR_PROPERTY_ID = "sellordernr";
	final static public Class SELLORDERNR_PROPERTY_CLASS = Integer.class;
	final static public String SELLORDERNR_NAME = "Sellordernr"; // with this ID you can access the internationalization

	/** Sellorderexternalnr */
	public String getSellorderexternalnr() { return iSellorderexternalnr; }
	public void setSellorderexternalnr(String value)
	{
		try
		{
			String lValue = iSellorderexternalnr;
			if (log4j.isDebugEnabled()) log4j.debug("setSellorderexternalnr: " + lValue + " -> " + value);
			fireVetoableChange(SELLORDEREXTERNALNR_PROPERTY_ID, lValue, value);
			iSellorderexternalnr = value;
			firePropertyChange(SELLORDEREXTERNALNR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="sellorderexternalnr")
	private String iSellorderexternalnr = null;
	final static public String SELLORDEREXTERNALNR_PROPERTY_ID = "sellorderexternalnr";
	final static public Class SELLORDEREXTERNALNR_PROPERTY_CLASS = String.class;
	final static public String SELLORDEREXTERNALNR_NAME = "Sellorderexternalnr"; // with this ID you can access the internationalization

	/** Sellorderoldnr */
	public String getSellorderoldnr() { return iSellorderoldnr; }
	public void setSellorderoldnr(String value)
	{
		try
		{
			String lValue = iSellorderoldnr;
			if (log4j.isDebugEnabled()) log4j.debug("setSellorderoldnr: " + lValue + " -> " + value);
			fireVetoableChange(SELLORDEROLDNR_PROPERTY_ID, lValue, value);
			iSellorderoldnr = value;
			firePropertyChange(SELLORDEROLDNR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="sellorderoldnr")
	private String iSellorderoldnr = null;
	final static public String SELLORDEROLDNR_PROPERTY_ID = "sellorderoldnr";
	final static public Class SELLORDEROLDNR_PROPERTY_CLASS = String.class;
	final static public String SELLORDEROLDNR_NAME = "Sellorderoldnr"; // with this ID you can access the internationalization

	/** Sellorderfacturedate */
	public java.util.Calendar getSellorderfacturedate() { return iSellorderfacturedate; }
	public void setSellorderfacturedate(java.util.Calendar value)
	{
		try
		{
			java.util.Calendar lValue = iSellorderfacturedate;
			if (log4j.isDebugEnabled()) log4j.debug("setSellorderfacturedate: " + lValue + " -> " + value);
			fireVetoableChange(SELLORDERFACTUREDATE_PROPERTY_ID, lValue, value);
			iSellorderfacturedate = value;
			firePropertyChange(SELLORDERFACTUREDATE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Temporal(TemporalType.TIMESTAMP) @Column(name="sellorderfacturedate")
	private java.util.Calendar iSellorderfacturedate = null;
	final static public String SELLORDERFACTUREDATE_PROPERTY_ID = "sellorderfacturedate";
	final static public Class SELLORDERFACTUREDATE_PROPERTY_CLASS = java.util.Calendar.class;
	final static public String SELLORDERFACTUREDATE_NAME = "Sellorderfacturedate"; // with this ID you can access the internationalization

	/** Dokstatus */
	public String getDokstatus() { return iDokstatus; }
	public void setDokstatus(String value)
	{
		try
		{
			String lValue = iDokstatus;
			if (log4j.isDebugEnabled()) log4j.debug("setDokstatus: " + lValue + " -> " + value);
			fireVetoableChange(DOKSTATUS_PROPERTY_ID, lValue, value);
			iDokstatus = value;
			firePropertyChange(DOKSTATUS_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="dokstatus")
	private String iDokstatus = null;
	final static public String DOKSTATUS_PROPERTY_ID = "dokstatus";
	final static public Class DOKSTATUS_PROPERTY_CLASS = String.class;
	final static public String DOKSTATUS_NAME = "Dokstatus"; // with this ID you can access the internationalization

	/** Doktype */
	public String getDoktype() { return iDoktype; }
	public void setDoktype(String value)
	{
		try
		{
			String lValue = iDoktype;
			if (log4j.isDebugEnabled()) log4j.debug("setDoktype: " + lValue + " -> " + value);
			fireVetoableChange(DOKTYPE_PROPERTY_ID, lValue, value);
			iDoktype = value;
			firePropertyChange(DOKTYPE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="doktype")
	private String iDoktype = null;
	final static public String DOKTYPE_PROPERTY_ID = "doktype";
	final static public Class DOKTYPE_PROPERTY_CLASS = String.class;
	final static public String DOKTYPE_NAME = "Doktype"; // with this ID you can access the internationalization

	/** Tebewerkendoor */
	public String getTebewerkendoor() { return iTebewerkendoor; }
	public void setTebewerkendoor(String value)
	{
		try
		{
			String lValue = iTebewerkendoor;
			if (log4j.isDebugEnabled()) log4j.debug("setTebewerkendoor: " + lValue + " -> " + value);
			fireVetoableChange(TEBEWERKENDOOR_PROPERTY_ID, lValue, value);
			iTebewerkendoor = value;
			firePropertyChange(TEBEWERKENDOOR_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="tebewerkendoor")
	private String iTebewerkendoor = null;
	final static public String TEBEWERKENDOOR_PROPERTY_ID = "tebewerkendoor";
	final static public Class TEBEWERKENDOOR_PROPERTY_CLASS = String.class;
	final static public String TEBEWERKENDOOR_NAME = "Tebewerkendoor"; // with this ID you can access the internationalization

	/** Created */
	public java.util.Calendar getCreated() { return iCreated; }
	public void setCreated(java.util.Calendar value)
	{
		try
		{
			java.util.Calendar lValue = iCreated;
			if (log4j.isDebugEnabled()) log4j.debug("setCreated: " + lValue + " -> " + value);
			fireVetoableChange(CREATED_PROPERTY_ID, lValue, value);
			iCreated = value;
			firePropertyChange(CREATED_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Temporal(TemporalType.TIMESTAMP) @Column(name="created")
	private java.util.Calendar iCreated = new java.util.GregorianCalendar();
	final static public String CREATED_PROPERTY_ID = "created";
	final static public Class CREATED_PROPERTY_CLASS = java.util.Calendar.class;
	final static public String CREATED_NAME = "Created"; // with this ID you can access the internationalization


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

	/** clone */
	public Object clone()
	{ 
		nl.reinders.bm.Docuware lNew = new nl.reinders.bm.Docuware();
		lNew.setRelationnr( getRelationnr() ); 
		lNew.setRelationname( getRelationname() ); 
		lNew.setSellordernr( getSellordernr() ); 
		lNew.setSellorderexternalnr( getSellorderexternalnr() ); 
		lNew.setSellorderoldnr( getSellorderoldnr() ); 
		lNew.setSellorderfacturedate( getSellorderfacturedate() ); 
		lNew.setDokstatus( getDokstatus() ); 
		lNew.setDoktype( getDoktype() ); 
		lNew.setTebewerkendoor( getTebewerkendoor() ); 
		lNew.setCreated( getCreated() ); 
		return lNew;
	}
	public nl.reinders.bm.Docuware cloneShallow() { return (nl.reinders.bm.Docuware)clone();}


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

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


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

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

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

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


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

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



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

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


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