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.firsthuanya.payment.service.PaymentService.java

public List<Payment> getPayments(Map<String, Object> queryConditions) throws OpenSessionException {
    SqlSession session = null;
    try {//from  w w  w  .  j  a  va 2  s . com
        session = openSession();
        PaymentMapper mapper = session.getMapper(PaymentMapper.class);
        return mapper.findPayments(queryConditions);
    } finally {
        if (session != null)
            session.close();
    }
}

From source file:com.firsthuanya.payment.service.PaymentService.java

public List<Payment> getAll() throws OpenSessionException {
    SqlSession session = openSession();
    try {//from w w  w  .  j a  v  a 2s  .  c o  m
        PaymentMapper mapper = session.getMapper(PaymentMapper.class);
        return mapper.findAll();
    } finally {
        session.close();
    }
}

From source file:com.firsthuanya.payment.service.PaymentService.java

public boolean hasSuchPayment(String id) throws OpenSessionException {
    SqlSession session = openSession();
    try {/*from   ww  w.  j av  a 2 s.  c  om*/
        PaymentMapper paymentMapper = session.getMapper(PaymentMapper.class);
        return (paymentMapper.find(id) != null);
    } finally {
        session.close();
    }
}

From source file:com.gf.components.mybatis.SqlSessionInInvoke.java

License:Apache License

@Override
public void invoke(Action<?, ?> action, FilterChain chain) throws Exception {

    SqlSessionSettings settings = findSettingsInNextObjects();
    SqlSession session = createSession(settings);
    try {/*from  ww  w .  j av a2s  .  co m*/

        Connection connection = session.getConnection();

        addToInvocationContext(session);
        addToInvocationContext(connection);
        chain.doNext();

        session.flushStatements();
        session.commit();

    } catch (Exception e) {
        session.rollback();
        throw e;
    } finally {
        try {
            session.close();
        } catch (Exception ex) {
            log.error("can't close session", ex);
        }
    }

}

From source file:com.github.abel533.entity.test.TestCount.java

License:Open Source License

@Test
public void testCountAllByNew() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {/*from   w  w w  .j  a va 2 s .com*/
        CommonMapper commonMapper = sqlSession.getMapper(CommonMapper.class);
        EntityMapper entityMapper = new EntityMapper(commonMapper);

        int count = entityMapper.count(new Country());

        Assert.assertEquals(183, count);
    } finally {
        sqlSession.close();
    }
}

From source file:com.github.abel533.entity.test.TestCount.java

License:Open Source License

@Test
public void testSelectOne() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {/*from   www. jav a  2s .  c om*/
        CommonMapper commonMapper = sqlSession.getMapper(CommonMapper.class);
        EntityMapper entityMapper = new EntityMapper(commonMapper);

        Country country = new Country();
        country.setCountrycode("CN");
        int count = entityMapper.count(country);

        Assert.assertEquals(1, count);
    } finally {
        sqlSession.close();
    }
}

From source file:com.github.abel533.entity.test.TestCount.java

License:Open Source License

@Test(expected = Exception.class)
public void testSelectAllByNull() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {// w  ww  .  jav  a 2  s . co m
        CommonMapper commonMapper = sqlSession.getMapper(CommonMapper.class);
        EntityMapper entityMapper = new EntityMapper(commonMapper);

        entityMapper.count(null);
    } finally {
        sqlSession.close();
    }
}

From source file:com.github.abel533.entity.test.TestDelete.java

License:Open Source License

@Test(expected = Exception.class)
public void testDeleteByNew() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {/*from w ww . j a v  a 2s.  co  m*/
        CommonMapper commonMapper = sqlSession.getMapper(CommonMapper.class);
        EntityMapper entityMapper = new EntityMapper(commonMapper);
        //?
        entityMapper.delete(new Country());
    } finally {
        //
        sqlSession.rollback();
        sqlSession.close();
    }
}

From source file:com.github.abel533.entity.test.TestDelete.java

License:Open Source License

@Test
public void testDeleteOne() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {/*  w ww. ja  v  a 2s.c  o  m*/
        CommonMapper commonMapper = sqlSession.getMapper(CommonMapper.class);
        EntityMapper entityMapper = new EntityMapper(commonMapper);

        Country country = new Country();
        country.setCountrycode("CN");
        int count = entityMapper.delete(country);

        Assert.assertEquals(1, count);
        Assert.assertEquals(182, entityMapper.count(new Country()));
    } finally {
        //
        sqlSession.rollback();
        sqlSession.close();
    }
}

From source file:com.github.abel533.entity.test.TestDelete.java

License:Open Source License

@Test(expected = Exception.class)
public void testDeleteNull() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {/*from   w  w  w.  jav  a2  s. com*/
        CommonMapper commonMapper = sqlSession.getMapper(CommonMapper.class);
        EntityMapper entityMapper = new EntityMapper(commonMapper);

        entityMapper.delete(null);
    } finally {
        sqlSession.close();
    }
}