List of usage examples for org.apache.ibatis.session SqlSession close
@Override
void close();
From source file:com.albertzhe.mybatis_helloworld.mapper.impl.AdminMapperImpl.java
public List<Admin> getAllAdmins() { SqlSession sqlSession = sqlSessionFactory.openSession(); List<Admin> admins = null; try {/* w w w .j av a2 s.c om*/ admins = sqlSession.selectList("com.albertzhe.mybatis_helloworld.mapper.AdminMapper.getAllAdmins"); } catch (Exception e) { e.printStackTrace(); } finally { sqlSession.close(); } return admins; }
From source file:com.baomidou.mybatisplus.test.MybatisMapperRefreshTest.java
License:Apache License
/** * Mybatis XML //from ww w .j ava 2 s . co m */ public static void main(String[] args) throws IOException, InterruptedException { InputStream in = UserMapperTest.class.getClassLoader().getResourceAsStream("mysql-config.xml"); MybatisSessionFactoryBuilder mf = new MybatisSessionFactoryBuilder(); mf.setGlobalConfig(new GlobalConfiguration(new MySqlInjector())); Resource[] resource = new ClassPathResource[] { new ClassPathResource("mysql/UserMapper.xml") }; SqlSessionFactory sessionFactory = mf.build(in); new MybatisMapperRefresh(resource, sessionFactory, 0, 5, true); boolean isReturn = false; SqlSession session = null; while (!isReturn) { try { session = sessionFactory.openSession(); UserMapper userMapper = session.getMapper(UserMapper.class); userMapper.selectListRow(new Pagination(1, 10)); resource[0].getFile().setLastModified(SystemClock.now()); session.commit(); session.close(); Thread.sleep(5000); } catch (Exception e) { e.printStackTrace(); } finally { if (session != null) { session.close(); } Thread.sleep(5000); } } System.exit(0); }
From source file:com.baomidou.mybatisplus.test.mysql.TransactionalTest.java
License:Apache License
/** * <p>/* w ww . j av a2 s . com*/ * * </p> */ public static void main(String[] args) { /* * ? */ InputStream in = TransactionalTest.class.getClassLoader().getResourceAsStream("mysql-config.xml"); MybatisSessionFactoryBuilder mf = new MybatisSessionFactoryBuilder(); SqlSessionFactory sessionFactory = mf.build(in); SqlSession sqlSession = sessionFactory.openSession(); /** * ? */ UserMapper userMapper = sqlSession.getMapper(UserMapper.class); int rlt = userMapper.insert(new User(IdWorker.getId(), "1", 1, 1)); System.err.println("--------- insertInjector --------- " + rlt); //session.commit(); sqlSession.rollback(); sqlSession.close(); }
From source file:com.beginner.core.dao.DaoSupport.java
License:Apache License
/** * {@inheritDoc}/*from w w w. ja va 2 s . c o m*/ */ @Override public void batchSave(String str, List objs) throws Exception { SqlSessionFactory sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory(); //? SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false); try { if (objs != null) { for (int i = 0, size = objs.size(); i < size; i++) { sqlSession.insert(str, objs.get(i)); } sqlSession.flushStatements(); sqlSession.commit(); sqlSession.clearCache(); } } finally { sqlSession.close(); } }
From source file:com.beginner.core.dao.DaoSupport.java
License:Apache License
/** * {@inheritDoc}/*from w w w . j av a 2 s. co m*/ */ @Override public void batchUpdate(String str, List objs) throws Exception { SqlSessionFactory sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory(); //? SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false); try { if (objs != null) { for (int i = 0, size = objs.size(); i < size; i++) { sqlSession.update(str, objs.get(i)); } sqlSession.flushStatements(); sqlSession.commit(); sqlSession.clearCache(); } } finally { sqlSession.close(); } }
From source file:com.beginner.core.dao.DaoSupport.java
License:Apache License
/** * {@inheritDoc}//from w w w .java 2 s . co m */ @Override public void batchDelete(String str, List objs) throws Exception { SqlSessionFactory sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory(); //? SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false); try { if (objs != null) { for (int i = 0, size = objs.size(); i < size; i++) { sqlSession.delete(str, objs.get(i)); } sqlSession.flushStatements(); sqlSession.commit(); sqlSession.clearCache(); } } finally { sqlSession.close(); } }
From source file:com.bibisco.manager.ArchitectureItemManager.java
License:GNU General Public License
public static ArchitectureItem load(ArchitectureItemType pArchitectureItemType) { ArchitectureItem lArchitectureItem = null; mLog.debug("Start load(ArchitectureItemType)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/*from w ww. j av a 2 s . com*/ ProjectMapper lProjectMapper = lSqlSession.getMapper(ProjectMapper.class); ProjectWithBLOBs lProjectWithBLOBs = lProjectMapper .selectByPrimaryKey(ContextManager.getInstance().getIdProject()); if (lProjectWithBLOBs != null) { switch (pArchitectureItemType) { case FABULA: lArchitectureItem = new ArchitectureItem(); lArchitectureItem.setTaskStatus( TaskStatus.getTaskStatusFromValue(lProjectWithBLOBs.getFabulaTaskStatus())); lArchitectureItem.setText(lProjectWithBLOBs.getFabula()); break; case PREMISE: lArchitectureItem = new ArchitectureItem(); lArchitectureItem.setTaskStatus( TaskStatus.getTaskStatusFromValue(lProjectWithBLOBs.getPremiseTaskStatus())); lArchitectureItem.setText(lProjectWithBLOBs.getPremise()); break; case SETTING: lArchitectureItem = new ArchitectureItem(); lArchitectureItem.setTaskStatus( TaskStatus.getTaskStatusFromValue(lProjectWithBLOBs.getSettingTaskStatus())); lArchitectureItem.setText(lProjectWithBLOBs.getSetting()); break; default: break; } } } catch (Throwable t) { mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End load(ArchitectureItemType)"); return lArchitectureItem; }
From source file:com.bibisco.manager.ArchitectureItemManager.java
License:GNU General Public License
public static void save(ArchitectureItem pArchitectureItem, ArchitectureItemType pArchitectureItemType) { mLog.debug("Start save(ArchitectureItem, ArchitectureItemType)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {// www . ja v a2 s. co m ProjectMapper lProjectMapper = lSqlSession.getMapper(ProjectMapper.class); ProjectWithBLOBs lProjectWithBLOBs = lProjectMapper .selectByPrimaryKey(ContextManager.getInstance().getIdProject()); switch (pArchitectureItemType) { case FABULA: lProjectWithBLOBs.setFabulaTaskStatus(pArchitectureItem.getTaskStatus().getValue()); lProjectWithBLOBs.setFabula(pArchitectureItem.getText()); break; case PREMISE: lProjectWithBLOBs.setPremiseTaskStatus(pArchitectureItem.getTaskStatus().getValue()); lProjectWithBLOBs.setPremise(pArchitectureItem.getText()); break; case SETTING: lProjectWithBLOBs.setSettingTaskStatus(pArchitectureItem.getTaskStatus().getValue()); lProjectWithBLOBs.setSetting(pArchitectureItem.getText()); break; default: break; } lProjectMapper.updateByPrimaryKeyWithBLOBs(lProjectWithBLOBs); lSqlSession.commit(); } catch (Throwable t) { mLog.error(t); lSqlSession.rollback(); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End save(ArchitectureItem, ArchitectureItemType)"); }
From source file:com.bibisco.manager.ChapterManager.java
License:GNU General Public License
public static ChapterDTO insert(ChapterDTO pChapterDTO) { mLog.debug("Start insert(Chapter)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/* www.j a v a 2 s. c om*/ ChaptersWithBLOBs lChapters = new ChaptersWithBLOBs(); lChapters.setTitle(pChapterDTO.getTitle()); lChapters.setPosition(pChapterDTO.getPosition()); lChapters.setReasonTaskStatus(TaskStatus.TODO.getValue()); ChaptersMapper lChaptersMapper = lSqlSession.getMapper(ChaptersMapper.class); lChaptersMapper.insert(lChapters); pChapterDTO.setIdChapter(lChapters.getIdChapter().intValue()); pChapterDTO.setTaskStatus(TaskStatus.TODO); lSqlSession.commit(); } catch (Throwable t) { mLog.error(t); lSqlSession.rollback(); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End insert(Chapter)"); return pChapterDTO; }
From source file:com.bibisco.manager.ChapterManager.java
License:GNU General Public License
public static ChapterDTO load(Integer pIntIdChapter) { ChapterDTO lChapterDTO;/*from w w w .j a v a 2 s. c om*/ mLog.debug("Start load(Integer)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try { VChaptersMapper lChaptersMapper = lSqlSession.getMapper(VChaptersMapper.class); VChaptersExample lVChaptersExample = new VChaptersExample(); lVChaptersExample.createCriteria().andIdChapterEqualTo(pIntIdChapter.longValue()); VChaptersWithBLOBs lChaptersWithBLOBs = lChaptersMapper.selectByExampleWithBLOBs(lVChaptersExample) .get(0); lChapterDTO = new ChapterDTO(); lChapterDTO.setIdChapter(lChaptersWithBLOBs.getIdChapter().intValue()); lChapterDTO.setPosition(lChaptersWithBLOBs.getPosition()); lChapterDTO.setTitle(lChaptersWithBLOBs.getTitle()); lChapterDTO.setReason(lChaptersWithBLOBs.getReason()); lChapterDTO.setReasonTaskStatus( TaskStatus.getTaskStatusFromValue(lChaptersWithBLOBs.getReasonTaskStatus())); lChapterDTO.setNote(lChaptersWithBLOBs.getNote()); lChapterDTO.setWordCount(lChaptersWithBLOBs.getWords()); lChapterDTO.setCharacterCount(lChaptersWithBLOBs.getCharacters()); lChapterDTO.setSceneList(loadScenes(lSqlSession, pIntIdChapter)); lChapterDTO.setTaskStatus(calculateChapterTaskStatus(lChaptersWithBLOBs)); } catch (Throwable t) { mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End load(Integer)"); return lChapterDTO; }