Skip to content
Browse files

changed clear function

  • Loading branch information...
1 parent 54c87dc commit 7d48f567e58d3f3684133d637ceac8a19ddfa8ad @phifty committed
View
2 src/main/java/me/phifty/graph/Nodes.java
@@ -15,6 +15,4 @@
public void remove(Object id, Handler<Boolean> handler) throws Exception;
- public void clear(Handler<Boolean> handler) throws Exception;
-
}
View
2 src/main/java/me/phifty/graph/Relationships.java
@@ -17,6 +17,4 @@
public void remove(Object id, Handler<Boolean> handler) throws Exception;
- public void clear(Handler<Boolean> handler) throws Exception;
-
}
View
36 src/main/java/me/phifty/graph/neo4j/Neo4jGraph.java
@@ -2,6 +2,10 @@
import me.phifty.graph.*;
import org.neo4j.graphdb.GraphDatabaseService;
+import org.neo4j.graphdb.Node;
+import org.neo4j.graphdb.Relationship;
+import org.neo4j.graphdb.Transaction;
+import org.neo4j.tooling.GlobalGraphOperations;
/**
* @author phifty <b.phifty@gmail.com>
@@ -56,21 +60,25 @@ public Complex complex() {
@Override
public void clear(final Handler<Boolean> handler) throws Exception {
- relationships().clear(new Handler<Boolean>() {
- @Override
- public void handle(final Boolean relationshipsDeleted) {
- try {
- nodes().clear(new Handler<Boolean>() {
- @Override
- public void handle(Boolean nodesDeleted) {
- handler.handle(nodesDeleted && relationshipsDeleted);
- }
- });
- } catch (Exception exception) {
- exception.printStackTrace();
- }
+ GlobalGraphOperations globalGraphOperations = GlobalGraphOperations.at(graphDatabaseService);
+ Transaction transaction = graphDatabaseService.beginTx();
+ try {
+ for (Relationship relationship : globalGraphOperations.getAllRelationships()) {
+ relationship.delete();
}
- });
+
+ for (Node node : globalGraphOperations.getAllNodes()) {
+ node.delete();
+ }
+
+ transaction.success();
+ handler.handle(true);
+ } catch (Exception exception) {
+ transaction.failure();
+ throw exception;
+ } finally {
+ transaction.finish();
+ }
}
@Override
View
19 src/main/java/me/phifty/graph/neo4j/Neo4jNodes.java
@@ -5,7 +5,6 @@
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
-import org.neo4j.tooling.GlobalGraphOperations;
import java.util.Map;
@@ -80,22 +79,4 @@ public void remove(Object id, Handler<Boolean> handler) throws Exception {
}
}
- @Override
- public void clear(Handler<Boolean> handler) throws Exception {
- Transaction transaction = graphDatabaseService.beginTx();
- try {
- GlobalGraphOperations globalGraphOperations = GlobalGraphOperations.at(graphDatabaseService);
- for (Node node : globalGraphOperations.getAllNodes()) {
- node.delete();
- }
- transaction.success();
- handler.handle(true);
- } catch (Exception exception) {
- transaction.failure();
- throw exception;
- } finally {
- transaction.finish();
- }
- }
-
}
View
21 src/main/java/me/phifty/graph/neo4j/Neo4jRelationships.java
@@ -3,10 +3,8 @@
import me.phifty.graph.Handler;
import me.phifty.graph.Relationships;
import org.neo4j.graphdb.*;
-import org.neo4j.tooling.GlobalGraphOperations;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -122,23 +120,4 @@ public void remove(Object id, Handler<Boolean> handler) throws Exception {
}
}
- @Override
- public void clear(Handler<Boolean> handler) throws Exception {
- Transaction transaction = graphDatabaseService.beginTx();
- try {
- GlobalGraphOperations globalGraphOperations = GlobalGraphOperations.at(graphDatabaseService);
- for (Relationship relationship : globalGraphOperations.getAllRelationships()) {
- relationship.delete();
- }
- transaction.success();
-
- handler.handle(true);
- } catch (Exception exception) {
- transaction.failure();
- throw exception;
- } finally {
- transaction.finish();
- }
- }
-
}

0 comments on commit 7d48f56

Please sign in to comment.
Something went wrong with that request. Please try again.