Galera,
Preciso fazer uma chamada a um procedure, pegar um ID do retorno dela e fazer um select.
Após isso, executar um rollback.
Uso EJB, sendo que a transação é controlada pelo glassfish.
Fiz da seguinte forma:
try {
connection = this.entityManagerController.getDataSource(credencial.getDomain()).getConnection();
callableStatement = connection.prepareCall("{call dbo.sp_CalculoImobiliario(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}");
if(!NumberUtils.isEmpty(idImobiliario)) {
callableStatement.setLong(1, idImobiliario);
} else {
callableStatement.setNull(1, Types.INTEGER);
}
if(!NumberUtils.isEmpty(codigoComposicaoReceita)) {
callableStatement.setLong(2, codigoComposicaoReceita);
} else {
callableStatement.setNull(2, Types.INTEGER);
}
callableStatement.setInt(3, DateUtils.getAnoAtual());
if(!NumberUtils.isEmpty(area)) {
callableStatement.setBigDecimal(4, area);
} else {
callableStatement.setNull(4, Types.DECIMAL);
}
if(!NumberUtils.isEmpty(medidaSecundaria)) {
callableStatement.setBigDecimal(5, medidaSecundaria);
} else {
callableStatement.setNull(5, Types.DECIMAL);
}
if(!NumberUtils.isEmpty(testada)) {
callableStatement.setBigDecimal(6, testada);
} else {
callableStatement.setNull(6, Types.DECIMAL);
}
if(!NumberUtils.isEmpty(fatorTopografia)) {
callableStatement.setLong(7, fatorTopografia);
} else {
callableStatement.setNull(7, Types.INTEGER);
}
if(!NumberUtils.isEmpty(fatorPedologia)) {
callableStatement.setLong(8, fatorPedologia);
} else {
callableStatement.setNull(8, Types.INTEGER);
}
if(!NumberUtils.isEmpty(fatorSituacao)) {
callableStatement.setLong(9, fatorSituacao);
} else {
callableStatement.setNull(9, Types.INTEGER);
}
if(!NumberUtils.isEmpty(fatorZoneamento)) {
callableStatement.setLong(10, fatorZoneamento);
} else {
callableStatement.setNull(10, Types.INTEGER);
}
if(!NumberUtils.isEmpty(fatorDesvio)) {
callableStatement.setLong(11, fatorDesvio);
} else {
callableStatement.setNull(11, Types.INTEGER);
}
if(!NumberUtils.isEmpty(fatorCorrego)) {
callableStatement.setLong(12, fatorCorrego);
} else {
callableStatement.setNull(12, Types.INTEGER);
}
if(!NumberUtils.isEmpty(fatorQuadra)) {
callableStatement.setBigDecimal(13, fatorQuadra);
} else {
callableStatement.setNull(13, Types.DECIMAL);
}
callableStatement.setLong(14, 0L);
callableStatement.setLong(15, 1L);
callableStatement.setNull(16, Types.INTEGER);
callableStatement.setString(17, emissao);
callableStatement.setBoolean(18, Boolean.FALSE);
callableStatement.setBoolean(19, Boolean.FALSE);
callableStatement.registerOutParameter(20, Types.DECIMAL);
callableStatement.registerOutParameter(21, Types.DECIMAL);
callableStatement.registerOutParameter(22, Types.DECIMAL);
callableStatement.registerOutParameter(23, Types.DECIMAL);
callableStatement.registerOutParameter(24, Types.DECIMAL);
callableStatement.registerOutParameter(25, Types.DECIMAL);
callableStatement.registerOutParameter(26, Types.NUMERIC);
callableStatement.registerOutParameter(27, Types.DECIMAL);
callableStatement.executeUpdate();
System.out.println("ID = " +callableStatement.getLong(26));
query = this.entityManagerController.getEntityManager(credencial.getDomain()).createNamedQuery("Imobiliario.obterInformacoesCertidaoAtualizada", Object[].class);
query.setParameter("idLancamentoAlfa", (Long) callableStatement.getLong(26));
results = query.getResultList();
throw new RoolbackProcedureException(results);
} finally {
this.closeSQLObjects(connection, callableStatement, null);
}
Sendo que o método está anotado com @TransactionAttribute(TransactionAttributeType.REQUIRED)
A exception é:
@ApplicationException(rollback = true)
public class RoolbackProcedureException extends Exception {
private static final long serialVersionUID = 1L;
private List<Object[]> results;
public RoolbackProcedureException() {
super();
}
public RoolbackProcedureException(String message, Throwable cause) {
super(message, cause);
}
public RoolbackProcedureException(String message) {
super(message);
}
public RoolbackProcedureException(Throwable cause) {
super(cause);
}
public RoolbackProcedureException(final List<Object[]> results) {
super();
this.results = results;
}
public List<Object[]> getResults() {
return results;
}
}
Tudo ok, porém, o rollback não funciona, mesmo se eu trocasse o throw new RoolbackProcedureException(results); por throw new RuntimeException().
Alguém tem alguma idéia pra me ajudar?