@Test public void testPersist() throws Exception { List<String> newValues = new ArrayList<>(); newValues.add("abc"); newValues.add("def"); db.persist(descriptor, newValues); List<String> ls = db.load(descriptor); Assert.assertEquals(itemsCount + 2, ls.size()); Assert.assertTrue(ls.contains("abc")); Assert.assertTrue(ls.contains("def")); Assert.assertTrue(ls.contains("1")); Assert.assertTrue(ls.contains("2")); }
@Override public void persist(ThreatListDescriptor descriptor, List<String> hashes) throws IOException { checkTableForDescriptor(descriptor); String sql = "INSERT INTO " + descriptor + " VALUES (?)"; try (Connection conn = dataSource.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { int offset = 0; int inserted = 0; for (String hash : hashes) { ps.setString(1, hash); inserted += ps.executeUpdate(); if (++offset == BATCH_SIZE) { conn.commit(); LOGGER.info("Inserted {} item(s)", inserted); offset = 0; inserted = 0; } } if (offset > 0) { conn.commit(); LOGGER.info("Inserted {} item(s)", inserted); } } catch (SQLException ex) { throw new IOException(ex); } }
SqlLocalDatabase implements LocalDatabase { @Override public void persist(ThreatListDescriptor descriptor, List<String> hashes) throws IOException { checkTableForDescriptor(descriptor); String sql = "INSERT INTO " + descriptor + " VALUES (?)"; try (Connection conn = dataSource.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { int offset = 0; int inserted = 0; for (String hash : hashes) { ps.setString(1, hash); inserted += ps.executeUpdate(); if (++offset == BATCH_SIZE) { conn.commit(); LOGGER.info("Inserted {} item(s)", inserted); offset = 0; inserted = 0; } } if (offset > 0) { conn.commit(); LOGGER.info("Inserted {} item(s)", inserted); } } catch (SQLException ex) { throw new IOException(ex); } } }
SqlLocalDatabase implements LocalDatabase { @Override public void persist(ThreatListDescriptor descriptor, List<String> hashes) throws IOException { checkTableForDescriptor(descriptor); String sql = "INSERT INTO " + descriptor + " VALUES (?)"; try (Connection conn = dataSource.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { int offset = 0; int inserted = 0; for (String hash : hashes) { ps.setString(1, hash); inserted += ps.executeUpdate(); if (++offset == BATCH_SIZE) { conn.commit(); LOGGER.info("Inserted {} item(s)", inserted); offset = 0; inserted = 0; } } if (offset > 0) { conn.commit(); LOGGER.info("Inserted {} item(s)", inserted); } } catch (SQLException ex) { throw new IOException(ex); } }  }
SqlLocalDatabase implements LocalDatabase { @Override public void persist(ThreatListDescriptor descriptor, List<String> hashes) throws IOException { checkTableForDescriptor(descriptor); String sql = "INSERT INTO " + descriptor + " VALUES (?)"; try (Connection conn = dataSource.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { int offset = 0; int inserted = 0; for (String hash : hashes) { ps.setString(1, hash); inserted += ps.executeUpdate(); if (++offset == BATCH_SIZE) { conn.commit(); LOGGER.info("Inserted {} item(s)", inserted); offset = 0; inserted = 0; } } if (offset > 0) { conn.commit(); LOGGER.info("Inserted {} item(s)", inserted); } } catch (SQLException ex) { throw new IOException(ex); } }  @Override List<String> load(ThreatListDescriptor descriptor); @Override void persist(ThreatListDescriptor descriptor, List<String> hashes); @Override boolean contains(String hash, ThreatListDescriptor descriptor); @Override void clear(ThreatListDescriptor descriptor); }
SqlLocalDatabase implements LocalDatabase { @Override public void persist(ThreatListDescriptor descriptor, List<String> hashes) throws IOException { checkTableForDescriptor(descriptor); String sql = "INSERT INTO " + descriptor + " VALUES (?)"; try (Connection conn = dataSource.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { int offset = 0; int inserted = 0; for (String hash : hashes) { ps.setString(1, hash); inserted += ps.executeUpdate(); if (++offset == BATCH_SIZE) { conn.commit(); LOGGER.info("Inserted {} item(s)", inserted); offset = 0; inserted = 0; } } if (offset > 0) { conn.commit(); LOGGER.info("Inserted {} item(s)", inserted); } } catch (SQLException ex) { throw new IOException(ex); } }  @Override List<String> load(ThreatListDescriptor descriptor); @Override void persist(ThreatListDescriptor descriptor, List<String> hashes); @Override boolean contains(String hash, ThreatListDescriptor descriptor); @Override void clear(ThreatListDescriptor descriptor);  }