use of org.apache.ibatis.scripting.xmltags.DynamicSqlSource in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldTrimWHEREInsteadOfANDForFirstCondition.
@Test
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());
}
use of org.apache.ibatis.scripting.xmltags.DynamicSqlSource in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldPerformStrictMatchOnForEachVariableSubstitution.
@Test
void shouldPerformStrictMatchOnForEachVariableSubstitution() throws Exception {
final Map<String, Object> param = new HashMap<>();
final Map<String, String> uuu = new HashMap<>();
uuu.put("u", "xyz");
List<Bean> uuuu = new ArrayList<>();
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.DynamicSqlSource in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method shouldConditionallyIncludeWhere.
@Test
void shouldConditionallyIncludeWhere() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE ID = ?";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"), new IfSqlNode(mixedContents(new TextSqlNode("WHERE ID = ?")), "true"));
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 shouldTrimCommaAfterSET.
@Test
void shouldTrimCommaAfterSET() throws Exception {
final String expected = "UPDATE BLOG SET NAME = ?";
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 = ?")), "true"))));
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 shouldTrimWHEREORWithCRLFForFirstCondition.
@Test
void shouldTrimWHEREORWithCRLFForFirstCondition() 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(" or\r\n ID = ? ")), "true"))));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}
Aggregations