List of usage examples for org.apache.ibatis.session SqlSession rollback
void rollback();
From source file:com.bibisco.test.TipManagerTest.java
License:GNU General Public License
@Before @After/* www. j a va 2 s .com*/ public void init() { SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try { PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class); Properties lProperties = new Properties(); lProperties.setProperty("sceneTip"); lProperties.setValue("true"); lPropertiesMapper.updateByPrimaryKey(lProperties); lProperties = new Properties(); lProperties.setProperty("donationTip"); lProperties.setValue(""); lPropertiesMapper.updateByPrimaryKey(lProperties); lProperties = new Properties(); lProperties.setProperty("chaptersdndTip"); lProperties.setValue("true"); lPropertiesMapper.updateByPrimaryKey(lProperties); lProperties = new Properties(); lProperties.setProperty("scenesdndTip"); lProperties.setValue("true"); lPropertiesMapper.updateByPrimaryKey(lProperties); lProperties = new Properties(); lProperties.setProperty("locationsdndTip"); lProperties.setValue("true"); lPropertiesMapper.updateByPrimaryKey(lProperties); lProperties = new Properties(); lProperties.setProperty("charactersdndTip"); lProperties.setValue("true"); lPropertiesMapper.updateByPrimaryKey(lProperties); lProperties = new Properties(); lProperties.setProperty("strandsdndTip"); lProperties.setValue("true"); lPropertiesMapper.updateByPrimaryKey(lProperties); lProperties = new Properties(); lProperties.setProperty("socialMediaTip"); lProperties.setValue("true"); lPropertiesMapper.updateByPrimaryKey(lProperties); lSqlSession.commit(); } catch (Throwable t) { lSqlSession.rollback(); } finally { lSqlSession.close(); } PropertiesManager.getInstance().reload(); }
From source file:com.bibisco.test.VersionManagerTest.java
License:GNU General Public License
@Before @After/* w w w. ja v a 2 s .c o m*/ public void init() { SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try { PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class); Properties lProperties = new Properties(); lProperties.setProperty("version"); lProperties.setValue("1.3.0"); lPropertiesMapper.updateByPrimaryKey(lProperties); lSqlSession.commit(); } catch (Throwable t) { lSqlSession.rollback(); } finally { lSqlSession.close(); } PropertiesManager.getInstance().reload(); }
From source file:com.company.project.service.UserMapperImpl.java
License:Apache License
@Override @Transactional("transactionManager") public int insert(Map user) { SqlSession session = sqlSessionFactory.openSession(); try {//w w w . j ava 2 s.co m return session.insert("com.company.project.persistence.UserMapper.insert", user); } catch (Exception e) { e.printStackTrace(); session.rollback(); } finally { session.close(); } return 0; }
From source file:com.company.project.service.UserMapperImpl.java
License:Apache License
public int update(Map user) { SqlSession session = sqlSessionFactory.openSession(); try {//w w w . j a v a 2 s. c o m return session.update("com.company.project.persistence.UserMapper.update", user); } catch (Exception e) { e.printStackTrace(); session.rollback(); } finally { session.close(); } return 0; }
From source file:com.company.project.service.UserMapperImpl.java
License:Apache License
public int delete(String username) { SqlSession session = sqlSessionFactory.openSession(); try {// w w w. ja v a 2s.c om return session.delete("com.company.project.persistence.UserMapper.delete", username); } catch (Exception e) { e.printStackTrace(); session.rollback(); } finally { session.close(); } return 0; }
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 w w w. j a v a 2 s . c o 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.TestDelete.java
License:Open Source License
@Test(expected = Exception.class) public void testDeleteByNew() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try {//from ww w. j a va 2 s . 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 {/* www . j a v a 2 s.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.TestDeleteByPrimaryKey.java
License:Open Source License
@Test public void testDeleteByPrimaryKey() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try {/*from ww w. j a v a 2 s . c om*/ CommonMapper commonMapper = sqlSession.getMapper(CommonMapper.class); EntityMapper entityMapper = new EntityMapper(commonMapper); //? int count = entityMapper.deleteByPrimaryKey(Country.class, 1); Assert.assertEquals(1, count); Assert.assertEquals(182, entityMapper.count(new Country())); } finally { // sqlSession.rollback(); sqlSession.close(); } }
From source file:com.github.abel533.entity.test.TestExample.java
License:Open Source License
@Test public void testDeleteByExample() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try {/*w w w. j a va 2s.com*/ CommonMapper commonMapper = sqlSession.getMapper(CommonMapper.class); EntityMapper entityMapper = new EntityMapper(commonMapper); Example example = new Example(Country.class); example.createCriteria().andGreaterThan("id", 100).andLessThanOrEqualTo("id", 150); int count = entityMapper.deleteByExample(example); Assert.assertEquals(50, count); example = new Example(Country.class); example.createCriteria().andLike("countryname", "A%"); count = entityMapper.deleteByExample(example); Assert.assertEquals(12, count); } finally { // sqlSession.rollback(); sqlSession.close(); } }