Search in sources :

Example 1 with InsertOption

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

the class AbstractBehaviorWritable method delegateBatchInsert.

// -----------------------------------------------------
// Batch Update
// ------------
protected int[] delegateBatchInsert(List<? extends Entity> entityList, InsertOption<? extends ConditionBean> option) {
    if (entityList.isEmpty()) {
        return EMPTY_INT_ARRAY;
    }
    final OptionalThing<InsertOption<? extends ConditionBean>> optOption = createOptionalInsertOption(option);
    adjustEntityListBeforeBatchInsert(entityList, option);
    if (entityList.isEmpty()) {
        // might be filtered
        return EMPTY_INT_ARRAY;
    }
    final BatchInsertCommand command = createBatchInsertCommand(entityList, option);
    RuntimeException cause = null;
    try {
        hookBeforeInsert(command, entityList, emptyOpt(), optOption);
        return invoke(command);
    } catch (RuntimeException e) {
        cause = e;
        throw e;
    } finally {
        hookFinallyInsert(command, entityList, emptyOpt(), optOption, createOptionalCause(cause));
    }
}
Also used : BatchInsertCommand(org.dbflute.bhv.core.command.BatchInsertCommand) InsertOption(org.dbflute.bhv.writable.InsertOption) ConditionBean(org.dbflute.cbean.ConditionBean)

Example 2 with InsertOption

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

the class AbstractBehaviorWritable method delegateInsert.

// ===================================================================================
// Delegate to Command
// ===================
// -----------------------------------------------------
// Entity Update
// -------------
protected int delegateInsert(Entity entity, InsertOption<? extends ConditionBean> option) {
    final OptionalThing<InsertOption<? extends ConditionBean>> optOption = createOptionalInsertOption(option);
    adjustEntityBeforeInsert(entity, optOption);
    final InsertEntityCommand command = createInsertEntityCommand(entity, option);
    RuntimeException cause = null;
    try {
        hookBeforeInsert(command, entity, emptyOpt(), optOption);
        return invoke(command);
    } catch (RuntimeException e) {
        cause = e;
        throw e;
    } finally {
        hookFinallyInsert(command, entity, emptyOpt(), optOption, createOptionalCause(cause));
    }
}
Also used : InsertEntityCommand(org.dbflute.bhv.core.command.InsertEntityCommand) InsertOption(org.dbflute.bhv.writable.InsertOption) ConditionBean(org.dbflute.cbean.ConditionBean)

Example 3 with InsertOption

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

the class AbstractBehaviorWritable method delegateQueryInsert.

// -----------------------------------------------------
// Query Update
// ------------
protected int delegateQueryInsert(Entity entity, ConditionBean inCB, ConditionBean resCB, InsertOption<? extends ConditionBean> option) {
    final OptionalThing<InsertOption<? extends ConditionBean>> optOption = createOptionalInsertOption(option);
    adjustEntityBeforeQueryInsert(entity, inCB, resCB, optOption);
    final QueryInsertCBCommand command = createQueryInsertCBCommand(entity, inCB, resCB, option);
    final OptionalThing<ConditionBean> optInCB = OptionalThing.of(inCB);
    RuntimeException cause = null;
    try {
        hookBeforeInsert(command, entity, optInCB, optOption);
        return invoke(command);
    } catch (RuntimeException e) {
        cause = e;
        throw e;
    } finally {
        hookFinallyInsert(command, entity, optInCB, optOption, createOptionalCause(cause));
    }
}
Also used : QueryInsertCBCommand(org.dbflute.bhv.core.command.QueryInsertCBCommand) InsertOption(org.dbflute.bhv.writable.InsertOption) ConditionBean(org.dbflute.cbean.ConditionBean)

Example 4 with InsertOption

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

the class AbstractBehaviorWritable method setupCommonColumnOfInsertIfNeeds.

/**
 * Set up common columns of insert if it needs.
 * @param entity The entity for insert. (NotNull)
 * @param option The optional option of insert. (NotNull, EmptyAllowed: when no option)
 */
protected void setupCommonColumnOfInsertIfNeeds(Entity entity, OptionalThing<InsertOption<? extends ConditionBean>> option) {
    if (option.filter(op -> op.isCommonColumnAutoSetupDisabled()).isPresent()) {
        return;
    }
    final CommonColumnAutoSetupper setupper = getCommonColumnAutoSetupper();
    assertCommonColumnAutoSetupperNotNull();
    setupper.handleCommonColumnOfInsertIfNeeds(entity);
}
Also used : OptimisticLockColumnValueNullException(org.dbflute.exception.OptimisticLockColumnValueNullException) BehaviorCommandMeta(org.dbflute.bhv.core.BehaviorCommandMeta) DeleteNonstrictEntityCommand(org.dbflute.bhv.core.command.DeleteNonstrictEntityCommand) QueryUpdateCBCommand(org.dbflute.bhv.core.command.QueryUpdateCBCommand) Entity(org.dbflute.Entity) DeleteOption(org.dbflute.bhv.writable.DeleteOption) UniqueInfo(org.dbflute.dbmeta.info.UniqueInfo) OptionalThing(org.dbflute.optional.OptionalThing) BatchDeleteNonstrictCommand(org.dbflute.bhv.core.command.BatchDeleteNonstrictCommand) IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException) BatchUpdateCommand(org.dbflute.bhv.core.command.BatchUpdateCommand) UpdateEntityCommand(org.dbflute.bhv.core.command.UpdateEntityCommand) ArrayList(java.util.ArrayList) DeleteEntityCommand(org.dbflute.bhv.core.command.DeleteEntityCommand) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) UpdateNonstrictEntityCommand(org.dbflute.bhv.core.command.UpdateNonstrictEntityCommand) ConditionBean(org.dbflute.cbean.ConditionBean) QueryDeleteCBCommand(org.dbflute.bhv.core.command.QueryDeleteCBCommand) UpdateOption(org.dbflute.bhv.writable.UpdateOption) CommonColumnAutoSetupper(org.dbflute.hook.CommonColumnAutoSetupper) IllegalBehaviorStateException(org.dbflute.exception.IllegalBehaviorStateException) SpecifyQuery(org.dbflute.cbean.scoping.SpecifyQuery) InsertEntityCommand(org.dbflute.bhv.core.command.InsertEntityCommand) QueryInsertSetupper(org.dbflute.bhv.writable.QueryInsertSetupper) BatchDeleteCommand(org.dbflute.bhv.core.command.BatchDeleteCommand) WritableOptionCall(org.dbflute.bhv.writable.WritableOptionCall) Set(java.util.Set) ResourceContext(org.dbflute.bhv.core.context.ResourceContext) BatchUpdateNonstrictCommand(org.dbflute.bhv.core.command.BatchUpdateNonstrictCommand) AbstractBatchUpdateCommand(org.dbflute.bhv.core.command.AbstractBatchUpdateCommand) BatchInsertCommand(org.dbflute.bhv.core.command.BatchInsertCommand) DBMeta(org.dbflute.dbmeta.DBMeta) List(java.util.List) EntityAlreadyDeletedException(org.dbflute.exception.EntityAlreadyDeletedException) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) EntityAlreadyUpdatedException(org.dbflute.exception.EntityAlreadyUpdatedException) InsertOption(org.dbflute.bhv.writable.InsertOption) QueryInsertCBCommand(org.dbflute.bhv.core.command.QueryInsertCBCommand) CommonColumnAutoSetupper(org.dbflute.hook.CommonColumnAutoSetupper)

Aggregations

InsertOption (org.dbflute.bhv.writable.InsertOption)4 ConditionBean (org.dbflute.cbean.ConditionBean)4 BatchInsertCommand (org.dbflute.bhv.core.command.BatchInsertCommand)2 InsertEntityCommand (org.dbflute.bhv.core.command.InsertEntityCommand)2 QueryInsertCBCommand (org.dbflute.bhv.core.command.QueryInsertCBCommand)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 Entity (org.dbflute.Entity)1 BehaviorCommandMeta (org.dbflute.bhv.core.BehaviorCommandMeta)1 AbstractBatchUpdateCommand (org.dbflute.bhv.core.command.AbstractBatchUpdateCommand)1 BatchDeleteCommand (org.dbflute.bhv.core.command.BatchDeleteCommand)1 BatchDeleteNonstrictCommand (org.dbflute.bhv.core.command.BatchDeleteNonstrictCommand)1 BatchUpdateCommand (org.dbflute.bhv.core.command.BatchUpdateCommand)1 BatchUpdateNonstrictCommand (org.dbflute.bhv.core.command.BatchUpdateNonstrictCommand)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 QueryUpdateCBCommand (org.dbflute.bhv.core.command.QueryUpdateCBCommand)1 UpdateEntityCommand (org.dbflute.bhv.core.command.UpdateEntityCommand)1