package com.fp.persistence.pgeneral.batch; import java.io.Serializable; import java.lang.reflect.Field; import java.sql.Date; import java.sql.Timestamp; 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 TGENEBATCHLOG */ @Entity(name = "TgeneBatchLog") @Table(name = "TGENEBATCHLOG") public class TgeneBatchLog 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 TgeneBatchLog */ @EmbeddedId private TgeneBatchLogKey pk; @Column(name = "TRANSACTIONMODULE", nullable = true) /** * Modulo al que pertence la transaccion */ private String transactionmodule; @Column(name = "TRANSACTIONCODE", nullable = true) /** * Codigo de transaccion dentro del modulo */ private Integer transactioncode; @Column(name = "TRANSACTIONVERSION", nullable = true) /** * Version de transaccion */ private Integer transactionversion; @Column(name = "FINITDATE", nullable = true) /** * Fecha real de inicio de ejecución del batch */ private Timestamp finitdate; @Column(name = "FENDDATE", nullable = true) /** * Fecha fin real de ejecución del batch */ private Timestamp fenddate; @Column(name = "TOTAL", nullable = true) /** * Número total de cuentas a procesar */ private Integer total; @Column(name = "EXECUTED", nullable = true) /** * Número total de cuentas ejecutadas */ private Integer executed; @Column(name = "TOTALOK", nullable = true) /** * Número de cuentas ejecutadas exitosamente */ private Integer totalok; @Column(name = "TOTALERROR", nullable = true) /** * Número de cuentas ejecutadas con error */ private Integer totalerror; /** Contructor por defecto */ public TgeneBatchLog() { } /** * Contructor de TgeneBatchLog * * @param pPk Clave Primaria del entity */ public TgeneBatchLog(TgeneBatchLogKey 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 TgeneBatchLog */ public static TgeneBatchLog find(EntityManager pEntityManager, TgeneBatchLogKey pKey) throws Exception { TgeneBatchLog obj = pEntityManager.find(TgeneBatchLog.class, pKey); return obj; } /** * Entrega la Clave primaria de TgeneBatchLog * * @return El objeto que referencia a la Clave primaria de TgeneBatchLog */ public TgeneBatchLogKey getPk() { return this.pk; } /** * Fija un nuevo valor a la Clave primaria de TgeneBatchLog * * @param pPk El objeto que referencia a la nueva Clave primaria de TgeneBatchLog */ public void setPk(TgeneBatchLogKey pPk) { this.pk = pPk; } /** * Obtiene el valor de transactionmodule * * @return valor de transactionmodule */ public String getTransactionmodule() { return this.transactionmodule; } /** * Fija el valor de transactionmodule * * @param pTransactionmodule nuevo Valor de transactionmodule */ public void setTransactionmodule(String pTransactionmodule) { this.transactionmodule = pTransactionmodule; } /** * Obtiene el valor de transactioncode * * @return valor de transactioncode */ public Integer getTransactioncode() { return this.transactioncode; } /** * Fija el valor de transactioncode * * @param pTransactioncode nuevo Valor de transactioncode */ public void setTransactioncode(Integer pTransactioncode) { this.transactioncode = pTransactioncode; } /** * Obtiene el valor de transactionversion * * @return valor de transactionversion */ public Integer getTransactionversion() { return this.transactionversion; } /** * Fija el valor de transactionversion * * @param pTransactionversion nuevo Valor de transactionversion */ public void setTransactionversion(Integer pTransactionversion) { this.transactionversion = pTransactionversion; } /** * Obtiene el valor de finitdate * * @return valor de finitdate */ public Timestamp getFinitdate() { return this.finitdate; } /** * Fija el valor de finitdate * * @param pFinitdate nuevo Valor de finitdate */ public void setFinitdate(Timestamp pFinitdate) { this.finitdate = pFinitdate; } /** * Obtiene el valor de fenddate * * @return valor de fenddate */ public Timestamp getFenddate() { return this.fenddate; } /** * Fija el valor de fenddate * * @param pFenddate nuevo Valor de fenddate */ public void setFenddate(Timestamp pFenddate) { this.fenddate = pFenddate; } /** * Obtiene el valor de total * * @return valor de total */ public Integer getTotal() { return this.total; } /** * Fija el valor de total * * @param pTotal nuevo Valor de total */ public void setTotal(Integer pTotal) { this.total = pTotal; } /** * Obtiene el valor de executed * * @return valor de executed */ public Integer getExecuted() { return this.executed; } /** * Fija el valor de executed * * @param pExecuted nuevo Valor de executed */ public void setExecuted(Integer pExecuted) { this.executed = pExecuted; } /** * Obtiene el valor de totalok * * @return valor de totalok */ public Integer getTotalok() { return this.totalok; } /** * Fija el valor de totalok * * @param pTotalok nuevo Valor de totalok */ public void setTotalok(Integer pTotalok) { this.totalok = pTotalok; } /** * Obtiene el valor de totalerror * * @return valor de totalerror */ public Integer getTotalerror() { return this.totalerror; } /** * Fija el valor de totalerror * * @param pTotalerror nuevo Valor de totalerror */ public void setTotalerror(Integer pTotalerror) { this.totalerror = pTotalerror; } @Override public boolean equals(Object rhs) { if (rhs == null) { return false; } if (!(rhs instanceof TgeneBatchLog)) { return false; } TgeneBatchLog that = (TgeneBatchLog) rhs; if ((this.getPk() == null) || (that.getPk() == null)) { return false; } return (this.getPk().equals(that.getPk())); } /** * Implementacion del metodo hashCode de la la entidad TgeneBatchLog * * @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 TgeneBatchLog */ @Override public Object createInstance() { TgeneBatchLog instance = new TgeneBatchLog(); instance.setPk(new TgeneBatchLogKey()); return instance; } /** * Clona la entidad TgeneBatchLog * * @see com.fp.dto.hb.HibernateBean#cloneMe() */ @Override public Object cloneMe() throws CloneNotSupportedException { TgeneBatchLog p = (TgeneBatchLog) this.clone(); p.setPk((TgeneBatchLogKey) this.pk.cloneMe()); return p; } // METODOS MANUALES private static final String JPQL_BATCH_IN_EXECUTION = "from TgeneBatchLog t " + "where t.transactionmodule = :transactionmodule and t.transactioncode = :transactioncode " + "and t.transactionversion =:transactionversion and t.pk.processdate = :processdate and t.fenddate is null "; /** * Metodo que retorna un registro que representa si un batch está en ejecucion dada la fecha de proceso * * @param pEntityManager * @param transactionmodule * @param transactioncode * @param transactionversion * @param processdate * @return * @throws Exception */ public static TgeneBatchLog findBatchInExecution(EntityManager pEntityManager, Date processdate, String transactionmodule, Integer transactioncode, Integer transactionversion) throws Exception { TgeneBatchLog tgeneBatchLog = null; Query qry = pEntityManager.createQuery(TgeneBatchLog.JPQL_BATCH_IN_EXECUTION); qry.setParameter("processdate", processdate); qry.setParameter("transactionmodule", transactionmodule); qry.setParameter("transactioncode", transactioncode); qry.setParameter("transactionversion", transactionversion); try { tgeneBatchLog = (TgeneBatchLog) qry.getSingleResult(); } catch (NoResultException e) { } return tgeneBatchLog; } private static final String JPQL_PENDING_BATCH_BY_MODULE = "from TgeneBatchLog t " + "where t.pk.processdate = :processdate and t.pk.journalid = :journalid and t.pk.modulecode = :modulecode and t.fenddate is null "; /** * Metodo que retorna un registro que representa si un batch está en ejecucion dada la fecha de proceso * * @param pEntityManager * @param transactionmodule * @param transactioncode * @param transactionversion * @param processdate * @return * @throws Exception */ public static TgeneBatchLog findPendingBatchByModule(EntityManager pEntityManager, Date processdate, String journalid, String modulecode) throws Exception { TgeneBatchLog tgeneBatchLog = null; Query qry = pEntityManager.createQuery(TgeneBatchLog.JPQL_PENDING_BATCH_BY_MODULE); qry.setParameter("processdate", processdate); qry.setParameter("journalid", journalid); qry.setParameter("modulecode", modulecode); try { tgeneBatchLog = (TgeneBatchLog) qry.getSingleResult(); } catch (NoResultException e) { } return tgeneBatchLog; } private static final String JPQL_BATCH_BY_JOURNALID = "from TgeneBatchLog t " + "where t.pk.processdate = :processdate and t.pk.journalid = :journalid "; /** * Metodo que retorna un registro que representa si un batch está en ejecucion dada la fecha de proceso * * @param pEntityManager * @param transactionmodule * @param transactioncode * @param transactionversion * @param processdate * @return * @throws Exception */ public static TgeneBatchLog findBatchByJournalid(EntityManager pEntityManager, Date processdate, String modulecode, String journalid) throws Exception { TgeneBatchLog tgeneBatchLog = null; Query qry = pEntityManager.createQuery(TgeneBatchLog.JPQL_BATCH_BY_JOURNALID); qry.setParameter("processdate", processdate); qry.setParameter("journalid", journalid); try { tgeneBatchLog = (TgeneBatchLog) qry.getSingleResult(); } catch (NoResultException e) { } return tgeneBatchLog; } }