Search in sources :

Example 1 with LoopCurrentVariableOutOfForCommentException

use of org.dbflute.twowaysql.exception.LoopCurrentVariableOutOfForCommentException in project dbflute-core by dbflute.

the class NodeChecker method throwLoopCurrentVariableOutOfForCommentException.

public static void throwLoopCurrentVariableOutOfForCommentException(String expression, String specifiedSql) {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("Loop's current variable was out of FOR comment scope.");
    br.addItem("Advice");
    br.addElement("Loop's current variables should be in FOR comment scope.");
    br.addElement("For example:");
    br.addElement("  (x):");
    br.addElement("    /*#current*/");
    br.addElement("    /*FOR*/.../*END*/");
    br.addElement("  (o):");
    br.addElement("    /*FOR*/");
    br.addElement("    /*#current*/");
    br.addElement("    /*END*/");
    br.addItem("Comment Expression");
    br.addElement(expression);
    br.addItem("Specified SQL");
    br.addElement(specifiedSql);
    final String msg = br.buildExceptionMessage();
    throw new LoopCurrentVariableOutOfForCommentException(msg);
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) LoopCurrentVariableOutOfForCommentException(org.dbflute.twowaysql.exception.LoopCurrentVariableOutOfForCommentException)

Example 2 with LoopCurrentVariableOutOfForCommentException

use of org.dbflute.twowaysql.exception.LoopCurrentVariableOutOfForCommentException in project dbflute-core by dbflute.

the class ForNodeTest method test_accept_currentParameter_outOfForComment.

public void test_accept_currentParameter_outOfForComment() throws Exception {
    // ## Arrange ##
    MockPmb pmb = new MockPmb();
    pmb.setMemberId(3);
    pmb.setMemberNameList(DfCollectionUtil.newArrayList("foo", "bar", "baz"));
    pmb.setMemberNameListInternalLikeSearchOption(new LikeSearchOption().likePrefix());
    StringBuilder sb = new StringBuilder();
    sb.append("select * from MEMBER").append(ln());
    sb.append(" /*#current*/where").append(ln());
    sb.append("   /*IF pmb.memberId != null*/").append(ln());
    sb.append("   MEMBER_ID = /*pmb.memberId*/").append(ln());
    sb.append("   /*END*/").append(ln());
    sb.append("   /*FOR pmb.memberNameList*/").append(ln());
    sb.append("   and MEMBER_NAME like /*#current*/'foo%'").append(ln());
    sb.append("   /*END*/").append(ln());
    sb.append(" /*END*/");
    SqlAnalyzer analyzer = new SqlAnalyzer(sb.toString(), false);
    Node rootNode = analyzer.analyze();
    CommandContext ctx = createCtx(pmb);
    // ## Act ##
    try {
        rootNode.accept(ctx);
        // ## Assert ##
        fail();
    } catch (LoopCurrentVariableOutOfForCommentException e) {
        // OK
        log(e.getMessage());
    }
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) LikeSearchOption(org.dbflute.cbean.coption.LikeSearchOption) LoopCurrentVariableOutOfForCommentException(org.dbflute.twowaysql.exception.LoopCurrentVariableOutOfForCommentException) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Aggregations

LoopCurrentVariableOutOfForCommentException (org.dbflute.twowaysql.exception.LoopCurrentVariableOutOfForCommentException)2 LikeSearchOption (org.dbflute.cbean.coption.LikeSearchOption)1 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)1 SqlAnalyzer (org.dbflute.twowaysql.SqlAnalyzer)1 CommandContext (org.dbflute.twowaysql.context.CommandContext)1