Search in sources :

Example 1 with TnCommandContextHandler

use of org.dbflute.s2dao.sqlhandler.TnCommandContextHandler in project dbflute-core by dbflute.

the class TnQueryInsertDynamicCommand method execute.

// ===================================================================================
// Execute
// =======
public Object execute(Object[] args) {
    // analyze arguments
    final Entity entity = extractEntityWithCheck(args);
    final ConditionBean intoCB = extractIntoConditionBeanWithCheck(args);
    final ConditionBean resourceCB = extractResourceConditionBeanWithCheck(args);
    final InsertOption<ConditionBean> option = extractInsertOptionWithCheck(args);
    prepareStatementConfigOnThreadIfExists(option);
    // arguments for execution (not contains an option)
    final String[] argNames = new String[] { "entity", "pmb" };
    final Class<?>[] argTypes = new Class<?>[] { entity.getClass(), resourceCB.getClass() };
    final Object[] realArgs = new Object[] { entity, resourceCB };
    // prepare context
    final List<TnPropertyType> boundPropTypeList = new ArrayList<TnPropertyType>();
    final CommandContext context;
    {
        final String twoWaySql = buildQueryInsertTwoWaySql(entity, intoCB, resourceCB, option, boundPropTypeList);
        context = createCommandContext(twoWaySql, argNames, argTypes, realArgs);
    }
    // execute
    final TnCommandContextHandler handler = createCommandContextHandler(context);
    handler.setExceptionMessageSqlArgs(context.getBindVariables());
    final boolean identityDisabled = option != null && option.isPrimaryKeyIdentityDisabled();
    if (identityDisabled) {
        disableIdentityGeneration(entity);
    }
    final int rows;
    RuntimeException sqlEx = null;
    try {
        rows = handler.execute(realArgs);
    } catch (RuntimeException e) {
        sqlEx = e;
        throw e;
    } finally {
        if (identityDisabled) {
            try {
                enableIdentityGeneration(entity);
            } catch (RuntimeException e) {
                if (sqlEx == null) {
                    throw e;
                }
            // ignore the exception when main SQL fails
            // not to close the main exception
            }
        }
    }
    return Integer.valueOf(rows);
}
Also used : Entity(org.dbflute.Entity) CommandContext(org.dbflute.twowaysql.context.CommandContext) ArrayList(java.util.ArrayList) TnCommandContextHandler(org.dbflute.s2dao.sqlhandler.TnCommandContextHandler) ConditionBean(org.dbflute.cbean.ConditionBean) TnPropertyType(org.dbflute.s2dao.metadata.TnPropertyType)

Example 2 with TnCommandContextHandler

use of org.dbflute.s2dao.sqlhandler.TnCommandContextHandler in project dbflute-core by dbflute.

the class TnAbstractQueryDynamicCommand method createCommandContextHandler.

// ===================================================================================
// CommandContext Handler
// ======================
protected TnCommandContextHandler createCommandContextHandler(CommandContext context) {
    final String executedSql = filterSqlStringByCallbackFilter(context.getSql());
    final TnCommandContextHandler handler = newCommandContextHandler(executedSql, context);
    handler.setUpdateSQLFailureProcessTitle(getUpdateSQLFailureProcessTitle());
    return handler;
}
Also used : TnCommandContextHandler(org.dbflute.s2dao.sqlhandler.TnCommandContextHandler)

Example 3 with TnCommandContextHandler

use of org.dbflute.s2dao.sqlhandler.TnCommandContextHandler in project dbflute-core by dbflute.

the class TnQueryDeleteDynamicCommand method execute.

// ===================================================================================
// Execute
// =======
public Object execute(Object[] args) {
    // analyze arguments
    final ConditionBean cb = extractConditionBeanWithCheck(args);
    final DeleteOption<ConditionBean> option = extractUpdateOptionWithCheck(args);
    prepareStatementConfigOnThreadIfExists(option);
    // arguments for execution (not contains an option)
    final String[] argNames = new String[] { "pmb" };
    final Class<?>[] argTypes = new Class<?>[] { cb.getClass() };
    final Object[] realArgs = new Object[] { cb };
    // prepare context
    final CommandContext context;
    {
        final String twoWaySql = buildQueryDeleteTwoWaySql(cb, option);
        context = createCommandContext(twoWaySql, argNames, argTypes, realArgs);
    }
    // execute
    final TnCommandContextHandler handler = createCommandContextHandler(context);
    handler.setExceptionMessageSqlArgs(context.getBindVariables());
    final int rows = handler.execute(realArgs);
    return Integer.valueOf(rows);
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) TnCommandContextHandler(org.dbflute.s2dao.sqlhandler.TnCommandContextHandler) ConditionBean(org.dbflute.cbean.ConditionBean)

Example 4 with TnCommandContextHandler

use of org.dbflute.s2dao.sqlhandler.TnCommandContextHandler in project dbflute-core by dbflute.

the class TnQueryUpdateDynamicCommand method execute.

// ===================================================================================
// Execute
// =======
public Object execute(Object[] args) {
    // analyze arguments
    final Entity entity = extractEntityWithCheck(args);
    final ConditionBean cb = extractConditionBeanWithCheck(args);
    final UpdateOption<ConditionBean> option = extractUpdateOptionWithCheck(args);
    prepareStatementConfigOnThreadIfExists(option);
    // arguments for execution (not contains an option)
    final String[] argNames = new String[] { "entity", "pmb" };
    final Class<?>[] argTypes = new Class<?>[] { entity.getClass(), cb.getClass() };
    final Object[] realArgs = new Object[] { entity, cb };
    // prepare context
    final List<TnPropertyType> boundPropTypeList = new ArrayList<TnPropertyType>();
    final CommandContext context;
    {
        final String twoWaySql = buildQueryUpdateTwoWaySql(entity, cb, option, boundPropTypeList);
        if (twoWaySql == null) {
            // non execute
            return 0;
        }
        context = createCommandContext(twoWaySql, argNames, argTypes, realArgs);
    }
    // execute
    final TnCommandContextHandler handler = createCommandContextHandler(context);
    handler.setExceptionMessageSqlArgs(context.getBindVariables());
    handler.setFirstBoundPropTypeList(boundPropTypeList);
    final int rows = handler.execute(realArgs);
    return Integer.valueOf(rows);
}
Also used : Entity(org.dbflute.Entity) CommandContext(org.dbflute.twowaysql.context.CommandContext) ArrayList(java.util.ArrayList) TnCommandContextHandler(org.dbflute.s2dao.sqlhandler.TnCommandContextHandler) ConditionBean(org.dbflute.cbean.ConditionBean) TnPropertyType(org.dbflute.s2dao.metadata.TnPropertyType)

Aggregations

TnCommandContextHandler (org.dbflute.s2dao.sqlhandler.TnCommandContextHandler)4 ConditionBean (org.dbflute.cbean.ConditionBean)3 CommandContext (org.dbflute.twowaysql.context.CommandContext)3 ArrayList (java.util.ArrayList)2 Entity (org.dbflute.Entity)2 TnPropertyType (org.dbflute.s2dao.metadata.TnPropertyType)2