@Test public void updateHeuristicHelp() throws SQLException { String help = "<p>\nTest\n</p>"; HeuristicsResultDB db = new HeuristicsResultDB(dbConfiguration); List<Heuristic> heuristics = new ArrayList<>(); Heuristic heuristic = mock(Heuristic.class); doReturn(help).when(heuristic).getHelp(); heuristics.add(heuristic); db.updateHeuristicHelp(heuristics); ResultSet rset = db.connection.createStatement().executeQuery("SELECT * FROM garmadon_heuristic_help"); HashMap<String, String> result = new HashMap<>(); while (rset.next()) { result.put(rset.getString(1), rset.getString(2)); } assertEquals(help, result.get(heuristic.getClass().getSimpleName())); }
public void updateHeuristicHelp(List<Heuristic> heuristics) { try { connection.prepareStatement(DELETE_ALL_HEURISTIC_HELP).execute(); } catch (SQLException ex) { LOGGER.warn("Error deleting all in {} table", HEURISTIC_HELP_TABLENAME, ex); return; } for (Heuristic heuristic : heuristics) { String heuristicName = heuristic.getClass().getSimpleName(); executeUpdate(() -> { Clob clob = connection.createClob(); clob.setString(1, heuristic.getHelp()); createHeuristicHelp.clearParameters(); createHeuristicHelp.setString(1, heuristicName); createHeuristicHelp.setClob(2, clob); return createHeuristicHelp.executeUpdate(); }, "Error when inserting help for " + heuristicName); } }
HeuristicsResultDB { public void updateHeuristicHelp(List<Heuristic> heuristics) { try { connection.prepareStatement(DELETE_ALL_HEURISTIC_HELP).execute(); } catch (SQLException ex) { LOGGER.warn("Error deleting all in {} table", HEURISTIC_HELP_TABLENAME, ex); return; } for (Heuristic heuristic : heuristics) { String heuristicName = heuristic.getClass().getSimpleName(); executeUpdate(() -> { Clob clob = connection.createClob(); clob.setString(1, heuristic.getHelp()); createHeuristicHelp.clearParameters(); createHeuristicHelp.setString(1, heuristicName); createHeuristicHelp.setClob(2, clob); return createHeuristicHelp.executeUpdate(); }, "Error when inserting help for " + heuristicName); } } }
HeuristicsResultDB { public void updateHeuristicHelp(List<Heuristic> heuristics) { try { connection.prepareStatement(DELETE_ALL_HEURISTIC_HELP).execute(); } catch (SQLException ex) { LOGGER.warn("Error deleting all in {} table", HEURISTIC_HELP_TABLENAME, ex); return; } for (Heuristic heuristic : heuristics) { String heuristicName = heuristic.getClass().getSimpleName(); executeUpdate(() -> { Clob clob = connection.createClob(); clob.setString(1, heuristic.getHelp()); createHeuristicHelp.clearParameters(); createHeuristicHelp.setString(1, heuristicName); createHeuristicHelp.setClob(2, clob); return createHeuristicHelp.executeUpdate(); }, "Error when inserting help for " + heuristicName); } } HeuristicsResultDB(DbConfiguration dbConfiguration); }
HeuristicsResultDB { public void updateHeuristicHelp(List<Heuristic> heuristics) { try { connection.prepareStatement(DELETE_ALL_HEURISTIC_HELP).execute(); } catch (SQLException ex) { LOGGER.warn("Error deleting all in {} table", HEURISTIC_HELP_TABLENAME, ex); return; } for (Heuristic heuristic : heuristics) { String heuristicName = heuristic.getClass().getSimpleName(); executeUpdate(() -> { Clob clob = connection.createClob(); clob.setString(1, heuristic.getHelp()); createHeuristicHelp.clearParameters(); createHeuristicHelp.setString(1, heuristicName); createHeuristicHelp.setClob(2, clob); return createHeuristicHelp.executeUpdate(); }, "Error when inserting help for " + heuristicName); } } HeuristicsResultDB(DbConfiguration dbConfiguration); void createHeuristicResult(HeuristicResult heuristicResult); void updateHeuristicHelp(List<Heuristic> heuristics); void executeUpdate(Callable action, String exceptionStr); }
HeuristicsResultDB { public void updateHeuristicHelp(List<Heuristic> heuristics) { try { connection.prepareStatement(DELETE_ALL_HEURISTIC_HELP).execute(); } catch (SQLException ex) { LOGGER.warn("Error deleting all in {} table", HEURISTIC_HELP_TABLENAME, ex); return; } for (Heuristic heuristic : heuristics) { String heuristicName = heuristic.getClass().getSimpleName(); executeUpdate(() -> { Clob clob = connection.createClob(); clob.setString(1, heuristic.getHelp()); createHeuristicHelp.clearParameters(); createHeuristicHelp.setString(1, heuristicName); createHeuristicHelp.setClob(2, clob); return createHeuristicHelp.executeUpdate(); }, "Error when inserting help for " + heuristicName); } } HeuristicsResultDB(DbConfiguration dbConfiguration); void createHeuristicResult(HeuristicResult heuristicResult); void updateHeuristicHelp(List<Heuristic> heuristics); void executeUpdate(Callable action, String exceptionStr);  }