* @param toDelete object to delete
* @param cascade kind of cascade used for dependent properties
* @param objectsBeingAccessed map containing subgraph of objects currently being delete, this is used to avoid loops, and NOT as a cache
*/
public <DataType> void performDelete(AbstractBluePrintsBackedFinderService<? extends Graph, DataType, ?> service, String objectVertexId, Vertex objectVertex, Class<?> valueClass, Map<Property, Collection<CascadeType>> containedProperties, DataType toDelete, CascadeType cascade, Map<String, Object> objectsBeingAccessed) {
Graph database = service.getDatabase();
for (Map.Entry<Property, Collection<CascadeType>> entry : containedProperties.entrySet()) {
Property p = entry.getKey();
// Static properties are by design not written
if (!p.hasModifier(Modifier.STATIC) && !Annotations.TRANSIENT.is(p)) {
// Per default, no operation is cascaded
CascadeType used = null;
// However, if property supports that cascade type, we cascade operation
if (entry.getValue().contains(cascade)) {
used = cascade;
}
if(used!=null) {
Class<?> rawPropertyType = p.getType();
Collection<CascadeType> toCascade = containedProperties.get(p);
if (Collection.class.isAssignableFrom(rawPropertyType)) {
if (logger.isLoggable(Level.FINEST)) {
logger.log(Level.FINEST, "property " + p.getName() + " is considered a collection one");
}
deleteCollection(service, database, p, toDelete, objectVertex, toCascade, objectsBeingAccessed);
// each value should be written as an independant value
} else if (Map.class.isAssignableFrom(rawPropertyType)) {
if (logger.isLoggable(Level.FINEST)) {
logger.log(Level.FINEST, "property " + p.getName() + " is considered a map one");
}
deleteMap(service, database, p, toDelete, objectVertex, toCascade, objectsBeingAccessed);
} else {
deleteSingle(service, database, p, toDelete, objectVertex, toCascade, objectsBeingAccessed);
}
}
}
}
/* We try to locate vertex in graph before to delete it. Indeed, mainly due cascade delete, this vertex may have already been removed */
Vertex notYetDeleted = service.getDriver().loadVertexFor(objectVertexId, service.getContainedClass().getName());
if(notYetDeleted!=null)
database.removeVertex(notYetDeleted);
}