Search in sources :

Example 81 with SqlAnalyzer

use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.

the class IfNodeTest method test_parse_IF_emptyCondition.

public void test_parse_IF_emptyCondition() {
    // ## Arrange ##
    String sql = "where";
    sql = sql + " /*IF */";
    sql = sql + " select foo";
    sql = sql + " /*END*/";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    // ## Act ##
    try {
        analyzer.analyze();
        // ## Assert ##
        fail();
    } catch (IfCommentConditionEmptyException e) {
        // OK
        log(e.getMessage());
    }
}
Also used : IfCommentConditionEmptyException(org.dbflute.twowaysql.exception.IfCommentConditionEmptyException) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 82 with SqlAnalyzer

use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.

the class EmbeddedVariableNodeTest method test_accept_inScope_notList.

public void test_accept_inScope_notList() {
    // ## Arrange ##
    String sql = "in /*$pmb.memberName*/('foo', 'bar')";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    Node rootNode = analyzer.analyze();
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberName("foo");
    CommandContext ctx = createCtx(pmb);
    // ## Act ##
    try {
        rootNode.accept(ctx);
        // ## Assert ##
        fail();
    } catch (EmbeddedVariableCommentInScopeNotListException e) {
        // OK
        log(e.getMessage());
    }
}
Also used : EmbeddedVariableCommentInScopeNotListException(org.dbflute.twowaysql.exception.EmbeddedVariableCommentInScopeNotListException) CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 83 with SqlAnalyzer

use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.

the class EmbeddedVariableNodeTest method test_analyze_dynamicBinding_IF.

public void test_analyze_dynamicBinding_IF() {
    // ## Arrange ##
    String sql = "/*BEGIN*/where";
    sql = sql + " /*IF pmb.memberId != null*/member.MEMBER_ID /*$pmb.memberName*//*END*/";
    sql = sql + "/*END*/";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    // ## Act ##
    Node rootNode = analyzer.analyze();
    // ## Assert ##
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberId(12);
    pmb.setMemberName("= /*IF pmb.memberId != null*/foo/*pmb.memberId*/99 bar/*END*/");
    CommandContext ctx = createCtx(pmb);
    rootNode.accept(ctx);
    log("ctx:" + ctx);
    String expected = "where member.MEMBER_ID = foo? bar";
    assertEquals(expected, ctx.getSql());
    assertEquals(1, ctx.getBindVariables().length);
    assertEquals(12, ctx.getBindVariables()[0]);
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 84 with SqlAnalyzer

use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.

the class EmbeddedVariableNodeTest method test_accept_number_basic.

public void test_accept_number_basic() {
    // ## Arrange ##
    String sql = "= /*$pmb.memberId*/8";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    Node rootNode = analyzer.analyze();
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberId(3);
    CommandContext ctx = createCtx(pmb);
    // ## Act ##
    rootNode.accept(ctx);
    // ## Assert ##
    log("ctx:" + ctx);
    assertEquals("= 3", ctx.getSql());
    assertEquals(0, ctx.getBindVariables().length);
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 85 with SqlAnalyzer

use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.

the class EmbeddedVariableNodeTest method test_accept_contains_bindSymbol.

public void test_accept_contains_bindSymbol() {
    // ## Arrange ##
    String sql = "in /*$pmb.memberName*/'foo'";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    Node rootNode = analyzer.analyze();
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberName("fo?o");
    CommandContext ctx = createCtx(pmb);
    // ## Act ##
    try {
        rootNode.accept(ctx);
        // ## Assert ##
        fail();
    } catch (EmbeddedVariableCommentContainsBindSymbolException e) {
        // OK
        log(e.getMessage());
    }
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) EmbeddedVariableCommentContainsBindSymbolException(org.dbflute.twowaysql.exception.EmbeddedVariableCommentContainsBindSymbolException) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Aggregations

SqlAnalyzer (org.dbflute.twowaysql.SqlAnalyzer)107 CommandContext (org.dbflute.twowaysql.context.CommandContext)99 LikeSearchOption (org.dbflute.cbean.coption.LikeSearchOption)33 List (java.util.List)5 EndCommentNotFoundException (org.dbflute.twowaysql.exception.EndCommentNotFoundException)3 IfCommentNotFoundPropertyException (org.dbflute.twowaysql.exception.IfCommentNotFoundPropertyException)3 MelodicNodeAdviceFactory (org.dbflute.bhv.core.melodicsql.MelodicNodeAdviceFactory)2 EmbeddedVariableCommentContainsBindSymbolException (org.dbflute.twowaysql.exception.EmbeddedVariableCommentContainsBindSymbolException)2 CommentTerminatorNotFoundException (org.dbflute.exception.CommentTerminatorNotFoundException)1 CommandContextCreator (org.dbflute.twowaysql.context.CommandContextCreator)1 BindVariableCommentIllegalParameterBeanSpecificationException (org.dbflute.twowaysql.exception.BindVariableCommentIllegalParameterBeanSpecificationException)1 BindVariableCommentInScopeNotListException (org.dbflute.twowaysql.exception.BindVariableCommentInScopeNotListException)1 BindVariableCommentParameterNullValueException (org.dbflute.twowaysql.exception.BindVariableCommentParameterNullValueException)1 EmbeddedVariableCommentInScopeNotListException (org.dbflute.twowaysql.exception.EmbeddedVariableCommentInScopeNotListException)1 EmbeddedVariableCommentParameterNullValueException (org.dbflute.twowaysql.exception.EmbeddedVariableCommentParameterNullValueException)1 ForCommentParameterNullElementException (org.dbflute.twowaysql.exception.ForCommentParameterNullElementException)1 IfCommentConditionEmptyException (org.dbflute.twowaysql.exception.IfCommentConditionEmptyException)1 InLoopOptionOutOfLoopException (org.dbflute.twowaysql.exception.InLoopOptionOutOfLoopException)1 LoopCurrentVariableOutOfForCommentException (org.dbflute.twowaysql.exception.LoopCurrentVariableOutOfForCommentException)1 SqlAnalyzerFactory (org.dbflute.twowaysql.factory.SqlAnalyzerFactory)1