@Test public void testContains() throws Exception { Assert.assertTrue(db.contains("1", descriptor)); Assert.assertTrue(db.contains("2", descriptor)); Assert.assertTrue(db.contains("3", descriptor)); Assert.assertTrue(db.contains("4", descriptor)); Assert.assertFalse(db.contains(String.valueOf(itemsCount + 1), descriptor)); Assert.assertFalse(db.contains(String.valueOf(itemsCount + 2), descriptor)); }
@Override public boolean contains(String hash, ThreatListDescriptor descriptor) throws IOException { checkTableForDescriptor(descriptor); String sql = "SELECT prefix FROM " + descriptor + " WHERE prefix=?"; try (Connection conn = dataSource.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { ps.setString(1, hash); try (ResultSet rs = ps.executeQuery()) { return rs.next(); } } catch (SQLException ex) { throw new IOException(ex); } }
SqlLocalDatabase implements LocalDatabase { @Override public boolean contains(String hash, ThreatListDescriptor descriptor) throws IOException { checkTableForDescriptor(descriptor); String sql = "SELECT prefix FROM " + descriptor + " WHERE prefix=?"; try (Connection conn = dataSource.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { ps.setString(1, hash); try (ResultSet rs = ps.executeQuery()) { return rs.next(); } } catch (SQLException ex) { throw new IOException(ex); } } }
SqlLocalDatabase implements LocalDatabase { @Override public boolean contains(String hash, ThreatListDescriptor descriptor) throws IOException { checkTableForDescriptor(descriptor); String sql = "SELECT prefix FROM " + descriptor + " WHERE prefix=?"; try (Connection conn = dataSource.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { ps.setString(1, hash); try (ResultSet rs = ps.executeQuery()) { return rs.next(); } } catch (SQLException ex) { throw new IOException(ex); } }  }
SqlLocalDatabase implements LocalDatabase { @Override public boolean contains(String hash, ThreatListDescriptor descriptor) throws IOException { checkTableForDescriptor(descriptor); String sql = "SELECT prefix FROM " + descriptor + " WHERE prefix=?"; try (Connection conn = dataSource.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { ps.setString(1, hash); try (ResultSet rs = ps.executeQuery()) { return rs.next(); } } 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 boolean contains(String hash, ThreatListDescriptor descriptor) throws IOException { checkTableForDescriptor(descriptor); String sql = "SELECT prefix FROM " + descriptor + " WHERE prefix=?"; try (Connection conn = dataSource.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { ps.setString(1, hash); try (ResultSet rs = ps.executeQuery()) { return rs.next(); } } 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);  }