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));
}
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;
}
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);
}
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);
}
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;
}
Aggregations