Example usage for org.apache.ibatis.session SqlSession getMapper

List of usage examples for org.apache.ibatis.session SqlSession getMapper

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSession getMapper.

Prototype

<T> T getMapper(Class<T> type);

Source Link

Document

Retrieves a mapper.

Usage

From source file:com.quancheng.mybatis.mapper.test.country.TestInsert.java

License:Open Source License

/**
 * ??null/*from   w  w  w  . j  ava 2  s  .co m*/
 */
@Test(expected = PersistenceException.class)
public void testDynamicInsertAllByNull() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        mapper.insert(null);
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country.TestInsert.java

License:Open Source License

/**
 * ??//from  www  . j ava  2 s . c  o  m
 */
@Test
public void testDynamicInsert() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = new Country();
        country.setId(10086);
        country.setCountrycode("CN");
        country.setCountryname("?");
        Assert.assertEquals(1, mapper.insert(country));

        //CN2
        country = new Country();
        country.setCountrycode("CN");
        List<Country> list = mapper.select(country);

        Assert.assertEquals(2, list.size());
        //??,??
        Assert.assertEquals(1, mapper.deleteByPrimaryKey(10086));
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country.TestInsert.java

License:Open Source License

/**
 * ?codenull?,?HH/* w ww.  j  a va  2s. c  om*/
 */
@Test
public void testDynamicInsertNull() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = new Country();
        country.setId(10086);
        country.setCountryname("?");
        Assert.assertEquals(1, mapper.insert(country));

        //CN2
        country = new Country();
        country.setId(10086);
        List<Country> list = mapper.select(country);

        Assert.assertEquals(1, list.size());
        Assert.assertNull(list.get(0).getCountrycode());
        //??,??
        Assert.assertEquals(1, mapper.deleteByPrimaryKey(10086));
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country.TestInsertSelective.java

License:Open Source License

/**
 * ??,id?null,//from w ww  .j  a  v a2s  .co  m
 */
@Test(expected = PersistenceException.class)
public void testDynamicInsertAll() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        mapper.insertSelective(new Country());
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country.TestInsertSelective.java

License:Open Source License

/**
 * ??null/*from   w w  w  . j av  a 2s  . c  o m*/
 */
@Test(expected = PersistenceException.class)
public void testDynamicInsertSelectiveAllByNull() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        mapper.insertSelective(null);
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country.TestInsertSelective.java

License:Open Source License

/**
 * ??//w w  w  . j  a  v  a 2s . c o m
 */
@Test
public void testDynamicInsertSelective() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = new Country();
        country.setId(10086);
        country.setCountrycode("CN");
        country.setCountryname("?");
        Assert.assertEquals(1, mapper.insertSelective(country));

        //CN2
        country = new Country();
        country.setCountrycode("CN");
        List<Country> list = mapper.select(country);

        Assert.assertEquals(2, list.size());
        //??,??
        Assert.assertEquals(1, mapper.deleteByPrimaryKey(10086));
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country.TestInsertSelective.java

License:Open Source License

/**
 * CountrycodeHH//from   w ww.  j  av  a  2 s. c om
 */
@Test
public void testDynamicInsertSelectiveNull() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = new Country();
        country.setId(10086);
        country.setCountryname("?");
        Assert.assertEquals(1, mapper.insertSelective(country));

        //CN2
        country = new Country();
        country.setId(10086);
        List<Country> list = mapper.select(country);

        Assert.assertEquals(1, list.size());
        //
        Assert.assertNotNull(list.get(0).getCountrycode());
        Assert.assertEquals("HH", list.get(0).getCountrycode());
        //??,??
        Assert.assertEquals(1, mapper.deleteByPrimaryKey(10086));
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country.TestSelect.java

License:Open Source License

/**
 * /*from   ww w  . j  ava 2  s .  co  m*/
 */
@Test
public void testDynamicSelectAll() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = new Country();
        List<Country> countryList;
        //country.setDynamicTableName123("country_123");
        //countryList = mapper.select(country);
        //
        //Assert.assertEquals(2, countryList.size());

        country.setDynamicTableName123(null);
        countryList = mapper.select(country);
        //
        Assert.assertEquals(183, countryList.size());
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country.TestSelect.java

License:Open Source License

/**
 * /*from ww w. j ava2s . c  om*/
 */
@Test
public void testDynamicSelectPage() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = new Country();
        country.setCountrycode("US");
        List<Country> countryList = mapper.selectPage(country, 0, 10);
        //
        Assert.assertEquals(1, countryList.size());

        countryList = mapper.selectPage(null, 100, 10);
        //
        Assert.assertEquals(10, countryList.size());
    } finally {
        sqlSession.close();
    }
}

From source file:com.quancheng.mybatis.mapper.test.country.TestSelect.java

License:Open Source License

/**
 * //from  w  w  w  .  j  ava 2s  .  c om
 */
@Test
public void testAllColumns() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = new Country();
        //35,'China','CN'
        country.setCountrycode("CN");
        country.setId(35);
        country.setCountryname("China");
        List<Country> countryList = mapper.select(country);
        Assert.assertEquals(1, countryList.size());
    } finally {
        sqlSession.close();
    }
}