243 lines
7.0 KiB
Plaintext
Executable File
243 lines
7.0 KiB
Plaintext
Executable File
package com.fp.persistence.pgeneral.result;
|
||
|
||
import java.io.Serializable;
|
||
import java.lang.reflect.Field;
|
||
|
||
import javax.persistence.Column;
|
||
import javax.persistence.EmbeddedId;
|
||
import javax.persistence.Entity;
|
||
import javax.persistence.EntityManager;
|
||
import javax.persistence.NoResultException;
|
||
import javax.persistence.Query;
|
||
import javax.persistence.Table;
|
||
import javax.persistence.Transient;
|
||
import javax.persistence.Version;
|
||
|
||
import com.fp.dto.hb.HibernateBean;
|
||
import com.fp.general.exception.GeneralException;
|
||
|
||
/** Clase que implementa la entidad de Hibernate que hace referencia a la tabla TGENERESULTS */
|
||
@Entity(name = "TgeneResults")
|
||
@Table(name = "TGENERESULTS")
|
||
public class TgeneResults 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 TgeneResults
|
||
*/
|
||
@EmbeddedId
|
||
private TgeneResultsKey pk;
|
||
|
||
@Version
|
||
@Column(name = "RECORDVERSION", nullable = true)
|
||
/**
|
||
* Codigo que valida caducidad de registro
|
||
*/
|
||
private Integer recordversion;
|
||
|
||
@Column(name = "DESCRIPTION", nullable = false)
|
||
/**
|
||
* Mensaje a presentar
|
||
*/
|
||
private String description;
|
||
|
||
/** Contructor por defecto */
|
||
public TgeneResults() {
|
||
}
|
||
|
||
/**
|
||
* Contructor de TgeneResults
|
||
*
|
||
* @param pPk Clave Primaria del entity
|
||
* @param pDescription Mensaje a presentar
|
||
*/
|
||
public TgeneResults(TgeneResultsKey pPk, String pDescription) {
|
||
this();
|
||
this.pk = pPk;
|
||
this.description = pDescription;
|
||
}
|
||
|
||
/**
|
||
* 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 TgeneResults
|
||
*/
|
||
public static TgeneResults find(EntityManager pEntityManager, TgeneResultsKey pKey) throws Exception {
|
||
TgeneResults obj = pEntityManager.find(TgeneResults.class, pKey);
|
||
return obj;
|
||
}
|
||
|
||
/**
|
||
* Entrega la Clave primaria de TgeneResults
|
||
*
|
||
* @return El objeto que referencia a la Clave primaria de TgeneResults
|
||
*/
|
||
public TgeneResultsKey getPk() {
|
||
return this.pk;
|
||
}
|
||
|
||
/**
|
||
* Fija un nuevo valor a la Clave primaria de TgeneResults
|
||
*
|
||
* @param pPk El objeto que referencia a la nueva Clave primaria de TgeneResults
|
||
*/
|
||
public void setPk(TgeneResultsKey pPk) {
|
||
this.pk = pPk;
|
||
}
|
||
|
||
/**
|
||
* 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;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de description
|
||
*
|
||
* @return valor de description
|
||
*/
|
||
public String getDescription() {
|
||
return this.description;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de description
|
||
*
|
||
* @param pDescription nuevo Valor de description
|
||
*/
|
||
public void setDescription(String pDescription) {
|
||
this.description = pDescription;
|
||
}
|
||
|
||
@Override
|
||
public boolean equals(Object rhs) {
|
||
if (rhs == null) {
|
||
return false;
|
||
}
|
||
if (!(rhs instanceof TgeneResults)) {
|
||
return false;
|
||
}
|
||
TgeneResults that = (TgeneResults) rhs;
|
||
if ((this.getPk() == null) || (that.getPk() == null)) {
|
||
return false;
|
||
}
|
||
return (this.getPk().equals(that.getPk()));
|
||
}
|
||
|
||
/**
|
||
* Implementacion del metodo hashCode de la la entidad TgeneResults
|
||
*
|
||
* @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 TgeneResults */
|
||
@Override
|
||
public Object createInstance() {
|
||
TgeneResults instance = new TgeneResults();
|
||
instance.setPk(new TgeneResultsKey());
|
||
return instance;
|
||
}
|
||
|
||
/**
|
||
* Clona la entidad TgeneResults
|
||
*
|
||
* @see com.fp.dto.hb.HibernateBean#cloneMe()
|
||
*/
|
||
@Override
|
||
public Object cloneMe() throws CloneNotSupportedException {
|
||
TgeneResults p = (TgeneResults) this.clone();
|
||
p.setPk((TgeneResultsKey) this.pk.cloneMe());
|
||
return p;
|
||
}
|
||
|
||
// Metodos manuales.
|
||
|
||
/**
|
||
* Sentencia que entrega el texto asociado a un codigo de error e idioma.
|
||
*/
|
||
private static final String JPQL = "from TgeneResults t where t.pk.resultcode = :resultcode and t.pk.languagecode = :languagecode";
|
||
|
||
/**
|
||
* Entrega la descripcion de un codigo de error.
|
||
*
|
||
* @param entityManager Referencia a una session de base de datos.
|
||
* @param resultcode Codigo de resultado a buscar la descripcion.
|
||
* @param languagecode Codigo de lenguaje a buscar la descripcion.
|
||
* @return TgeneResults
|
||
* @throws Exception
|
||
*/
|
||
public static TgeneResults find(EntityManager entityManager, String resultcode, String languagecode) throws Exception {
|
||
Query qry = entityManager.createQuery(JPQL);
|
||
qry.setParameter("resultcode", resultcode);
|
||
qry.setParameter("languagecode", languagecode);
|
||
try {
|
||
return (TgeneResults) qry.getSingleResult();
|
||
} catch (NoResultException e) {
|
||
throw new GeneralException("GENE-0044", "DESCRIPCI<43>N DEL MENSAJE APLICATIVO: {0} IDIOMA: {1} NO DEFINIDO EN TGENERESULTS", resultcode,
|
||
languagecode);
|
||
}
|
||
}
|
||
|
||
}
|