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

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


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



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

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

	/** Cleaneduntil */
	public java.util.Calendar getCleaneduntil() { return iCleaneduntil; }
	public void setCleaneduntil(java.util.Calendar value)
	{
		try
		{
			java.util.Calendar lValue = iCleaneduntil;
			if (log4j.isDebugEnabled()) log4j.debug("setCleaneduntil: " + lValue + " -> " + value);
			fireVetoableChange(CLEANEDUNTIL_PROPERTY_ID, lValue, value);
			iCleaneduntil = value;
			firePropertyChange(CLEANEDUNTIL_PROPERTY_ID, lValue, value);
		}
		catch (java.beans.PropertyVetoException e) { throw new java.lang.IllegalArgumentException("Value vetoed: " + e.getMessage()); }
	}
	@Temporal(TemporalType.TIMESTAMP) @Column(name="cleaneduntil")
	private java.util.Calendar iCleaneduntil = null;
	final static public String CLEANEDUNTIL_PROPERTY_ID = "cleaneduntil";
	final static public Class CLEANEDUNTIL_PROPERTY_CLASS = java.util.Calendar.class;
	final static public String CLEANEDUNTIL_NAME = "Cleaneduntil"; // with this ID you can access the internationalization


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

	/** clone */
	public Object clone()
	{ 
		nl.reinders.bm.Cleaneduntil lNew = new nl.reinders.bm.Cleaneduntil();
		lNew.setCleaneduntil( getCleaneduntil() ); 
		return lNew;
	}
	public nl.reinders.bm.Cleaneduntil cloneShallow() { return (nl.reinders.bm.Cleaneduntil)clone();}


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

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


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

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

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

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


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

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



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

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


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