RefreshOperation extends AbstractNeo4JOperation { @Override public void execute(final Connection connection, final Graph<Node, Edge> graph) throws SQLException { for (final Node node : graph.vertexSet()) { final List<SetExpression> attributes = node.getAttributes().stream().filter(a -> !a.isId()) .map(a -> property(identifier(node.getId()).property(a.getName()), literal(a.getValue()))).collect(toList()); final UpdateNext query = merge(node.toPath().withIdAttributes().build()).set(attributes); executeQuery(connection, query.toString()); } for (final Edge edge : graph.edgeSet()) { final Node sourceNode = edge.getSourceNode(); final Node targetNode = edge.getTargetNode(); final List<SetExpression> attributes = edge.getAttributes().stream() .map(a -> property(identifier(edge.getId()).property(a.getName()), literal(a.getValue()))).collect(toList()); final UpdateNext query = match(sourceNode.toPath().withIdAttributes().build(), targetNode.toPath().withIdAttributes().build()) .merge(edge.toPath().build()).set(attributes); executeQuery(connection, query.toString()); } }  @Override void execute(final Connection connection, final Graph<Node, Edge> graph);  }
@Test public void testExecute() throws Exception { final Node n1 = graphElementFactory.createNode("n1", Arrays.asList("A"), ImmutableMap.<String, Object>builder().put("id", 1l).put("value", "A").build()); final Node n2 = graphElementFactory.createNode("n2", Arrays.asList("A"), ImmutableMap.<String, Object>builder().put("id", 2l).build()); final Edge e1 = graphElementFactory.createEdge(n1, n2, "e1", Arrays.asList("E"), ImmutableMap.<String, Object>builder().put("id", 3l).put("value", "C").build()); final Graph<Node, Edge> graph = new DefaultDirectedGraph<>(new ClassBasedEdgeFactory<>(Edge.class)); graph.addVertex(n1); graph.addVertex(n2); graph.addEdge(e1.getSourceNode(), e1.getTargetNode(), e1); operation.execute(connection, graph); final ArgumentCaptor<String> queryCaptor = ArgumentCaptor.forClass(String.class); verify(operation, times(3)).executeQuery(eq(connection), queryCaptor.capture()); final List<String> queries = queryCaptor.getAllValues(); assertThat(queries.get(0), containsString("MERGE (n1:A {id:1}) SET n1.value=\"A\"")); assertThat(queries.get(1), containsString("MERGE (n2:A {id:2})")); assertThat(queries.get(2), containsString("MATCH (n1:A {id:1}),(n2:A {id:2}) MERGE (n1)-[e1:E]->(n2) SET e1.id=3,e1.value=\"C\"")); }