Example usage for org.apache.ibatis.session SqlSession close

List of usage examples for org.apache.ibatis.session SqlSession close

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSession close.

Prototype

@Override
void close();

Source Link

Document

Closes the session.

Usage

From source file:com.bibisco.manager.SceneManager.java

License:GNU General Public License

public static void delete(Integer pIntIdScene) {

    mLog.debug("Start delete(Integer)");

    SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {/*from  www  . j a  va2s  . c om*/

        // load scene
        ScenesMapper lScenesMapper = lSqlSession.getMapper(ScenesMapper.class);
        Scenes lScenes = lScenesMapper.selectByPrimaryKey(pIntIdScene.longValue());

        // load all scene revisions
        SceneRevisionsExample lSceneRevisionsExample = new SceneRevisionsExample();
        lSceneRevisionsExample.createCriteria().andIdSceneEqualTo(lScenes.getIdScene().intValue());
        SceneRevisionsMapper lSceneRevisionsMapper = lSqlSession.getMapper(SceneRevisionsMapper.class);
        List<SceneRevisions> lListSceneRevisions = lSceneRevisionsMapper
                .selectByExample(lSceneRevisionsExample);

        // delete all scene revision characters and all scene revision strands
        SceneRevisionCharactersMapper lSceneRevisionCharactersMapper = lSqlSession
                .getMapper(SceneRevisionCharactersMapper.class);
        SceneRevisionStrandsMapper lSceneRevisionStrandsMapper = lSqlSession
                .getMapper(SceneRevisionStrandsMapper.class);
        for (SceneRevisions lSceneRevisions : lListSceneRevisions) {
            SceneRevisionCharactersExample lSceneRevisionCharactersExample = new SceneRevisionCharactersExample();
            lSceneRevisionCharactersExample.createCriteria()
                    .andIdSceneRevisionEqualTo(lSceneRevisions.getIdSceneRevision().intValue());
            lSceneRevisionCharactersMapper.deleteByExample(lSceneRevisionCharactersExample);

            SceneRevisionStrandsExample lSceneRevisionStrandsExample = new SceneRevisionStrandsExample();
            lSceneRevisionStrandsExample.createCriteria()
                    .andIdSceneRevisionEqualTo(lSceneRevisions.getIdSceneRevision().intValue());
            lSceneRevisionStrandsMapper.deleteByExample(lSceneRevisionStrandsExample);
        }

        // delete all scene revisions
        lSceneRevisionsMapper.deleteByExample(lSceneRevisionsExample);

        // delete scene
        lScenesMapper.deleteByPrimaryKey(lScenes.getIdScene());

        // shift down scenes
        lScenesMapper.shiftDown(lScenes.getPosition(), Integer.MAX_VALUE, lScenes.getIdChapter());

        lSqlSession.commit();

    } catch (Throwable t) {
        mLog.error(t);
        lSqlSession.rollback();
        throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION);
    } finally {
        lSqlSession.close();
    }

    mLog.debug("End delete(Integer)");

}

From source file:com.bibisco.manager.SceneManager.java

License:GNU General Public License

public static SceneRevisionDTO changeRevision(Integer pIntIdScene, Integer pIntNewRevision) {

    SceneRevisionDTO lSceneRevisionDTO = null;

    mLog.debug("Start changeRevision(" + pIntIdScene, "," + pIntNewRevision, ")");

    SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {// w  w  w.j av a 2s . c  om

        SceneRevisionsMapper lSceneRevisionsMapper = lSqlSession.getMapper(SceneRevisionsMapper.class);

        // deselect all revisions
        deselectAllRevisions(lSqlSession, pIntIdScene);

        // select new revision
        SceneRevisions lSceneRevisions = new SceneRevisions();
        lSceneRevisions.setIdSceneRevision(pIntNewRevision.longValue());
        lSceneRevisions.setSelected("Y");
        lSceneRevisionsMapper.updateByPrimaryKeySelective(lSceneRevisions);

        // reload scene with new revision
        lSceneRevisionDTO = load(lSqlSession, pIntIdScene);

        lSqlSession.commit();

    } catch (Throwable t) {
        mLog.error(t);
        lSqlSession.rollback();
        throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION);
    } finally {
        lSqlSession.close();
    }

    mLog.debug("End changeRevision(" + pIntIdScene, "," + pIntNewRevision, ")");

    return lSceneRevisionDTO;
}

From source file:com.bibisco.manager.SceneManager.java

License:GNU General Public License

public static SceneDTO insert(SceneDTO pSceneDTO) {

    mLog.debug("Start insert(SceneDTO)");

    SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {/*from   www .  j a  va2  s  .  c  o  m*/

        // Insert scene
        Scenes lScenes = new Scenes();
        lScenes.setIdChapter(pSceneDTO.getIdChapter());
        lScenes.setDescription(pSceneDTO.getDescription());
        lScenes.setPosition(pSceneDTO.getPosition());

        ScenesMapper lScenesMapper = lSqlSession.getMapper(ScenesMapper.class);
        lScenesMapper.insertSelective(lScenes);

        pSceneDTO.setIdScene(lScenes.getIdScene().intValue());
        pSceneDTO.setTaskStatus(TaskStatus.TODO);

        // insert scene revision
        SceneRevisions lSceneRevisions = new SceneRevisions();
        lSceneRevisions.setIdScene(lScenes.getIdScene().intValue());
        lSceneRevisions.setRevisionNumber(1);
        lSceneRevisions.setSelected("Y");
        lSceneRevisions.setWords(0);
        lSceneRevisions.setCharacters(0);

        SceneRevisionsMapper lSceneRevisionsMapper = lSqlSession.getMapper(SceneRevisionsMapper.class);
        lSceneRevisionsMapper.insert(lSceneRevisions);

        lSqlSession.commit();

    } catch (Throwable t) {
        mLog.error(t);
        lSqlSession.rollback();
        throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION);
    } finally {
        lSqlSession.close();
    }

    mLog.debug("End insert(SceneRevisionDTO)");

    return pSceneDTO;
}

From source file:com.bibisco.manager.SceneManager.java

License:GNU General Public License

public static void move(Integer pIntIdScene, Integer pIntDestPosition) {

    mLog.debug("Start move(Integer, Integer)");

    SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();

    try {//from w ww . j  a  v a  2 s  .  com

        // get scene to update
        ScenesMapper lScenesMapper = lSqlSession.getMapper(ScenesMapper.class);
        Scenes lScenes = lScenesMapper.selectByPrimaryKey(pIntIdScene.longValue());
        Integer pIntSourcePosition = lScenes.getPosition();

        if (pIntSourcePosition.intValue() != pIntDestPosition.intValue()) {

            // update scene position with fake position to preserve unique index before shift
            lScenes.setPosition(-1);
            lScenesMapper.updateByPrimaryKey(lScenes);

            // update other scenes' position
            Integer lIntStartPosition;
            Integer lIntEndPosition;
            if (pIntSourcePosition > pIntDestPosition) {
                lIntStartPosition = pIntDestPosition;
                lIntEndPosition = pIntSourcePosition;
                lScenesMapper.shiftUp(lIntStartPosition, lIntEndPosition, lScenes.getIdChapter());
            } else {
                lIntStartPosition = pIntSourcePosition;
                lIntEndPosition = pIntDestPosition;
                lScenesMapper.shiftDown(lIntStartPosition, lIntEndPosition, lScenes.getIdChapter());
            }

            // update scene position
            lScenes.setPosition(pIntDestPosition);
            lScenesMapper.updateByPrimaryKey(lScenes);

            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.SceneManager.java

License:GNU General Public License

public static void save(SceneDTO pSceneDTO) {

    mLog.debug("Start save(SceneDTO)");

    SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {/*  w w  w.ja va  2  s  . co m*/

        Scenes lScenes = new Scenes();
        lScenes.setIdScene(pSceneDTO.getIdScene().longValue());
        lScenes.setPosition(pSceneDTO.getPosition());
        lScenes.setDescription(pSceneDTO.getDescription());
        lScenes.setIdChapter(pSceneDTO.getIdChapter());
        lScenes.setTaskStatus(pSceneDTO.getTaskStatus() != null ? pSceneDTO.getTaskStatus().getValue() : null);

        ScenesMapper lScenesMapper = lSqlSession.getMapper(ScenesMapper.class);
        lScenesMapper.updateByPrimaryKeySelective(lScenes);

        lSqlSession.commit();

    } catch (Throwable t) {
        mLog.error(t);
        lSqlSession.rollback();
        throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION);
    } finally {
        lSqlSession.close();
    }

    mLog.debug("End save(SceneDTO)");
}

From source file:com.bibisco.manager.SceneManager.java

License:GNU General Public License

public static void save(SceneRevisionDTO pSceneRevisionDTO) {

    mLog.debug("Start save(SceneDTO)");

    SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {/*from   w  ww  . j ava 2 s .  co  m*/

        Scenes lScenes = new Scenes();
        lScenes.setIdScene(pSceneRevisionDTO.getIdScene().longValue());
        lScenes.setPosition(pSceneRevisionDTO.getPosition());
        lScenes.setTaskStatus(
                pSceneRevisionDTO.getTaskStatus() != null ? pSceneRevisionDTO.getTaskStatus().getValue()
                        : null);

        ScenesMapper lScenesMapper = lSqlSession.getMapper(ScenesMapper.class);
        lScenesMapper.updateByPrimaryKeySelective(lScenes);

        SceneRevisions lSceneRevisions = new SceneRevisions();
        lSceneRevisions.setIdScene(pSceneRevisionDTO.getIdScene());
        lSceneRevisions.setIdSceneRevision(pSceneRevisionDTO.getIdRevision().longValue());
        lSceneRevisions.setRevisionNumber(pSceneRevisionDTO.getRevision());
        lSceneRevisions.setSelected("Y");
        lSceneRevisions.setIdLocation(pSceneRevisionDTO.getIdLocation());
        lSceneRevisions.setPointOfView(
                pSceneRevisionDTO.getPointOfView() != null ? pSceneRevisionDTO.getPointOfView().getValue()
                        : null);
        lSceneRevisions.setPointOfViewIdCharacter(pSceneRevisionDTO.getIdCharacterPointOfView());
        lSceneRevisions.setScene(pSceneRevisionDTO.getText());
        lSceneRevisions.setSceneDate(pSceneRevisionDTO.getSceneDate());
        lSceneRevisions.setWords(pSceneRevisionDTO.getWordCount());
        lSceneRevisions.setCharacters(pSceneRevisionDTO.getCharacterCount());
        SceneRevisionsMapper lSceneRevisionsMapper = lSqlSession.getMapper(SceneRevisionsMapper.class);
        lSceneRevisionsMapper.updateByPrimaryKeyWithBLOBs(lSceneRevisions);

        // save characters
        SceneRevisionCharactersMapper lSceneRevisionCharactersMapper = lSqlSession
                .getMapper(SceneRevisionCharactersMapper.class);
        SceneRevisionCharactersExample lSceneRevisionCharactersExample = new SceneRevisionCharactersExample();
        lSceneRevisionCharactersExample.createCriteria()
                .andIdSceneRevisionEqualTo((pSceneRevisionDTO.getIdRevision()));
        lSceneRevisionCharactersMapper.deleteByExample(lSceneRevisionCharactersExample);

        if (pSceneRevisionDTO.getCharacters() != null && pSceneRevisionDTO.getCharacters().size() > 0) {
            for (Integer lIntIdCharacter : pSceneRevisionDTO.getCharacters()) {
                SceneRevisionCharactersKey lSceneRevisionCharactersKey = new SceneRevisionCharactersKey();
                lSceneRevisionCharactersKey.setIdCharacter(lIntIdCharacter);
                lSceneRevisionCharactersKey.setIdSceneRevision(pSceneRevisionDTO.getIdRevision());
                lSceneRevisionCharactersMapper.insert(lSceneRevisionCharactersKey);
            }
        }

        // save strands
        SceneRevisionStrandsMapper lSceneRevisionStrandsMapper = lSqlSession
                .getMapper(SceneRevisionStrandsMapper.class);
        SceneRevisionStrandsExample lSceneRevisionStrandsExample = new SceneRevisionStrandsExample();
        lSceneRevisionStrandsExample.createCriteria()
                .andIdSceneRevisionEqualTo((pSceneRevisionDTO.getIdRevision()));
        lSceneRevisionStrandsMapper.deleteByExample(lSceneRevisionStrandsExample);

        if (pSceneRevisionDTO.getStrands() != null && pSceneRevisionDTO.getStrands().size() > 0) {
            for (Integer lIntIdStrand : pSceneRevisionDTO.getStrands()) {
                SceneRevisionStrandsKey lSceneRevisionStrands = new SceneRevisionStrandsKey();
                lSceneRevisionStrands.setIdStrand(lIntIdStrand);
                lSceneRevisionStrands.setIdSceneRevision(pSceneRevisionDTO.getIdRevision());
                lSceneRevisionStrandsMapper.insert(lSceneRevisionStrands);
            }
        }

        lSqlSession.commit();

    } catch (Throwable t) {
        mLog.error(t);
        lSqlSession.rollback();
        throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION);
    } finally {
        lSqlSession.close();
    }

    mLog.debug("End save(SceneDTO)");
}

From source file:com.bibisco.manager.SceneTagsManager.java

License:GNU General Public License

/**
 * @return a Map as// ww w.  j  a  va 2  s  .c  o m
 * 
 *                 Chapter.1 Chapter.2 Chapter.3
 * - character.1 -     X         X
 * - character.2 -               X
 * - character.3 -     X         X          
 * 
 */
public static Map<String, List<Boolean>> getCharactersChaptersPresence() {

    Map<String, List<Boolean>> lMapCharacterChapterPresence = new HashMap<String, List<Boolean>>();

    mLog.debug("Start getCharactersChaptersDistribution()");

    List<com.bibisco.bean.CharacterDTO> lListCharacterDTO = CharacterManager.loadAll();
    List<ChapterDTO> lListChapters = ChapterManager.loadAll();

    if (CollectionUtils.isEmpty(lListCharacterDTO) || CollectionUtils.isEmpty(lListChapters)) {
        mLog.debug("End getStrandsChaptersDistribution()");
        return lMapCharacterChapterPresence;
    }

    SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {

        VSceneTagsMapper lVSceneTagsMapper = lSqlSession.getMapper(VSceneTagsMapper.class);
        VSceneTagsExample lVSceneTagsExample = new VSceneTagsExample();
        lVSceneTagsExample.setOrderByClause("chapter_position, id_character");
        List<VSceneTags> lListVSceneTags = lVSceneTagsMapper.selectByExample(lVSceneTagsExample);

        if (lListVSceneTags != null && lListVSceneTags.size() > 0) {

            Map<Integer, Set<Integer>> lMapCharactersChaptersDistribution = new HashMap<Integer, Set<Integer>>();
            int lIntLastChapter = -1;
            Set<Integer> lSetChapterCharacters = null;

            // filter duplicate items using a set
            for (VSceneTags lVSceneTags : lListVSceneTags) {
                if (lVSceneTags.getChapterPosition().intValue() != lIntLastChapter) {
                    lSetChapterCharacters = new HashSet<Integer>();
                    lMapCharactersChaptersDistribution.put(lVSceneTags.getChapterPosition(),
                            lSetChapterCharacters);
                    lIntLastChapter = lVSceneTags.getChapterPosition();
                }
                if (lVSceneTags.getIdCharacter() != null) {
                    lSetChapterCharacters.add(lVSceneTags.getIdCharacter().intValue());
                }
            }

            // populate result map
            for (CharacterDTO lCharacterDTO : lListCharacterDTO) {
                List<Boolean> lListCharacterChapterPresence = new ArrayList<Boolean>();
                lMapCharacterChapterPresence.put(lCharacterDTO.getIdCharacter().toString(),
                        lListCharacterChapterPresence);
                for (ChapterDTO lChapterDTO : lListChapters) {
                    Set<Integer> lSetCharacters = lMapCharactersChaptersDistribution
                            .get(lChapterDTO.getPosition());
                    if (lSetCharacters != null && !lSetCharacters.isEmpty()
                            && lSetCharacters.contains(lCharacterDTO.getIdCharacter())) {
                        lListCharacterChapterPresence.add(Boolean.TRUE);
                    } else {
                        lListCharacterChapterPresence.add(Boolean.FALSE);
                    }
                }
            }
        }

    } catch (Throwable t) {
        mLog.error(t);
        throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION);
    } finally {
        lSqlSession.close();
    }

    mLog.debug("End getCharactersChaptersDistribution()");

    return lMapCharacterChapterPresence;
}

From source file:com.bibisco.manager.SceneTagsManager.java

License:GNU General Public License

/**
**
 * @return a Map as/*from  w  w w  .j  ava  2 s.com*/
 * 
 *                 Chapter.1 Chapter.2 Chapter.3
 * - location.1 -     X         X
 * - location.2 -               X
 * - location.3 -     X         X          
 * 
 */
public static Map<String, List<Boolean>> getLocationsChaptersPresence() {

    Map<String, List<Boolean>> lMapLocationChapterPresence = new HashMap<String, List<Boolean>>();

    mLog.debug("Start getLocationsChaptersDistribution()");

    List<com.bibisco.bean.LocationDTO> lListLocationDTO = LocationManager.loadAll();
    List<ChapterDTO> lListChapters = ChapterManager.loadAll();

    if (CollectionUtils.isEmpty(lListLocationDTO) || CollectionUtils.isEmpty(lListChapters)) {
        mLog.debug("End getStrandsChaptersDistribution()");
        return lMapLocationChapterPresence;
    }

    SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {

        VSceneTagsMapper lVSceneTagsMapper = lSqlSession.getMapper(VSceneTagsMapper.class);
        VSceneTagsExample lVSceneTagsExample = new VSceneTagsExample();
        lVSceneTagsExample.setOrderByClause("chapter_position, id_location");
        List<VSceneTags> lListVSceneTags = lVSceneTagsMapper.selectByExample(lVSceneTagsExample);

        if (lListVSceneTags != null && lListVSceneTags.size() > 0) {

            Map<Integer, Set<Integer>> lMapLocationsChaptersDistribution = new HashMap<Integer, Set<Integer>>();
            int lIntLastChapter = -1;
            Set<Integer> lSetChapterLocations = null;

            // filter duplicate items using a set
            for (VSceneTags lVSceneTags : lListVSceneTags) {
                if (lVSceneTags.getChapterPosition().intValue() != lIntLastChapter) {
                    lSetChapterLocations = new HashSet<Integer>();
                    lMapLocationsChaptersDistribution.put(lVSceneTags.getChapterPosition(),
                            lSetChapterLocations);
                    lIntLastChapter = lVSceneTags.getChapterPosition();
                }
                if (lVSceneTags.getIdLocation() != null) {
                    lSetChapterLocations.add(lVSceneTags.getIdLocation().intValue());
                }

            }

            // populate result map
            for (LocationDTO lLocationDTO : lListLocationDTO) {
                List<Boolean> lListLocationChapterPresence = new ArrayList<Boolean>();
                lMapLocationChapterPresence.put(lLocationDTO.getIdLocation().toString(),
                        lListLocationChapterPresence);
                for (ChapterDTO lChapterDTO : lListChapters) {
                    Set<Integer> lSetLocations = lMapLocationsChaptersDistribution
                            .get(lChapterDTO.getPosition());
                    if (lSetLocations != null && !lSetLocations.isEmpty()
                            && lSetLocations.contains(lLocationDTO.getIdLocation())) {
                        lListLocationChapterPresence.add(Boolean.TRUE);
                    } else {
                        lListLocationChapterPresence.add(Boolean.FALSE);
                    }
                }
            }
        }

    } catch (Throwable t) {
        mLog.error(t);
        throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION);
    } finally {
        lSqlSession.close();
    }

    mLog.debug("End getLocationsChaptersDistribution()");

    return lMapLocationChapterPresence;
}

From source file:com.bibisco.manager.SceneTagsManager.java

License:GNU General Public License

/**
 * @return a Map as/*from ww w  . j  a  v a2 s .c  o  m*/
 * 
 *                 Chapter.1 Chapter.2 Chapter.3
 * - strand.1 -     X         X
 * - strand.2 -               X
 * - strand.3 -     X         X          
 * 
 */
public static Map<String, List<Boolean>> getStrandsChaptersPresence() {

    Map<String, List<Boolean>> lMapStrandChapterPresence = new HashMap<String, List<Boolean>>();

    mLog.debug("Start getStrandsChaptersDistribution()");

    List<com.bibisco.bean.StrandDTO> lListStrandDTO = StrandManager.loadAll();
    List<ChapterDTO> lListChapters = ChapterManager.loadAll();

    if (CollectionUtils.isEmpty(lListStrandDTO) || CollectionUtils.isEmpty(lListChapters)) {
        mLog.debug("End getStrandsChaptersDistribution()");
        return lMapStrandChapterPresence;
    }

    SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {

        VSceneTagsMapper lVSceneTagsMapper = lSqlSession.getMapper(VSceneTagsMapper.class);
        VSceneTagsExample lVSceneTagsExample = new VSceneTagsExample();
        lVSceneTagsExample.setOrderByClause("chapter_position, id_strand");
        List<VSceneTags> lListVSceneTags = lVSceneTagsMapper.selectByExample(lVSceneTagsExample);

        if (lListVSceneTags != null && lListVSceneTags.size() > 0) {

            Map<Integer, Set<Integer>> lMapStrandsChaptersDistribution = new HashMap<Integer, Set<Integer>>();
            int lIntLastChapter = -1;
            Set<Integer> lSetChapterStrands = null;

            // filter duplicate items using a set
            for (VSceneTags lVSceneTags : lListVSceneTags) {
                if (lVSceneTags.getChapterPosition().intValue() != lIntLastChapter) {
                    lSetChapterStrands = new HashSet<Integer>();
                    lMapStrandsChaptersDistribution.put(lVSceneTags.getChapterPosition(), lSetChapterStrands);
                    lIntLastChapter = lVSceneTags.getChapterPosition();
                }
                if (lVSceneTags.getIdStrand() != null) {
                    lSetChapterStrands.add(lVSceneTags.getIdStrand().intValue());
                }

            }

            // populate result map
            for (StrandDTO lStrandDTO : lListStrandDTO) {
                List<Boolean> lListStrandChapterPresence = new ArrayList<Boolean>();
                lMapStrandChapterPresence.put(lStrandDTO.getIdStrand().toString(), lListStrandChapterPresence);
                for (ChapterDTO lChapterDTO : lListChapters) {
                    Set<Integer> lSetStrands = lMapStrandsChaptersDistribution.get(lChapterDTO.getPosition());
                    if (lSetStrands != null && !lSetStrands.isEmpty()
                            && lSetStrands.contains(lStrandDTO.getIdStrand())) {
                        lListStrandChapterPresence.add(Boolean.TRUE);
                    } else {
                        lListStrandChapterPresence.add(Boolean.FALSE);
                    }
                }
            }
        }

    } catch (Throwable t) {
        mLog.error(t);
        throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION);
    } finally {
        lSqlSession.close();
    }

    mLog.debug("End getStrandsChaptersDistribution()");

    return lMapStrandChapterPresence;
}

From source file:com.bibisco.manager.SceneTagsManager.java

License:GNU General Public License

/**
 * @return a Map as// w w  w  .j  a va  2 s . c om
 * 
 *                 Chapter.1 Chapter.2 Chapter.3
 * - pointOfView.1 -     X         X
 * - pointOfView.2 -               X
 * - pointOfView.3 -     X         X          
 * 
 */
public static Map<String, List<Boolean>> getPointOfViewsChaptersPresence() {

    Map<String, List<Boolean>> lMapPointOfViewChapterPresence = new HashMap<String, List<Boolean>>();

    mLog.debug("Start getPointOfViewsChaptersDistribution()");

    List<PointOfView4AnalysisDTO> lListPointOfViewDTO = getPointOfView4AnalysisList();
    List<ChapterDTO> lListChapters = ChapterManager.loadAll();

    SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {

        VSceneTagsMapper lVSceneTagsMapper = lSqlSession.getMapper(VSceneTagsMapper.class);
        VSceneTagsExample lVSceneTagsExample = new VSceneTagsExample();
        lVSceneTagsExample.setOrderByClause("chapter_position, point_of_view, point_of_view_id_character");
        List<VSceneTags> lListVSceneTags = lVSceneTagsMapper.selectByExample(lVSceneTagsExample);

        if (lListVSceneTags != null && lListVSceneTags.size() > 0) {

            Map<Integer, Set<String>> lMapPointOfViewsChaptersDistribution = new HashMap<Integer, Set<String>>();
            int lIntLastChapter = -1;
            Set<String> lSetChapterPointOfViews = null;

            // filter duplicate items using a set
            for (VSceneTags lVSceneTags : lListVSceneTags) {
                if (lVSceneTags.getChapterPosition().intValue() != lIntLastChapter) {
                    lSetChapterPointOfViews = new HashSet<String>();
                    lMapPointOfViewsChaptersDistribution.put(lVSceneTags.getChapterPosition(),
                            lSetChapterPointOfViews);
                    lIntLastChapter = lVSceneTags.getChapterPosition();
                }
                if (lVSceneTags.getPointOfView() != null) {
                    lSetChapterPointOfViews.add(lVSceneTags.getIdPointOfView4Analysis());
                }
            }

            // populate result map
            for (PointOfView4AnalysisDTO lPointOfView4AnalysisDTO : lListPointOfViewDTO) {
                List<Boolean> lListPointOfViewChapterPresence = new ArrayList<Boolean>();
                lMapPointOfViewChapterPresence.put(lPointOfView4AnalysisDTO.getIdPointOfView4Analysis(),
                        lListPointOfViewChapterPresence);
                for (ChapterDTO lChapterDTO : lListChapters) {
                    Set<String> lSetPointOfViews = lMapPointOfViewsChaptersDistribution
                            .get(lChapterDTO.getPosition());
                    if (lSetPointOfViews != null && !lSetPointOfViews.isEmpty() && lSetPointOfViews
                            .contains(lPointOfView4AnalysisDTO.getIdPointOfView4Analysis())) {
                        lListPointOfViewChapterPresence.add(Boolean.TRUE);
                    } else {
                        lListPointOfViewChapterPresence.add(Boolean.FALSE);
                    }
                }
            }
        }

    } catch (Throwable t) {
        mLog.error(t);
        throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION);
    } finally {
        lSqlSession.close();
    }

    mLog.debug("End getPointOfViewsChaptersDistribution()");

    return lMapPointOfViewChapterPresence;
}