Search in sources :

Example 21 with ConditionBean

use of org.dbflute.cbean.ConditionBean 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 22 with ConditionBean

use of org.dbflute.cbean.ConditionBean 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 23 with ConditionBean

use of org.dbflute.cbean.ConditionBean in project dbflute-core by dbflute.

the class TnRowCreatorExtension method processDerivedMap.

protected void processDerivedMap(ResultSet rs, Map<String, Map<String, Integer>> selectIndexMap, Map<String, TnPropertyMapping> propertyCache, Object row) throws SQLException {
    final ConditionBean cb = ConditionBeanContext.getConditionBeanOnThread();
    final SqlClause sqlClause = cb.getSqlClause();
    if (!sqlClause.hasSpecifiedDerivingSubQuery()) {
        return;
    }
    final DerivedMappable mappable = (DerivedMappable) row;
    final List<String> derivingAliasList = sqlClause.getSpecifiedDerivingAliasList();
    DerivedTypeHandler typeHandler = null;
    for (String derivingAlias : derivingAliasList) {
        // propertyCache has alias name when derived-referrer as case-insensitive
        if (propertyCache.containsKey(derivingAlias)) {
            // already handled
            continue;
        }
        if (!derivingAlias.startsWith(DERIVED_MAPPABLE_ALIAS_PREFIX)) {
            // might be exception but no need to be strict here
            continue;
        }
        if (typeHandler == null) {
            // basically fixed instance returned
            typeHandler = cb.xgetDerivedTypeHandler();
            if (typeHandler == null) {
                // no way, just in case
                String msg = "Not found the type handler from condition-bean: " + cb.asTableDbName();
                throw new IllegalStateException(msg);
            }
        }
        final HpDerivingSubQueryInfo derivingInfo = sqlClause.getSpecifiedDerivingInfo(derivingAlias);
        final ValueType valueType = TnValueTypes.getValueType(typeHandler.findMappingType(derivingInfo));
        final String onQueryAlias = Srl.substringFirstRear(derivingAlias, DERIVED_MAPPABLE_ALIAS_PREFIX);
        Object selectedValue = getValue(rs, onQueryAlias, valueType, selectIndexMap);
        selectedValue = typeHandler.convertToMapValue(derivingInfo, selectedValue);
        mappable.registerDerivedValue(derivingAlias, selectedValue);
    }
}
Also used : DerivedMappable(org.dbflute.dbmeta.accessory.DerivedMappable) ValueType(org.dbflute.jdbc.ValueType) DerivedTypeHandler(org.dbflute.dbmeta.accessory.DerivedTypeHandler) SqlClause(org.dbflute.cbean.sqlclause.SqlClause) HpDerivingSubQueryInfo(org.dbflute.cbean.chelper.HpDerivingSubQueryInfo) ConditionBean(org.dbflute.cbean.ConditionBean)

Example 24 with ConditionBean

use of org.dbflute.cbean.ConditionBean in project dbflute-core by dbflute.

the class TnStatementFactoryImpl method findStatementConfigOnThread.

// -----------------------------------------------------
// StatementConfig
// ---------------
protected StatementConfig findStatementConfigOnThread() {
    final StatementConfig config;
    if (ConditionBeanContext.isExistConditionBeanOnThread()) {
        final ConditionBean cb = ConditionBeanContext.getConditionBeanOnThread();
        config = cb.getStatementConfig();
    } else if (OutsideSqlContext.isExistOutsideSqlContextOnThread()) {
        final OutsideSqlContext context = OutsideSqlContext.getOutsideSqlContextOnThread();
        config = context.getStatementConfig();
    } else {
        // update or no exist
        config = InternalMapContext.getUpdateStatementConfig();
    }
    return config;
}
Also used : OutsideSqlContext(org.dbflute.outsidesql.OutsideSqlContext) ConditionBean(org.dbflute.cbean.ConditionBean) StatementConfig(org.dbflute.jdbc.StatementConfig)

Example 25 with ConditionBean

use of org.dbflute.cbean.ConditionBean 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)

Aggregations

ConditionBean (org.dbflute.cbean.ConditionBean)45 DeleteOption (org.dbflute.bhv.writable.DeleteOption)7 UpdateOption (org.dbflute.bhv.writable.UpdateOption)7 ArrayList (java.util.ArrayList)5 InsertOption (org.dbflute.bhv.writable.InsertOption)5 Entity (org.dbflute.Entity)4 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)4 List (java.util.List)3 AbstractBatchUpdateCommand (org.dbflute.bhv.core.command.AbstractBatchUpdateCommand)3 BatchDeleteCommand (org.dbflute.bhv.core.command.BatchDeleteCommand)3 BatchDeleteNonstrictCommand (org.dbflute.bhv.core.command.BatchDeleteNonstrictCommand)3 BatchInsertCommand (org.dbflute.bhv.core.command.BatchInsertCommand)3 BatchUpdateCommand (org.dbflute.bhv.core.command.BatchUpdateCommand)3 BatchUpdateNonstrictCommand (org.dbflute.bhv.core.command.BatchUpdateNonstrictCommand)3 DeleteEntityCommand (org.dbflute.bhv.core.command.DeleteEntityCommand)3 DeleteNonstrictEntityCommand (org.dbflute.bhv.core.command.DeleteNonstrictEntityCommand)3 InsertEntityCommand (org.dbflute.bhv.core.command.InsertEntityCommand)3 QueryDeleteCBCommand (org.dbflute.bhv.core.command.QueryDeleteCBCommand)3 QueryInsertCBCommand (org.dbflute.bhv.core.command.QueryInsertCBCommand)3 QueryUpdateCBCommand (org.dbflute.bhv.core.command.QueryUpdateCBCommand)3