Search in sources :

Example 1 with ForCommentParameterNullElementException

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

the class ForNodeTest method test_accept_currentParameter_in_Bind_null_notAllowed.

public void test_accept_currentParameter_in_Bind_null_notAllowed() throws Exception {
    // ## Arrange ##
    MockPmb pmb = new MockPmb();
    pmb.setMemberId(3);
    pmb.setMemberNameList(DfCollectionUtil.newArrayList("foo", null, "baz"));
    pmb.setMemberNameListInternalLikeSearchOption(new LikeSearchOption().likePrefix());
    StringBuilder sb = new StringBuilder();
    sb.append("select * from MEMBER").append(ln());
    sb.append(" /*BEGIN*/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(), true);
    Node rootNode = analyzer.analyze();
    CommandContext ctx = createCtx(pmb);
    // ## Act ##
    try {
        rootNode.accept(ctx);
        // ## Assert ##
        fail();
    } catch (ForCommentParameterNullElementException e) {
        // OK
        log(e.getMessage());
    }
}
Also used : ForCommentParameterNullElementException(org.dbflute.twowaysql.exception.ForCommentParameterNullElementException) CommandContext(org.dbflute.twowaysql.context.CommandContext) LikeSearchOption(org.dbflute.cbean.coption.LikeSearchOption) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 2 with ForCommentParameterNullElementException

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

the class ScopeNode method handleLoopElementNullParameter.

protected void handleLoopElementNullParameter(Node child, LoopInfo loopInfo) {
    if (child instanceof BindVariableNode && ((BindVariableNode) child).isBlockNullParameter()) {
        final Object parameter = loopInfo.getCurrentParameter();
        if (parameter == null) {
            final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
            br.addNotice("The parameter in list for bind variable was null.");
            br.addItem("Advice");
            br.addElement("Bind variable for select does not allow null value.");
            br.addElement("Confirm your target parameter in the list.");
            br.addItem("Parameter List");
            br.addElement(loopInfo.getParameterList());
            br.addItem("Current Index");
            br.addElement(loopInfo.getLoopIndex());
            br.addItem("FOR Comment Expression");
            br.addElement(loopInfo.getExpression());
            br.addItem("Specified SQL");
            br.addElement(loopInfo.getSpecifiedSql());
            String msg = br.buildExceptionMessage();
            throw new ForCommentParameterNullElementException(msg);
        }
    }
}
Also used : ForCommentParameterNullElementException(org.dbflute.twowaysql.exception.ForCommentParameterNullElementException) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder)

Aggregations

ForCommentParameterNullElementException (org.dbflute.twowaysql.exception.ForCommentParameterNullElementException)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