Database Reference
In-Depth Information
Listing 11-4. Creating a Node
import java.util.HashMap;
import java.util.Map;
import org.neo4j.graphdb.Node;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.template.Neo4jOperations;
// class
public class SDNServiceClass {
@Autowired
public Neo4jOperations neo4jTemplate;
public Node createNode(){
// create map
Map props=new HashMap<>();
props.put("id", 100);
props.put("name","firstNode");
Node node = neo4jTemplate.createNode(props);
return node;
}
}
Retrieving and Updating a Node
Once nodes have been added to the database, you need a way to retrieve and modify them. Listing 11-5 shows one
way to find a node by its node id and update it. As mentioned earlier, there are a few ways to manage the retrieval of a
node and modify its properties.
Listing 11-5. Retrieving and Updating a Node
public class SDNServiceClass {
@Autowired
public Neo4jOperations neo4jTemplate;
public void updateNode(){
// get the node
Node node = neo4jTemplate.getNode(10);
// update node properties
node.setProperty("firstname","Greg");
node.setProperty("lastname","Jordan");
neo4jTemplate.save(node);
}
}
 
Search WWH ::




Custom Search