Database Reference
In-Depth Information
neo4jTemplate.delete(relationship);
//alternatively you could delete the relationship between two nodes
// retrieve the node by its node id value, in this case 10
Node greg = neo4jTemplate.getNode(10);
// retrieve the node by its node id value, in this case 1
Node jeremy = neo4jTemplate.getNode(1);
neo4jTemplate.deleteRelationshipBetween(greg, jeremy, "FOLLOWS");
}
}
Using Labels
Labels function as specific meta-descriptions that can be applied to nodes. Labels were introduced in Neo4j 2.0 in
order to help in querying and can also function as a way to quickly create a subgraph.
Adding a Label to Nodes
In SDN, you can add one more labels to a node using LabelBasedStrategyCypherHelper . As shown in Listing 11-10,
the setLabelsOnNode function takes one or more labels as argument. You can return each of the labels on a node by
calling its getLabels function. The value used for the label should be any nonempty string or numeric value.
Listing 11-10. Adding Labels to a Node
public class SDNServiceClass {
@Autowired
public Neo4jOperations neo4jTemplate;
public void addLabels(){
// retrieve the node by its node id value, in this case 10
Node greg = neo4jTemplate.getNode(10);
// array of labels
String[] labelArray = {"Admin","Developer"};
//setup CypherQueryEngine
CypherQueryEngine cqe = neo4jTemplate.getGraphDatabase().queryEngine();
// instantiate LabelBasedStrategyCypherHelper
LabelBasedStrategyCypherHelper lbsch = new LabelBasedStrategyCypherHelper(cqe);
// set the labels
lbsch.setLabelsOnNode(greg.getId(),new ArrayList<String>(Arrays.
asList(labelArray)));
}
}
 
Search WWH ::




Custom Search