Search in sources :

Example 71 with CommandContext

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

the class SqlAnalyzerTest method test_analyze_nativeBinding_overlook.

public void test_analyze_nativeBinding_overlook() {
    // ## Arrange ##
    SqlAnalyzer analyzer = new SqlAnalyzer("select ?", false).overlookNativeBinding();
    // ## Act ##
    Node node = analyzer.analyze();
    // ## Assert ##
    SimpleMapPmb<Object> pmb = preparePmb();
    CommandContext ctx = prepareCtx(pmb, node);
    String sql = ctx.getSql();
    assertEquals("select ?", sql);
    assertEquals(0, ctx.getBindVariables().length);
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlPartsNode(org.dbflute.twowaysql.node.SqlPartsNode) Node(org.dbflute.twowaysql.node.Node)

Example 72 with CommandContext

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

the class SqlAnalyzerTest method test_analyze_FOR_keepLine_if_true.

// ===================================================================================
// FOR Comment
// ===========
public void test_analyze_FOR_keepLine_if_true() {
    // ## Arrange ##
    SimpleMapPmb<Object> pmb = preparePmb();
    StringBuilder sb = new StringBuilder();
    sb.append("select *");
    sb.append(ln());
    sb.append(ln()).append("/*FOR pmb.dstore*/");
    sb.append(ln()).append("/*$#current*/mystic");
    sb.append(ln()).append("/*END*/");
    sb.append(ln()).append("/*FOR pmb.dstore*/oneman/*END*/");
    sb.append(ln()).append("/*$pmb.iks*/");
    String twoway = sb.toString();
    SqlAnalyzer analyzer = new SqlAnalyzer(twoway, false);
    // ## Act ##
    Node node = analyzer.analyze();
    // ## Assert ##
    CommandContext ctx = prepareCtx(pmb, node);
    String sql = ctx.getSql();
    log(ln() + sql);
    assertEquals("select *\n\n\nuni\n\ncity\n\nonemanoneman\namba", sql);
    assertEquals(0, ctx.getBindVariables().length);
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlPartsNode(org.dbflute.twowaysql.node.SqlPartsNode) Node(org.dbflute.twowaysql.node.Node)

Example 73 with CommandContext

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

the class SqlAnalyzerTest method test_analyze_bindVariable_basic.

// ===================================================================================
// BindVariable Comment
// ====================
public void test_analyze_bindVariable_basic() {
    // ## Arrange ##
    String twoway = "/*BEGIN*/where";
    twoway = twoway + " /*IF pmb.sea*/member.MEMBER_ID = /*pmb.iks*/'abc'/*END*/";
    twoway = twoway + " /*IF pmb.land*/and member.MEMBER_NAME = /*pmb.iks*/'stu'/*END*/";
    twoway = twoway + "/*END*/";
    SqlAnalyzer analyzer = new SqlAnalyzer(twoway, false);
    // ## Act ##
    Node node = analyzer.analyze();
    // ## Assert ##
    SimpleMapPmb<Object> pmb = preparePmb();
    CommandContext ctx = prepareCtx(pmb, node);
    String sql = ctx.getSql();
    log(ln() + sql);
    String expected = "where member.MEMBER_ID = ? ";
    assertEquals(expected, sql);
    assertEquals(1, ctx.getBindVariables().length);
    assertEquals("amba", ctx.getBindVariables()[0]);
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlPartsNode(org.dbflute.twowaysql.node.SqlPartsNode) Node(org.dbflute.twowaysql.node.Node)

Example 74 with CommandContext

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

the class BeginNodeTest method test_parse_BEGIN_for_where_either_true_or.

public void test_parse_BEGIN_for_where_either_true_or() {
    // ## Arrange ##
    String sql = "/*BEGIN*/where";
    sql = sql + " /*IF pmb.memberId != null*/member.MEMBER_ID = 3/*END*/";
    sql = sql + " /*IF pmb.memberName != null*/or member.MEMBER_NAME = 'TEST'/*END*/";
    sql = sql + "/*END*/";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    // ## Act ##
    Node rootNode = analyzer.analyze();
    // ## Assert ##
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberName("pmb");
    CommandContext ctx = createCtx(pmb);
    rootNode.accept(ctx);
    log("ctx:" + ctx);
    String expected = "where  member.MEMBER_NAME = 'TEST'";
    assertEquals(expected, ctx.getSql());
}
Also used : CommandContext(org.dbflute.twowaysql.context.CommandContext) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer)

Example 75 with CommandContext

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

the class BeginNodeTest method test_parse_BEGIN_that_has_nested_BEGIN_true.

// ===================================================================================
// Nested
// ======
public void test_parse_BEGIN_that_has_nested_BEGIN_true() {
    // ## Arrange ##
    String sql = "/*BEGIN*/where";
    sql = sql + " ";
    sql = sql + "/*IF pmb.memberName != null*/";
    sql = sql + "FIXED";
    sql = sql + "/*END*/";
    sql = sql + " ";
    sql = sql + "/*BEGIN*/";
    sql = sql + "FIXED2 /*IF true*/and BBB/*END*/ /*IF true*/and CCC/*END*/";
    sql = sql + "/*END*/";
    sql = sql + "/*END*/";
    SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
    // ## Act ##
    Node rootNode = analyzer.analyze();
    // ## Assert ##
    MockMemberPmb pmb = new MockMemberPmb();
    pmb.setMemberName("foo");
    CommandContext ctx = createCtx(pmb);
    rootNode.accept(ctx);
    log("ctx:" + ctx);
    // Basically Unsupported!
    assertEquals("where FIXED FIXED2 BBB and CCC", ctx.getSql());
}
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