Merge pull request 'fixes bug #AL-2144' (#28) from AL-2144 into master

Reviewed-on: http://18.235.188.113:3000/adm/ModelWeb/pulls/28
Reviewed-by: fabio <fabio.faria@rjconsultores.com.br>
Reviewed-by: wallace <wallace@rjconsultores.com.br>
master
Lucas Taiã 2023-02-03 21:07:22 +00:00
commit 6421dd28b7
4 changed files with 39 additions and 33 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>br.com.rjconsultores</groupId>
<artifactId>ModelWeb</artifactId>
<version>1.0.30</version>
<version>1.0.31</version>
<distributionManagement>
<repository>
<id>rj-releases</id>

View File

@ -1,6 +1,7 @@
package com.rjconsultores.ventaboletos.constantes;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -45,14 +46,32 @@ public class CustomEnumTypeHibernate implements UserType, ParameterizedType {
return x.hashCode();
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
Object result = null;
try {
String name = rs.getString(names[0]);
if (!rs.wasNull()) {
result = Enum.valueOf(returnedClass(), name);
boolean enumName = Boolean.valueOf(parameters.get("enumName").toString());
int sqlType = Integer.valueOf(parameters.get("sqlType").toString());
if (enumName) {
result = Enum.valueOf(returnedClass(), name);
} else {
Class typeClass = null;
Object parameterType = null;
if (Types.INTEGER == sqlType) {
typeClass = Integer.class;
parameterType = Integer.valueOf(name);
} else if (Types.VARCHAR == sqlType) {
typeClass = String.class;
parameterType = name;
}
Method enumMethod = returnedClass().getMethod(parameters.get("enumMethod").toString(),
new Class[] { typeClass });
result = enumMethod.invoke(returnedClass(), new Object[] { parameterType });
}
}
} catch (Exception e) {
result = null;
@ -74,23 +93,29 @@ public class CustomEnumTypeHibernate implements UserType, ParameterizedType {
}
@Override
@SuppressWarnings("rawtypes")
public Object deepCopy(Object value) throws HibernateException {
return value;
if (value == null)
return null;
else {
Enum enumerator = (Enum) value;
return enumerator;
}
}
@Override
public boolean isMutable() {
return true;
return false;
}
@Override
public Serializable disassemble(Object value) throws HibernateException {
return (Serializable) value;
return (value instanceof Serializable) ? (Serializable) deepCopy(value) : null;
}
@Override
public Object assemble(Serializable cached, Object owner) throws HibernateException {
return cached;
return deepCopy(cached);
}
@Override

View File

@ -82,7 +82,8 @@ public class FormaPago implements Serializable, Auditavel<FormaPago> {
@Parameter(name = "type", value = "com.rjconsultores.ventaboletos.constantes.CustomEnumTypeHibernate"),
@Parameter(name = "class", value = "com.rjconsultores.ventaboletos.enums.TipoFormapago"),
@Parameter(name = "sqlType", value = "4")/*Types.INTEGER*/,
@Parameter(name = "enumName", value = "false")})
@Parameter(name = "enumName", value = "false"),
@Parameter(name = "enumMethod", value = "getTipoFormapagoByValor")})
@Column(name = "TIPO_PAGO")
private com.rjconsultores.ventaboletos.enums.TipoFormapago tipoFormapago;
@Column(name = "CVESISTEMA")

View File

@ -46,32 +46,12 @@ public enum TipoFormapago {
}
public static TipoFormapago getTipoFormapagoByValor(Integer valor) {
if(TipoFormapago.DINHEIRO.getValor().equals(valor)) {
return TipoFormapago.DINHEIRO;
} else if(TipoFormapago.DEBITO.getValor().equals(valor)) {
return TipoFormapago.DEBITO;
} else if(TipoFormapago.CREDITO.getValor().equals(valor)) {
return TipoFormapago.CREDITO;
} else if(TipoFormapago.NOTA_CREDITO.getValor().equals(valor)) {
return TipoFormapago.NOTA_CREDITO;
} else if(TipoFormapago.TROCA_PASSAGEM.getValor().equals(valor)) {
return TipoFormapago.TROCA_PASSAGEM;
} else if(TipoFormapago.IMPRESSAO_PASSAGEM.getValor().equals(valor)) {
return TipoFormapago.IMPRESSAO_PASSAGEM;
} else if(TipoFormapago.ORDEM_SERVICO.getValor().equals(valor)) {
return TipoFormapago.ORDEM_SERVICO;
} else if(TipoFormapago.BOLETO_ABERTO.getValor().equals(valor)) {
return TipoFormapago.BOLETO_ABERTO;
} else if(TipoFormapago.PACOTE.getValor().equals(valor)) {
return TipoFormapago.PACOTE;
} else if(TipoFormapago.RESERVA.getValor().equals(valor)) {
return TipoFormapago.RESERVA;
} else if(TipoFormapago.CHEQUE.getValor().equals(valor)) {
return TipoFormapago.CHEQUE;
} else if(TipoFormapago.DEPOSITO.getValor().equals(valor)) {
return TipoFormapago.DEPOSITO;
}
for (TipoFormapago tipoFormapago : TipoFormapago.values()) {
if (tipoFormapago.getValor().equals(valor)) {
return tipoFormapago;
}
}
return null;
}