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

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


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

	/** Address */
	public nl.reinders.bm.Address getAddress() { return iAddress; }
	public void setAddress(nl.reinders.bm.Address value)
	{
		if (value == iAddress) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Address lValue = iAddress;
			fireVetoableChange(ADDRESS_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeCalendarsWhereIAmAddress( (nl.reinders.bm.Calendar)this );
			iAddress = value;
			if (value != null) value.addCalendarsWhereIAmAddress( (nl.reinders.bm.Calendar)this );
			firePropertyChange(ADDRESS_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.Address.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="addressnr") 
	private nl.reinders.bm.Address iAddress;
	final static public String ADDRESS_PROPERTY_ID = "address";
	final static public Class ADDRESS_PROPERTY_CLASS = nl.reinders.bm.Address.class;
	final static public String ADDRESS_NAME = "Address"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="addressnr", insertable=false, updatable=false)
	private java.math.BigDecimal iAddressnr = null;

	/** 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.removeCalendarsWhereIAmContact( (nl.reinders.bm.Calendar)this );
			iContact = value;
			if (value != null) value.addCalendarsWhereIAmContact( (nl.reinders.bm.Calendar)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
	// to make IN queryies possible
	@Column(name="contactnr", insertable=false, updatable=false)
	private java.math.BigDecimal iContactnr = null;

	/** Employee */
	public nl.reinders.bm.Employee getEmployee() { return iEmployee; }
	public void setEmployee(nl.reinders.bm.Employee value)
	{
		if (value == iEmployee) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Employee lValue = iEmployee;
			fireVetoableChange(EMPLOYEE_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeCalendarsWhereIAmEmployee( (nl.reinders.bm.Calendar)this );
			iEmployee = value;
			if (value != null) value.addCalendarsWhereIAmEmployee( (nl.reinders.bm.Calendar)this );
			firePropertyChange(EMPLOYEE_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.Employee.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="employeenr") 
	private nl.reinders.bm.Employee iEmployee;
	final static public String EMPLOYEE_PROPERTY_ID = "employee";
	final static public Class EMPLOYEE_PROPERTY_CLASS = nl.reinders.bm.Employee.class;
	final static public String EMPLOYEE_NAME = "Employee"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="employeenr", insertable=false, updatable=false)
	private java.math.BigDecimal iEmployeenr = null;

	/** Relation */
	public nl.reinders.bm.Relation getRelation() { return iRelation; }
	public void setRelation(nl.reinders.bm.Relation value)
	{
		if (value == iRelation) return; // optimalisation and prevent looping
		try
		{
			nl.reinders.bm.Relation lValue = iRelation;
			fireVetoableChange(RELATION_PROPERTY_ID, lValue, value);
			if (lValue != null) lValue.removeCalendarsWhereIAmRelation( (nl.reinders.bm.Calendar)this );
			iRelation = value;
			if (value != null) value.addCalendarsWhereIAmRelation( (nl.reinders.bm.Calendar)this );
			firePropertyChange(RELATION_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.Relation.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE} ) @JoinColumn(name="relationnr") 
	private nl.reinders.bm.Relation iRelation;
	final static public String RELATION_PROPERTY_ID = "relation";
	final static public Class RELATION_PROPERTY_CLASS = nl.reinders.bm.Relation.class;
	final static public String RELATION_NAME = "Relation"; // with this ID you can access the internationalization
	// to make IN queryies possible
	@Column(name="relationnr", insertable=false, updatable=false)
	private java.math.BigDecimal iRelationnr = null;



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

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

	/** RemindMoment */
	public java.util.Calendar getRemindMoment() { return iRemindMoment; }
	public void setRemindMoment(java.util.Calendar value)
	{
		try
		{
			java.util.Calendar lValue = iRemindMoment;
			if (log4j.isDebugEnabled()) log4j.debug("setRemindMoment: " + lValue + " -> " + value);
			fireVetoableChange(REMINDMOMENT_PROPERTY_ID, lValue, value);
			iRemindMoment = value;
			firePropertyChange(REMINDMOMENT_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Temporal(TemporalType.TIMESTAMP) @Column(name="remind_moment")
	private java.util.Calendar iRemindMoment = null;
	final static public String REMINDMOMENT_PROPERTY_ID = "remindMoment";
	final static public Class REMINDMOMENT_PROPERTY_CLASS = java.util.Calendar.class;
	final static public String REMINDMOMENT_NAME = "RemindMoment"; // with this ID you can access the internationalization

	/** MeetingStart */
	public java.util.Calendar getMeetingStart() { return iMeetingStart; }
	public void setMeetingStart(java.util.Calendar value)
	{
		try
		{
			java.util.Calendar lValue = iMeetingStart;
			if (log4j.isDebugEnabled()) log4j.debug("setMeetingStart: " + lValue + " -> " + value);
			fireVetoableChange(MEETINGSTART_PROPERTY_ID, lValue, value);
			iMeetingStart = value;
			firePropertyChange(MEETINGSTART_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Temporal(TemporalType.TIMESTAMP) @Column(name="meeting_start")
	private java.util.Calendar iMeetingStart = null;
	final static public String MEETINGSTART_PROPERTY_ID = "meetingStart";
	final static public Class MEETINGSTART_PROPERTY_CLASS = java.util.Calendar.class;
	final static public String MEETINGSTART_NAME = "MeetingStart"; // with this ID you can access the internationalization

	/** MeetingEnd */
	public java.util.Calendar getMeetingEnd() { return iMeetingEnd; }
	public void setMeetingEnd(java.util.Calendar value)
	{
		try
		{
			java.util.Calendar lValue = iMeetingEnd;
			if (log4j.isDebugEnabled()) log4j.debug("setMeetingEnd: " + lValue + " -> " + value);
			fireVetoableChange(MEETINGEND_PROPERTY_ID, lValue, value);
			iMeetingEnd = value;
			firePropertyChange(MEETINGEND_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Temporal(TemporalType.TIMESTAMP) @Column(name="meeting_end")
	private java.util.Calendar iMeetingEnd = null;
	final static public String MEETINGEND_PROPERTY_ID = "meetingEnd";
	final static public Class MEETINGEND_PROPERTY_CLASS = java.util.Calendar.class;
	final static public String MEETINGEND_NAME = "MeetingEnd"; // 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

	/** IsDone */
	public Integer getIsDone() { return iIsDone; }
	public void setIsDone(Integer value)
	{
		try
		{
			Integer lValue = iIsDone;
			if (log4j.isDebugEnabled()) log4j.debug("setIsDone: " + lValue + " -> " + value);
			fireVetoableChange(ISDONE_PROPERTY_ID, lValue, value);
			iIsDone = value;
			firePropertyChange(ISDONE_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Column(name="is_done")
	private Integer iIsDone = null;
	final static public String ISDONE_PROPERTY_ID = "isDone";
	final static public Class ISDONE_PROPERTY_CLASS = Integer.class;
	final static public String ISDONE_NAME = "IsDone"; // 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

	/** Inserted */
	public java.util.Calendar getInserted() { return iInserted; }
	public void setInserted(java.util.Calendar value)
	{
		try
		{
			java.util.Calendar lValue = iInserted;
			if (log4j.isDebugEnabled()) log4j.debug("setInserted: " + lValue + " -> " + value);
			fireVetoableChange(INSERTED_PROPERTY_ID, lValue, value);
			iInserted = value;
			firePropertyChange(INSERTED_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Temporal(TemporalType.TIMESTAMP) @Column(name="inserted")
	private java.util.Calendar iInserted = new java.util.GregorianCalendar();
	final static public String INSERTED_PROPERTY_ID = "inserted";
	final static public Class INSERTED_PROPERTY_CLASS = java.util.Calendar.class;
	final static public String INSERTED_NAME = "Inserted"; // with this ID you can access the internationalization


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

	/** clone */
	public Object clone()
	{ 
		nl.reinders.bm.Calendar lNew = new nl.reinders.bm.Calendar();
		lNew.setAddress( getAddress() ); 
		lNew.setContact( getContact() ); 
		lNew.setEmployee( getEmployee() ); 
		lNew.setRelation( getRelation() ); 
		lNew.setRemindMoment( getRemindMoment() ); 
		lNew.setMeetingStart( getMeetingStart() ); 
		lNew.setMeetingEnd( getMeetingEnd() ); 
		lNew.setDescription( getDescription() ); 
		lNew.setIsDone( getIsDone() ); 
		// not cloning this column: lNew.setDwhmodified( getDwhmodified() ); 
		// not cloning this column: lNew.setDwhby( getDwhby() ); 
		lNew.setInserted( getInserted() ); 
		return lNew;
	}
	public nl.reinders.bm.Calendar cloneShallow() { return (nl.reinders.bm.Calendar)clone();}


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

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


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

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

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

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


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

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



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

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


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