Search in sources :

Example 1 with SetSqlNode

use of org.apache.ibatis.scripting.xmltags.SetSqlNode 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());
}
Also used : DynamicSqlSource(org.apache.ibatis.scripting.xmltags.DynamicSqlSource) TextSqlNode(org.apache.ibatis.scripting.xmltags.TextSqlNode) Configuration(org.apache.ibatis.session.Configuration) BoundSql(org.apache.ibatis.mapping.BoundSql) IfSqlNode(org.apache.ibatis.scripting.xmltags.IfSqlNode) SetSqlNode(org.apache.ibatis.scripting.xmltags.SetSqlNode) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 2 with SetSqlNode

use of org.apache.ibatis.scripting.xmltags.SetSqlNode 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());
}
Also used : DynamicSqlSource(org.apache.ibatis.scripting.xmltags.DynamicSqlSource) TextSqlNode(org.apache.ibatis.scripting.xmltags.TextSqlNode) Configuration(org.apache.ibatis.session.Configuration) BoundSql(org.apache.ibatis.mapping.BoundSql) IfSqlNode(org.apache.ibatis.scripting.xmltags.IfSqlNode) SetSqlNode(org.apache.ibatis.scripting.xmltags.SetSqlNode) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Aggregations

BaseDataTest (org.apache.ibatis.BaseDataTest)2 BoundSql (org.apache.ibatis.mapping.BoundSql)2 DynamicSqlSource (org.apache.ibatis.scripting.xmltags.DynamicSqlSource)2 IfSqlNode (org.apache.ibatis.scripting.xmltags.IfSqlNode)2 SetSqlNode (org.apache.ibatis.scripting.xmltags.SetSqlNode)2 TextSqlNode (org.apache.ibatis.scripting.xmltags.TextSqlNode)2 Configuration (org.apache.ibatis.session.Configuration)2 Test (org.junit.Test)2