Fixing corner cases
This commit is contained in:
parent
ada9439ab9
commit
6afde17b0f
|
@ -108,11 +108,11 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
* An operation can affects multiple instances (e.g. create, update)
|
* An operation can affects multiple instances (e.g. create, update)
|
||||||
* We need to know if the instance is the entry point of the operation
|
* We need to know if the instance is the entry point of the operation
|
||||||
* or if it is just a subordinated operation.
|
* or if it is just a subordinated operation.
|
||||||
* This is required for example in addTocontext to trigger sanity check
|
* This is required for example in delete to trigger sanity check
|
||||||
* in the Resource when the action is performed directly on the Facet,
|
* in the Resource when the action is performed directly on the Facet.
|
||||||
* or the Resource sanity check is not required to be triggered
|
* Resource sanity check is not required to be triggered by the Facet
|
||||||
* because the entry point of the action already take care
|
* because the entry point of the action already take care
|
||||||
* of triggering this action (e.g. the update was invoked on the Resource and
|
* of triggering this action (e.g. the delete was invoked on the Resource and
|
||||||
* each describing Facets must not trigger multiple time the sanityCheck).
|
* each describing Facets must not trigger multiple time the sanityCheck).
|
||||||
*/
|
*/
|
||||||
protected boolean entryPoint;
|
protected boolean entryPoint;
|
||||||
|
|
|
@ -45,8 +45,19 @@ import com.orientechnologies.orient.core.record.OVertex;
|
||||||
*/
|
*/
|
||||||
public class ResourceManagement extends EntityManagement<Resource, ResourceType> {
|
public class ResourceManagement extends EntityManagement<Resource, ResourceType> {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In case of a resource is deleted due to cascade effect the sanity check is not required.
|
||||||
|
* The Resource and all its facets are deleted.
|
||||||
|
*/
|
||||||
|
private boolean sanityCheckNotRequired;
|
||||||
|
|
||||||
public ResourceManagement() {
|
public ResourceManagement() {
|
||||||
super(AccessType.RESOURCE);
|
super(AccessType.RESOURCE);
|
||||||
|
this.sanityCheckNotRequired = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSanityCheckNotRequired() {
|
||||||
|
this.sanityCheckNotRequired = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -229,7 +240,6 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
||||||
relationManagement.setElement(edge);
|
relationManagement.setElement(edge);
|
||||||
relationManagement.internalDelete();
|
relationManagement.internalDelete();
|
||||||
affectedInstances.putAll(relationManagement.getAffectedInstances());
|
affectedInstances.putAll(relationManagement.getAffectedInstances());
|
||||||
addToRelationManagements(relationManagement);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -392,7 +402,10 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||||
if(operation == Operation.DELETE) {
|
|
||||||
|
// In case of a resource is deleted due to cascade effect is look like is the entry point
|
||||||
|
// of the operation and the sanity check is not required. The Resource and all its facets are deleted.
|
||||||
|
if(sanityCheckNotRequired || (entryPoint && operation == Operation.DELETE)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -717,6 +717,9 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
|
|
||||||
// pre-loading target entity because after deleting the relation we will not be able to get it
|
// pre-loading target entity because after deleting the relation we will not be able to get it
|
||||||
T t = getTargetEntityManagement();
|
T t = getTargetEntityManagement();
|
||||||
|
if(targetEntityManagement instanceof ResourceManagement) {
|
||||||
|
((ResourceManagement) targetEntityManagement).setSanityCheckNotRequired();
|
||||||
|
}
|
||||||
|
|
||||||
affectedInstances.put(uuid, serializeSelfAsJsonNode());
|
affectedInstances.put(uuid, serializeSelfAsJsonNode());
|
||||||
element.delete();
|
element.delete();
|
||||||
|
@ -728,7 +731,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
|
|
||||||
case cascadeWhenOrphan:
|
case cascadeWhenOrphan:
|
||||||
OVertex target = t.getElement();
|
OVertex target = t.getElement();
|
||||||
Iterable<OEdge> iterable = t.getElement().getEdges(ODirection.IN);
|
Iterable<OEdge> iterable = target.getEdges(ODirection.IN);
|
||||||
Iterator<OEdge> iterator = iterable.iterator();
|
Iterator<OEdge> iterator = iterable.iterator();
|
||||||
if(iterator.hasNext()) {
|
if(iterator.hasNext()) {
|
||||||
logger.trace("{} point to {} which is not orphan. Giving {} directive, it will be keep.", element,
|
logger.trace("{} point to {} which is not orphan. Giving {} directive, it will be keep.", element,
|
||||||
|
|
Loading…
Reference in New Issue