Search in sources :

Example 16 with BoundSql

use of org.apache.ibatis.mapping.BoundSql in project mybatis-3 by mybatis.

the class DynamicSqlSourceTest method shouldDemonstrateMultipartExpectedTextWithNoLoopsOrConditionals.

@Test
public void shouldDemonstrateMultipartExpectedTextWithNoLoopsOrConditionals() throws Exception {
    final String expected = "SELECT * FROM BLOG WHERE ID = ?";
    DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"), new TextSqlNode("WHERE ID = ?"));
    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) BoundSql(org.apache.ibatis.mapping.BoundSql) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 17 with BoundSql

use of org.apache.ibatis.mapping.BoundSql 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 18 with BoundSql

use of org.apache.ibatis.mapping.BoundSql 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());
}
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) WhereSqlNode(org.apache.ibatis.scripting.xmltags.WhereSqlNode) IfSqlNode(org.apache.ibatis.scripting.xmltags.IfSqlNode) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 19 with BoundSql

use of org.apache.ibatis.mapping.BoundSql in project mybatis-3 by mybatis.

the class DynamicSqlSourceTest method shouldDemonstrateSimpleExpectedTextWithNoLoopsOrConditionals.

@Test
public void shouldDemonstrateSimpleExpectedTextWithNoLoopsOrConditionals() throws Exception {
    final String expected = "SELECT * FROM BLOG";
    final MixedSqlNode sqlNode = mixedContents(new TextSqlNode(expected));
    DynamicSqlSource source = createDynamicSqlSource(sqlNode);
    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) BoundSql(org.apache.ibatis.mapping.BoundSql) MixedSqlNode(org.apache.ibatis.scripting.xmltags.MixedSqlNode) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 20 with BoundSql

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

Aggregations

BoundSql (org.apache.ibatis.mapping.BoundSql)39 Test (org.junit.Test)24 BaseDataTest (org.apache.ibatis.BaseDataTest)23 DynamicSqlSource (org.apache.ibatis.scripting.xmltags.DynamicSqlSource)23 TextSqlNode (org.apache.ibatis.scripting.xmltags.TextSqlNode)23 Configuration (org.apache.ibatis.session.Configuration)18 IfSqlNode (org.apache.ibatis.scripting.xmltags.IfSqlNode)17 MappedStatement (org.apache.ibatis.mapping.MappedStatement)12 WhereSqlNode (org.apache.ibatis.scripting.xmltags.WhereSqlNode)10 CacheKey (org.apache.ibatis.cache.CacheKey)8 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Executor (org.apache.ibatis.executor.Executor)5 MetaObject (org.apache.ibatis.reflection.MetaObject)5 RowBounds (org.apache.ibatis.session.RowBounds)5 ResultHandler (org.apache.ibatis.session.ResultHandler)4 Connection (java.sql.Connection)3 Map (java.util.Map)3 SqlSource (org.apache.ibatis.mapping.SqlSource)3 ChooseSqlNode (org.apache.ibatis.scripting.xmltags.ChooseSqlNode)3