Search in sources :

Example 66 with CommandContext

use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.

the class TnAbstractTwoWaySqlCommand method execute.

// ===================================================================================
// Execute
// =======
public Object execute(Object[] args) {
    final Node rootNode = getRootNode(args);
    final CommandContext ctx = apply(rootNode, args, getArgNames(args), getArgTypes(args));
    final String executedSql = filterExecutedSql(ctx);
    final TnBasicParameterHandler handler = createBasicParameterHandler(ctx, executedSql);
    final Object[] bindVariables = ctx.getBindVariables();
    final Class<?>[] bindVariableTypes = ctx.getBindVariableTypes();
    return filterReturnValue(handler.execute(bindVariables, bindVariableTypes));
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) Node(org.dbflute.twowaysql.node.Node) TnBasicParameterHandler(org.dbflute.s2dao.sqlhandler.TnBasicParameterHandler)

Example 67 with CommandContext

use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.

the class TnAbstractTwoWaySqlCommand method apply.

// ===================================================================================
// Argument Handling
// =================
protected CommandContext apply(Node rootNode, Object[] args, String[] argNames, Class<?>[] argTypes) {
    final CommandContext ctx = createCommandContext(args, argNames, argTypes);
    rootNode.accept(ctx);
    return ctx;
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext)

Example 68 with CommandContext

use of org.dbflute.twowaysql.context.CommandContext 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 69 with CommandContext

use of org.dbflute.twowaysql.context.CommandContext 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)

Example 70 with CommandContext

use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.

the class EmbeddedVariableNode method processDynamicBinding.

protected boolean processDynamicBinding(CommandContext ctx, Object firstValue, Class<?> firstType, String embeddedString) {
    final ScopeInfo first = Srl.extractScopeFirst(embeddedString, "/*", "*/");
    if (first == null) {
        return false;
    }
    // unsupported general purpose options in dynamic for now, e.g. MailFlute, may be almost unneeded
    final SqlAnalyzer analyzer = new SqlAnalyzer(embeddedString, _blockNullParameter);
    final Node rootNode = analyzer.analyze();
    final CommandContextCreator creator = new CommandContextCreator(new String[] { "pmb" }, new Class<?>[] { firstType });
    final CommandContext rootCtx = creator.createCommandContext(new Object[] { firstValue });
    rootNode.accept(rootCtx);
    final String sql = rootCtx.getSql();
    ctx.addSql(sql, rootCtx.getBindVariables(), rootCtx.getBindVariableTypes());
    return true;
}
Also used : CommandContextCreator(org.dbflute.twowaysql.context.CommandContextCreator) CommandContext(org.dbflute.twowaysql.context.CommandContext) ScopeInfo(org.dbflute.util.Srl.ScopeInfo) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Aggregations

CommandContext (org.dbflute.twowaysql.context.CommandContext)116 SqlAnalyzer (org.dbflute.twowaysql.SqlAnalyzer)99 LikeSearchOption (org.dbflute.cbean.coption.LikeSearchOption)31 Node (org.dbflute.twowaysql.node.Node)11 SqlPartsNode (org.dbflute.twowaysql.node.SqlPartsNode)9 List (java.util.List)5 ConditionBean (org.dbflute.cbean.ConditionBean)3 TnCommandContextHandler (org.dbflute.s2dao.sqlhandler.TnCommandContextHandler)3 CommandContextCreator (org.dbflute.twowaysql.context.CommandContextCreator)3 IfCommentNotFoundPropertyException (org.dbflute.twowaysql.exception.IfCommentNotFoundPropertyException)3 ArrayList (java.util.ArrayList)2 Entity (org.dbflute.Entity)2 MelodicNodeAdviceFactory (org.dbflute.bhv.core.melodicsql.MelodicNodeAdviceFactory)2 TnPropertyType (org.dbflute.s2dao.metadata.TnPropertyType)2 EmbeddedVariableCommentContainsBindSymbolException (org.dbflute.twowaysql.exception.EmbeddedVariableCommentContainsBindSymbolException)2 EmbeddedVariableNode (org.dbflute.twowaysql.node.EmbeddedVariableNode)2 TnBasicParameterHandler (org.dbflute.s2dao.sqlhandler.TnBasicParameterHandler)1 BindVariableCommentIllegalParameterBeanSpecificationException (org.dbflute.twowaysql.exception.BindVariableCommentIllegalParameterBeanSpecificationException)1 BindVariableCommentInScopeNotListException (org.dbflute.twowaysql.exception.BindVariableCommentInScopeNotListException)1 BindVariableCommentParameterNullValueException (org.dbflute.twowaysql.exception.BindVariableCommentParameterNullValueException)1