369 lines
11 KiB
Plaintext
Executable File
369 lines
11 KiB
Plaintext
Executable File
package com.fp.persistence.pgeneral.acco;
|
||
|
||
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.LockModeType;
|
||
import javax.persistence.NoResultException;
|
||
import javax.persistence.Query;
|
||
import javax.persistence.Table;
|
||
import javax.persistence.Transient;
|
||
|
||
import com.fp.common.exception.CommonException;
|
||
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 TGENEACCOUNTSEQUENCE */
|
||
@Entity(name = "TgeneAccountSequence")
|
||
@Table(name = "TGENEACCOUNTSEQUENCE")
|
||
public class TgeneAccountSequence 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 TgeneAccountSequence
|
||
*/
|
||
@EmbeddedId
|
||
private TgeneAccountSequenceKey pk;
|
||
|
||
@Column(name = "PRODUCTCODE", nullable = true)
|
||
/**
|
||
* Codigo de producto
|
||
*/
|
||
private String productcode;
|
||
|
||
@Column(name = "SUBPRODUCTCODE", nullable = true)
|
||
/**
|
||
* Codigo de subproducto
|
||
*/
|
||
private String subproductcode;
|
||
|
||
@Column(name = "OFFICECODE", nullable = true)
|
||
/**
|
||
* Codigo de oficina
|
||
*/
|
||
private Integer officecode;
|
||
|
||
@Column(name = "BRANCHCODE", nullable = true)
|
||
/**
|
||
* Codigo de sucursal
|
||
*/
|
||
private Integer branchcode;
|
||
|
||
@Column(name = "COMPANYCODE", nullable = true)
|
||
/**
|
||
* Codigo de compania al que pertenece la oficina
|
||
*/
|
||
private Integer companycode;
|
||
|
||
@Column(name = "SEQUENTIALNUMBER", nullable = false)
|
||
/**
|
||
* Consecutivo de cuenta
|
||
*/
|
||
private String sequentialnumber;
|
||
|
||
/** Contructor por defecto */
|
||
public TgeneAccountSequence() {
|
||
}
|
||
|
||
/**
|
||
* Contructor de TgeneAccountSequence
|
||
*
|
||
* @param pPk Clave Primaria del entity
|
||
* @param pSequentialnumber Consecutivo de cuenta
|
||
*/
|
||
public TgeneAccountSequence(TgeneAccountSequenceKey pPk, String pSequentialnumber) {
|
||
this();
|
||
this.pk = pPk;
|
||
this.sequentialnumber = pSequentialnumber;
|
||
}
|
||
|
||
/**
|
||
* 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 TgeneAccountSequence
|
||
*/
|
||
public static TgeneAccountSequence find(EntityManager pEntityManager, TgeneAccountSequenceKey pKey) throws Exception {
|
||
TgeneAccountSequence obj = pEntityManager.find(TgeneAccountSequence.class, pKey);
|
||
return obj;
|
||
}
|
||
|
||
/**
|
||
* Entrega la Clave primaria de TgeneAccountSequence
|
||
*
|
||
* @return El objeto que referencia a la Clave primaria de TgeneAccountSequence
|
||
*/
|
||
public TgeneAccountSequenceKey getPk() {
|
||
return this.pk;
|
||
}
|
||
|
||
/**
|
||
* Fija un nuevo valor a la Clave primaria de TgeneAccountSequence
|
||
*
|
||
* @param pPk El objeto que referencia a la nueva Clave primaria de TgeneAccountSequence
|
||
*/
|
||
public void setPk(TgeneAccountSequenceKey pPk) {
|
||
this.pk = pPk;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de productcode
|
||
*
|
||
* @return valor de productcode
|
||
*/
|
||
public String getProductcode() {
|
||
return this.productcode;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de productcode
|
||
*
|
||
* @param pProductcode nuevo Valor de productcode
|
||
*/
|
||
public void setProductcode(String pProductcode) {
|
||
this.productcode = pProductcode;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de subproductcode
|
||
*
|
||
* @return valor de subproductcode
|
||
*/
|
||
public String getSubproductcode() {
|
||
return this.subproductcode;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de subproductcode
|
||
*
|
||
* @param pSubproductcode nuevo Valor de subproductcode
|
||
*/
|
||
public void setSubproductcode(String pSubproductcode) {
|
||
this.subproductcode = pSubproductcode;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de officecode
|
||
*
|
||
* @return valor de officecode
|
||
*/
|
||
public Integer getOfficecode() {
|
||
return this.officecode;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de officecode
|
||
*
|
||
* @param pOfficecode nuevo Valor de officecode
|
||
*/
|
||
public void setOfficecode(Integer pOfficecode) {
|
||
this.officecode = pOfficecode;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de branchcode
|
||
*
|
||
* @return valor de branchcode
|
||
*/
|
||
public Integer getBranchcode() {
|
||
return this.branchcode;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de branchcode
|
||
*
|
||
* @param pBranchcode nuevo Valor de branchcode
|
||
*/
|
||
public void setBranchcode(Integer pBranchcode) {
|
||
this.branchcode = pBranchcode;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de companycode
|
||
*
|
||
* @return valor de companycode
|
||
*/
|
||
public Integer getCompanycode() {
|
||
return this.companycode;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de companycode
|
||
*
|
||
* @param pCompanycode nuevo Valor de companycode
|
||
*/
|
||
public void setCompanycode(Integer pCompanycode) {
|
||
this.companycode = pCompanycode;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de sequentialnumber
|
||
*
|
||
* @return valor de sequentialnumber
|
||
*/
|
||
public String getSequentialnumber() {
|
||
return this.sequentialnumber;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de sequentialnumber
|
||
*
|
||
* @param pSequentialnumber nuevo Valor de sequentialnumber
|
||
*/
|
||
public void setSequentialnumber(String pSequentialnumber) {
|
||
this.sequentialnumber = pSequentialnumber;
|
||
}
|
||
|
||
@Override
|
||
public boolean equals(Object rhs) {
|
||
if (rhs == null) {
|
||
return false;
|
||
}
|
||
if (!(rhs instanceof TgeneAccountSequence)) {
|
||
return false;
|
||
}
|
||
TgeneAccountSequence that = (TgeneAccountSequence) 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 TgeneAccountSequence
|
||
*
|
||
* @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 TgeneAccountSequence */
|
||
@Override
|
||
public Object createInstance() {
|
||
TgeneAccountSequence instance = new TgeneAccountSequence();
|
||
instance.setPk(new TgeneAccountSequenceKey());
|
||
return instance;
|
||
}
|
||
|
||
/**
|
||
* Clona la entidad TgeneAccountSequence
|
||
*
|
||
* @see com.fp.dto.hb.HibernateBean#cloneMe()
|
||
*/
|
||
@Override
|
||
public Object cloneMe() throws CloneNotSupportedException {
|
||
TgeneAccountSequence p = (TgeneAccountSequence) this.clone();
|
||
p.setPk((TgeneAccountSequenceKey) this.pk.cloneMe());
|
||
return p;
|
||
}
|
||
|
||
|
||
// METODOS MANUALES
|
||
|
||
/** Sentencia que obtiene un registro de TgeneAccountSequence con la secuencia de numeros de cuenta. */
|
||
private static final String HQL = "from TgeneAccountSequence t " + " where t.pk.modulecode = :modulecode "
|
||
+ " and coalesce(productcode,:productcode) = :productcode " + " and coalesce(subproductcode,:subproductcode) = :subproductcode "
|
||
+ " and coalesce(officecode,:officecode) = :officecode " + " and coalesce(branchcode,:branchcode) = :branchcode "
|
||
+ " and coalesce(companycode,:companycode) = :companycode ";
|
||
|
||
/** Sentencia que obtiene la cuenta de secuencias en TgeneAccountSequence por modulo. */
|
||
private static final String HQL_SEQ = "select count(t.pk.modulecode) " + " from TgeneAccountSequence t " + " where t.pk.modulecode = :modulecode ";
|
||
|
||
/**
|
||
* Metodo que entrega datos de la tabla dada la clave primaria.
|
||
*
|
||
* @param pEntityManager referencia de la session a obtener datos del bean.
|
||
* @param pModule Codigo de modulo
|
||
* @param pProduct Codigo de producto
|
||
* @param pSubproduct Codigo de sub producto
|
||
* @param pBranchcode Codigo de sucursal
|
||
* @param pOfficecode Codigo de oficina
|
||
* @param pCompany Codigo de compania
|
||
* @return TgeneAccountSequence
|
||
*/
|
||
public static TgeneAccountSequence findWithhold(EntityManager pEntityManager, String pModule, String pProduct, String pSubproduct,
|
||
Integer pBranch, Integer pOffice, Integer pCompany) throws Exception {
|
||
Query qry = pEntityManager.createQuery(TgeneAccountSequence.HQL);
|
||
qry.setParameter("modulecode", pModule);
|
||
qry.setParameter("productcode", pProduct);
|
||
qry.setParameter("subproductcode", pSubproduct);
|
||
qry.setParameter("branchcode", pBranch);
|
||
qry.setParameter("officecode", pOffice);
|
||
qry.setParameter("companycode", pCompany);
|
||
qry.setLockMode(LockModeType.PESSIMISTIC_READ);
|
||
try {
|
||
return (TgeneAccountSequence) qry.getSingleResult();
|
||
} catch (NoResultException e) {
|
||
throw new CommonException("CORE-0025", "SECUENCIA DE CUENTA NO DEFINIDA EN TGENEACCOUNTSEQUENCE MODULO: {0}", pModule);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Metodo que entrega la cuenta de secuencias en TgeneAccountSequence por modulo. Devuelve '0' si no hay ningun registro
|
||
*
|
||
* @param pEntityManager referencia de la session a obtener datos del bean.
|
||
* @param pModule Codigo de modulo
|
||
* @return Numero de secuencias por modulo
|
||
*/
|
||
public static String getAmountSequences(EntityManager pEntityManager, String pModule) throws Exception {
|
||
Query qry = pEntityManager.createQuery(TgeneAccountSequence.HQL_SEQ);
|
||
qry.setParameter("modulecode", pModule);
|
||
try {
|
||
return qry.getSingleResult().toString();
|
||
} catch (NoResultException e) {
|
||
throw new GeneralException("CORE-0025", "SECUENCIA DE CUENTA NO DEFINIDA EN TGENEACCOUNTSEQUENCE MODULO: {}", pModule);
|
||
}
|
||
}
|
||
|
||
}
|