Database Reference
In-Depth Information
Caution
A label will not exist on the database server until it has been added to at least one node.
Removing a Label
Removing a label uses similar syntax as adding a label to a node. After the given label has been removed from the
node (Listing 11-11), the return value is a list of labels still on the node.
Listing 11-11. Removing a Label from a Node
public class SDNServiceClass {
@Autowired
public Neo4jOperations neo4jTemplate;
public void removeLabel(){
// retrieve the node by its node id value, in this case 10
Node greg = neo4jTemplate.getNode(10);
greg.removeLabel(DynamicLabel.label("Admin"));
}
}
Querying with a Label
To get nodes that use a specific label, use the method called getNodesWithLabel . This method's returns value is an
iterable (Listing 11-12).
Listing 11-12. Querying with a Label
public class SDNServiceClass {
@Autowired
public Neo4jOperations neo4jTemplate;
public Iterable<Node> getNodesWithLabel(){
CypherQueryEngine cqe = neo4jTemplate.getGraphDatabase().queryEngine();
LabelBasedStrategyCypherHelper lbsch = new LabelBasedStrategyCypherHelper(cqe);
Iterable<Node> nodes = lbsch.getNodesWithLabel("Developer");
return nodes;
}
}
 
 
Search WWH ::




Custom Search