use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class EmbeddedVariableNodeTest method test_analyze_basic.
// ===================================================================================
// Basic
// =====
public void test_analyze_basic() {
// ## Arrange ##
String sql = "/*BEGIN*/where";
sql = sql + " /*IF pmb.memberId != null*/member.MEMBER_ID = /*$pmb.memberId*//*END*/";
sql = sql + " /*IF pmb.memberName != null*/and member.MEMBER_NAME = /*$pmb.memberName*/'TEST'/*END*/";
sql = sql + "/*END*/";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
// ## Act ##
Node rootNode = analyzer.analyze();
// ## Assert ##
MockMemberPmb pmb = new MockMemberPmb();
pmb.setMemberId(12);
pmb.setMemberName("foo");
CommandContext ctx = createCtx(pmb);
rootNode.accept(ctx);
log("ctx:" + ctx);
String expected = "where member.MEMBER_ID = 12 and member.MEMBER_NAME = 'foo'";
assertEquals(expected, ctx.getSql());
assertEquals(0, ctx.getBindVariables().length);
}
use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class EmbeddedVariableNodeTest method test_accept_string_basic.
public void test_accept_string_basic() {
// ## 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("= 'bar'", ctx.getSql());
assertEquals(0, ctx.getBindVariables().length);
}
use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class EmbeddedVariableNodeTest method test_accept_inScope_array_string_basic.
public void test_accept_inScope_array_string_basic() {
// ## Arrange ##
String sql = "in /*$pmb.memberNames*/('foo', 'bar')";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
Node rootNode = analyzer.analyze();
MockMemberPmb pmb = new MockMemberPmb();
pmb.setMemberNames(new String[] { "baz", "qux" });
CommandContext ctx = createCtx(pmb);
// ## Act ##
rootNode.accept(ctx);
// ## Assert ##
log("ctx:" + ctx);
assertEquals("in ('baz', 'qux')", ctx.getSql());
assertEquals(0, ctx.getBindVariables().length);
}
use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class EmbeddedVariableNodeTest 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 ##
try {
rootNode.accept(ctx);
// ## Assert ##
fail();
} catch (EmbeddedVariableCommentContainsBindSymbolException e) {
// OK
log(e.getMessage());
}
}
use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class EmbeddedVariableNodeTest method test_accept_inScope_list_string_basic.
// ===================================================================================
// InScope
// =======
public void test_accept_inScope_list_string_basic() {
// ## 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", "qux"));
CommandContext ctx = createCtx(pmb);
// ## Act ##
rootNode.accept(ctx);
// ## Assert ##
log("ctx:" + ctx);
assertEquals("in ('baz', 'qux')", ctx.getSql());
assertEquals(0, ctx.getBindVariables().length);
}
Aggregations