@Test(expected = EntityNotFoundException.class) public void throwsExceptionWhenKeyIsNotFound() throws Exception { repo.find("does not exist"); }
@Override public String find(String key) throws EntityNotFoundException, PersistenceException { try (PreparedStatement statement = database.prepare( "SELECT `value` FROM client_configuration WHERE `key` = ? LIMIT 1" )) { statement.setString(1, key); try (ResultSet resultSet = statement.executeQuery()) { if (!resultSet.next()) { throw new EntityNotFoundException("key not found: " + key); } return resultSet.getString(1); } } catch (SQLException e) { throw new PersistenceException("failed searching for client configuration with key: " + key, e); } }
SqliteClientConfigRepository implements ClientConfigRepository { @Override public String find(String key) throws EntityNotFoundException, PersistenceException { try (PreparedStatement statement = database.prepare( "SELECT `value` FROM client_configuration WHERE `key` = ? LIMIT 1" )) { statement.setString(1, key); try (ResultSet resultSet = statement.executeQuery()) { if (!resultSet.next()) { throw new EntityNotFoundException("key not found: " + key); } return resultSet.getString(1); } } catch (SQLException e) { throw new PersistenceException("failed searching for client configuration with key: " + key, e); } } }
SqliteClientConfigRepository implements ClientConfigRepository { @Override public String find(String key) throws EntityNotFoundException, PersistenceException { try (PreparedStatement statement = database.prepare( "SELECT `value` FROM client_configuration WHERE `key` = ? LIMIT 1" )) { statement.setString(1, key); try (ResultSet resultSet = statement.executeQuery()) { if (!resultSet.next()) { throw new EntityNotFoundException("key not found: " + key); } return resultSet.getString(1); } } catch (SQLException e) { throw new PersistenceException("failed searching for client configuration with key: " + key, e); } } SqliteClientConfigRepository(ClientDatabase database); }
SqliteClientConfigRepository implements ClientConfigRepository { @Override public String find(String key) throws EntityNotFoundException, PersistenceException { try (PreparedStatement statement = database.prepare( "SELECT `value` FROM client_configuration WHERE `key` = ? LIMIT 1" )) { statement.setString(1, key); try (ResultSet resultSet = statement.executeQuery()) { if (!resultSet.next()) { throw new EntityNotFoundException("key not found: " + key); } return resultSet.getString(1); } } catch (SQLException e) { throw new PersistenceException("failed searching for client configuration with key: " + key, e); } } SqliteClientConfigRepository(ClientDatabase database); @Override String find(String key); @Override boolean contains(String key); @Override void save(String key, String value); }
SqliteClientConfigRepository implements ClientConfigRepository { @Override public String find(String key) throws EntityNotFoundException, PersistenceException { try (PreparedStatement statement = database.prepare( "SELECT `value` FROM client_configuration WHERE `key` = ? LIMIT 1" )) { statement.setString(1, key); try (ResultSet resultSet = statement.executeQuery()) { if (!resultSet.next()) { throw new EntityNotFoundException("key not found: " + key); } return resultSet.getString(1); } } catch (SQLException e) { throw new PersistenceException("failed searching for client configuration with key: " + key, e); } } SqliteClientConfigRepository(ClientDatabase database); @Override String find(String key); @Override boolean contains(String key); @Override void save(String key, String value);  }