use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class ForNodeTest method test_accept_allStars_connectorAdjustment.
public void test_accept_allStars_connectorAdjustment() 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*//*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(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_several_basic.
public void test_accept_allStars_several_basic() throws Exception {
// ## Arrange ##
MockPmb pmb = new MockPmb();
pmb.setMemberNameList(DfCollectionUtil.newArrayList("foo", "bar", "baz"));
pmb.setMemberNameListInternalLikeSearchOption(new LikeSearchOption().likeContain());
pmb.setMemberAccountList(DfCollectionUtil.newArrayList("ab%c", "%def"));
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(" /*FOR pmb.memberAccountList*//*FIRST*/and (/*END*/").append(ln());
sb.append(" /*NEXT 'or '*/MEMBER_ACCOUNT 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(Srl.count(actual, "MEMBER_NAME") == 3);
assertTrue(actual.contains(" and ("));
assertTrue(actual.contains(" MEMBER_ACCOUNT like ?"));
assertTrue(actual.contains(" or MEMBER_ACCOUNT like ?"));
assertTrue(Srl.count(actual, "MEMBER_ACCOUNT") == 2);
assertTrue(actual.contains(" )"));
assertTrue(Srl.count(actual, " )") == 2);
assertEquals("%foo%", ctx.getBindVariables()[0]);
assertEquals("%bar%", ctx.getBindVariables()[1]);
assertEquals("%baz%", ctx.getBindVariables()[2]);
assertEquals("ab%c", ctx.getBindVariables()[3]);
assertEquals("%def", ctx.getBindVariables()[4]);
}
use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class ForNodeTest method test_accept_LastAnd.
public void test_accept_LastAnd() 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(" where").append(ln());
sb.append(" /*FOR pmb.memberNameList*/").append(ln());
sb.append(" /*LAST*/and /*END*/MEMBER_NAME like /*#current*/'foo%'").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(" MEMBER_NAME like ? escape '|'"));
assertTrue(actual.contains(" and MEMBER_NAME like ? escape '|'"));
assertTrue(Srl.count(actual, "MEMBER_NAME") == 3);
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_FirstAnd.
public void test_accept_FirstAnd() 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(" where").append(ln());
sb.append(" /*FOR pmb.memberNameList*/").append(ln());
sb.append(" /*FIRST*/and /*END*/MEMBER_NAME like /*#current*/'foo%'").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(" and MEMBER_NAME like ? escape '|'"));
assertTrue(actual.contains(" MEMBER_NAME like ? escape '|'"));
assertTrue(Srl.count(actual, "MEMBER_NAME") == 3);
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_currentParameter_in_IF.
public void test_accept_currentParameter_in_IF() throws Exception {
// ## Arrange ##
MockPmb pmb = new MockPmb();
pmb.setMemberNameList(DfCollectionUtil.newArrayList("foo", "bar", "bazzzz"));
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*//*FIRST*/and (/*END*/").append(ln());
sb.append(" /*IF #current == 'foo'*/").append(ln());
sb.append(" /*NEXT 'or '*/MEMBER_NAME like /*#current*/'foo%'").append(ln());
sb.append(" /*END*/");
sb.append(" /*IF #current == 'bar'*/").append(ln());
sb.append(" /*NEXT 'or '*/MEMBER_ACCOUNT like /*#current*/'foo%'").append(ln());
sb.append(" /*END*/");
sb.append(" /*IF #current.length() == 6*/").append(ln());
sb.append(" /*NEXT 'or '*/MEMBER_BAZ like /*#current*/'foo%'").append(ln());
sb.append(" /*END*/");
sb.append(" /*IF #current.length() == 99*/").append(ln());
sb.append(" /*NEXT 'or '*/MEMBER_BAZ like /*#current*/'foo%'").append(ln());
sb.append(" /*END*/");
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_ACCOUNT like ? escape '|'"));
assertTrue(actual.contains(" or MEMBER_BAZ like ? escape '|'"));
assertTrue(Srl.count(actual, "MEMBER_NAME") == 1);
assertTrue(Srl.count(actual, "MEMBER_ACCOUNT") == 1);
assertTrue(Srl.count(actual, "MEMBER_BAZ") == 1);
assertTrue(actual.contains(" )"));
assertEquals("%foo%", ctx.getBindVariables()[0]);
assertEquals("%bar%", ctx.getBindVariables()[1]);
assertEquals("%bazzzz%", ctx.getBindVariables()[2]);
}
Aggregations