Search in sources :

Example 1 with Cascadeable

use of com.qcadoo.model.api.types.Cascadeable in project qcadoo by qcadoo.

the class DataAccessServiceImpl method performCascadeStrategy.

private EntityOpResult performCascadeStrategy(final Entity entity, final FieldType fieldType, final Collection<Entity> children, final Set<EntitySignature> traversedEntities) {
    if (children == null || children.isEmpty()) {
        return EntityOpResult.successfull();
    }
    boolean isManyToManyType = fieldType instanceof ManyToManyType;
    InternalDataDefinition childDataDefinition = (InternalDataDefinition) ((DataDefinitionHolder) fieldType).getDataDefinition();
    Cascadeable.Cascade cascade = ((Cascadeable) fieldType).getCascade();
    if (Cascadeable.Cascade.NULLIFY.equals(cascade)) {
        if (!isManyToManyType) {
            return performCascadeNullification(childDataDefinition, children, entity, fieldType);
        }
        return EntityOpResult.successfull();
    } else if (Cascadeable.Cascade.DELETE.equals(cascade)) {
        return performCascadeDelete(childDataDefinition, children, isManyToManyType, traversedEntities);
    } else {
        throw new IllegalArgumentException(String.format("Unsupported cascade value '%s'", cascade));
    }
}
Also used : Cascadeable(com.qcadoo.model.api.types.Cascadeable) ManyToManyType(com.qcadoo.model.api.types.ManyToManyType) InternalDataDefinition(com.qcadoo.model.internal.api.InternalDataDefinition)

Aggregations

Cascadeable (com.qcadoo.model.api.types.Cascadeable)1 ManyToManyType (com.qcadoo.model.api.types.ManyToManyType)1 InternalDataDefinition (com.qcadoo.model.internal.api.InternalDataDefinition)1