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

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

Introduction

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

Prototype

@Override
void close();

Source Link

Document

Closes the session.

Usage

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

License:Open Source License

/**
 * ??null/*  w  ww  .jav a2s  .  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

/**
 * ??/*from  w  w  w  .ja  v  a  2 s  .  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  w w.  j a va  2s . c  o m*/
 */
@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

/**
 * /*w ww  .  java  2s  . c  om*/
 */
@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  . ja  v a 2s  .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

/**
 * // w  w w  .  j av a 2  s .  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();
    }
}

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

License:Open Source License

/**
 * ?null//from w  w w . j  a  va 2s  .  co m
 */
@Test
public void testDynamicSelectAllByNull() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        mapper.select(null);
    } finally {
        sqlSession.close();
    }
}

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

License:Open Source License

/**
 * ??/*from  w  ww . j  a  va 2  s  .c  o m*/
 */
@Test
public void testDynamicSelect() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = new Country();
        country.setCountrycode("CN");
        List<Country> countryList = mapper.select(country);

        Assert.assertEquals(1, countryList.size());
        Assert.assertEquals(true, countryList.get(0).getId() == 35);
        Assert.assertEquals("China", countryList.get(0).getCountryname());
    } finally {
        sqlSession.close();
    }
}

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

License:Open Source License

/**
 * ?/*from w  ww . ja  va2  s .c  om*/
 */
@Test
public void testDynamicSelectZero() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = new Country();
        country.setCountrycode("CN");
        country.setCountryname("?");// China
        List<Country> countryList = mapper.select(country);

        Assert.assertEquals(0, countryList.size());
    } finally {
        sqlSession.close();
    }
}

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

License:Open Source License

/**
 * ?,?//from w ww.  j  a v  a2  s  .  co m
 */
@Test
public void testDynamicSelectNotFoundKeyProperties() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        //?
        Assert.assertEquals(183, mapper.select(new Key()).size());

        Key key = new Key();
        key.setCountrycode("CN");
        key.setCountrytel("+86");
        Assert.assertEquals(1, mapper.select(key).size());
    } finally {
        sqlSession.close();
    }
}