class CypherExecutor implements AutoCloseable { private final Driver driver; public CypherExecutor(String uri, String username, String password) { this.driver = GraphDatabase.driver(uri, AuthTokens.basic(username, password)) } public <T> List<T> readCyphers(String cypher, Function<Record, T> mapper) { try (Session session = driver.session()) { Result result = session.run(cypher); return result.list(mapper); } } @Override public void close() throws Exception { driver.close(); } }