package com.fp.persistence.pgeneral.gene;

import java.io.Serializable;
import java.lang.reflect.Field;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;

import com.fp.dto.hb.HibernateBean;

/** Clase que implementa la entidad de Hibernate que hace referencia a la tabla TGENEFUNCTIONS */
@Entity(name = "TgeneFunctions")
@Table(name = "TGENEFUNCTIONS")
public class TgeneFunctions extends com.fp.dto.AbstractDataTransport implements Serializable, HibernateBean, Cloneable {
    /**
     * HashCode asociado con la Instancia
     */
    @Transient
    private int hashValue = 0;

    /**
     * Version de la Clase
     */
    private static final long serialVersionUID = 1L;

    /**
     * Clave primaria de la Entidad TgeneFunctions
     */
    @Id
    @Column(name = "NAME", nullable = false, updatable = false)
    private String pk;

    @Column(name = "CLASSNAME", nullable = false)
    /**
     * NOMBRE DE LA CLASE
     */
    private String classname;

    @Column(name = "DESCRIPTION", nullable = true)
    private String description;

    @Column(name = "ACTIVE", nullable = true)
    /**
     * ESTADO DE LA FUNCION
     */
    private String active;

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String pDescription) {
        this.description = pDescription;
    }

    @Version
    @Column(name = "RECORDVERSION", nullable = true)
    /**
     * MANEJO DE OPTIMISTIC LOCKING
     */
    private Integer recordversion;

    /** Contructor por defecto */
    public TgeneFunctions() {
    }

    /**
     * Contructor de TgeneFunctions
     * 
     * @param pPk Clave Primaria del entity
     * @param pClassname NOMBRE DE LA CLASE
     */
    public TgeneFunctions(String pPk, String pClassname) {
        this();
        this.pk = pPk;
        this.classname = pClassname;
    }

    /**
     * Metodo que entrega datos de la tabla dada la clave primaria.
     * 
     * @param pEntityManager referencia de la session a obtener datos del bean.
     * @param pKey Caleve primaria del bean.
     * @return TgeneFunctions
     */
    public static TgeneFunctions find(EntityManager pEntityManager, Object pKey) throws Exception {
        TgeneFunctions obj = pEntityManager.find(TgeneFunctions.class, pKey);
        return obj;
    }

    /**
     * Entrega la Clave primaria de TgeneFunctions
     * 
     * @return El objeto que referencia a la Clave primaria de TgeneFunctions
     */
    public String getPk() {
        return this.pk;
    }

    /**
     * Fija un nuevo valor a la Clave primaria de TgeneFunctions
     * 
     * @param pPk El objeto que referencia a la nueva Clave primaria de TgeneFunctions
     */
    public void setPk(String pPk) {
        this.pk = pPk;
    }

    /**
     * Obtiene el valor de classname
     * 
     * @return valor de classname
     */
    public String getClassname() {
        return this.classname;
    }

    /**
     * Fija el valor de classname
     * 
     * @param pClassname nuevo Valor de classname
     */
    public void setClassname(String pClassname) {
        this.classname = pClassname;
    }

    /**
     * Obtiene el valor de active
     * 
     * @return valor de active
     */
    public String getActive() {
        return this.active;
    }

    /**
     * Fija el valor de active
     * 
     * @param pActive nuevo Valor de active
     */
    public void setActive(String pActive) {
        this.active = pActive;
    }

    /**
     * Obtiene el valor de recordversion
     * 
     * @return valor de recordversion
     */
    public Integer getRecordversion() {
        return this.recordversion;
    }

    /**
     * Fija el valor de recordversion
     * 
     * @param pRecordversion nuevo Valor de recordversion
     */
    public void setRecordversion(Integer pRecordversion) {
        this.recordversion = pRecordversion;
    }

    @Override
    public boolean equals(Object rhs) {
        if (rhs == null) {
            return false;
        }
        if (!(rhs instanceof TgeneFunctions)) {
            return false;
        }
        TgeneFunctions that = (TgeneFunctions) rhs;
        if ((this.getPk() == null) || (that.getPk() == null)) {
            return false;
        }
        return (this.getPk().equals(that.getPk()));
    }

    /**
     * Implementacion del metodo hashCode de la la entidad TgeneFunctions
     * 
     * @return el hashCode la instancia
     */
    @Override
    public int hashCode() {
        if (this.hashValue == 0) {
            int result = 17;
            if (this.getPk() == null) {
                result = super.hashCode();
            } else {
                result = this.getPk().hashCode();
            }
            this.hashValue = result;
        }
        return this.hashValue;
    }

    /** Implementacion toString */
    @Override
    public String toString() {
        Field[] fs = this.getClass().getDeclaredFields();
        String data = "";
        for (Field f : fs) {
            try {
                String name = f.getName();
                if (f.getType().getName().compareTo("java.util.Set") == 0) {
                    continue;
                }
                if ((name.compareTo("hashValue") == 0) || (name.compareTo("serialVersionUID") == 0)) {
                    continue;
                }
                data += name + "=" + f.get(this) + ";";
            } catch (Exception e) {
                continue;
            }
        }
        if (data.compareTo("") == 0) {
            data = super.toString();
        }
        return data;
    }

    /** Implementacion de la creacion de un bean en blanco TgeneFunctions */
    @Override
    public Object createInstance() {
        TgeneFunctions instance = new TgeneFunctions();
        return instance;
    }

    /**
     * Clona la entidad TgeneFunctions
     * 
     * @see com.fp.dto.hb.HibernateBean#cloneMe()
     */
    @Override
    public Object cloneMe() throws CloneNotSupportedException {
        TgeneFunctions p = (TgeneFunctions) this.clone();
        return p;
    }
}
