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);
}
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());
}
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());
}
Aggregations