Skip to content

Instantly share code, notes, and snippets.

@jexp
Created February 19, 2011 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jexp/835408 to your computer and use it in GitHub Desktop.
Save jexp/835408 to your computer and use it in GitHub Desktop.
Request for Feedback on Spring Data Graph Template API
public interface Neo4jOperations {
<T> T doInTransaction(GraphTransactionCallback<T> callback);
<T> T execute(GraphCallback<T> callback);
Node getReferenceNode();
Node getNode(long id);
Node createNode(Property... props);
Relationship getRelationship(long id);
Relationship createRelationship(Node startNode, Node endNode, RelationshipType type, Property... props);
void index(PropertyContainer primitive, String indexName, String field, Object value);
void index(PropertyContainer primitive, String field, Object value);
<T> Iterable<T> queryNodes(String indexName, Object queryOrQueryObject, PathMapper<T> pathMapper);
<T> Iterable<T> retrieveNodes(String indexName, String field, String value, PathMapper<T> pathMapper);
<T> Iterable<T> queryRelationships(String indexName, Object queryOrQueryObject, PathMapper<T> pathMapper);
<T> Iterable<T> retrieveRelationships(String indexName, String field, String value, PathMapper<T> pathMapper);
<T> Iterable<T> traverse(Node startNode, TraversalDescription traversal, PathMapper<T> pathMapper);
<T> Iterable<T> traverseDirectRelationships(Node startNode, RelationshipType type, Direction direction, PathMapper<T> pathMapper);
<T> Iterable<T> traverseDirectRelationships(Node startNode, PathMapper<T> pathMapper, RelationshipType... type);
<T> Iterable<T> traverseDirectRelationships(Node startNode, PathMapper<T> pathMapper);
}
// Usage:
@Test
public void testDoInTransaction() throws Exception {
Node refNode = template.doInTransaction(new GraphTransactionCallback<Node>() {
@Override
public Node doWithGraph(Status status, GraphDatabaseService graph) throws Exception {
Node referenceNode = graph.getReferenceNode();
referenceNode.setProperty("test", "testDoInTransaction");
return referenceNode;
}
});
assertEquals("same reference node",referenceNode,refNode);
assertTestPropertySet(referenceNode, "testDoInTransaction");
}
@Test
public void testCreateNodeWithProperties() throws Exception {
Node node=template.createNode(_("test", "testCreateNodeWithProperties"));
assertTestPropertySet(node, "testCreateNodeWithProperties");
}
Iterable<String> result=template.traverse(startNode, Traversal.description().filter(returnAllButStartNode()).relationships(HAS),
new PathMapper<String>() {
@Override
public String mapPath(Path path) {
return (String) path.endNode().getProperty("name", "");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment