Search in sources :

Example 1 with CommandContextCreator

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

the class SqlAnalyzerTest method prepareCtx.

protected CommandContext prepareCtx(SimpleMapPmb<Object> pmb, Node node) {
    CommandContextCreator creator = new CommandContextCreator(new String[] { "pmb" }, new Class<?>[] { pmb.getClass() });
    CommandContext ctx = creator.createCommandContext(new Object[] { pmb });
    node.accept(ctx);
    return ctx;
}
Also used : CommandContextCreator(org.dbflute.twowaysql.context.CommandContextCreator) CommandContext(org.dbflute.twowaysql.context.CommandContext)

Example 2 with CommandContextCreator

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

the class SqlAnalyzer method convertTwoWaySql2DisplaySql.

public static String convertTwoWaySql2DisplaySql(SqlAnalyzerFactory factory, String twoWaySql, String[] argNames, Class<?>[] argTypes, Object[] args, BoundDateDisplayStyle dateDisplayStyle) {
    final CommandContext context;
    {
        final SqlAnalyzer parser = createSqlAnalyzer4DisplaySql(factory, twoWaySql);
        final Node node = parser.analyze();
        final CommandContextCreator creator = new CommandContextCreator(argNames, argTypes);
        context = creator.createCommandContext(args);
        node.accept(context);
    }
    final String preparedSql = context.getSql();
    final DisplaySqlBuilder builder = new DisplaySqlBuilder(dateDisplayStyle);
    return builder.buildDisplaySql(preparedSql, context.getBindVariables());
}
Also used : CommandContextCreator(org.dbflute.twowaysql.context.CommandContextCreator) CommandContext(org.dbflute.twowaysql.context.CommandContext) BindVariableNode(org.dbflute.twowaysql.node.BindVariableNode) LoopFirstNode(org.dbflute.twowaysql.node.LoopFirstNode) ForNode(org.dbflute.twowaysql.node.ForNode) BeginNode(org.dbflute.twowaysql.node.BeginNode) SqlPartsNode(org.dbflute.twowaysql.node.SqlPartsNode) EmbeddedVariableNode(org.dbflute.twowaysql.node.EmbeddedVariableNode) SqlConnectorNode(org.dbflute.twowaysql.node.SqlConnectorNode) LoopNextNode(org.dbflute.twowaysql.node.LoopNextNode) ElseNode(org.dbflute.twowaysql.node.ElseNode) LoopLastNode(org.dbflute.twowaysql.node.LoopLastNode) LoopAbstractNode(org.dbflute.twowaysql.node.LoopAbstractNode) RootNode(org.dbflute.twowaysql.node.RootNode) IfNode(org.dbflute.twowaysql.node.IfNode) Node(org.dbflute.twowaysql.node.Node)

Example 3 with CommandContextCreator

use of org.dbflute.twowaysql.context.CommandContextCreator in project lastaflute by lastaflute.

the class SimpleTemplateManager method prepareContext.

// ===================================================================================
// Prepare Context
// ===============
protected CommandContext prepareContext(Object pmb) {
    final Object filteredPmb = filterPmb(pmb);
    final String[] argNames = new String[] { "pmb" };
    final Class<?>[] argTypes = new Class<?>[] { filteredPmb.getClass() };
    final CommandContextCreator creator = newCommandContextCreator(argNames, argTypes);
    return creator.createCommandContext(new Object[] { filteredPmb });
}
Also used : CommandContextCreator(org.dbflute.twowaysql.context.CommandContextCreator)

Example 4 with CommandContextCreator

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

CommandContextCreator (org.dbflute.twowaysql.context.CommandContextCreator)4 CommandContext (org.dbflute.twowaysql.context.CommandContext)3 SqlAnalyzer (org.dbflute.twowaysql.SqlAnalyzer)1 BeginNode (org.dbflute.twowaysql.node.BeginNode)1 BindVariableNode (org.dbflute.twowaysql.node.BindVariableNode)1 ElseNode (org.dbflute.twowaysql.node.ElseNode)1 EmbeddedVariableNode (org.dbflute.twowaysql.node.EmbeddedVariableNode)1 ForNode (org.dbflute.twowaysql.node.ForNode)1 IfNode (org.dbflute.twowaysql.node.IfNode)1 LoopAbstractNode (org.dbflute.twowaysql.node.LoopAbstractNode)1 LoopFirstNode (org.dbflute.twowaysql.node.LoopFirstNode)1 LoopLastNode (org.dbflute.twowaysql.node.LoopLastNode)1 LoopNextNode (org.dbflute.twowaysql.node.LoopNextNode)1 Node (org.dbflute.twowaysql.node.Node)1 RootNode (org.dbflute.twowaysql.node.RootNode)1 SqlConnectorNode (org.dbflute.twowaysql.node.SqlConnectorNode)1 SqlPartsNode (org.dbflute.twowaysql.node.SqlPartsNode)1 ScopeInfo (org.dbflute.util.Srl.ScopeInfo)1