Search in sources :

Example 26 with DynamicSqlSource

use of org.apache.ibatis.scripting.xmltags.DynamicSqlSource in project mybatis-3 by mybatis.

the class DynamicSqlSourceTest method shouldMapNullStringsToEmptyStrings.

@Test
void shouldMapNullStringsToEmptyStrings() {
    final String expected = "id=${id}";
    final MixedSqlNode sqlNode = mixedContents(new TextSqlNode(expected));
    final DynamicSqlSource source = new DynamicSqlSource(new Configuration(), sqlNode);
    String sql = source.getBoundSql(new Bean(null)).getSql();
    Assertions.assertEquals("id=", sql);
}
Also used : DynamicSqlSource(org.apache.ibatis.scripting.xmltags.DynamicSqlSource) TextSqlNode(org.apache.ibatis.scripting.xmltags.TextSqlNode) Configuration(org.apache.ibatis.session.Configuration) MixedSqlNode(org.apache.ibatis.scripting.xmltags.MixedSqlNode) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test)

Example 27 with DynamicSqlSource

use of org.apache.ibatis.scripting.xmltags.DynamicSqlSource in project mybatis-3 by mybatis.

the class DynamicSqlSourceTest method shouldConditionallyExcludeWhere.

@Test
void shouldConditionallyExcludeWhere() throws Exception {
    final String expected = "SELECT * FROM BLOG";
    DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"), new IfSqlNode(mixedContents(new TextSqlNode("WHERE ID = ?")), "false"));
    BoundSql boundSql = source.getBoundSql(null);
    assertEquals(expected, boundSql.getSql());
}
Also used : DynamicSqlSource(org.apache.ibatis.scripting.xmltags.DynamicSqlSource) TextSqlNode(org.apache.ibatis.scripting.xmltags.TextSqlNode) BoundSql(org.apache.ibatis.mapping.BoundSql) IfSqlNode(org.apache.ibatis.scripting.xmltags.IfSqlNode) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test)

Example 28 with DynamicSqlSource

use of org.apache.ibatis.scripting.xmltags.DynamicSqlSource in project mybatis-3 by mybatis.

the class DynamicSqlSourceTest method shouldConditionallyChooseFirst.

@Test
void shouldConditionallyChooseFirst() throws Exception {
    final String expected = "SELECT * FROM BLOG WHERE CATEGORY = ?";
    DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"), new ChooseSqlNode(new ArrayList<SqlNode>() {

        {
            add(new IfSqlNode(mixedContents(new TextSqlNode("WHERE CATEGORY = ?")), "true"));
            add(new IfSqlNode(mixedContents(new TextSqlNode("WHERE CATEGORY = 'NONE'")), "false"));
        }
    }, mixedContents(new TextSqlNode("WHERE CATEGORY = 'DEFAULT'"))));
    BoundSql boundSql = source.getBoundSql(null);
    assertEquals(expected, boundSql.getSql());
}
Also used : DynamicSqlSource(org.apache.ibatis.scripting.xmltags.DynamicSqlSource) ChooseSqlNode(org.apache.ibatis.scripting.xmltags.ChooseSqlNode) TextSqlNode(org.apache.ibatis.scripting.xmltags.TextSqlNode) BoundSql(org.apache.ibatis.mapping.BoundSql) ArrayList(java.util.ArrayList) IfSqlNode(org.apache.ibatis.scripting.xmltags.IfSqlNode) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test)

Aggregations

DynamicSqlSource (org.apache.ibatis.scripting.xmltags.DynamicSqlSource)28 TextSqlNode (org.apache.ibatis.scripting.xmltags.TextSqlNode)26 BaseDataTest (org.apache.ibatis.BaseDataTest)25 Test (org.junit.jupiter.api.Test)25 BoundSql (org.apache.ibatis.mapping.BoundSql)24 IfSqlNode (org.apache.ibatis.scripting.xmltags.IfSqlNode)18 Configuration (org.apache.ibatis.session.Configuration)18 WhereSqlNode (org.apache.ibatis.scripting.xmltags.WhereSqlNode)10 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 ChooseSqlNode (org.apache.ibatis.scripting.xmltags.ChooseSqlNode)3 ForEachSqlNode (org.apache.ibatis.scripting.xmltags.ForEachSqlNode)3 MixedSqlNode (org.apache.ibatis.scripting.xmltags.MixedSqlNode)3 SetSqlNode (org.apache.ibatis.scripting.xmltags.SetSqlNode)3 StaticSqlSource (org.apache.ibatis.builder.StaticSqlSource)2 MapperSqlSource (com.qiuyj.mybatis.MapperSqlSource)1 Reader (java.io.Reader)1 Section (org.apache.ibatis.domain.blog.Section)1 SelectKeyGenerator (org.apache.ibatis.executor.keygen.SelectKeyGenerator)1 MappedStatement (org.apache.ibatis.mapping.MappedStatement)1