211 lines
6.3 KiB
Plaintext
Executable File
211 lines
6.3 KiB
Plaintext
Executable File
package com.fp.persistence.pgeneral.acco;
|
||
|
||
import java.io.Serializable;
|
||
import java.lang.reflect.Field;
|
||
import java.math.BigDecimal;
|
||
|
||
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 com.fp.dto.hb.HibernateBean;
|
||
|
||
/** Clase que implementa la entidad de Hibernate que hace referencia a la tabla TGENEACCOUNTPAYABLE */
|
||
@Entity(name = "TgeneAccountPayable")
|
||
@Table(name = "TGENEACCOUNTPAYABLE")
|
||
public class TgeneAccountPayable extends com.fp.dto.AbstractDataBalanceTransport 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 TgeneAccountPayable
|
||
*/
|
||
@EmbeddedId
|
||
private TgeneAccountPayableKey pk;
|
||
|
||
@Column(name = "BALANCE", nullable = true)
|
||
/**
|
||
* Saldo de la cuenta por pagar.
|
||
*/
|
||
private BigDecimal balance;
|
||
|
||
/** Contructor por defecto */
|
||
public TgeneAccountPayable() {
|
||
}
|
||
|
||
/**
|
||
* Contructor de TgeneAccountPayable
|
||
*
|
||
* @param pPk Clave Primaria del entity
|
||
*/
|
||
public TgeneAccountPayable(TgeneAccountPayableKey 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 TgeneAccountPayable
|
||
*/
|
||
public static TgeneAccountPayable find(EntityManager pEntityManager, TgeneAccountPayableKey pKey) throws Exception {
|
||
TgeneAccountPayable obj = pEntityManager.find(TgeneAccountPayable.class, pKey);
|
||
return obj;
|
||
}
|
||
|
||
/**
|
||
* Entrega la Clave primaria de TgeneAccountPayable
|
||
*
|
||
* @return El objeto que referencia a la Clave primaria de TgeneAccountPayable
|
||
*/
|
||
public TgeneAccountPayableKey getPk() {
|
||
return this.pk;
|
||
}
|
||
|
||
/**
|
||
* Fija un nuevo valor a la Clave primaria de TgeneAccountPayable
|
||
*
|
||
* @param pPk El objeto que referencia a la nueva Clave primaria de TgeneAccountPayable
|
||
*/
|
||
public void setPk(TgeneAccountPayableKey pPk) {
|
||
this.pk = pPk;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de balance
|
||
*
|
||
* @return valor de balance
|
||
*/
|
||
public BigDecimal getBalance() {
|
||
return this.balance;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de balance
|
||
*
|
||
* @param pBalance nuevo Valor de balance
|
||
*/
|
||
public void setBalance(BigDecimal pBalance) {
|
||
this.balance = pBalance;
|
||
}
|
||
|
||
@Override
|
||
public boolean equals(Object rhs) {
|
||
if (rhs == null) {
|
||
return false;
|
||
}
|
||
if (!(rhs instanceof TgeneAccountPayable)) {
|
||
return false;
|
||
}
|
||
TgeneAccountPayable that = (TgeneAccountPayable) rhs;
|
||
if ((this.getPk() == null) || (that.getPk() == null)) {
|
||
return false;
|
||
}
|
||
return (this.getPk().equals(that.getPk()));
|
||
}
|
||
|
||
/**
|
||
* Implementaci<63>n del metodo hashCode de la la entidad TgeneAccountPayable
|
||
*
|
||
* @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<63>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<63>n de la creaci<63>n de un bean en blanco TgeneAccountPayable */
|
||
@Override
|
||
public Object createInstance() {
|
||
TgeneAccountPayable instance = new TgeneAccountPayable();
|
||
instance.setPk(new TgeneAccountPayableKey());
|
||
return instance;
|
||
}
|
||
|
||
/**
|
||
* Clona la entidad TgeneAccountPayable
|
||
*
|
||
* @see com.fp.dto.hb.HibernateBean#cloneMe()
|
||
*/
|
||
@Override
|
||
public Object cloneMe() throws CloneNotSupportedException {
|
||
TgeneAccountPayable p = (TgeneAccountPayable) this.clone();
|
||
p.setPk((TgeneAccountPayableKey) this.pk.cloneMe());
|
||
return p;
|
||
}
|
||
|
||
// METODOS MANUALES
|
||
/** Sentencia que devuelve saldos de cuentas por pagar. */
|
||
private static final String JPQL_PAYABLE = "from TgeneAccountPayable t " + " where t.pk.account = :account " + " and t.pk.company = :company ";
|
||
|
||
/**
|
||
* Entrega un registro de saldos de cuentas por pagar.
|
||
*
|
||
* @param pEntityManager Session de la base de datos.
|
||
* @param pAccount Numero de cuenta.
|
||
* @param pCompany Codigo de compania a la que pertenece la cuenta.
|
||
* @return TgeneAccountPayable
|
||
* @throws Exception
|
||
*/
|
||
public static TgeneAccountPayable findByAccountNumber(EntityManager pEntityManager, String pAccount, Integer pCompany) throws Exception {
|
||
Query qry = pEntityManager.createQuery(TgeneAccountPayable.JPQL_PAYABLE);
|
||
qry.setParameter("account", pAccount);
|
||
qry.setParameter("company", pCompany);
|
||
try {
|
||
return (TgeneAccountPayable) qry.getSingleResult();
|
||
} catch (NoResultException e) {
|
||
return null;
|
||
}
|
||
}
|
||
|
||
}
|