package com.fp.persistence.pgeneral.acco; import java.io.Serializable; import java.lang.reflect.Field; import java.math.BigDecimal; import java.util.List; import javax.persistence.Column; import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.Query; import javax.persistence.Table; import javax.persistence.Transient; import com.fp.common.helper.Constant; import com.fp.dto.hb.HibernateBean; /** Clase que implementa la entidad de Hibernate que hace referencia a la tabla TGENEACCOUNTFORDEBIT */ @Entity(name = "TgeneAccountForDebit") @Table(name = "TGENEACCOUNTFORDEBIT") public class TgeneAccountForDebit 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 TgeneAccountForDebit */ @EmbeddedId private TgeneAccountForDebitKey pk; @Column(name = "DEBITACCOUNT", nullable = true) /** * Numero de cuenta a debitar cuando el cargo se cobra con debito a la cuenta. */ private String debitaccount; @Column(name = "DEBITACCOUNTINGCODE", nullable = true) /** * Codigo contable cuando el cargo se cobra con debito a la cuenta. */ private String debitaccountingcode; @Column(name = "CURRENCY", nullable = true) /** * Codigo de moneda de la cuenta de la operacion. */ private String currency; @Column(name = "VALUE", nullable = true) /** * Valor en la moneda de la cuenta, la compra venta se hace en funcion a la moneda de la cuenta debito */ private BigDecimal value; /** Contructor por defecto */ public TgeneAccountForDebit() { } /** * Contructor de TgeneAccountForDebit * * @param pPk Clave Primaria del entity */ public TgeneAccountForDebit(TgeneAccountForDebitKey pPk) { 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 TgeneAccountForDebit */ public static TgeneAccountForDebit find(EntityManager pEntityManager, TgeneAccountForDebitKey pKey) throws Exception { TgeneAccountForDebit obj = pEntityManager.find(TgeneAccountForDebit.class, pKey); return obj; } /** * Entrega la Clave primaria de TgeneAccountForDebit * * @return El objeto que referencia a la Clave primaria de TgeneAccountForDebit */ public TgeneAccountForDebitKey getPk() { return pk; } /** * Fija un nuevo valor a la Clave primaria de TgeneAccountForDebit * * @param pPk El objeto que referencia a la nueva Clave primaria de TgeneAccountForDebit */ public void setPk(TgeneAccountForDebitKey pPk) { pk = pPk; } /** * Obtiene el valor de debitaccount * * @return valor de debitaccount */ public String getDebitaccount() { return debitaccount; } /** * Fija el valor de debitaccount * * @param pDebitaccount nuevo Valor de debitaccount */ public void setDebitaccount(String pDebitaccount) { debitaccount = pDebitaccount; } /** * Obtiene el valor de debitaccountingcode * * @return valor de debitaccountingcode */ public String getDebitaccountingcode() { return debitaccountingcode; } /** * Fija el valor de debitaccountingcode * * @param pDebitaccountingcode nuevo Valor de debitaccountingcode */ public void setDebitaccountingcode(String pDebitaccountingcode) { debitaccountingcode = pDebitaccountingcode; } /** * Obtiene el valor de currency * * @return valor de currency */ public String getCurrency() { return currency; } /** * Fija el valor de currency * * @param pCurrency nuevo Valor de currency */ public void setCurrency(String pCurrency) { currency = pCurrency; } /** * Obtiene el valor de value * * @return valor de value */ public BigDecimal getValue() { return value; } /** * Fija el valor de value * * @param pValue nuevo Valor de value */ public void setValue(BigDecimal pValue) { value = pValue; } public boolean equals(Object rhs) { if (rhs == null) return false; if (!(rhs instanceof TgeneAccountForDebit)) return false; TgeneAccountForDebit that = (TgeneAccountForDebit) 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 TgeneAccountForDebit * * @return el hashCode la instancia */ 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 */ 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 TgeneAccountForDebit */ public Object createInstance() { TgeneAccountForDebit instance = new TgeneAccountForDebit(); instance.setPk(new TgeneAccountForDebitKey()); return instance; } /** * Clona la entidad TgeneAccountForDebit * * @see com.fp.dto.hb.HibernateBean#cloneMe() */ public Object cloneMe() throws CloneNotSupportedException { TgeneAccountForDebit p = (TgeneAccountForDebit) this.clone(); p.setPk((TgeneAccountForDebitKey) this.pk.cloneMe()); return p; } //Metodos manuales /** Sentencia que devuelve datos de la tabla TgeneAccountForDebit.*/ private static final String HQL_ACCOUNT_FOR_DEBIT = "from TgeneAccountForDebit tafd " + " where tafd.pk.account = :account "+ " and tafd.pk.company = :company "; /** * Entrega datos de cuentas a debitar para cancelar el valor de la cuneta. * @param pAccount Numero de cuenta. * @param pCompany Codigo de compania. * @return List * @throws Exception */ @SuppressWarnings(Constant.VUNCHECKED) public static List find(EntityManager pEntityManager, String pAccount,Integer pCompany) throws Exception { List ldebits = null; Query qry = pEntityManager.createQuery(HQL_ACCOUNT_FOR_DEBIT); qry.setParameter("account", pAccount); qry.setParameter("company", pCompany); ldebits = qry.getResultList(); return ldebits; } }