correção toString enums

master
lucas.taia 2023-01-31 10:11:54 -03:00
parent 03bf64d5be
commit 7438fb4737
7 changed files with 65 additions and 112 deletions

View File

@ -7,6 +7,7 @@ import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import java.util.Properties; import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.usertype.ParameterizedType; import org.hibernate.usertype.ParameterizedType;
import org.hibernate.usertype.UserType; import org.hibernate.usertype.UserType;
@ -60,11 +61,15 @@ public class CustomEnumTypeHibernate implements UserType, ParameterizedType {
} }
@Override @Override
@SuppressWarnings("rawtypes")
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
if (value == null) { int sqlType = Integer.valueOf(parameters.get("sqlType").toString()) ;
st.setNull(index, Types.VARCHAR); boolean enumName = Boolean.valueOf(parameters.get("enumName").toString()) ;
if (value == null || StringUtils.isEmpty(value.toString())) {
st.setNull(index, sqlType);
} else { } else {
st.setObject(index, value.toString(), Types.VARCHAR); Enum enumerator = (Enum) value;
st.setObject(index, enumName ? enumerator.name() : enumerator.ordinal(), sqlType);
} }
} }

View File

@ -1,104 +1,40 @@
package com.rjconsultores.ventaboletos.constantes; package com.rjconsultores.ventaboletos.constantes;
public enum TipoEventoExtra { public enum TipoEventoExtra {
NAO_ESPECIFICADO{
public String toString() { OUTRO("OUTRO"),
return " "; SEGURO_OPCIONAL("SEGURO_OPCIONAL"),
} EXCESSO_BAGAGEM("EXCESSO_BAGAGEM"),
}, TAXA_EMBARQUE("TAXA_EMBARQUE"),
OUTRO{ SEGURO_RESSARCIMENTO("SEGURO_RESSARCIMENTO"),
public String toString() { TAXA_EMBARQUE_RESSARCIMENTO("TAXA_EMBARQUE_RESSARCIMENTO"),
return "OUTRO"; MULTA("MULTA"),
} DIF_MAIOR("DIF_MAIOR"),
}, DIF_MENOR("DIF_MENOR"),
SEGURO_OPCIONAL{ SUPRIMENTO("SUPRIMENTO"),
public String toString() { SANGRIA("SANGRIA"),
return "SEGURO_OPCIONAL"; RECARGA_CELULAR("RECARGA_CELULAR"),
} RECARGA_TV("RECARGA_TV"),
}, RECARGA_PIN("RECARGA_PIN"),
EXCESSO_BAGAGEM{ PACOTE("PACOTE"),
public String toString() { SMART_CARD("SMART_CARD"),
return "EXCESSO_BAGAGEM"; TAXA_CONVENIENCIA_SVI("TAXA_CONVENIENCIA_SVI"),
} TARIFA_SAFER("TARIFA_SAFER"),
}, JUROS_CARTAO_CREDITO("JUROS_CARTAO_CREDITO"),
TAXA_EMBARQUE{ ;
public String toString() {
return "TAXA_EMBARQUE"; private String descricao;
}
}, private TipoEventoExtra(String descricao) {
SEGURO_RESSARCIMENTO{ this.descricao = descricao;
public String toString() { }
return "SEGURO_RESSARCIMENTO";
} public String getDescricao() {
}, return descricao;
TAXA_EMBARQUE_RESSARCIMENTO{ }
public String toString() {
return "TAXA_EMBARQUE_RESSARCIMENTO"; @Override
} public String toString() {
}, return getDescricao();
MULTA{ }
public String toString() {
return "MULTA";
}
},
DIF_MAIOR{
public String toString() {
return "DIF_MAIOR";
}
},
DIF_MENOR{
public String toString() {
return "DIF_MENOR";
}
},
SUPRIMENTO{
public String toString() {
return "SUPRIMENTO";
}
},
SANGRIA{
public String toString() {
return "SANGRIA";
}
},
RECARGA_CELULAR{
public String toString() {
return "RECARGA_CELULAR";
}
},
RECARGA_TV{
public String toString() {
return "RECARGA_TV";
}
},
RECARGA_PIN{
public String toString() {
return "RECARGA_PIN";
}
},
PACOTE{
public String toString() {
return "PACOTE";
}
},
SMART_CARD{
public String toString() {
return "SMART_CARD";
}
},
TAXA_CONVENIENCIA_SVI{
public String toString() {
return "TAXA_CONVENIENCIA_SVI";
}
},
TARIFA_SAFER{
public String toString() {
return "TARIFA_SAFER";
}
},
JUROS_CARTAO_CREDITO{
public String toString() {
return "JUROS_CARTAO_CREDITO";
}
};
} }

View File

@ -25,8 +25,6 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.Transient; import javax.persistence.Transient;
import org.apache.commons.lang.BooleanUtils;
import org.hibernate.annotations.Parameter; import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
@ -104,13 +102,17 @@ public class Categoria implements Serializable, Auditavel<Categoria>{
@Type(type = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate", parameters = { @Type(type = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate", parameters = {
@Parameter(name = "type", value = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate"), @Parameter(name = "type", value = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate"),
@Parameter(name = "class", value = "com.rjconsultores.ventaboletos.enums.TipoDescontoMonitrip.class"), }) @Parameter(name = "class", value = "com.rjconsultores.ventaboletos.enums.TipoDescontoMonitrip"),
@Parameter(name = "sqlType", value = "12")/*Types.VARCHAR*/,
@Parameter(name = "enumName", value = "true")})
@Column(name = "desconto_monitrip") @Column(name = "desconto_monitrip")
private com.rjconsultores.ventaboletos.enums.TipoDescontoMonitrip tipoDescontoMonitrip; private com.rjconsultores.ventaboletos.enums.TipoDescontoMonitrip tipoDescontoMonitrip;
@Type(type = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate", parameters = { @Type(type = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate", parameters = {
@Parameter(name = "type", value = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate"), @Parameter(name = "type", value = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate"),
@Parameter(name = "class", value = "com.rjconsultores.ventaboletos.enums.TipoDescontoBPe.class"), }) @Parameter(name = "class", value = "com.rjconsultores.ventaboletos.enums.TipoDescontoBPe"),
@Parameter(name = "sqlType", value = "12")/*Types.VARCHAR*/,
@Parameter(name = "enumName", value = "true")})
@Column(name = "DESCONTOBPE") @Column(name = "DESCONTOBPE")
private com.rjconsultores.ventaboletos.enums.TipoDescontoBPe tipoDescontoBPe; private com.rjconsultores.ventaboletos.enums.TipoDescontoBPe tipoDescontoBPe;

View File

@ -86,7 +86,9 @@ public class ClaseServicio implements Serializable, Auditavel<ClaseServicio> {
@Type(type = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate", parameters = { @Type(type = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate", parameters = {
@Parameter(name = "type", value = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate"), @Parameter(name = "type", value = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate"),
@Parameter(name = "class", value = "com.rjconsultores.ventaboletos.enums.TipoClasseServicoBPe.class"), }) @Parameter(name = "class", value = "com.rjconsultores.ventaboletos.enums.TipoClasseServicoBPe"),
@Parameter(name = "sqlType", value = "12")/*Types.VARCHAR*/,
@Parameter(name = "enumName", value = "true")})
@Column(name = "desconto_monitrip") @Column(name = "desconto_monitrip")
private com.rjconsultores.ventaboletos.enums.TipoClasseServicoBPe tipoDescontoMonitrip; private com.rjconsultores.ventaboletos.enums.TipoClasseServicoBPe tipoDescontoMonitrip;

View File

@ -66,7 +66,9 @@ public class EstacionSitef implements Serializable {
@Type(type = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate", parameters = { @Type(type = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate", parameters = {
@Parameter(name = "type", value = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate"), @Parameter(name = "type", value = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate"),
@Parameter(name = "class", value = "com.rjconsultores.ventaboletos.enums.TipoIntegracaoTEF.class"), }) @Parameter(name = "class", value = "com.rjconsultores.ventaboletos.enums.TipoIntegracaoTEF"),
@Parameter(name = "sqlType", value = "12")/*Types.VARCHAR*/,
@Parameter(name = "enumName", value = "true")})
@Column(name = "TIPO_INTEGRACAO") @Column(name = "TIPO_INTEGRACAO")
private com.rjconsultores.ventaboletos.enums.TipoIntegracaoTEF tipoIntegracao; private com.rjconsultores.ventaboletos.enums.TipoIntegracaoTEF tipoIntegracao;

View File

@ -80,7 +80,9 @@ public class FormaPago implements Serializable, Auditavel<FormaPago> {
@Type(type = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate", parameters = { @Type(type = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate", parameters = {
@Parameter(name = "type", value = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate"), @Parameter(name = "type", value = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate"),
@Parameter(name = "class", value = "com.rjconsultores.ventaboletos.enums.TipoFormapago.class"), }) @Parameter(name = "class", value = "com.rjconsultores.ventaboletos.enums.TipoFormapago"),
@Parameter(name = "sqlType", value = "4")/*Types.INTEGER*/,
@Parameter(name = "enumName", value = "false")})
@Column(name = "TIPO_PAGO") @Column(name = "TIPO_PAGO")
private com.rjconsultores.ventaboletos.enums.TipoFormapago tipoFormapago; private com.rjconsultores.ventaboletos.enums.TipoFormapago tipoFormapago;
@Column(name = "CVESISTEMA") @Column(name = "CVESISTEMA")
@ -98,7 +100,9 @@ public class FormaPago implements Serializable, Auditavel<FormaPago> {
@Type(type = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate", parameters = { @Type(type = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate", parameters = {
@Parameter(name = "type", value = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate"), @Parameter(name = "type", value = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate"),
@Parameter(name = "class", value = "com.rjconsultores.ventaboletos.enums.TipoCarteiraDigital.class"), }) @Parameter(name = "class", value = "com.rjconsultores.ventaboletos.enums.TipoCarteiraDigital"),
@Parameter(name = "sqlType", value = "12")/*Types.VARCHAR*/,
@Parameter(name = "enumName", value = "true")})
@Column(name = "TIPO_CARTEIRA_DIGITAL") @Column(name = "TIPO_CARTEIRA_DIGITAL")
private com.rjconsultores.ventaboletos.enums.TipoCarteiraDigital tipoCarteiraDigital; private com.rjconsultores.ventaboletos.enums.TipoCarteiraDigital tipoCarteiraDigital;

View File

@ -105,7 +105,9 @@ public class TipoEventoExtra implements Serializable {
@Type(type = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate", parameters = { @Type(type = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate", parameters = {
@Parameter(name = "type", value = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate"), @Parameter(name = "type", value = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate"),
@Parameter(name = "class", value = "com.rjconsultores.ventaboletos.constantes.TipoEventoExtra"), }) @Parameter(name = "class", value = "com.rjconsultores.ventaboletos.constantes.TipoEventoExtra"),
@Parameter(name = "sqlType", value = "12")/*Types.VARCHAR*/,
@Parameter(name = "enumName", value = "true")})
@Column(name = "CVETIPOEVENTO") @Column(name = "CVETIPOEVENTO")
private com.rjconsultores.ventaboletos.constantes.TipoEventoExtra cvetipoevento; private com.rjconsultores.ventaboletos.constantes.TipoEventoExtra cvetipoevento;