diff --git a/src/com/rjconsultores/ventaboletos/FlyWay.java b/src/com/rjconsultores/ventaboletos/FlyWay.java index aa0a744c0..c6a4506e2 100644 --- a/src/com/rjconsultores/ventaboletos/FlyWay.java +++ b/src/com/rjconsultores/ventaboletos/FlyWay.java @@ -70,6 +70,7 @@ public class FlyWay { fixVersion(s, "20162410.1119", "20161024.1119", "V20161024_1119__mantis7904.sql"); s.close(); + c.close(); } catch (SQLException e) { log.error(e.getMessage(), e); @@ -198,13 +199,24 @@ public class FlyWay { } } + Connection c = null; + PreparedStatement ps = null; + try { - Connection c = flyway.getDataSource().getConnection(); - PreparedStatement ps = c.prepareStatement("update flyway_scripts set activo = 0 where nome like ?"); + c = flyway.getDataSource().getConnection(); + ps = c.prepareStatement("update flyway_scripts set activo = 0 where nome like ?"); ps.setString(1, errorCallback.getScriptError().replace(".sql", "")); ps.executeUpdate(); } catch (SQLException e1) { + } finally { + if (ps != null) { + try { ps.close(); } catch (SQLException e1) {} + } + + if (c != null) { + try { c.close(); } catch (SQLException e1) {} + } } } @@ -242,6 +254,10 @@ public class FlyWay { ResultSet rs = s.executeQuery(sb.toString()); while (rs.next()) { + if (!isRegistroValido(rs.getString("nome_arquivo"), rs.getString("sql_arquivo"))) { + continue; + } + Timestamp timestamp = rs.getTimestamp("datahora"); FlyWayCustomDetail detail = new FlyWayCustomDetail(); @@ -258,6 +274,7 @@ public class FlyWay { rs.close(); s.close(); + c.close(); } catch (SQLException e) { log.error(e.getMessage(), e); @@ -318,6 +335,44 @@ public class FlyWay { return retorno; } + private boolean isRegistroValido(String versao, String sql) { + boolean valido = true; + + String v[] = versao.split("_"); + + if (!versao.startsWith("V")) { + valido = false; + } else { + if (!(v.length == 4)) { + valido = false; + } + } + + if (!valido) { + Connection c = null; + PreparedStatement ps = null; + + try { + c = dataSource.getConnection(); + ps = c.prepareStatement("update flyway_scripts set activo = 0 where nome like ?"); + ps.setString(1, versao); + ps.executeUpdate(); + + } catch (SQLException e1) { + } finally { + if (ps != null) { + try { ps.close(); } catch (SQLException e1) {} + } + + if (c != null) { + try { c.close(); } catch (SQLException e1) {} + } + } + } + + return valido; + } + private boolean existeSchema(Connection c) { StringBuilder sb = new StringBuilder(); sb.append("SELECT count(table_name) as existe FROM all_tables WHERE table_name = 'schema_version_cst'"); @@ -334,7 +389,8 @@ public class FlyWay { rs.close(); s.close(); - + c.close(); + if (existe > 0) { return true; }