package com.fp.persistence.pgeneral.product; import java.io.Serializable; import java.lang.reflect.Field; import java.util.List; 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; /** Clase que implementa la entidad de Hibernate que hace referencia a la tabla TGENESUBPRODCLIENTDATA */ @Entity(name = "TgeneSubprodClientData") @Table(name = "TGENESUBPRODCLIENTDATA") public class TgeneSubprodClientData 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 TgeneSubprodClientData */ @EmbeddedId private TgeneSubprodClientDataKey pk; @Column(name = "MODIFIABLE", nullable = true) /** * Y indica que la informacion del cliente es modificable en la transaccion de verificaciond e informacion de clientes. */ private String modifiable; @Version @Column(name = "RECORDVERSION", nullable = true) /** * Optimistic locking del registro. */ private Integer recordversion; @Column(name = "ACTIVE", nullable = true) /** * Y indica que la validacion de la pagina esta activa. */ private String active; @Column(name = "PRESENTATIONORDER", nullable = true) /** * Orden de presentacion */ private Integer presentationorder; /** Contructor por defecto */ public TgeneSubprodClientData() { } /** * Contructor de TgeneSubprodClientData * * @param pPk Clave Primaria del entity */ public TgeneSubprodClientData(TgeneSubprodClientDataKey pPk) { this(); this.pk = pPk; } /** * 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 TgeneSubprodClientData */ public static TgeneSubprodClientData find(EntityManager pEntityManager, TgeneSubprodClientDataKey pKey) throws Exception { TgeneSubprodClientData obj = pEntityManager.find(TgeneSubprodClientData.class, pKey); return obj; } /** * Entrega la Clave primaria de TgeneSubprodClientData * * @return El objeto que referencia a la Clave primaria de TgeneSubprodClientData */ public TgeneSubprodClientDataKey getPk() { return this.pk; } /** * Fija un nuevo valor a la Clave primaria de TgeneSubprodClientData * * @param pPk El objeto que referencia a la nueva Clave primaria de TgeneSubprodClientData */ public void setPk(TgeneSubprodClientDataKey pPk) { this.pk = pPk; } /** * Obtiene el valor de modifiable * * @return valor de modifiable */ public String getModifiable() { return this.modifiable; } /** * Fija el valor de modifiable * * @param pModifiable nuevo Valor de modifiable */ public void setModifiable(String pModifiable) { this.modifiable = pModifiable; } /** * 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 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 presentationorder * * @return valor de presentationorder */ public Integer getPresentationorder() { return this.presentationorder; } /** * Fija el valor de presentationorder * * @param pPresentationorder nuevo Valor de presentationorder */ public void setPresentationorder(Integer pPresentationorder) { this.presentationorder = pPresentationorder; } @Override public boolean equals(Object rhs) { if (rhs == null) { return false; } if (!(rhs instanceof TgeneSubprodClientData)) { return false; } TgeneSubprodClientData that = (TgeneSubprodClientData) rhs; if ((this.getPk() == null) || (that.getPk() == null)) { return false; } return (this.getPk().equals(that.getPk())); } /** * Implementación del metodo hashCode de la la entidad TgeneSubprodClientData * * @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; } /** Implementación 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; } /** Implementación de la creación de un bean en blanco TgeneSubprodClientData */ @Override public Object createInstance() { TgeneSubprodClientData instance = new TgeneSubprodClientData(); instance.setPk(new TgeneSubprodClientDataKey()); return instance; } /** * Clona la entidad TgeneSubprodClientData * * @see com.fp.dto.hb.HibernateBean#cloneMe() */ @Override public Object cloneMe() throws CloneNotSupportedException { TgeneSubprodClientData p = (TgeneSubprodClientData) this.clone(); p.setPk((TgeneSubprodClientDataKey) this.pk.cloneMe()); return p; } // METODOS MANUALES /** Sentencia que devuelve la definicion datos de clientes requeridos para aprobar una solicitud. */ private static final String JPQL_SUBPROD_CLIENT_DATA = "from TgeneSubprodClientData tcd " + " where tcd.pk.modulecode = :modulecode " + " and tcd.pk.productcode = :productcode " + " and tcd.pk.subproductcode = :subproductcode " + " and tcd.pk.persontypecatalog = :persontype " + " and tcd.pk.relationshipcode = :relationshipcode " + " order by tcd.presentationorder "; /** * Metodo que entrega una lista de datos requeridos de clientes por producto. * * @param pModuleCode Codigo de modulo. * @param pProductCode Codigo de producto. * @param pSubproductCode Codigo de subproducto. * @param pPersontype Tipo de persona. * @return List * @throws Exception */ @SuppressWarnings("unchecked") public static List findByProduct(EntityManager pEntityManager, String pModuleCode, String pProductCode, String pSubproductCode, String pPersontype, String pRelationshipcode) throws Exception { List ldata = null; Query qry = pEntityManager.createQuery(TgeneSubprodClientData.JPQL_SUBPROD_CLIENT_DATA); qry.setParameter(com.fp.common.helper.Constant.VMODULECODE, pModuleCode); qry.setParameter(com.fp.common.helper.Constant.VPRODUCTCODE, pProductCode); qry.setParameter(com.fp.common.helper.Constant.VSUBPRODUCTCODE, pSubproductCode); qry.setParameter("persontype", pPersontype); qry.setParameter("relationshipcode", pRelationshipcode); ldata = qry.getResultList(); return ldata; } /** Sentencia que devuelve la definicion datos de clientes requeridos para aprobar una solicitud. */ private static final String JPQL_SUBPROD_CLIENT_DATA_ACTIVE = "from TgeneSubprodClientData tcd " + " where tcd.pk.modulecode = :modulecode " + " and tcd.pk.productcode = :productcode " + " and tcd.pk.subproductcode = :subproductcode " + " and tcd.pk.persontypecatalog = :persontype " + " and tcd.pk.relationshipcode = :relationshipcode " + " and tcd.active = 'Y' " + " order by tcd.presentationorder "; /** * Metodo que entrega una lista de datos requeridos de clientes por producto. * * @param pModuleCode Codigo de modulo. * @param pProductCode Codigo de producto. * @param pSubproductCode Codigo de subproducto. * @param pPersontype Tipo de persona. * @return List * @throws Exception */ @SuppressWarnings("unchecked") public static List findByProductActive(EntityManager pEntityManager, String pModuleCode, String pProductCode, String pSubproductCode, String pPersontype, String pRelationshipcode) throws Exception { List ldata = null; Query qry = pEntityManager.createQuery(TgeneSubprodClientData.JPQL_SUBPROD_CLIENT_DATA_ACTIVE); qry.setParameter(com.fp.common.helper.Constant.VMODULECODE, pModuleCode); qry.setParameter(com.fp.common.helper.Constant.VPRODUCTCODE, pProductCode); qry.setParameter(com.fp.common.helper.Constant.VSUBPRODUCTCODE, pSubproductCode); qry.setParameter("persontype", pPersontype); qry.setParameter("relationshipcode", pRelationshipcode); ldata = qry.getResultList(); return ldata; } /** * Sentencia SQL que obtiene un objeto de tipo TgeneSolicitude */ private static final String JPQL_SUBPRODUCT_CLIENT_DATA = "from TgeneSubprodClientData tgs" + " where tgs.pk.modulecode = :modulecode" + " and tgs.pk.productcode = :productcode" + " and tgs.pk.subproductcode = :subproductcode" + " and tgs.pk.persontypecatalog = :persontypecatalog" + " and tgs.pk.persontypecatalogcode = :persontypecatalogcode" + " and tgs.pk.relationshipcode = :relationshipcode" + " and tgs.pk.title = :title"; /** * Metodo que devuelve un objeto de tipo TgeneSubprodClientData * * @param modulecode * @param productcode * @param subproductcode * @param persontype * @param relationshipcode * @param title * @return * @throws Exception */ public static TgeneSubprodClientData find(EntityManager pEntityManager, String modulecode, String productcode, String subproductcode, String persontype, String relationshipcode, String title) throws Exception { Query qry = pEntityManager.createQuery(TgeneSubprodClientData.JPQL_SUBPRODUCT_CLIENT_DATA); qry.setParameter("modulecode", modulecode); qry.setParameter("productcode", productcode); qry.setParameter("subproductcode", subproductcode); qry.setParameter("persontypecatalog", persontype); qry.setParameter("persontypecatalogcode", "PERSONTYPE"); qry.setParameter("relationshipcode", relationshipcode); qry.setParameter("title", title); try { return (TgeneSubprodClientData) qry.getSingleResult(); } catch (NoResultException e) { return null; } } }