Suresh Payankannur

Showing posts with label neo4j. Show all posts
Showing posts with label neo4j. Show all posts

Wednesday, May 28, 2014

Executing Cypher Queries using Spring Data Neo4jTemplate


In addition to standard CRUD methods, org.springframework.data.neo4j.support.Neo4jTemplate provides the ability to execute Cypher queries. The following example shows how to use Neo4jTemplate:
@ContextConfiguration(locations = {"classpath:/test-config.xml"})
public class QueryTest extends AbstractTestNGSpringContextTests {
    @Test
    public void testQuery() {
        Object result = template.exec(new GraphCallback<Object>() {
                public Object doWithGraph(GraphDatabase graph) throws Exception {
                    QueryEngine engine = graph.queryEngine();
                    
                    Result<Map<String, Object>> result
                        = engine.query("match n return n", null);

                    for (Map<String, Object> m : result) {
                        for (Map.Entry<String, Object> e : m.entrySet()) {
                            Node node = (Node) e.getValue();
                            System.out.println("===>>" + node.getId());
                            System.out.println("===>>" + node.getLabels());

                        }
                    }
                    return null;
                }
            });
    }
    @Autowired
    private Neo4jTemplate template;
}


Saturday, May 24, 2014

Neo4j Labels Cannot be Deleted


In Neo4j version 2.1.0-RC2 labels once created cannot be deleted, even after all the nodes has been dropped. The only way around is to completely delete the database!
create (u:User {name: "John Doe", email: "johndoe@nowhere.com"})
create (b:Blog {name: "My Blog"})
match n delete n
Now if looking at the WebUI, you can see both labels are still present. In addition, by calling the REST API http://localhost:7474/db/data/labels returns both labels, even though there are no nodes referring to it. There is no current API or command to delete these orphaned labels.

Blog Archive

Scroll To Top