Search in sources :

Example 31 with CommandContext

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

the class SqlAnalyzerTest method test_analyze_IF_keepLine_if_false.

public void test_analyze_IF_keepLine_if_false() {
    // ## Arrange ##
    SimpleMapPmb<Object> pmb = preparePmb();
    StringBuilder sb = new StringBuilder();
    sb.append("select *");
    sb.append(ln());
    sb.append(ln()).append("/*IF pmb.sea*/mystic/*END*/");
    sb.append(ln()).append("/*IF pmb.land*/");
    sb.append(ln()).append("oneman");
    sb.append(ln()).append("/*END*/");
    sb.append(ln()).append("/*$pmb.iks*/");
    String twoway = sb.toString();
    SqlAnalyzer analyzer = new SqlAnalyzer(twoway, false);
    // ## Act ##
    Node node = analyzer.analyze();
    // ## Assert ##
    CommandContext ctx = prepareCtx(pmb, node);
    String sql = ctx.getSql();
    log(ln() + sql);
    assertEquals("select *\n\nmystic\n\namba", sql);
    assertEquals(0, ctx.getBindVariables().length);
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlPartsNode(org.dbflute.twowaysql.node.SqlPartsNode) Node(org.dbflute.twowaysql.node.Node)

Example 32 with CommandContext

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

the class SqlAnalyzerTest method test_analyze_FOR_keepLine_if_false.

public void test_analyze_FOR_keepLine_if_false() {
    // ## Arrange ##
    StringBuilder sb = new StringBuilder();
    sb.append("select *");
    sb.append(ln());
    sb.append(ln()).append("/*FOR pmb.bonvo*/");
    sb.append(ln()).append("/*$#current*/mystic");
    sb.append(ln()).append("/*END*/");
    sb.append(ln()).append("/*FOR pmb.bonvo*/oneman/*END*/");
    sb.append(ln()).append("/*$pmb.iks*/");
    String twoway = sb.toString();
    SqlAnalyzer analyzer = new SqlAnalyzer(twoway, false);
    // ## Act ##
    Node node = analyzer.analyze();
    // ## Assert ##
    SimpleMapPmb<Object> pmb = preparePmb();
    CommandContext ctx = prepareCtx(pmb, node);
    String sql = ctx.getSql();
    log(ln() + sql);
    assertEquals("select *\n\n\n\namba", sql);
    assertEquals(0, ctx.getBindVariables().length);
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlPartsNode(org.dbflute.twowaysql.node.SqlPartsNode) Node(org.dbflute.twowaysql.node.Node)

Example 33 with CommandContext

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

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

the class SqlAnalyzerTest method test_analyze_bindVariable_nonSwitchToEmbedded_meansNormal.

public void test_analyze_bindVariable_nonSwitchToEmbedded_meansNormal() {
    // ## Arrange ##
    String twoway = "/*BEGIN*/where";
    twoway = twoway + " /*IF pmb.sea*/member.MEMBER_ID = /*pmb.iks*/'abc'/*END*/";
    twoway = twoway + " /*IF pmb.land*/and member.MEMBER_NAME = /*pmb.iks*/'stu'/*END*/";
    twoway = twoway + " /*FOR pmb.dstore*/";
    twoway = twoway + "   /*#current*/mystic";
    twoway = twoway + " /*END*/";
    twoway = twoway + "/*END*/";
    SqlAnalyzer analyzer = new SqlAnalyzer(twoway, false);
    // ## Act ##
    Node node = analyzer.analyze();
    // ## Assert ##
    SimpleMapPmb<Object> pmb = preparePmb();
    CommandContext ctx = prepareCtx(pmb, node);
    String sql = ctx.getSql();
    log(ln() + sql);
    String expected = "where member.MEMBER_ID = ?     ?    ? ";
    assertEquals(expected, sql);
    assertEquals(3, ctx.getBindVariables().length);
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlPartsNode(org.dbflute.twowaysql.node.SqlPartsNode) Node(org.dbflute.twowaysql.node.Node)

Example 35 with CommandContext

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

the class SqlAnalyzerTest method test_analyze_bindVariable_switchToEmbedded_dangerous.

public void test_analyze_bindVariable_switchToEmbedded_dangerous() {
    // ## Arrange ##
    String twoway = "/*BEGIN*/where";
    twoway = twoway + " /*IF pmb.sea*/member.MEMBER_ID = /*pmb.iks*/'abc'/*END*/";
    twoway = twoway + " /*IF pmb.land*/and member.MEMBER_NAME = /*pmb.iks*/'stu'/*END*/";
    twoway = twoway + " /*FOR pmb.dstore*/";
    twoway = twoway + "   /*#current*/mystic";
    twoway = twoway + " /*END*/";
    twoway = twoway + "/*END*/";
    SqlAnalyzer analyzer = new SqlAnalyzer(twoway, false).switchBindingToReplaceOnlyEmbedded();
    // ## Act ##
    Node node = analyzer.analyze();
    // ## Assert ##
    SimpleMapPmb<Object> pmb = preparePmb();
    CommandContext ctx = prepareCtx(pmb, node);
    String sql = ctx.getSql();
    log(ln() + sql);
    String expected = "where member.MEMBER_ID = 'amba''abc'     unimystic    citymystic ";
    assertEquals(expected, sql);
    assertEquals(0, ctx.getBindVariables().length);
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlPartsNode(org.dbflute.twowaysql.node.SqlPartsNode) Node(org.dbflute.twowaysql.node.Node)

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