702 lines
18 KiB
Plaintext
Executable File
702 lines
18 KiB
Plaintext
Executable File
package com.fp.persistence.pcustomer.gene;
|
||
|
||
import java.io.Serializable;
|
||
import java.lang.reflect.Field;
|
||
import java.sql.Timestamp;
|
||
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.common.helper.Constant;
|
||
import com.fp.dto.hb.HibernateBean;
|
||
import com.fp.dto.hb.Log;
|
||
|
||
import javax.persistence.GeneratedValue;
|
||
import org.hibernate.annotations.GenericGenerator;
|
||
import org.hibernate.annotations.Parameter;
|
||
|
||
/**
|
||
* Clase que implementa la entidad de Hibernate que hace referencia a la tabla TCUSTPERSONADDRESS
|
||
*/
|
||
@Entity(name = "TcustPersonAddress")
|
||
@Table(name = "TCUSTPERSONADDRESS")
|
||
public class TcustPersonAddress extends com.fp.dto.AbstractDataTransport implements Serializable, HibernateBean, Cloneable, Log {
|
||
|
||
/**
|
||
* 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 TcustPersonAddress
|
||
*/
|
||
@EmbeddedId
|
||
@GenericGenerator(name = "seq_id", strategy = "com.fp.general.keygen.SubSequenceKey", parameters = {
|
||
@Parameter(name = "sql", value = "select coalesce(max(ADDRESSNUMBER),0)+1 from TCUSTPERSONADDRESS where PERSONCODE = :personcode and DATETO = :dateto"),
|
||
@Parameter(name = "type", value = "java.lang.Integer"),
|
||
@Parameter(name = "param", value = "personcode,pk.personcode;dateto,pk.dateto"), @Parameter(name = "field", value = "addressnumber") })
|
||
@GeneratedValue(generator = "seq_id")
|
||
private TcustPersonAddressKey pk;
|
||
|
||
@Column(name = "DATEFROM", nullable = true)
|
||
/**
|
||
* Fecha desde la cual esta vigente el registro de la direccion.
|
||
*/
|
||
private Timestamp datefrom;
|
||
|
||
@Version
|
||
@Column(name = "RECORDVERSION", nullable = true)
|
||
/**
|
||
* Manejo de optimistic locking
|
||
*/
|
||
private Integer recordversion;
|
||
|
||
@Column(name = "ADDRESSTYPECATALOG", nullable = true)
|
||
/**
|
||
* Codigo de catalogo 1 OFICINA, 2 DOMICILIO
|
||
*/
|
||
private String addresstypecatalog;
|
||
|
||
@Column(name = "ADDRESSTYPECATALOGCODE", nullable = true)
|
||
/**
|
||
* Codigo de tabla de catalogo ADDRESSTYPE, codigo de tipo de saldo
|
||
*/
|
||
private String addresstypecatalogcode;
|
||
|
||
@Column(name = "COUNTRYCODE", nullable = true)
|
||
/**
|
||
* Codigo de pa<70>s
|
||
*/
|
||
private String countrycode;
|
||
|
||
@Column(name = "PROVINCECODE", nullable = true)
|
||
/**
|
||
* Codigo de provincia
|
||
*/
|
||
private String provincecode;
|
||
|
||
@Column(name = "CANTONCODE", nullable = true)
|
||
/**
|
||
* Codigo de canton
|
||
*/
|
||
private String cantoncode;
|
||
|
||
@Column(name = "CITYCODE", nullable = true)
|
||
/**
|
||
* Codigo de cuidad
|
||
*/
|
||
private String citycode;
|
||
|
||
@Column(name = "INGRESSUSERCODE", nullable = true)
|
||
/**
|
||
* Codigo de usuario que crea el registro
|
||
*/
|
||
private String ingressusercode;
|
||
|
||
@Column(name = "MODIFYUSERCODE", nullable = true)
|
||
/**
|
||
* Codigo de usuario que modifica el registro
|
||
*/
|
||
private String modifyusercode;
|
||
|
||
@Column(name = "PRINCIPAL", nullable = true)
|
||
/**
|
||
* Y indica que es la direccion principal del cliente, N no es la direccion
|
||
* principal
|
||
*/
|
||
private String principal;
|
||
|
||
@Column(name = "STREET", nullable = true)
|
||
/**
|
||
* Calle o avenida en la que se encuentra la direccion
|
||
*/
|
||
private String street;
|
||
|
||
@Column(name = "STREETNUMBER", nullable = true)
|
||
/**
|
||
* Numero de casa o departamento
|
||
*/
|
||
private String streetnumber;
|
||
|
||
@Column(name = "DEPARTMENT", nullable = true)
|
||
/**
|
||
* Numero de departamento
|
||
*/
|
||
private String department;
|
||
|
||
@Column(name = "URBANIZATION", nullable = true)
|
||
/**
|
||
* Nombre del urbanizacion
|
||
*/
|
||
private String urbanization;
|
||
|
||
@Column(name = "ADDRESS", nullable = true)
|
||
/**
|
||
* Texto libre de la direccion.
|
||
*/
|
||
private String address;
|
||
|
||
@Column(name = "REMARK", nullable = true)
|
||
/**
|
||
* Comentarios, texto libre
|
||
*/
|
||
private String remark;
|
||
|
||
@Column(name = "PARROQUIACODE", nullable = true)
|
||
/**
|
||
* Codigo de parroquia
|
||
*/
|
||
private String parroquiacode;
|
||
|
||
/**
|
||
* Contructor por defecto
|
||
*/
|
||
public TcustPersonAddress() {
|
||
}
|
||
|
||
/**
|
||
* Contructor de TcustPersonAddress
|
||
*
|
||
* @param pPk Clave Primaria del entity
|
||
*/
|
||
public TcustPersonAddress(TcustPersonAddressKey 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 TcustPersonAddress
|
||
*/
|
||
public static TcustPersonAddress find(EntityManager pEntityManager, TcustPersonAddressKey pKey) throws Exception {
|
||
TcustPersonAddress obj = pEntityManager.find(TcustPersonAddress.class, pKey);
|
||
return obj;
|
||
}
|
||
|
||
/**
|
||
* Entrega la Clave primaria de TcustPersonAddress
|
||
*
|
||
* @return El objeto que referencia a la Clave primaria de TcustPersonAddress
|
||
*/
|
||
public TcustPersonAddressKey getPk() {
|
||
return this.pk;
|
||
}
|
||
|
||
/**
|
||
* Fija un nuevo valor a la Clave primaria de TcustPersonAddress
|
||
*
|
||
* @param pPk El objeto que referencia a la nueva Clave primaria de TcustPersonAddress
|
||
*/
|
||
public void setPk(TcustPersonAddressKey pPk) {
|
||
this.pk = pPk;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de datefrom
|
||
*
|
||
* @return valor de datefrom
|
||
*/
|
||
public Timestamp getDatefrom() {
|
||
return this.datefrom;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de datefrom
|
||
*
|
||
* @param pDatefrom nuevo Valor de datefrom
|
||
*/
|
||
public void setDatefrom(Timestamp pDatefrom) {
|
||
this.datefrom = pDatefrom;
|
||
}
|
||
|
||
/**
|
||
* 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 addresstypecatalog
|
||
*
|
||
* @return valor de addresstypecatalog
|
||
*/
|
||
public String getAddresstypecatalog() {
|
||
return this.addresstypecatalog;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de addresstypecatalog
|
||
*
|
||
* @param pAddresstypecatalog nuevo Valor de addresstypecatalog
|
||
*/
|
||
public void setAddresstypecatalog(String pAddresstypecatalog) {
|
||
this.addresstypecatalog = pAddresstypecatalog;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de addresstypecatalogcode
|
||
*
|
||
* @return valor de addresstypecatalogcode
|
||
*/
|
||
public String getAddresstypecatalogcode() {
|
||
return this.addresstypecatalogcode;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de addresstypecatalogcode
|
||
*
|
||
* @param pAddresstypecatalogcode nuevo Valor de addresstypecatalogcode
|
||
*/
|
||
public void setAddresstypecatalogcode(String pAddresstypecatalogcode) {
|
||
this.addresstypecatalogcode = pAddresstypecatalogcode;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de countrycode
|
||
*
|
||
* @return valor de countrycode
|
||
*/
|
||
public String getCountrycode() {
|
||
return this.countrycode;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de countrycode
|
||
*
|
||
* @param pCountrycode nuevo Valor de countrycode
|
||
*/
|
||
public void setCountrycode(String pCountrycode) {
|
||
this.countrycode = pCountrycode;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de provincecode
|
||
*
|
||
* @return valor de provincecode
|
||
*/
|
||
public String getProvincecode() {
|
||
return this.provincecode;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de provincecode
|
||
*
|
||
* @param pProvincecode nuevo Valor de provincecode
|
||
*/
|
||
public void setProvincecode(String pProvincecode) {
|
||
this.provincecode = pProvincecode;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de cantoncode
|
||
*
|
||
* @return valor de cantoncode
|
||
*/
|
||
public String getCantoncode() {
|
||
return this.cantoncode;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de cantoncode
|
||
*
|
||
* @param pCantoncode nuevo Valor de cantoncode
|
||
*/
|
||
public void setCantoncode(String pCantoncode) {
|
||
this.cantoncode = pCantoncode;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de citycode
|
||
*
|
||
* @return valor de citycode
|
||
*/
|
||
public String getCitycode() {
|
||
return this.citycode;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de citycode
|
||
*
|
||
* @param pCitycode nuevo Valor de citycode
|
||
*/
|
||
public void setCitycode(String pCitycode) {
|
||
this.citycode = pCitycode;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de ingressusercode
|
||
*
|
||
* @return valor de ingressusercode
|
||
*/
|
||
public String getIngressusercode() {
|
||
return this.ingressusercode;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de ingressusercode
|
||
*
|
||
* @param pIngressusercode nuevo Valor de ingressusercode
|
||
*/
|
||
public void setIngressusercode(String pIngressusercode) {
|
||
this.ingressusercode = pIngressusercode;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de modifyusercode
|
||
*
|
||
* @return valor de modifyusercode
|
||
*/
|
||
public String getModifyusercode() {
|
||
return this.modifyusercode;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de modifyusercode
|
||
*
|
||
* @param pModifyusercode nuevo Valor de modifyusercode
|
||
*/
|
||
public void setModifyusercode(String pModifyusercode) {
|
||
this.modifyusercode = pModifyusercode;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de principal
|
||
*
|
||
* @return valor de principal
|
||
*/
|
||
public String getPrincipal() {
|
||
return this.principal;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de principal
|
||
*
|
||
* @param pPrincipal nuevo Valor de principal
|
||
*/
|
||
public void setPrincipal(String pPrincipal) {
|
||
this.principal = pPrincipal;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de street
|
||
*
|
||
* @return valor de street
|
||
*/
|
||
public String getStreet() {
|
||
return this.street;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de street
|
||
*
|
||
* @param pStreet nuevo Valor de street
|
||
*/
|
||
public void setStreet(String pStreet) {
|
||
this.street = pStreet;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de streetnumber
|
||
*
|
||
* @return valor de streetnumber
|
||
*/
|
||
public String getStreetnumber() {
|
||
return this.streetnumber;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de streetnumber
|
||
*
|
||
* @param pStreetnumber nuevo Valor de streetnumber
|
||
*/
|
||
public void setStreetnumber(String pStreetnumber) {
|
||
this.streetnumber = pStreetnumber;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de department
|
||
*
|
||
* @return valor de department
|
||
*/
|
||
public String getDepartment() {
|
||
return this.department;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de department
|
||
*
|
||
* @param pDepartment nuevo Valor de department
|
||
*/
|
||
public void setDepartment(String pDepartment) {
|
||
this.department = pDepartment;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de urbanization
|
||
*
|
||
* @return valor de urbanization
|
||
*/
|
||
public String getUrbanization() {
|
||
return this.urbanization;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de urbanization
|
||
*
|
||
* @param pUrbanization nuevo Valor de urbanization
|
||
*/
|
||
public void setUrbanization(String pUrbanization) {
|
||
this.urbanization = pUrbanization;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de address
|
||
*
|
||
* @return valor de address
|
||
*/
|
||
public String getAddress() {
|
||
return this.address;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de address
|
||
*
|
||
* @param pAddress nuevo Valor de address
|
||
*/
|
||
public void setAddress(String pAddress) {
|
||
this.address = pAddress;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de remark
|
||
*
|
||
* @return valor de remark
|
||
*/
|
||
public String getRemark() {
|
||
return this.remark;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de remark
|
||
*
|
||
* @param pRemark nuevo Valor de remark
|
||
*/
|
||
public void setRemark(String pRemark) {
|
||
this.remark = pRemark;
|
||
}
|
||
|
||
/**
|
||
* Obtiene el valor de parroquiacode
|
||
*
|
||
* @return valor de parroquiacode
|
||
*/
|
||
public String getParroquiacode() {
|
||
return this.parroquiacode;
|
||
}
|
||
|
||
/**
|
||
* Fija el valor de parroquiacode
|
||
*
|
||
* @param pParroquiacode nuevo Valor de parroquiacode
|
||
*/
|
||
public void setParroquiacode(String pParroquiacode) {
|
||
this.parroquiacode = pParroquiacode;
|
||
}
|
||
|
||
@Override
|
||
public boolean equals(Object rhs) {
|
||
if (rhs == null) {
|
||
return false;
|
||
}
|
||
if (!(rhs instanceof TcustPersonAddress)) {
|
||
return false;
|
||
}
|
||
TcustPersonAddress that = (TcustPersonAddress) 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 TcustPersonAddress
|
||
*
|
||
* @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 TcustPersonAddress
|
||
*/
|
||
@Override
|
||
public Object createInstance() {
|
||
TcustPersonAddress instance = new TcustPersonAddress();
|
||
instance.setPk(new TcustPersonAddressKey());
|
||
return instance;
|
||
}
|
||
|
||
/**
|
||
* Clona la entidad TcustPersonAddress
|
||
*
|
||
* @see com.fp.dto.hb.HibernateBean#cloneMe()
|
||
*/
|
||
@Override
|
||
public Object cloneMe() throws CloneNotSupportedException {
|
||
TcustPersonAddress p = (TcustPersonAddress) this.clone();
|
||
p.setPk((TcustPersonAddressKey) this.pk.cloneMe());
|
||
return p;
|
||
}
|
||
|
||
public Object getId() {
|
||
return this.pk;
|
||
}
|
||
|
||
// Metodos manuales
|
||
private static final String JPQL_EMAIL = "from TcustPersonAddress t" + " where t.pk.personcode = :personcode " + " and t.pk.dateto = :dateto "
|
||
+ " and t.addresstypecatalog = :addresstype ";
|
||
|
||
/**
|
||
* Metodo que emtrega la direccion email de una persona, si existe mas de una direccion email asociada a una persona
|
||
* entrega la primera que encuentre en la base.
|
||
*
|
||
* @param pEntityManager Session de la base de datos
|
||
* @param pPersonCode Codigo de persona.
|
||
* @return String
|
||
* @throws Exception
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
public static String getEmail(EntityManager pEntityManager, Integer pPersonCode) throws Exception {
|
||
String email = null;
|
||
Query qry = pEntityManager.createQuery(TcustPersonAddress.JPQL_EMAIL);
|
||
qry.setParameter("personcode", pPersonCode);
|
||
qry.setParameter("dateto", Constant.getDefaultExpiryTimestamp());
|
||
qry.setParameter("addresstype", "3");
|
||
List<TcustPersonAddress> ldata = qry.getResultList();
|
||
if ((ldata == null) || ldata.isEmpty()) {
|
||
return email;
|
||
}
|
||
for (TcustPersonAddress obj : ldata) {
|
||
email = obj.getAddress();
|
||
break;
|
||
}
|
||
return email;
|
||
}
|
||
|
||
/**
|
||
* Sentencia que devuelve un registro vigente de TcustPersonAddress
|
||
*/
|
||
private static final String JPQL_PERSON_ADDRESS = "from TcustPersonAddress tcpa" + " where tcpa.pk.personcode = :personcode"
|
||
+ " and tcpa.pk.addressnumber = :addressnumber" + " and tcpa.pk.dateto = :dateto";
|
||
|
||
/**
|
||
* Metodo que entrega datos de una Direccion definida en TcustPersonAddress.
|
||
*
|
||
* @param pEntityManager Session de la base de datos.
|
||
* @param personcode Codigo de la persona a quien pertenece la Direccion.
|
||
* @param addressnumber Numero de la direccion.
|
||
* @return tcustPersonAddress
|
||
* @throws Exception
|
||
*/
|
||
public static TcustPersonAddress findByPersonCode(EntityManager pEntityManager, Integer personcode, Integer addressnumber) throws Exception {
|
||
Query qry = pEntityManager.createQuery(TcustPersonAddress.JPQL_PERSON_ADDRESS);
|
||
qry.setParameter("personcode", personcode);
|
||
qry.setParameter("addressnumber", addressnumber);
|
||
qry.setParameter("dateto", Constant.getDefaultExpiryDate());
|
||
try {
|
||
return (TcustPersonAddress) qry.getSingleResult();
|
||
} catch (NoResultException e) {
|
||
return null;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Sentencia que devuelve un registro vigente de TcustPersonAddress
|
||
*/
|
||
private static final String JPQL_PERSON = "from TcustPersonAddress tcpa" + " where tcpa.pk.personcode = :personcode"
|
||
+ " and tcpa.pk.dateto = :dateto";
|
||
|
||
/**
|
||
* Metodo que entrega datos de una Direccion definida en TcustPersonAddress.
|
||
*
|
||
* @param pEntityManager Session de la base de datos.
|
||
* @param personcode Codigo de la persona a quien pertenece la Direccion.
|
||
* @param addressnumber Numero de la direccion.
|
||
* @return tcustPersonAddress
|
||
* @throws Exception
|
||
*/
|
||
public static List<TcustPersonAddress> findByPersonCode(EntityManager pEntityManager, Integer personcode) throws Exception {
|
||
Query qry = pEntityManager.createQuery(TcustPersonAddress.JPQL_PERSON);
|
||
qry.setParameter("personcode", personcode);
|
||
qry.setParameter("dateto", Constant.getDefaultExpiryDate());
|
||
return qry.getResultList();
|
||
}
|
||
}
|