Search in sources :

Example 1 with DeleteOption

use of org.dbflute.bhv.writable.DeleteOption in project dbflute-core by dbflute.

the class AbstractBehaviorWritable method delegateQueryDelete.

protected int delegateQueryDelete(ConditionBean cb, DeleteOption<? extends ConditionBean> option) {
    final OptionalThing<DeleteOption<? extends ConditionBean>> optOption = createOptionalDeleteOption(option);
    adjustEntityBeforeQueryDelete(cb, optOption);
    final QueryDeleteCBCommand command = createQueryDeleteCBCommand(cb, option);
    final OptionalThing<ConditionBean> optCB = OptionalThing.of(cb);
    RuntimeException cause = null;
    try {
        hookBeforeDelete(command, emptyOpt(), optCB, optOption);
        return invoke(command);
    } catch (RuntimeException e) {
        cause = e;
        throw e;
    } finally {
        hookFinallyDelete(command, emptyOpt(), optCB, optOption, createOptionalCause(cause));
    }
}
Also used : DeleteOption(org.dbflute.bhv.writable.DeleteOption) QueryDeleteCBCommand(org.dbflute.bhv.core.command.QueryDeleteCBCommand) ConditionBean(org.dbflute.cbean.ConditionBean)

Example 2 with DeleteOption

use of org.dbflute.bhv.writable.DeleteOption in project dbflute-core by dbflute.

the class AbstractBehaviorWritable method delegateBatchDelete.

protected int[] delegateBatchDelete(List<? extends Entity> entityList, DeleteOption<? extends ConditionBean> option) {
    if (entityList.isEmpty()) {
        return EMPTY_INT_ARRAY;
    }
    if (asDBMeta().hasOptimisticLock()) {
        final List<? extends Entity> deletedList = adjustEntityListBeforeBatchDelete(entityList, option, false);
        if (deletedList.isEmpty()) {
            // might be filtered
            return EMPTY_INT_ARRAY;
        }
        final BatchDeleteCommand command = createBatchDeleteCommand(deletedList, option);
        final OptionalThing<Object> optEntityList = OptionalThing.of(entityList);
        final OptionalThing<DeleteOption<? extends ConditionBean>> optOption = createOptionalDeleteOption(option);
        RuntimeException cause = null;
        try {
            hookBeforeDelete(command, optEntityList, emptyOpt(), optOption);
            return invoke(command);
        } catch (RuntimeException e) {
            cause = e;
            throw e;
        } finally {
            hookFinallyDelete(command, optEntityList, emptyOpt(), optOption, createOptionalCause(cause));
        }
    } else {
        return delegateBatchDeleteNonstrict(entityList, option);
    }
}
Also used : BatchDeleteCommand(org.dbflute.bhv.core.command.BatchDeleteCommand) DeleteOption(org.dbflute.bhv.writable.DeleteOption) ConditionBean(org.dbflute.cbean.ConditionBean)

Example 3 with DeleteOption

use of org.dbflute.bhv.writable.DeleteOption in project dbflute-core by dbflute.

the class AbstractBehaviorWritable method delegateDelete.

protected int delegateDelete(Entity entity, DeleteOption<? extends ConditionBean> option) {
    final OptionalThing<DeleteOption<? extends ConditionBean>> optOption = createOptionalDeleteOption(option);
    adjustEntityBeforeDelete(entity, optOption);
    if (asDBMeta().hasOptimisticLock()) {
        final DeleteEntityCommand command = createDeleteEntityCommand(entity, option);
        final OptionalThing<Object> optEntity = OptionalThing.of(entity);
        RuntimeException cause = null;
        try {
            hookBeforeDelete(command, optEntity, emptyOpt(), optOption);
            return invoke(command);
        } catch (RuntimeException e) {
            cause = e;
            throw e;
        } finally {
            hookFinallyDelete(command, optEntity, emptyOpt(), optOption, createOptionalCause(cause));
        }
    } else {
        return delegateDeleteNonstrict(entity, option);
    }
}
Also used : DeleteOption(org.dbflute.bhv.writable.DeleteOption) DeleteEntityCommand(org.dbflute.bhv.core.command.DeleteEntityCommand) ConditionBean(org.dbflute.cbean.ConditionBean)

Example 4 with DeleteOption

use of org.dbflute.bhv.writable.DeleteOption in project dbflute-core by dbflute.

the class AbstractBehaviorWritable method delegateBatchDeleteNonstrict.

protected int[] delegateBatchDeleteNonstrict(List<? extends Entity> entityList, DeleteOption<? extends ConditionBean> option) {
    if (entityList.isEmpty()) {
        return EMPTY_INT_ARRAY;
    }
    final List<? extends Entity> deletedList = adjustEntityListBeforeBatchDelete(entityList, option, true);
    if (deletedList.isEmpty()) {
        // might be filtered
        return EMPTY_INT_ARRAY;
    }
    final BatchDeleteNonstrictCommand command = createBatchDeleteNonstrictCommand(deletedList, option);
    final OptionalThing<Object> optEntityList = OptionalThing.of(entityList);
    final OptionalThing<DeleteOption<? extends ConditionBean>> optOption = createOptionalDeleteOption(option);
    RuntimeException cause = null;
    try {
        hookBeforeDelete(command, optEntityList, emptyOpt(), optOption);
        return invoke(command);
    } catch (RuntimeException e) {
        cause = e;
        throw e;
    } finally {
        hookFinallyDelete(command, optEntityList, emptyOpt(), optOption, createOptionalCause(cause));
    }
}
Also used : DeleteOption(org.dbflute.bhv.writable.DeleteOption) BatchDeleteNonstrictCommand(org.dbflute.bhv.core.command.BatchDeleteNonstrictCommand) ConditionBean(org.dbflute.cbean.ConditionBean)

Example 5 with DeleteOption

use of org.dbflute.bhv.writable.DeleteOption in project dbflute-core by dbflute.

the class AbstractBehaviorWritable method delegateDeleteNonstrict.

protected int delegateDeleteNonstrict(Entity entity, DeleteOption<? extends ConditionBean> option) {
    final OptionalThing<DeleteOption<? extends ConditionBean>> optOption = createOptionalDeleteOption(option);
    adjustEntityBeforeDelete(entity, optOption);
    final DeleteNonstrictEntityCommand command = createDeleteNonstrictEntityCommand(entity, option);
    final OptionalThing<Object> optEntity = OptionalThing.of(entity);
    RuntimeException cause = null;
    try {
        hookBeforeDelete(command, optEntity, emptyOpt(), optOption);
        return invoke(command);
    } catch (RuntimeException e) {
        cause = e;
        throw e;
    } finally {
        hookFinallyDelete(command, optEntity, emptyOpt(), optOption, createOptionalCause(cause));
    }
}
Also used : DeleteNonstrictEntityCommand(org.dbflute.bhv.core.command.DeleteNonstrictEntityCommand) DeleteOption(org.dbflute.bhv.writable.DeleteOption) ConditionBean(org.dbflute.cbean.ConditionBean)

Aggregations

DeleteOption (org.dbflute.bhv.writable.DeleteOption)5 ConditionBean (org.dbflute.cbean.ConditionBean)5 BatchDeleteCommand (org.dbflute.bhv.core.command.BatchDeleteCommand)1 BatchDeleteNonstrictCommand (org.dbflute.bhv.core.command.BatchDeleteNonstrictCommand)1 DeleteEntityCommand (org.dbflute.bhv.core.command.DeleteEntityCommand)1 DeleteNonstrictEntityCommand (org.dbflute.bhv.core.command.DeleteNonstrictEntityCommand)1 QueryDeleteCBCommand (org.dbflute.bhv.core.command.QueryDeleteCBCommand)1