I have a problem I hope and you can help me, what happens is that I have a list that I extract from the database, and what I want is to validate before inserting, that if a record exists in the list that do not insert it This is my insert method:
public void insertSale() {
origin_adm = Session.getOriginAdmActiva();
cve_usr = Session.getUserCve();
tipoVenta.setOrigin_adm(Integer.parseInt(origin_adm));
tipoVenta.setUsr_cve(cve_usr);
if (tipoVenta.getCve_type_of_sale() == null) {
tipoVenta.setCve_type_of_sale(0);
}
//System.out.println("Descripcion..." + tipoVenta.getDesc_type_of_sale());
if (tipoVenta.getDesc_type_of_sale() == null || tipoVenta.getDesc_type_of_sale().equals("")) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error: ", "Campo Requerido."));
RequestContext.getCurrentInstance().update("alertaDistribucion");
RequestContext.getCurrentInstance().execute("ocultaMsj(3000)");
}
else {
int ultimoRegistro = dao.saveTypeSale(tipoVenta);
if (tipoVenta.getCve_type_of_sale() == 0) {
System.out.println("Entro insert...");
TipoVentaDTO tipoVentaDTO = new TipoVentaDTO();
tipoVentaDTO.setOrigin_adm(tipoVenta.getOrigin_adm());
tipoVentaDTO.setCve_type_of_sale(ultimoRegistro);
tipoVentaDTO.setDesc_type_of_sale(tipoVenta.getDesc_type_of_sale());
tipoVentaDTO.setUsr_cve(tipoVenta.getUsr_cve());
listTipoVentas.add(tipoVentaDTO);
listTipoVentasFiltradas.add(tipoVentaDTO);
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Exito: ", "Venta insertada exitosamente."));
RequestContext.getCurrentInstance().update("alertaDistribucion");
RequestContext.getCurrentInstance().execute("ocultaMsj(3000)");
} else {
System.out.println("Entro update...");
for (int i = 0; i < listTipoVentas.size(); i++) {
if (listTipoVentas.get(i).getCve_type_of_sale() == tipoVenta.getCve_type_of_sale()) {
listTipoVentas.get(i).setDesc_type_of_sale(tipoVenta.getDesc_type_of_sale());
}
}
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Exito: ", "venta actualizada exitosamente."));
RequestContext.getCurrentInstance().update("alertaDistribucion");
RequestContext.getCurrentInstance().execute("ocultaMsj(3000)");
}
reset();
RequestContext.getCurrentInstance().execute("cancelar()");
}
}
I have no idea how to start that validation, I hope and you can help me with this problem, I remain alert, kind regards and if you need any other information, I'll gladly put it.