Search in sources :

Example 61 with CommandContext

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

the class IfNodeTest method test_parse_IF_true.

// ===================================================================================
// Basic
// =====
public void test_parse_IF_true() {
    // ## Arrange ##
    String sql = "/*IF pmb.memberName != null*/and member.MEMBER_NAME = 'TEST'/*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);
    assertEquals("and member.MEMBER_NAME = 'TEST'", ctx.getSql());
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 62 with CommandContext

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

the class IfNodeTest method test_parse_IF_Else_ifValid_in_BEGIN.

public void test_parse_IF_Else_ifValid_in_BEGIN() {
    // ## Arrange ##
    String sql = "/*BEGIN*/where";
    sql = sql + " /*IF pmb.memberId != null*/";
    sql = sql + " select foo";
    sql = sql + "  -- ELSE select count(*)";
    sql = sql + " /*END*/";
    sql = sql + " /*END*/";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    // ## Act ##
    Node rootNode = analyzer.analyze();
    // ## Assert ##
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberId(3);
    CommandContext ctx = createCtx(pmb);
    rootNode.accept(ctx);
    log("ctx:" + ctx);
    String expected = "where  select foo   ";
    assertEquals(expected, ctx.getSql());
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 63 with CommandContext

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

the class IfNodeTest method test_parse_IF_Else_elseValid_in_BEGIN.

public void test_parse_IF_Else_elseValid_in_BEGIN() {
    // ## Arrange ##
    String sql = "/*BEGIN*/where";
    sql = sql + " /*IF pmb.memberId != null*/";
    sql = sql + " select foo";
    sql = sql + "  -- ELSE select count(*)";
    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 select count(*)  ";
    assertEquals(expected, ctx.getSql());
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 64 with CommandContext

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

the class IfNodeTest method test_parse_IF_false.

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

Example 65 with CommandContext

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

the class IfNodeTest method test_parse_IF_Else_elseValid.

// ===================================================================================
// Else
// ====
public void test_parse_IF_Else_elseValid() {
    // ## Arrange ##
    String sql = "where";
    sql = sql + " /*IF pmb.memberId != null*/";
    sql = sql + " select foo";
    sql = sql + "  -- ELSE select count(*)";
    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 select count(*) ";
    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