use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class ForNodeTest method test_accept_allStars_connectorAdjustment_LAST.
public void test_accept_allStars_connectorAdjustment_LAST() throws Exception {
// ## Arrange ##
MockPmb pmb = new MockPmb();
pmb.setMemberNameList(DfCollectionUtil.newArrayList("foo", "bar", "baz"));
pmb.setMemberNameListInternalLikeSearchOption(new LikeSearchOption().likeContain());
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*//*LAST '@'*//*FIRST*/and (/*END*/").append(ln());
sb.append(" /*NEXT 'or '*/MEMBER_NAME like /*#current*/'foo%'").append(ln());
sb.append(" /*LAST*/)/*END*//*END*/").append(ln());
sb.append(" /*END*/");
SqlAnalyzer analyzer = new SqlAnalyzer(sb.toString(), false);
Node rootNode = analyzer.analyze();
CommandContext ctx = createCtx(pmb);
// ## Act ##
rootNode.accept(ctx);
// ## Assert ##
String actual = ctx.getSql();
log(ln() + actual);
assertTrue(actual.contains(" ("));
assertTrue(actual.contains(" MEMBER_NAME like ? escape '|'"));
assertTrue(actual.contains(" or MEMBER_NAME like ? escape '|'"));
assertTrue(actual.contains(" @"));
assertTrue(Srl.count(actual, "@") == 1);
assertTrue(Srl.count(actual, "MEMBER_NAME") == 3);
assertTrue(actual.contains(" )"));
assertEquals("%foo%", ctx.getBindVariables()[0]);
assertEquals("%bar%", ctx.getBindVariables()[1]);
assertEquals("%baz%", ctx.getBindVariables()[2]);
}
use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class ForNodeTest method test_accept_allStars_embedded_either_true.
public void test_accept_allStars_embedded_either_true() throws Exception {
// ## Arrange ##
MockPmb pmb = new MockPmb();
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(" /*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*//*FIRST*/and (/*END*/").append(ln());
sb.append(" /*NEXT 'or '*/MEMBER_NAME like /*$#current*/'foo%'").append(ln());
sb.append(" /*LAST*/)/*END*//*END*/").append(ln());
sb.append(" /*END*/");
SqlAnalyzer analyzer = new SqlAnalyzer(sb.toString(), false);
Node rootNode = analyzer.analyze();
CommandContext ctx = createCtx(pmb);
// ## Act ##
rootNode.accept(ctx);
// ## Assert ##
String actual = ctx.getSql();
log(ln() + actual);
assertTrue(actual.contains(" ("));
assertTrue(actual.contains(" MEMBER_NAME like 'foo%' escape '|'"));
assertTrue(actual.contains(" or MEMBER_NAME like 'bar%' escape '|'"));
assertTrue(actual.contains(" or MEMBER_NAME like 'baz%' escape '|'"));
assertTrue(Srl.count(actual, "MEMBER_NAME") == 3);
assertTrue(actual.contains(" )"));
assertEquals(0, ctx.getBindVariables().length);
}
use of org.dbflute.twowaysql.SqlAnalyzer 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]);
}
use of org.dbflute.twowaysql.SqlAnalyzer 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());
}
}
use of org.dbflute.twowaysql.SqlAnalyzer 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]);
}
Aggregations