Skip to content

Instantly share code, notes, and snippets.

@Jotschi
Created April 29, 2015 21:41
Show Gist options
  • Save Jotschi/13a7b88417251dd2c45c to your computer and use it in GitHub Desktop.
Save Jotschi/13a7b88417251dd2c45c to your computer and use it in GitHub Desktop.
import java.util.concurrent.CompletableFuture;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.ResourceIterable;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.event.KernelEventHandler;
import org.neo4j.graphdb.event.TransactionEventHandler;
import org.neo4j.graphdb.index.IndexManager;
import org.neo4j.graphdb.schema.Schema;
import org.neo4j.graphdb.traversal.BidirectionalTraversalDescription;
import org.neo4j.graphdb.traversal.TraversalDescription;
public class AsyncGraphDatabaseServiceWrapper {
private GraphDatabaseService db;
public AsyncGraphDatabaseServiceWrapper(GraphDatabaseService db) {
this.db = db;
}
public CompletableFuture<Node> createNode() {
return CompletableFuture.supplyAsync(() -> {
Node node = db.createNode();
return node;
});
}
public CompletableFuture<Node> createNode(Label... labels) {
return CompletableFuture.supplyAsync(() -> {
return db.createNode(labels);
});
}
public CompletableFuture<Node> getNodeById(long id) {
return CompletableFuture.supplyAsync(() -> {
return db.getNodeById(id);
});
}
public CompletableFuture<Relationship> getRelationshipById(long id) {
return CompletableFuture.supplyAsync(() -> {
return db.getRelationshipById(id);
});
}
public CompletableFuture<ResourceIterable<Node>> findNodesByLabelAndProperty(Label label, String key, Object value) {
return CompletableFuture.supplyAsync(() -> {
return db.findNodesByLabelAndProperty(label, key, value);
});
}
public CompletableFuture<Boolean> isAvailable(long timeout) {
return CompletableFuture.supplyAsync(() -> {
return db.isAvailable(timeout);
});
}
public void shutdown() {
db.shutdown();
}
public CompletableFuture<Transaction> beginTx() {
return CompletableFuture.supplyAsync(() -> {
return db.beginTx();
});
}
public <T> CompletableFuture<TransactionEventHandler<T>> registerTransactionEventHandler(TransactionEventHandler<T> handler) {
return CompletableFuture.supplyAsync(() -> {
return db.registerTransactionEventHandler(handler);
});
}
public <T> CompletableFuture<TransactionEventHandler<T>> unregisterTransactionEventHandler(TransactionEventHandler<T> handler) {
return CompletableFuture.supplyAsync(() -> {
return db.unregisterTransactionEventHandler(handler);
});
}
public CompletableFuture<KernelEventHandler> registerKernelEventHandler(KernelEventHandler handler) {
return CompletableFuture.supplyAsync(() -> {
return db.registerKernelEventHandler(handler);
});
}
public CompletableFuture<KernelEventHandler> unregisterKernelEventHandler(KernelEventHandler handler) {
return CompletableFuture.supplyAsync(() -> {
return db.unregisterKernelEventHandler(handler);
});
}
public CompletableFuture<Schema> schema() {
return CompletableFuture.supplyAsync(() -> {
return db.schema();
});
}
public CompletableFuture<IndexManager> index() {
return CompletableFuture.supplyAsync(() -> {
return db.index();
});
}
public CompletableFuture<TraversalDescription> traversalDescription() {
return CompletableFuture.supplyAsync(() -> {
return db.traversalDescription();
});
}
public CompletableFuture<BidirectionalTraversalDescription> bidirectionalTraversalDescription() {
return CompletableFuture.supplyAsync(() -> {
return db.bidirectionalTraversalDescription();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment