List of usage examples for org.apache.ibatis.session SqlSession close
@Override
void close();
From source file:com.bibisco.test.RichTextEditorSettingsManagerTest.java
License:GNU General Public License
@Test public void testSaveSettingsWithoutAutoSaveEnabled() { RichTextEditorSettings lRichTextEditorSettings = new RichTextEditorSettings(); lRichTextEditorSettings.setFont("arial"); lRichTextEditorSettings.setSize("small"); lRichTextEditorSettings.setIndentParagraphEnabled(true); lRichTextEditorSettings.setSpellCheckEnabled(true); lRichTextEditorSettings.setAutoSaveEnabled(false); RichTextEditorSettingsManager.save(lRichTextEditorSettings); SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); Properties lProperties;/*from w ww .j a va 2s. c o m*/ String lStrAutoSaveEnabled; try { PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class); lProperties = lPropertiesMapper.selectByPrimaryKey("autoSaveEnabled"); lStrAutoSaveEnabled = lProperties.getValue(); } finally { lSqlSession.close(); } Assert.assertEquals(lStrAutoSaveEnabled, "false"); }
From source file:com.bibisco.test.TipManagerTest.java
License:GNU General Public License
@Test public void testDisableTip() { TipManager.disableTip("sceneTip"); SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); Properties lProperties;/*from w w w .ja v a 2 s . co m*/ try { PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class); lProperties = lPropertiesMapper.selectByPrimaryKey("sceneTip"); } finally { lSqlSession.close(); } Assert.assertEquals(lProperties.getValue(), "false"); }
From source file:com.bibisco.test.TipManagerTest.java
License:GNU General Public License
@Test public void testDonationTip29DaysFromNow() { DateFormat lDateFormat = new SimpleDateFormat(DATE_FORMAT); Date lDate29DaysFromNow = DateUtils.addDays(new Date(), -29); SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/*w ww . ja v a2 s.co m*/ PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class); Properties lProperties = new Properties(); lProperties.setProperty("donationTip"); lProperties.setValue(lDateFormat.format(lDate29DaysFromNow)); lPropertiesMapper.updateByPrimaryKey(lProperties); lSqlSession.commit(); } catch (Throwable t) { lSqlSession.rollback(); } finally { lSqlSession.close(); } PropertiesManager.getInstance().reload(); TipSettings lTipSettings = TipManager.load(); Assert.assertEquals(lTipSettings.isDonationTip(), false); }
From source file:com.bibisco.test.TipManagerTest.java
License:GNU General Public License
@Test public void testDonationTip30DaysFromNow() { DateFormat lDateFormat = new SimpleDateFormat(DATE_FORMAT); Date lDate29DaysFromNow = DateUtils.addDays(new Date(), -30); SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/*from w ww .j a v a 2s . c om*/ PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class); Properties lProperties = new Properties(); lProperties.setProperty("donationTip"); lProperties.setValue(lDateFormat.format(lDate29DaysFromNow)); lPropertiesMapper.updateByPrimaryKey(lProperties); lSqlSession.commit(); } catch (Throwable t) { lSqlSession.rollback(); } finally { lSqlSession.close(); } PropertiesManager.getInstance().reload(); TipSettings lTipSettings = TipManager.load(); Assert.assertEquals(lTipSettings.isDonationTip(), true); }
From source file:com.bibisco.test.TipManagerTest.java
License:GNU General Public License
@Before @After//from ww w . j ava2 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("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/*from ww w .jav 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 public Map get(String username) { // note standard MyBatis API usage - opening and closing the session manually SqlSession session = sqlSessionFactory.openSession(); try {//from ww w. j a va 2s . c o m return session.selectOne("com.company.project.persistence.UserMapper.get", username); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); } return null; }
From source file:com.company.project.service.UserMapperImpl.java
License:Apache License
@Override public List getAll() { SqlSession session = sqlSessionFactory.openSession(); try {//w ww .j a v a2 s . com return session.selectList("com.company.project.persistence.UserMapper.getAll"); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); } return null; }
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 {/*from w w w . j ava 2 s. c o 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
@Transactional("txManager") public int insertx(Map user) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status = txManager.getTransaction(def); SqlSession session = sqlSessionFactory.openSession(); int result = 0; try {//from ww w . ja v a 2s. c o m result = session.insert("com.company.project.persistence.UserMapper.insert", user); txManager.commit(status); // will not insert if this line is removed //txManager.rollback(status); } catch (Exception e) { e.printStackTrace(); //session.rollback(); txManager.rollback(status); } finally { session.close(); } return result; }