/** * Seta informacoes importantes para a gravacao dados. As informacoes serao preenchidas nas * collections: colCamposPK, colCamposTodos * * @param colGrupos * @param colCamposPK * @param colCamposTodos * @throws Exception */ @Override public void setInfoSave( final Integer idVisao, final Collection colCamposPK, final Collection colCamposTodos) throws Exception { final GrupoVisaoCamposNegocioDao grupoVisaoCamposNegocioDao = new GrupoVisaoCamposNegocioDao(); final CamposObjetoNegocioDao camposObjetoNegocioDao = new CamposObjetoNegocioDao(); final GrupoVisaoDao grupoVisaoDao = new GrupoVisaoDao(); final Collection colGrupos = grupoVisaoDao.findByIdVisaoAtivos(idVisao); if (colGrupos != null) { for (final Iterator it = colGrupos.iterator(); it.hasNext(); ) { final GrupoVisaoDTO grupoVisaoDTO = (GrupoVisaoDTO) it.next(); grupoVisaoDTO.setColCamposVisao( grupoVisaoCamposNegocioDao.findByIdGrupoVisaoAtivos(grupoVisaoDTO.getIdGrupoVisao())); if (grupoVisaoDTO.getColCamposVisao() != null) { for (final Iterator it2 = grupoVisaoDTO.getColCamposVisao().iterator(); it2.hasNext(); ) { final GrupoVisaoCamposNegocioDTO grupoVisaoCamposNegocioDTO = (GrupoVisaoCamposNegocioDTO) it2.next(); CamposObjetoNegocioDTO camposObjetoNegocioDTO = new CamposObjetoNegocioDTO(); camposObjetoNegocioDTO.setIdCamposObjetoNegocio( grupoVisaoCamposNegocioDTO.getIdCamposObjetoNegocio()); camposObjetoNegocioDTO = (CamposObjetoNegocioDTO) camposObjetoNegocioDao.restore(camposObjetoNegocioDTO); if (camposObjetoNegocioDTO != null) { camposObjetoNegocioDTO.setFormula(grupoVisaoCamposNegocioDTO.getFormula()); camposObjetoNegocioDTO.setTipoNegocio(grupoVisaoCamposNegocioDTO.getTipoNegocio()); if (camposObjetoNegocioDTO.getPk().equalsIgnoreCase("S")) { colCamposPK.add(camposObjetoNegocioDTO); } colCamposTodos.add(camposObjetoNegocioDTO); } } } } } }
public void updateFromMap( final Map map, final Collection colCampos, final UsuarioDTO usuarioDto, final VisaoDao visaoDao, final HttpServletRequest request) throws Exception { final List lstParms = new ArrayList<>(); final List lstWhere = new ArrayList<>(); String strFields = ""; String strWhere = ""; final String strTable = this.generateFrom(colCampos); String sql = "UPDATE " + strTable + " "; for (final Iterator it = colCampos.iterator(); it.hasNext(); ) { final CamposObjetoNegocioDTO camposObjetoNegocioDTO = (CamposObjetoNegocioDTO) it.next(); String strVal = ""; if (camposObjetoNegocioDTO.getFormula() != null && !camposObjetoNegocioDTO.getFormula().trim().equalsIgnoreCase("") && !camposObjetoNegocioDTO .getTipoNegocio() .trim() .equalsIgnoreCase(MetaUtil.CLASS_AND_METHOD)) { strVal = this.executeFormula(camposObjetoNegocioDTO.getFormula(), map, camposObjetoNegocioDTO); } else { strVal = (String) map.get(camposObjetoNegocioDTO.getNomeDB().trim().toUpperCase()); } if (!camposObjetoNegocioDTO.getPk().equalsIgnoreCase("S")) { if (strVal != null) { if (!strFields.equalsIgnoreCase("")) { strFields += ","; } strFields += "" + camposObjetoNegocioDTO.getNomeDB().trim() + " = ?"; lstParms.add( MetaUtil.convertType( camposObjetoNegocioDTO.getTipoDB().trim(), strVal, camposObjetoNegocioDTO.getPrecisionDB(), request)); } } else { if (strVal != null) { if (!strWhere.equalsIgnoreCase("")) { strWhere += " AND "; } strWhere += "" + camposObjetoNegocioDTO.getNomeDB() + " = ?"; lstWhere.add( MetaUtil.convertType( camposObjetoNegocioDTO.getTipoDB().trim(), strVal, camposObjetoNegocioDTO.getPrecisionDB(), request)); } } } sql += " SET " + strFields + " WHERE " + strWhere; lstParms.addAll(lstWhere); if (strFields != null && !strFields.trim().equalsIgnoreCase("")) { visaoDao.execUpdate(sql, lstParms.toArray()); if (UtilStrings.nullToVazio( ParametroUtil.getValorParametroCitSmartHashMap(ParametroSistema.USE_LOG, "false")) .equalsIgnoreCase("true")) { new Thread(new RegistraLogDinamicView(lstParms.toArray(), "U", sql, usuarioDto, strTable)) .start(); } } if (!map.containsKey("REMOVED")) { map.put("REMOVED", "false"); } String removed = (String) map.get("REMOVED"); if (removed == null) { removed = "false"; } if (removed.equalsIgnoreCase("X")) { // A nova arquitetura coloca esta informacao. removed = "true"; } String sqlUltAtualizAndLogicDelete = ""; if (removed.equalsIgnoreCase("true")) { sqlUltAtualizAndLogicDelete = "UPDATE " + strTable + " SET DELETED = 'Y' WHERE " + strWhere; try { visaoDao.execUpdate(sqlUltAtualizAndLogicDelete, lstWhere.toArray()); if (UtilStrings.nullToVazio( ParametroUtil.getValorParametroCitSmartHashMap(ParametroSistema.USE_LOG, "false")) .equalsIgnoreCase("true")) { new Thread( new RegistraLogDinamicView( lstWhere.toArray(), "D", sqlUltAtualizAndLogicDelete, usuarioDto, strTable)) .start(); } } catch (final Exception e) { LOGGER.debug("SQL executado:" + sqlUltAtualizAndLogicDelete); throw new LogicException( "Não foi possível realizar a exclusão do registro! Verifique se possui o Campo 'DELETED' do tipo CHAR(1) no Banco de dados!"); } } }