use of org.apache.ibatis.scripting.xmltags.IfSqlNode in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldTrimNoWhereClause.
@Test
public void shouldTrimNoWhereClause() throws Exception {
final String expected = "SELECT * FROM BLOG";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"), new WhereSqlNode(new Configuration(), mixedContents(new IfSqlNode(mixedContents(new TextSqlNode(" and ID = ? ")), "false"), new IfSqlNode(mixedContents(new TextSqlNode("OR NAME = ? ")), "false"))));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
use of org.apache.ibatis.scripting.xmltags.IfSqlNode in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldTrimSETInsteadOfCOMMAForBothConditions.
@Test
public void shouldTrimSETInsteadOfCOMMAForBothConditions() throws Exception {
final String expected = "UPDATE BLOG SET ID = ?, NAME = ?";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("UPDATE BLOG"), new SetSqlNode(new Configuration(), mixedContents(new IfSqlNode(mixedContents(new TextSqlNode(" ID = ?, ")), "true"), new IfSqlNode(mixedContents(new TextSqlNode(" NAME = ?, ")), "true"))));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
use of org.apache.ibatis.scripting.xmltags.IfSqlNode in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldTrimWHEREORWithTABForFirstCondition.
@Test
public void shouldTrimWHEREORWithTABForFirstCondition() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE \t ID = ?";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"), new WhereSqlNode(new Configuration(), mixedContents(new IfSqlNode(mixedContents(new TextSqlNode(" or\t ID = ? ")), "true"))));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
use of org.apache.ibatis.scripting.xmltags.IfSqlNode in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldConditionallyChooseSecond.
@Test
public void shouldConditionallyChooseSecond() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE CATEGORY = 'NONE'";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"), new ChooseSqlNode(new ArrayList<SqlNode>() {
{
add(new IfSqlNode(mixedContents(new TextSqlNode("WHERE CATEGORY = ?")), "false"));
add(new IfSqlNode(mixedContents(new TextSqlNode("WHERE CATEGORY = 'NONE'")), "true"));
}
}, mixedContents(new TextSqlNode("WHERE CATEGORY = 'DEFAULT'"))));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
use of org.apache.ibatis.scripting.xmltags.IfSqlNode in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldTrimWHEREInsteadOfANDForFirstCondition.
@Test
public void shouldTrimWHEREInsteadOfANDForFirstCondition() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE ID = ?";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"), new WhereSqlNode(new Configuration(), mixedContents(new IfSqlNode(mixedContents(new TextSqlNode(" and ID = ? ")), "true"), new IfSqlNode(mixedContents(new TextSqlNode(" or NAME = ? ")), "false"))));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
Aggregations