*/
private void updateSingle(Property p, DataType toUpdate, Vertex rootVertex, CascadeType cascade, Map<String, Object> objectsBeingAccessed) {
Object value = p.get(toUpdate);
// As a convention, null values are never stored
if(value!=null) {
Vertex valueVertex = getVertexFor(value, cascade, objectsBeingAccessed);
Edge link = null;
// Get previously existing vertex
Iterator<Edge> existingIterator = rootVertex.getOutEdges(GraphUtils.getEdgeNameFor(p)).iterator();
// property is single-valued, so iteration can be done at most one
if(existingIterator.hasNext()) {
// There is an existing edge, change its target and maybe delete previous one
Edge existing = existingIterator.next();
if(existing.getInVertex().equals(valueVertex)) {
// Nothing to do
link = existing;
} else {
// delete edge (TODO maybe delete vertex)
database.removeEdge(existing);
link = database.addEdge(rootVertex.getId().toString()+"_to_"+valueVertex.getId().toString(),
rootVertex, valueVertex, GraphUtils.getEdgeNameFor(p));
}
}
if(existingIterator.hasNext()) {
if (logger.isLoggable(Level.SEVERE)) {
// There is some incoherent data in graph .. log it !
StringBuilder sOut = new StringBuilder("An object with the following monovalued property\n").append(p.toGenericString()).append(" is linked to more than one vertex :");
while(existingIterator.hasNext()) {
sOut.append("\n\t").append(existingIterator.next().getInVertex().toString());
}
logger.log(Level.SEVERE, "Graph contains some incoherence :"+sOut.toString());
}
} else {
if(link==null)
// Now create edge
link = database.addEdge(rootVertex.getId().toString()+"_to_"+valueVertex.getId().toString(),
rootVertex, valueVertex, GraphUtils.getEdgeNameFor(p));
}
}
}