Search in sources :

Example 91 with CommandContext

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

the class BindVariableNodeTest method test_accept_inLoopOption_outOfLoop.

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

Example 92 with CommandContext

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

the class BindVariableNodeTest method test_accept_null_notAllowed.

public void test_accept_null_notAllowed() {
    // ## Arrange ##
    String sql = "= /*pmb.memberId*/8";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, true);
    Node rootNode = analyzer.analyze();
    MockMemberPmb pmb = new MockMemberPmb();
    CommandContext ctx = createCtx(pmb);
    // ## Act ##
    try {
        rootNode.accept(ctx);
        // ## Assert ##
        fail();
    } catch (BindVariableCommentParameterNullValueException e) {
        // OK
        log(e.getMessage());
    }
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer) BindVariableCommentParameterNullValueException(org.dbflute.twowaysql.exception.BindVariableCommentParameterNullValueException)

Example 93 with CommandContext

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

the class BindVariableNodeTest method test_accept_inLoopOption_melodic.

public void test_accept_inLoopOption_melodic() {
    // ## Arrange ##
    String sql = "= /*FOR pmb.memberNameList*//*#current:likePrefix*/'foo'/*END*/";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false) {

        @Override
        protected NodeAdviceFactory getNodeAdviceFactory() {
            return new MelodicNodeAdviceFactory();
        }
    };
    Node rootNode = analyzer.analyze();
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberNameList(DfCollectionUtil.newArrayList("foo", "bar", "baz"));
    CommandContext ctx = createCtx(pmb);
    // ## Act ##
    rootNode.accept(ctx);
    // ## Assert ##
    log("ctx:" + ctx);
    assertEquals("= ? escape '|' ? escape '|' ? escape '|' ", ctx.getSql());
    assertEquals(3, ctx.getBindVariables().length);
    assertEquals("foo%", ctx.getBindVariables()[0]);
    assertEquals("bar%", ctx.getBindVariables()[1]);
    assertEquals("baz%", ctx.getBindVariables()[2]);
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) MelodicNodeAdviceFactory(org.dbflute.bhv.core.melodicsql.MelodicNodeAdviceFactory) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 94 with CommandContext

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

the class BindVariableNodeTest method test_accept_inScope_bindSymbol.

public void test_accept_inScope_bindSymbol() {
    // ## Arrange ##
    String sql = "in /*pmb.memberNameList*/('foo', 'bar')";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    Node rootNode = analyzer.analyze();
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberNameList(DfCollectionUtil.newArrayList("baz", "q?ux"));
    CommandContext ctx = createCtx(pmb);
    // ## Act ##
    rootNode.accept(ctx);
    // ## Assert ##
    log("ctx:" + ctx);
    assertEquals("in (?, ?)", ctx.getSql());
    assertEquals(2, ctx.getBindVariables().length);
    assertEquals("baz", ctx.getBindVariables()[0]);
    assertEquals("q?ux", ctx.getBindVariables()[1]);
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 95 with CommandContext

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

the class BindVariableNodeTest method test_accept_string.

public void test_accept_string() {
    // ## Arrange ##
    String sql = "= /*pmb.memberName*/'foo'";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    Node rootNode = analyzer.analyze();
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberName("bar");
    CommandContext ctx = createCtx(pmb);
    // ## Act ##
    rootNode.accept(ctx);
    // ## Assert ##
    log("ctx:" + ctx);
    assertEquals("= ?", ctx.getSql());
    assertEquals(1, ctx.getBindVariables().length);
    assertEquals("bar", ctx.getBindVariables()[0]);
}
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