Search in sources :

Example 36 with CommandContext

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

the class SqlAnalyzerTest method test_analyze_IF_keepLine_if_true.

// *detail tests for analyze() are moved to node tests
// ===================================================================================
// IF Comment
// ==========
public void test_analyze_IF_keepLine_if_true() {
    // ## Arrange ##
    SimpleMapPmb<Object> pmb = preparePmb();
    StringBuilder sb = new StringBuilder();
    sb.append("select *");
    sb.append(ln());
    sb.append(ln()).append("/*IF pmb.sea*/");
    sb.append(ln()).append("mystic");
    sb.append(ln()).append("/*END*/");
    sb.append(ln()).append("/*IF pmb.land*/oneman/*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\n\nmystic\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 37 with CommandContext

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

the class BeginNodeTest method test_parse_BEGIN_that_has_nested_IFIF_all_false.

public void test_parse_BEGIN_that_has_nested_IFIF_all_false() {
    // ## Arrange ##
    String sql = "/*BEGIN*/where";
    sql = sql + " ";
    sql = sql + "/*IF pmb.memberId != null*/";
    sql = sql + "AAA /*IF false*/and BBB /*IF false*/and CCC/*END*//*END*/ /*IF false*/and DDD/*END*/";
    sql = sql + "/*END*/";
    sql = sql + "/*END*/";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    // ## Act ##
    Node rootNode = analyzer.analyze();
    // ## Assert ##
    MockMemberPmb pmb = new MockMemberPmb();
    CommandContext ctx = createCtx(pmb);
    rootNode.accept(ctx);
    log("ctx:" + ctx);
    assertEquals("", ctx.getSql());
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 38 with CommandContext

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

the class BeginNodeTest method test_parse_BEGIN_that_has_nested_BEGIN_false.

public void test_parse_BEGIN_that_has_nested_BEGIN_false() {
    // ## Arrange ##
    String sql = "/*BEGIN*/where";
    sql = sql + " ";
    sql = sql + "/*IF pmb.memberName != null*/";
    sql = sql + "FIXED";
    sql = sql + "/*END*/";
    sql = sql + " ";
    sql = sql + "/*BEGIN*/";
    sql = sql + "FIXED2 /*IF false*/and BBB/*END*/ /*IF false*/and CCC/*END*/";
    sql = sql + "/*END*/";
    sql = sql + "/*END*/";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    // ## Act ##
    Node rootNode = analyzer.analyze();
    // ## Assert ##
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberName("foo");
    CommandContext ctx = createCtx(pmb);
    rootNode.accept(ctx);
    log("ctx:" + ctx);
    // Basically Unsupported!
    assertEquals("where FIXED ", ctx.getSql());
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 39 with CommandContext

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

the class BeginNodeTest method test_parse_BEGIN_for_where_either_true.

public void test_parse_BEGIN_for_where_either_true() {
    // ## Arrange ##
    String sql = "/*BEGIN*/where";
    sql = sql + " /*IF pmb.memberId != null*/member.MEMBER_ID = 3/*END*/";
    sql = sql + " /*IF pmb.memberName != null*/and member.MEMBER_NAME = 'TEST'/*END*/";
    sql = sql + "/*END*/";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    // ## Act ##
    Node rootNode = analyzer.analyze();
    // ## Assert ##
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberName("pmb");
    CommandContext ctx = createCtx(pmb);
    rootNode.accept(ctx);
    log("ctx:" + ctx);
    String expected = "where  member.MEMBER_NAME = 'TEST'";
    assertEquals(expected, ctx.getSql());
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 40 with CommandContext

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

the class BeginNodeTest method test_parse_BEGIN_that_has_nested_BEGIN_toponly_false_either_true.

public void test_parse_BEGIN_that_has_nested_BEGIN_toponly_false_either_true() {
    // ## Arrange ##
    String sql = "/*BEGIN*/where";
    sql = sql + " ";
    sql = sql + "/*IF pmb.memberName != null*/";
    sql = sql + "FIXED";
    sql = sql + "/*END*/";
    sql = sql + " ";
    sql = sql + "/*BEGIN*/";
    sql = sql + "FIXED2 /*IF false*/and BBB/*END*/ /*IF true*/and CCC/*END*/";
    sql = sql + "/*END*/";
    sql = sql + "/*END*/";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    // ## Act ##
    Node rootNode = analyzer.analyze();
    // ## Assert ##
    MockMemberPmb pmb = new MockMemberPmb();
    CommandContext ctx = createCtx(pmb);
    rootNode.accept(ctx);
    log("ctx:" + ctx);
    assertEquals("where  FIXED2  CCC", ctx.getSql());
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) 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