List of usage examples for org.apache.ibatis.session SqlSession close
@Override
void close();
From source file:com.bibisco.manager.SceneTagsManager.java
License:GNU General Public License
public static List<PointOfView4AnalysisDTO> getPointOfView4AnalysisList() { mLog.debug("Start getPointOfView4AnalysisList()"); List<PointOfView4AnalysisDTO> lListPointOfView4AnalysisDTO = new ArrayList<PointOfView4AnalysisDTO>(); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {//from www. ja v a2s . c o m VPointOfView4AnalysisExample lVPointOfView4AnalysisExample = new VPointOfView4AnalysisExample(); lVPointOfView4AnalysisExample.setOrderByClause("point_of_view, position"); VPointOfView4AnalysisMapper lVPointOfView4AnalysisMapper = lSqlSession .getMapper(VPointOfView4AnalysisMapper.class); List<VPointOfView4Analysis> lListVPointOfView4Analysis = lVPointOfView4AnalysisMapper .selectByExample(lVPointOfView4AnalysisExample); if (lListVPointOfView4Analysis != null && lListVPointOfView4Analysis.size() > 0) { for (VPointOfView4Analysis lVPointOfView4Analysis : lListVPointOfView4Analysis) { PointOfView4AnalysisDTO lPointOfView4AnalysisDTO = new PointOfView4AnalysisDTO(); lPointOfView4AnalysisDTO .setIdPointOfView4Analysis(lVPointOfView4Analysis.getIdPointOfView4Analysis()); lPointOfView4AnalysisDTO.setCharacterName(lVPointOfView4Analysis.getPointOfViewCharacterName()); lPointOfView4AnalysisDTO.setIdCharacter(lVPointOfView4Analysis.getPointOfViewIdCharacter()); lPointOfView4AnalysisDTO.setPointOfView( PointOfView.getPointOfViewFromValue(lVPointOfView4Analysis.getPointOfView())); lListPointOfView4AnalysisDTO.add(lPointOfView4AnalysisDTO); } } } catch (Throwable t) { mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End getPointOfView4AnalysisList()"); return lListPointOfView4AnalysisDTO; }
From source file:com.bibisco.manager.SceneTagsManager.java
License:GNU General Public License
public static Map<Integer, List<CharacterSceneDTO>> getCharacterSceneAnalysis() { Map<Integer, List<CharacterSceneDTO>> lMapCharacterSceneAnalysis = new HashMap<Integer, List<CharacterSceneDTO>>(); mLog.debug("Start getCharacterSceneAnalysis()"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/*from ww w . ja v a 2s.co m*/ VCharacterSceneExample lVCharacterSceneExample = new VCharacterSceneExample(); lVCharacterSceneExample.setOrderByClause("main_character desc, character_position, scene_date "); VCharacterSceneMapper lVCharacterSceneMapper = lSqlSession.getMapper(VCharacterSceneMapper.class); List<VCharacterScene> lListVCharacterScene = lVCharacterSceneMapper .selectByExample(lVCharacterSceneExample); if (lListVCharacterScene != null && lListVCharacterScene.size() > 0) { int lIntLastCharacter = -1; List<CharacterSceneDTO> lListCharacterSceneDTO = null; for (VCharacterScene lVCharacterScene : lListVCharacterScene) { if (lVCharacterScene.getIdCharacter().intValue() != lIntLastCharacter) { lListCharacterSceneDTO = new ArrayList<CharacterSceneDTO>(); lMapCharacterSceneAnalysis.put(lVCharacterScene.getIdCharacter().intValue(), lListCharacterSceneDTO); lIntLastCharacter = lVCharacterScene.getIdCharacter().intValue(); } CharacterSceneDTO lCharacterSceneDTO = new CharacterSceneDTO(); lCharacterSceneDTO.setIdCharacter(lVCharacterScene.getIdCharacter().intValue()); lCharacterSceneDTO.setCharacterName(lVCharacterScene.getCharacterName()); lCharacterSceneDTO.setIdChapter(lVCharacterScene.getIdChapter().intValue()); lCharacterSceneDTO.setChapterPosition(lVCharacterScene.getChapterPosition()); lCharacterSceneDTO.setChapterTitle(lVCharacterScene.getChapterTitle()); lCharacterSceneDTO.setIdScene(lVCharacterScene.getIdScene().intValue()); lCharacterSceneDTO.setSceneDate(lVCharacterScene.getSceneDate()); lCharacterSceneDTO.setSceneDescription(lVCharacterScene.getSceneDescription()); if (lVCharacterScene.getIdLocation() != null) { lCharacterSceneDTO.setIdLocation(lVCharacterScene.getIdLocation().intValue()); } lCharacterSceneDTO.setLocationNation(lVCharacterScene.getLocationNation()); lCharacterSceneDTO.setLocationState(lVCharacterScene.getLocationState()); lCharacterSceneDTO.setLocationCity(lVCharacterScene.getLocationCity()); lCharacterSceneDTO.setLocationName(lVCharacterScene.getLocationName()); lListCharacterSceneDTO.add(lCharacterSceneDTO); } } } catch (Throwable t) { mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End getCharacterSceneAnalysis()"); return lMapCharacterSceneAnalysis; }
From source file:com.bibisco.manager.StrandManager.java
License:GNU General Public License
public static List<StrandDTO> loadAll() { List<StrandDTO> lListStrandDTO = null; mLog.debug("Start loadAll()"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/*from w w w . j a v a 2 s . c o m*/ StrandsMapper lStrandsMapper = lSqlSession.getMapper(StrandsMapper.class); StrandsExample lStrandsExample = new StrandsExample(); lStrandsExample.setOrderByClause("position"); List<Strands> lListStrands = lStrandsMapper.selectByExampleWithBLOBs(lStrandsExample); if (lListStrands != null && lListStrands.size() > 0) { lListStrandDTO = new ArrayList<StrandDTO>(); for (Strands lStrands : lListStrands) { lListStrandDTO.add(createStrandDTOFromStrands(lStrands)); } } } catch (Throwable t) { mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End loadAll()"); return lListStrandDTO; }
From source file:com.bibisco.manager.StrandManager.java
License:GNU General Public License
public static StrandDTO insert(StrandDTO pStrandDTO) { mLog.debug("Start insert(StrandDTO)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/* w w w. j a v a 2s. c om*/ Strands lStrands = new Strands(); lStrands.setName(pStrandDTO.getName()); lStrands.setPosition(pStrandDTO.getPosition()); StrandsMapper lStrandsMapper = lSqlSession.getMapper(StrandsMapper.class); lStrandsMapper.insertSelective(lStrands); pStrandDTO.setIdStrand(lStrands.getIdStrand().intValue()); pStrandDTO.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(StrandDTO)"); return pStrandDTO; }
From source file:com.bibisco.manager.StrandManager.java
License:GNU General Public License
public static boolean deleteByPosition(Integer pIntPosition) { boolean lBlnResult; mLog.debug("Start deleteByPosition(" + pIntPosition + ")"); // get strand by position SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/*from ww w .j a va 2 s . co m*/ StrandsMapper lStrandsMapper = lSqlSession.getMapper(StrandsMapper.class); // get strand by position StrandsExample lStrandsExample = new StrandsExample(); lStrandsExample.createCriteria().andPositionEqualTo(pIntPosition); Strands lStrands = lStrandsMapper.selectByExample(lStrandsExample).get(0); // check if strand is referenced boolean lBlnIsReferenced = checkIfReferenced(lStrands.getIdStrand().intValue(), lSqlSession); // strand is not referenced, go on if (!lBlnIsReferenced) { // delete strand lStrandsMapper.deleteByPrimaryKey(lStrands.getIdStrand()); // shift down other strand lStrandsMapper.shiftDown(pIntPosition, Integer.MAX_VALUE); lBlnResult = true; } // strand is referenced, stop else { lBlnResult = false; } lSqlSession.commit(); } catch (Throwable t) { mLog.error(t); lSqlSession.rollback(); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End deleteStrandByPosition(" + pIntPosition + ")"); return lBlnResult; }
From source file:com.bibisco.manager.StrandManager.java
License:GNU General Public License
public static void move(Integer pIntSourcePosition, Integer pIntDestPosition) { mLog.debug("Start move(Integer, Integer)"); if (!pIntSourcePosition.equals(pIntDestPosition)) { SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance() .getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {// w w w .j a v a 2 s.c o m StrandsExample lStrandsExample = new StrandsExample(); lStrandsExample.createCriteria().andPositionEqualTo(pIntSourcePosition); StrandsMapper lStrandsMapper = lSqlSession.getMapper(StrandsMapper.class); // get strand to update Strands lStrands = lStrandsMapper.selectByExample(lStrandsExample).get(0); // update strand position with fake position to preserve unique index before shift lStrands.setPosition(-1); lStrandsMapper.updateByPrimaryKey(lStrands); // update other strands' position Integer lIntStartPosition; Integer lIntEndPosition; if (pIntSourcePosition > pIntDestPosition) { lIntStartPosition = pIntDestPosition; lIntEndPosition = pIntSourcePosition; lStrandsMapper.shiftUp(lIntStartPosition, lIntEndPosition); } else { lIntStartPosition = pIntSourcePosition; lIntEndPosition = pIntDestPosition; lStrandsMapper.shiftDown(lIntStartPosition, lIntEndPosition); } // update strand position lStrands.setPosition(pIntDestPosition); lStrandsMapper.updateByPrimaryKey(lStrands); lSqlSession.commit(); } catch (Throwable t) { mLog.error(t); lSqlSession.rollback(); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } } mLog.debug("End move(Integer, Integer)"); }
From source file:com.bibisco.manager.StrandManager.java
License:GNU General Public License
public static StrandDTO load(Integer pIntIdStrand) { StrandDTO lStrandDTO = null;//from w ww.ja v a 2 s . co m mLog.debug("Start load(Integer)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try { StrandsMapper lStrandsMapper = lSqlSession.getMapper(StrandsMapper.class); Strands lStrands = lStrandsMapper.selectByPrimaryKey(pIntIdStrand.longValue()); lStrandDTO = createStrandDTOFromStrands(lStrands); } catch (Throwable t) { mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End load(Integer)"); return lStrandDTO; }
From source file:com.bibisco.manager.StrandManager.java
License:GNU General Public License
public static void save(StrandDTO pStrandDTO) { mLog.debug("Start update(StrandDTO)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {// w w w. j a va 2 s. co m Strands lStrands = new Strands(); lStrands.setIdStrand(pStrandDTO.getIdStrand().longValue()); lStrands.setName(pStrandDTO.getName()); lStrands.setDescription(pStrandDTO.getDescription()); if (pStrandDTO.getTaskStatus() != null) { lStrands.setTaskStatus(pStrandDTO.getTaskStatus().getValue()); } StrandsMapper lStrandsMapper = lSqlSession.getMapper(StrandsMapper.class); lStrandsMapper.updateByPrimaryKeySelective(lStrands); lSqlSession.commit(); } catch (Throwable t) { mLog.error(t); lSqlSession.rollback(); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End insert(StrandDTO)"); }
From source file:com.bibisco.manager.TipManager.java
License:GNU General Public License
public static TipSettings load() { TipSettings lTipSettings = null;/*from w w w. j a va2s . co m*/ List<Properties> lListProperties = null; mLog.debug("Start loadTipSettings()"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryBibisco(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try { PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class); lListProperties = lPropertiesMapper.selectByExample(new PropertiesExample()); } catch (Throwable t) { mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } lTipSettings = new TipSettings(); for (Properties lProperties : lListProperties) { if (lProperties.getProperty().equalsIgnoreCase("sceneTip")) { lTipSettings.setSceneTip(Boolean.parseBoolean(lProperties.getValue())); continue; } else if (lProperties.getProperty().equalsIgnoreCase("chaptersdndTip")) { lTipSettings.getDndTipMap().put(lProperties.getProperty(), Boolean.parseBoolean(lProperties.getValue())); continue; } else if (lProperties.getProperty().equalsIgnoreCase("scenesdndTip")) { lTipSettings.getDndTipMap().put(lProperties.getProperty(), Boolean.parseBoolean(lProperties.getValue())); continue; } else if (lProperties.getProperty().equalsIgnoreCase("locationsdndTip")) { lTipSettings.getDndTipMap().put(lProperties.getProperty(), Boolean.parseBoolean(lProperties.getValue())); continue; } else if (lProperties.getProperty().equalsIgnoreCase("charactersdndTip")) { lTipSettings.getDndTipMap().put(lProperties.getProperty(), Boolean.parseBoolean(lProperties.getValue())); continue; } else if (lProperties.getProperty().equalsIgnoreCase("strandsdndTip")) { lTipSettings.getDndTipMap().put(lProperties.getProperty(), Boolean.parseBoolean(lProperties.getValue())); continue; } else if (lProperties.getProperty().equalsIgnoreCase("socialMediaTip")) { lTipSettings.setSocialMediaTip(Boolean.parseBoolean(lProperties.getValue())); continue; } else if (lProperties.getProperty().equalsIgnoreCase("donationTip")) { lTipSettings.setDonationTip(getDonationTip(lProperties)); } } mLog.debug("End loadTipSettings()"); return lTipSettings; }
From source file:com.bibisco.manager.TipManager.java
License:GNU General Public License
private static boolean getDonationTip(Properties lProperties) { if (lProperties.getValue() == "false") { return false; }//from www . j a v a 2 s .co m // it's first time... else if (StringUtils.isEmpty(lProperties.getValue())) { String lStrDate = mDateFormat.format(new Date()); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance() .getSqlSessionFactoryBibisco(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try { PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class); Properties lPropertiesToInsert = new Properties(); lPropertiesToInsert.setProperty("donationTip"); lPropertiesToInsert.setValue(lStrDate); lPropertiesMapper.updateByPrimaryKey(lPropertiesToInsert); lSqlSession.commit(); } catch (Throwable t) { mLog.error(t); lSqlSession.rollback(); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } return false; } else { try { Date lDate = mDateFormat.parse(lProperties.getValue()); Date lDateNow = new Date(); if (lDateNow.after(DateUtils.addDays(lDate, 30))) { return true; } else { return false; } } catch (ParseException e) { mLog.error(e); return false; } } }