Search in sources :

Example 1 with MixedSqlNode

use of org.apache.ibatis.scripting.xmltags.MixedSqlNode 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 2 with MixedSqlNode

use of org.apache.ibatis.scripting.xmltags.MixedSqlNode in project mybatis-3 by mybatis.

the class DynamicSqlSourceTest method createDynamicSqlSource.

private DynamicSqlSource createDynamicSqlSource(SqlNode... contents) throws IOException, SQLException {
    createBlogDataSource();
    final String resource = "org/apache/ibatis/builder/MapperConfig.xml";
    final Reader reader = Resources.getResourceAsReader(resource);
    SqlSessionFactory sqlMapper = new SqlSessionFactoryBuilder().build(reader);
    Configuration configuration = sqlMapper.getConfiguration();
    MixedSqlNode sqlNode = mixedContents(contents);
    return new DynamicSqlSource(configuration, sqlNode);
}
Also used : DynamicSqlSource(org.apache.ibatis.scripting.xmltags.DynamicSqlSource) Configuration(org.apache.ibatis.session.Configuration) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) MixedSqlNode(org.apache.ibatis.scripting.xmltags.MixedSqlNode)

Example 3 with MixedSqlNode

use of org.apache.ibatis.scripting.xmltags.MixedSqlNode in project mybatis-3 by mybatis.

the class DynamicSqlSourceTest method shouldMapNullStringsToEmptyStrings.

@Test
public void shouldMapNullStringsToEmptyStrings() {
    final String expected = "id=${id}";
    final MixedSqlNode sqlNode = mixedContents(new TextSqlNode(expected));
    final DynamicSqlSource source = new DynamicSqlSource(new Configuration(), sqlNode);
    String sql = source.getBoundSql(new Bean(null)).getSql();
    Assert.assertEquals("id=", sql);
}
Also used : DynamicSqlSource(org.apache.ibatis.scripting.xmltags.DynamicSqlSource) TextSqlNode(org.apache.ibatis.scripting.xmltags.TextSqlNode) Configuration(org.apache.ibatis.session.Configuration) MixedSqlNode(org.apache.ibatis.scripting.xmltags.MixedSqlNode) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Aggregations

DynamicSqlSource (org.apache.ibatis.scripting.xmltags.DynamicSqlSource)3 MixedSqlNode (org.apache.ibatis.scripting.xmltags.MixedSqlNode)3 BaseDataTest (org.apache.ibatis.BaseDataTest)2 TextSqlNode (org.apache.ibatis.scripting.xmltags.TextSqlNode)2 Configuration (org.apache.ibatis.session.Configuration)2 Test (org.junit.Test)2 Reader (java.io.Reader)1 BoundSql (org.apache.ibatis.mapping.BoundSql)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)1