use of org.apache.ibatis.scripting.xmltags.TextSqlNode in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldTrimNoSetClause.
@Test
public void shouldTrimNoSetClause() throws Exception {
final String expected = "UPDATE BLOG";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("UPDATE BLOG"), new SetSqlNode(new Configuration(), mixedContents(new IfSqlNode(mixedContents(new TextSqlNode(" , ID = ? ")), "false"), new IfSqlNode(mixedContents(new TextSqlNode(", NAME = ? ")), "false"))));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
use of org.apache.ibatis.scripting.xmltags.TextSqlNode in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldTrimWHEREANDWithCRLFForFirstCondition.
@Test
public void shouldTrimWHEREANDWithCRLFForFirstCondition() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE \r\n ID = ?";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"), new WhereSqlNode(new Configuration(), mixedContents(new IfSqlNode(mixedContents(new TextSqlNode(" and\r\n ID = ? ")), "true"))));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
use of org.apache.ibatis.scripting.xmltags.TextSqlNode in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldConditionallyExcludeWhere.
@Test
public 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.TextSqlNode in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldPerformStrictMatchOnForEachVariableSubstitution.
@Test
public void shouldPerformStrictMatchOnForEachVariableSubstitution() throws Exception {
final Map<String, Object> param = new HashMap<String, Object>();
final Map<String, String> uuu = new HashMap<String, String>();
uuu.put("u", "xyz");
List<Bean> uuuu = new ArrayList<Bean>();
uuuu.add(new Bean("bean id"));
param.put("uuu", uuu);
param.put("uuuu", uuuu);
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("INSERT INTO BLOG (ID, NAME, NOTE, COMMENT) VALUES"), new ForEachSqlNode(new Configuration(), mixedContents(new TextSqlNode("#{uuu.u}, #{u.id}, #{ u,typeHandler=org.apache.ibatis.type.StringTypeHandler}," + " #{u:VARCHAR,typeHandler=org.apache.ibatis.type.StringTypeHandler}")), "uuuu", "uu", "u", "(", ")", ","));
BoundSql boundSql = source.getBoundSql(param);
assertEquals(4, boundSql.getParameterMappings().size());
assertEquals("uuu.u", boundSql.getParameterMappings().get(0).getProperty());
assertEquals("__frch_u_0.id", boundSql.getParameterMappings().get(1).getProperty());
assertEquals("__frch_u_0", boundSql.getParameterMappings().get(2).getProperty());
assertEquals("__frch_u_0", boundSql.getParameterMappings().get(3).getProperty());
}
use of org.apache.ibatis.scripting.xmltags.TextSqlNode in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldSkipForEachWhenCollectionIsEmpty.
@Test
public void shouldSkipForEachWhenCollectionIsEmpty() throws Exception {
final HashMap<String, Integer[]> parameterObject = new HashMap<String, Integer[]>() {
{
put("array", new Integer[] {});
}
};
final String expected = "SELECT * FROM BLOG";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"), new ForEachSqlNode(new Configuration(), mixedContents(new TextSqlNode("#{item}")), "array", null, "item", "WHERE id in (", ")", ","));
BoundSql boundSql = source.getBoundSql(parameterObject);
assertEquals(expected, boundSql.getSql());
assertEquals(0, boundSql.getParameterMappings().size());
}
Aggregations