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.TestSelectAll.java

License:Open Source License

/**
 * /*from w w  w. j a  v  a 2s. c o m*/
 */
@Test
public void testDynamicSelectPage() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);

        List<Country> countryList = mapper.selectAll();
        //
        Assert.assertEquals(183, countryList.size());
    } finally {
        sqlSession.close();
    }
}

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

License:Open Source License

/**
 * //from w w w.  jav a  2s.c  o m
 */
@Test
public void testDynamicSelectPage2() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);

        List<Country> countryList = mapper.selectAll();
        //
        Assert.assertEquals(183, countryList.size());
        //selectAll?
        Assert.assertEquals(183, (int) countryList.get(0).getId());
    } finally {
        sqlSession.close();
    }
}

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

License:Open Source License

/**
 * ?PK/*  w  ww.  j  a  v a2s .co m*/
 */
@Test
public void testDynamicSelectByPrimaryKey2() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = mapper.selectByPrimaryKey(35);

        Assert.assertNotNull(country);
        Assert.assertEquals(true, country.getId() == 35);
        Assert.assertEquals("China", country.getCountryname());
        Assert.assertEquals("CN", country.getCountrycode());
    } finally {
        sqlSession.close();
    }
}

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

License:Open Source License

/**
 * ???//from w  w  w .  j  a  va2  s  .c o  m
 */
@Test
public void testDynamicSelectByPrimaryKey() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = new Country();
        country.setId(35);
        country = mapper.selectByPrimaryKey(country);
        Assert.assertNotNull(country);
        Assert.assertEquals(true, country.getId() == 35);
        Assert.assertEquals("China", country.getCountryname());
        Assert.assertEquals("CN", country.getCountrycode());
    } finally {
        sqlSession.close();
    }
}

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

License:Open Source License

/**
 * ?/* w  ww  .  j av a  2  s.c  om*/
 */
@Test
public void testDynamicSelectByPrimaryKeyZero() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Assert.assertNull(mapper.selectByPrimaryKey(new Country()));
        Assert.assertNull(mapper.selectByPrimaryKey(new HashMap<String, Object>()));
        Assert.assertNull(mapper.selectByPrimaryKey(-10));
        Assert.assertNull(mapper.selectByPrimaryKey(0));
        Assert.assertNull(mapper.selectByPrimaryKey(1000));
        Assert.assertNull(mapper.selectByPrimaryKey(null));
    } finally {
        sqlSession.close();
    }
}

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

License:Open Source License

/**
 * Map???/* ww w  . ja va  2s.  c o  m*/
 */
@Test
public void testSelectByPrimaryKeyMap() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);

        Map map = new HashMap();
        map.put("id", 35);
        Country country = mapper.selectByPrimaryKey(map);
        Assert.assertNotNull(country);
        Assert.assertEquals(true, country.getId() == 35);
        Assert.assertEquals("China", country.getCountryname());
        Assert.assertEquals("CN", country.getCountrycode());

        map = new HashMap();
        map.put("countryname", "China");
        Assert.assertNull(mapper.selectByPrimaryKey(map));
    } finally {
        sqlSession.close();
    }
}

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

License:Open Source License

/**
 * ??//from w  ww . j av a 2s .  c  om
 */
@Test(expected = Exception.class)
public void testDynamicDeleteNotFoundKeyProperties() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        mapper.selectByPrimaryKey(new Key());
    } finally {
        sqlSession.close();
    }
}

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

License:Open Source License

/**
 * ?//  w w  w .j  a v a 2s .  c om
 */
@Test
public void testDynamicDeleteException() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        mapper.selectByPrimaryKey(100);
    } finally {
        sqlSession.close();
    }
}

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

License:Open Source License

/**
 * //from  w ww  .  j  a  va  2 s  .  c  om
 */
@Test
public void testDynamicSelectCount() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        //
        Assert.assertEquals(183, mapper.selectCount(new Country()));
    } finally {
        sqlSession.close();
    }
}

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

License:Open Source License

/**
 * ?null/*  w  w  w  .j  a va  2 s  . c om*/
 */
@Test
public void testDynamicSelectAllByNull() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        //
        Assert.assertEquals(183, mapper.selectCount(null));
    } finally {
        sqlSession.close();
    }
}