List of usage examples for org.apache.ibatis.session SqlSession getMapper
<T> T getMapper(Class<T> type);
From source file:com.bibisco.manager.CharacterManager.java
License:GNU General Public License
private static void move(Integer pIntSourcePosition, Integer pIntDestPosition, boolean pBlnMainCharacter) { mLog.debug("Start move(Integer, Integer, boolean)"); if (!pIntSourcePosition.equals(pIntDestPosition)) { SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance() .getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/*w ww .j a v a 2 s. co m*/ CharactersMapper lCharactersMapper = lSqlSession.getMapper(CharactersMapper.class); //get character by position and main flag CharactersExample lCharactersExample = new CharactersExample(); lCharactersExample.createCriteria().andPositionEqualTo(pIntSourcePosition) .andMainCharacterEqualTo(pBlnMainCharacter ? "Y" : "N"); Characters lCharacters = lCharactersMapper.selectByExample(lCharactersExample).get(0); // update character position with fake position to preserve unique index before shift lCharacters.setPosition(-1); lCharactersMapper.updateByPrimaryKey(lCharacters); // update other Characters' position Integer lIntStartPosition; Integer lIntEndPosition; if (pIntSourcePosition > pIntDestPosition) { lIntStartPosition = pIntDestPosition; lIntEndPosition = pIntSourcePosition; lCharactersMapper.shiftUp(lIntStartPosition, lIntEndPosition, pBlnMainCharacter ? "Y" : "N"); } else { lIntStartPosition = pIntSourcePosition; lIntEndPosition = pIntDestPosition; lCharactersMapper.shiftDown(lIntStartPosition, lIntEndPosition, pBlnMainCharacter ? "Y" : "N"); } // update character position lCharacters.setPosition(pIntDestPosition); lCharactersMapper.updateByPrimaryKey(lCharacters); 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, boolean)"); }
From source file:com.bibisco.manager.CharacterManager.java
License:GNU General Public License
public static CharacterInfoQuestionsDTO loadCharacterInfoQuestions( CharacterInfoQuestions pCharacterInfoQuestions, Integer lIntIdCharacter) { CharacterInfoQuestionsDTO lCharacterInfoQuestionsDTO; mLog.debug("Start loadCharacterInfo(CharacterInfoQuestions, Integer)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/*from w ww . j ava 2s.c o m*/ CharactersMapper lCharactersMapper = lSqlSession.getMapper(CharactersMapper.class); CharactersWithBLOBs lCharacters = lCharactersMapper.selectByPrimaryKey(lIntIdCharacter.longValue()); lCharacterInfoQuestionsDTO = new CharacterInfoQuestionsDTO(); lCharacterInfoQuestionsDTO.setId(lIntIdCharacter); lCharacterInfoQuestionsDTO.setCharacterInfoQuestions(pCharacterInfoQuestions); switch (pCharacterInfoQuestions) { case BEHAVIORS: lCharacterInfoQuestionsDTO.setFreeText(lCharacters.getBehaviorsFreeText()); lCharacterInfoQuestionsDTO .setTaskStatus(TaskStatus.getTaskStatusFromValue(lCharacters.getBehaviorsTaskStatus())); lCharacterInfoQuestionsDTO .setInterviewMode(lCharacters.getBehaviorsInterview().equals("Y") ? true : false); break; case IDEAS: lCharacterInfoQuestionsDTO.setFreeText(lCharacters.getIdeasFreeText()); lCharacterInfoQuestionsDTO .setTaskStatus(TaskStatus.getTaskStatusFromValue(lCharacters.getIdeasTaskStatus())); lCharacterInfoQuestionsDTO .setInterviewMode(lCharacters.getIdeasInterview().equals("Y") ? true : false); break; case PERSONAL_DATA: lCharacterInfoQuestionsDTO.setFreeText(lCharacters.getPersonalDataFreeText()); lCharacterInfoQuestionsDTO .setTaskStatus(TaskStatus.getTaskStatusFromValue(lCharacters.getPersonalDataTaskStatus())); lCharacterInfoQuestionsDTO .setInterviewMode(lCharacters.getPersonalDataInterview().equals("Y") ? true : false); break; case PHYSIONOMY: lCharacterInfoQuestionsDTO.setFreeText(lCharacters.getPhysionomyFreeText()); lCharacterInfoQuestionsDTO .setTaskStatus(TaskStatus.getTaskStatusFromValue(lCharacters.getPhysionomyTaskStatus())); lCharacterInfoQuestionsDTO .setInterviewMode(lCharacters.getPhysionomyInterview().equals("Y") ? true : false); break; case PSYCHOLOGY: lCharacterInfoQuestionsDTO.setFreeText(lCharacters.getPsychologyFreeText()); lCharacterInfoQuestionsDTO .setTaskStatus(TaskStatus.getTaskStatusFromValue(lCharacters.getPsychologyTaskStatus())); lCharacterInfoQuestionsDTO .setInterviewMode(lCharacters.getPsychologyInterview().equals("Y") ? true : false); break; case SOCIOLOGY: lCharacterInfoQuestionsDTO.setFreeText(lCharacters.getSociologyFreeText()); lCharacterInfoQuestionsDTO .setTaskStatus(TaskStatus.getTaskStatusFromValue(lCharacters.getSociologyTaskStatus())); lCharacterInfoQuestionsDTO .setInterviewMode(lCharacters.getSociologyInterview().equals("Y") ? true : false); break; default: break; } // get answers CharacterInfosExample lCharacterInfosExample = new CharacterInfosExample(); lCharacterInfosExample.createCriteria().andCharacterInfoTypeEqualTo(pCharacterInfoQuestions.name()) .andIdCharacterEqualTo(lCharacters.getIdCharacter().intValue()); lCharacterInfosExample.setOrderByClause("question"); CharacterInfosMapper lCharacterInfosMapper = lSqlSession.getMapper(CharacterInfosMapper.class); List<CharacterInfos> lListCharacterInfos = lCharacterInfosMapper .selectByExampleWithBLOBs(lCharacterInfosExample); List<String> lListAnswers = new ArrayList<String>(); for (CharacterInfos lCharacterInfos : lListCharacterInfos) { lListAnswers.add(StringUtils.defaultString(lCharacterInfos.getInfo())); } lCharacterInfoQuestionsDTO.setAnswerList(lListAnswers); } catch (Throwable t) { mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End loadCharacterInfo(CharacterInfoQuestions, Integer)"); return lCharacterInfoQuestionsDTO; }
From source file:com.bibisco.manager.CharacterManager.java
License:GNU General Public License
public static CharacterInfoWithoutQuestionsDTO loadCharacterInfoWithoutQuestions( CharacterInfoWithoutQuestions pCharacterInfoWithoutQuestions, Integer lIntIdCharacter) { CharacterInfoWithoutQuestionsDTO lCharacterInfoWithoutQuestionsDTO; mLog.debug("Start loadCharacterInfoWithoutQuestions(CharacterInfoWithoutQuestions, Integer)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/*from ww w. j av a 2 s .co m*/ CharactersMapper lCharactersMapper = lSqlSession.getMapper(CharactersMapper.class); CharactersWithBLOBs lCharacters = lCharactersMapper.selectByPrimaryKey(lIntIdCharacter.longValue()); lCharacterInfoWithoutQuestionsDTO = new CharacterInfoWithoutQuestionsDTO(); lCharacterInfoWithoutQuestionsDTO.setId(lIntIdCharacter); lCharacterInfoWithoutQuestionsDTO.setCharacterInfoWithoutQuestions(pCharacterInfoWithoutQuestions); switch (pCharacterInfoWithoutQuestions) { case CONFLICT: lCharacterInfoWithoutQuestionsDTO .setTaskStatus(TaskStatus.getTaskStatusFromValue(lCharacters.getConflictTaskStatus())); lCharacterInfoWithoutQuestionsDTO.setInfo(lCharacters.getConflict()); break; case EVOLUTION_DURING_THE_STORY: lCharacterInfoWithoutQuestionsDTO.setTaskStatus( TaskStatus.getTaskStatusFromValue(lCharacters.getEvolutionduringthestoryTaskStatus())); lCharacterInfoWithoutQuestionsDTO.setInfo(lCharacters.getEvolutionduringthestory()); break; case LIFE_BEFORE_STORY_BEGINNING: lCharacterInfoWithoutQuestionsDTO.setTaskStatus( TaskStatus.getTaskStatusFromValue(lCharacters.getLifebeforestorybeginningTaskStatus())); lCharacterInfoWithoutQuestionsDTO.setInfo(lCharacters.getLifebeforestorybeginning()); break; default: break; } } catch (Throwable t) { mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End loadCharacterInfoWithoutQuestions(CharacterInfoWithoutQuestions, Integer)"); return lCharacterInfoWithoutQuestionsDTO; }
From source file:com.bibisco.manager.CharacterManager.java
License:GNU General Public License
public static void saveCharacterInfoQuestions(CharacterInfoQuestionsDTO pCharacterInfoQuestionsDTO) { mLog.debug("Start saveCharacterInfoQuestions(CharacterInfoQuestionsDTO)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {//w w w . j a v a2 s. com //update characters table CharactersWithBLOBs lCharacters = new CharactersWithBLOBs(); lCharacters.setIdCharacter(pCharacterInfoQuestionsDTO.getId().longValue()); switch (pCharacterInfoQuestionsDTO.getCharacterInfoQuestions()) { case BEHAVIORS: lCharacters.setBehaviorsFreeText(pCharacterInfoQuestionsDTO.getFreeText()); lCharacters.setBehaviorsInterview(pCharacterInfoQuestionsDTO.getInterviewMode() ? "Y" : "N"); lCharacters.setBehaviorsTaskStatus(pCharacterInfoQuestionsDTO.getTaskStatus().getValue()); break; case IDEAS: lCharacters.setIdeasFreeText(pCharacterInfoQuestionsDTO.getFreeText()); lCharacters.setIdeasInterview(pCharacterInfoQuestionsDTO.getInterviewMode() ? "Y" : "N"); lCharacters.setIdeasTaskStatus(pCharacterInfoQuestionsDTO.getTaskStatus().getValue()); break; case PERSONAL_DATA: lCharacters.setPersonalDataFreeText(pCharacterInfoQuestionsDTO.getFreeText()); lCharacters.setPersonalDataInterview(pCharacterInfoQuestionsDTO.getInterviewMode() ? "Y" : "N"); lCharacters.setPersonalDataTaskStatus(pCharacterInfoQuestionsDTO.getTaskStatus().getValue()); break; case PHYSIONOMY: lCharacters.setPhysionomyFreeText(pCharacterInfoQuestionsDTO.getFreeText()); lCharacters.setPhysionomyInterview(pCharacterInfoQuestionsDTO.getInterviewMode() ? "Y" : "N"); lCharacters.setPhysionomyTaskStatus(pCharacterInfoQuestionsDTO.getTaskStatus().getValue()); break; case PSYCHOLOGY: lCharacters.setPsychologyFreeText(pCharacterInfoQuestionsDTO.getFreeText()); lCharacters.setPsychologyInterview(pCharacterInfoQuestionsDTO.getInterviewMode() ? "Y" : "N"); lCharacters.setPsychologyTaskStatus(pCharacterInfoQuestionsDTO.getTaskStatus().getValue()); break; case SOCIOLOGY: lCharacters.setSociologyFreeText(pCharacterInfoQuestionsDTO.getFreeText()); lCharacters.setSociologyInterview(pCharacterInfoQuestionsDTO.getInterviewMode() ? "Y" : "N"); lCharacters.setSociologyTaskStatus(pCharacterInfoQuestionsDTO.getTaskStatus().getValue()); break; default: break; } CharactersMapper lCharactersMapper = lSqlSession.getMapper(CharactersMapper.class); lCharactersMapper.updateByPrimaryKeySelective(lCharacters); //update character info table CharacterInfosMapper lCharacterInfosMapper = lSqlSession.getMapper(CharacterInfosMapper.class); CharacterInfosExample lCharacterInfosExample = new CharacterInfosExample(); lCharacterInfosExample.createCriteria() .andCharacterInfoTypeEqualTo(pCharacterInfoQuestionsDTO.getCharacterInfoQuestions().name()) .andIdCharacterEqualTo(pCharacterInfoQuestionsDTO.getId()); lCharacterInfosMapper.deleteByExample(lCharacterInfosExample); for (int i = 1; i <= pCharacterInfoQuestionsDTO.getAnswerList().size(); i++) { CharacterInfos lCharacterInfos = new CharacterInfos(); lCharacterInfos.setCharacterInfoType(pCharacterInfoQuestionsDTO.getCharacterInfoQuestions().name()); lCharacterInfos.setIdCharacter(pCharacterInfoQuestionsDTO.getId()); lCharacterInfos.setQuestion(i); lCharacterInfos.setInfo(pCharacterInfoQuestionsDTO.getAnswerList().get(i - 1)); lCharacterInfosMapper.insert(lCharacterInfos); } lSqlSession.commit(); } catch (Throwable t) { mLog.error(t); lSqlSession.rollback(); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End saveCharacterInfoQuestions(CharacterInfoQuestionsDTO)"); }
From source file:com.bibisco.manager.CharacterManager.java
License:GNU General Public License
public static void saveCharacterInfoWithoutQuestions( CharacterInfoWithoutQuestionsDTO pCharacterInfoWithoutQuestionsDTO) { mLog.debug("Start saveCharacterInfoWithoutQuestions(CharacterInfoQuestionsDTO)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/* w w w . j a va 2s.c om*/ //update characters table CharactersWithBLOBs lCharacters = new CharactersWithBLOBs(); lCharacters.setIdCharacter(pCharacterInfoWithoutQuestionsDTO.getId().longValue()); switch (pCharacterInfoWithoutQuestionsDTO.getCharacterInfoWithoutQuestions()) { case CONFLICT: lCharacters.setConflict(pCharacterInfoWithoutQuestionsDTO.getInfo()); lCharacters.setConflictTaskStatus(pCharacterInfoWithoutQuestionsDTO.getTaskStatus().getValue()); break; case EVOLUTION_DURING_THE_STORY: lCharacters.setEvolutionduringthestory(pCharacterInfoWithoutQuestionsDTO.getInfo()); lCharacters.setEvolutionduringthestoryTaskStatus( pCharacterInfoWithoutQuestionsDTO.getTaskStatus().getValue()); break; case LIFE_BEFORE_STORY_BEGINNING: lCharacters.setLifebeforestorybeginning(pCharacterInfoWithoutQuestionsDTO.getInfo()); lCharacters.setLifebeforestorybeginningTaskStatus( pCharacterInfoWithoutQuestionsDTO.getTaskStatus().getValue()); break; default: break; } CharactersMapper lCharactersMapper = lSqlSession.getMapper(CharactersMapper.class); lCharactersMapper.updateByPrimaryKeySelective(lCharacters); lSqlSession.commit(); } catch (Throwable t) { mLog.error(t); lSqlSession.rollback(); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End saveCharacterInfoWithoutQuestions(CharacterInfoQuestionsDTO)"); }
From source file:com.bibisco.manager.CharacterManager.java
License:GNU General Public License
public static void changeCharacterName(CharacterDTO pCharacterDTO) { mLog.debug("Start save(CharacterDTO)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/*w w w . j av a 2 s .c o m*/ CharactersWithBLOBs lCharacters = new CharactersWithBLOBs(); lCharacters.setIdCharacter(pCharacterDTO.getIdCharacter().longValue()); lCharacters.setName(pCharacterDTO.getName()); CharactersMapper lCharactersMapper = lSqlSession.getMapper(CharactersMapper.class); lCharactersMapper.updateByPrimaryKeySelective(lCharacters); lSqlSession.commit(); } catch (Throwable t) { mLog.error(t); lSqlSession.rollback(); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End save(CharacterDTO)"); }
From source file:com.bibisco.manager.CharacterManager.java
License:GNU General Public License
public static SecondaryCharacterDTO loadSecondaryCharacter(Integer lIntIdCharacter) { SecondaryCharacterDTO lSecondaryCharacterDTO = null; mLog.debug("Start loadSecondaryCharacter(Integer)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/* ww w.ja v a 2 s . c om*/ CharactersMapper lCharactersMapper = lSqlSession.getMapper(CharactersMapper.class); CharactersWithBLOBs lCharacters = lCharactersMapper.selectByPrimaryKey(lIntIdCharacter.longValue()); lSecondaryCharacterDTO = createSecondaryCharacterDTOFromCharacters(lCharacters); lSecondaryCharacterDTO.setDescription(lCharacters.getSecondaryCharacterDescription()); } catch (Throwable t) { mLog.error(t); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End loadSecondaryCharacter(Integer)"); return lSecondaryCharacterDTO; }
From source file:com.bibisco.manager.CharacterManager.java
License:GNU General Public License
public static void saveSecondaryCharacter(SecondaryCharacterDTO pSecondaryCharacterDTO) { mLog.debug("Start saveSecondaryCharacter(SecondaryCharacterDTO)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {// ww w. ja v a 2s . co m CharactersWithBLOBs lCharacters = new CharactersWithBLOBs(); lCharacters.setIdCharacter(pSecondaryCharacterDTO.getIdCharacter().longValue()); lCharacters.setSecondaryCharacterDescription(pSecondaryCharacterDTO.getDescription()); lCharacters .setSecondaryCharacterDescriptionTaskStatus(pSecondaryCharacterDTO.getTaskStatus().getValue()); CharactersMapper lCharactersMapper = lSqlSession.getMapper(CharactersMapper.class); lCharactersMapper.updateByPrimaryKeySelective(lCharacters); lSqlSession.commit(); } catch (Throwable t) { mLog.error(t); lSqlSession.rollback(); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End saveSecondaryCharacter(SecondaryCharacterDTO)"); }
From source file:com.bibisco.manager.HttpManager.java
License:GNU General Public License
private static boolean showMessage(WebMessage pWebMessage) { boolean lBlnResult = false; mLog.debug("Start showMessage(WebMessage)"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryBibisco(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/* ww w. j a va2 s .c om*/ MessagesMapper lMessagesMapper = lSqlSession.getMapper(MessagesMapper.class); Messages lMessages = lMessagesMapper.selectByPrimaryKey(pWebMessage.getIdMessage()); if (lMessages != null) { // message already read: check if i can show another time if (lMessages.getNumberOfViews() < pWebMessage.getNumberOfViewsAllowed()) { lMessages.setNumberOfViews(lMessages.getNumberOfViews() + 1); lMessagesMapper.updateByPrimaryKey(lMessages); lBlnResult = true; } else { lBlnResult = false; } } else { // message not read lMessages = new Messages(); lMessages.setIdMessage(pWebMessage.getIdMessage()); lMessages.setNumberOfViews(1); lMessagesMapper.insert(lMessages); lBlnResult = true; } lSqlSession.commit(); } catch (Throwable t) { mLog.error(t); lSqlSession.rollback(); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("End showMessage(WebMessage)"); return lBlnResult; }
From source file:com.bibisco.manager.ImageManager.java
License:GNU General Public License
public static ImageDTO insert(ImageDTO pImageDTO) { mLog.debug("Start insert(ImageDTO)"); // validate preconditions Validate.notNull(pImageDTO, "argument ImageDTO cannot be null"); Validate.notNull(pImageDTO.getIdElement(), "argument ImageDTO.idElement cannot be null"); Validate.notNull(pImageDTO.getElementType(), "argument ImageDTO.elementType cannot be null"); Validate.notNull(pImageDTO.getInputStream(), "argument ImageDTO.inputStream cannot be null"); Validate.notEmpty(pImageDTO.getSourceFileName(), "argument ImageDTO.sourceFileName cannot be empty"); Validate.notEmpty(pImageDTO.getDescription(), "argument ImageDTO.description cannot be empty"); SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject(); SqlSession lSqlSession = lSqlSessionFactory.openSession(); try {/*from ww w .j av a2 s . c om*/ // write file to file system String lStrFileName = writeFile(pImageDTO); Images lImages = new Images(); lImages.setDescription(pImageDTO.getDescription()); lImages.setIdElement(pImageDTO.getIdElement()); lImages.setElementType(pImageDTO.getElementType().getValue()); lImages.setFileName(lStrFileName); ImagesMapper lImagesMapper = lSqlSession.getMapper(ImagesMapper.class); lImagesMapper.insert(lImages); pImageDTO.setIdImage(lImages.getIdImage().intValue()); pImageDTO.setTargetFileName(lStrFileName); lSqlSession.commit(); } catch (Throwable t) { mLog.error(t); lSqlSession.rollback(); throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION); } finally { lSqlSession.close(); } mLog.debug("Start insert(ImageDTO)"); return pImageDTO; }