1 package eu.ehri.project.core.impl.neo4j;
2
3
4 import com.tinkerpop.blueprints.CloseableIterable;
5 import com.tinkerpop.blueprints.Edge;
6 import org.neo4j.graphdb.Relationship;
7 import org.neo4j.graphdb.index.IndexHits;
8
9 import java.util.Iterator;
10
11
12 public class Neo4j2EdgeIterable<T extends Edge> implements CloseableIterable<Neo4j2Edge> {
13
14 private final Iterable<Relationship> relationships;
15 private final Neo4j2Graph graph;
16
17
18
19
20 @Deprecated
21 public Neo4j2EdgeIterable(Iterable<Relationship> relationships, Neo4j2Graph graph, boolean checkTransaction) {
22 this(relationships, graph);
23 }
24
25 public Neo4j2EdgeIterable(Iterable<Relationship> relationships, Neo4j2Graph graph) {
26 this.relationships = relationships;
27 this.graph = graph;
28 }
29
30 public Iterator<Neo4j2Edge> iterator() {
31 graph.autoStartTransaction(true);
32 return new Iterator<Neo4j2Edge>() {
33 private final Iterator<Relationship> itty = relationships.iterator();
34
35 public void remove() {
36 graph.autoStartTransaction(true);
37 this.itty.remove();
38 }
39
40 public Neo4j2Edge next() {
41 graph.autoStartTransaction(false);
42 return new Neo4j2Edge(this.itty.next(), graph);
43 }
44
45 public boolean hasNext() {
46 graph.autoStartTransaction(false);
47 return this.itty.hasNext();
48 }
49 };
50 }
51
52 public void close() {
53 if (this.relationships instanceof IndexHits) {
54 ((IndexHits) this.relationships).close();
55 }
56 }
57 }