use of org.apache.ibatis.mapping.BoundSql in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldConditionallyDefault.
@Test
public void shouldConditionallyDefault() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE CATEGORY = 'DEFAULT'";
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'")), "false"));
}
}, mixedContents(new TextSqlNode("WHERE CATEGORY = 'DEFAULT'"))));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
use of org.apache.ibatis.mapping.BoundSql in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldTrimWHEREANDWithTABForFirstCondition.
@Test
public void shouldTrimWHEREANDWithTABForFirstCondition() 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(" and\t ID = ? ")), "true"))));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
use of org.apache.ibatis.mapping.BoundSql in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldTrimWHEREANDWithLFForFirstCondition.
@Test
public void shouldTrimWHEREANDWithLFForFirstCondition() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE \n ID = ?";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"), new WhereSqlNode(new Configuration(), mixedContents(new IfSqlNode(mixedContents(new TextSqlNode(" and\n ID = ? ")), "true"))));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
use of org.apache.ibatis.mapping.BoundSql 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.mapping.BoundSql in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldHandleOgnlExpression.
@Test
public void shouldHandleOgnlExpression() throws Exception {
final HashMap<String, String> parameterObject = new HashMap<String, String>() {
{
put("name", "Steve");
}
};
final String expected = "Expression test: 3 / yes.";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("Expression test: ${name.indexOf('v')} / ${name in {'Bob', 'Steve'\\} ? 'yes' : 'no'}."));
BoundSql boundSql = source.getBoundSql(parameterObject);
assertEquals(expected, boundSql.getSql());
}
Aggregations