Search in sources :

Example 76 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_root_has_both.

public void test_parse_BEGIN_that_has_nested_IFIF_root_has_both() {
    // ## Arrange ##
    String sql = "/*BEGIN*/where";
    sql = sql + " ";
    sql = sql + "/*IF pmb.memberId != null*/";
    sql = sql + "FIXED";
    sql = sql + "/*END*/";
    sql = sql + " ";
    sql = sql + "/*IF pmb.memberName != null*/";
    sql = sql + "and AAA /*IF true*/and BBB /*IF true*/and CCC/*END*//*END*/ /*IF true*/and DDD/*END*/";
    sql = sql + "/*END*/";
    sql = sql + "/*END*/";
    sql = sql + " ";
    sql = sql + "/*BEGIN*/where";
    sql = sql + " ";
    sql = sql + "/*IF pmb.memberId != null*/";
    sql = sql + "FIXED";
    sql = sql + "/*END*/";
    sql = sql + " ";
    sql = sql + "/*IF pmb.memberName != null*/";
    sql = sql + "and AAA /*IF true*/and BBB /*IF true*/and CCC/*END*//*END*/ /*IF true*/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();
    pmb.setMemberName("foo");
    CommandContext ctx = createCtx(pmb);
    rootNode.accept(ctx);
    log("ctx:" + ctx);
    String expected = "where  AAA and BBB and CCC and DDD where  AAA and BBB and CCC and DDD";
    assertEquals(expected, ctx.getSql());
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 77 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_nonsense_all_true.

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

Example 78 with CommandContext

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

the class BeginNodeTest method test_parse_BEGIN_for_select_either_true.

public void test_parse_BEGIN_for_select_either_true() {
    // ## Arrange ##
    String sql = "select /*BEGIN*/";
    sql = sql + "/*IF pmb.memberId != null*/member.MEMBER_ID as c1/*END*/";
    sql = sql + "/*IF pmb.memberName != null*/, member.MEMBER_NAME as c2/*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);
    String expected = "select member.MEMBER_NAME as c2";
    assertEquals(expected, ctx.getSql());
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 79 with CommandContext

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

the class BeginNodeTest method test_parse_BEGIN_for_select_all_false.

public void test_parse_BEGIN_for_select_all_false() {
    // ## Arrange ##
    String sql = "select /*BEGIN*/";
    sql = sql + "/*IF pmb.memberId != null*/member.MEMBER_ID as c1/*END*/";
    sql = sql + "/*IF pmb.memberName != null*/, member.MEMBER_NAME as c2/*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);
    String expected = "select ";
    assertEquals(expected, ctx.getSql());
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 80 with CommandContext

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

the class BeginNodeTest method test_parse_BEGIN_for_where_all_true.

// ===================================================================================
// Basic
// =====
public void test_parse_BEGIN_for_where_all_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.setMemberId(3);
    pmb.setMemberName("foo");
    CommandContext ctx = createCtx(pmb);
    rootNode.accept(ctx);
    log("ctx:" + ctx);
    String expected = "where member.MEMBER_ID = 3 and member.MEMBER_NAME = 'TEST'";
    assertEquals(expected, 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