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

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

Introduction

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

Prototype

<T> T getMapper(Class<T> type);

Source Link

Document

Retrieves a mapper.

Usage

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  ww.  ja v a  2  s. c o  m
        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   w w  w .ja v a2  s .  c o 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

private static boolean checkIfReferenced(Integer pIntIdStrand, SqlSession pSqlSession) {

    boolean lBlnResult = false;

    mLog.debug("Start checkIfReferenced(Integer, SqlSession)");

    SceneRevisionStrandsExample lSceneRevisionStrandExample = new SceneRevisionStrandsExample();
    lSceneRevisionStrandExample.createCriteria().andIdStrandEqualTo(pIntIdStrand);
    SceneRevisionStrandsMapper lSceneRevisionStrandsMapper = pSqlSession
            .getMapper(SceneRevisionStrandsMapper.class);
    List<SceneRevisionStrandsKey> lSceneRevisionStrandsKeyList = lSceneRevisionStrandsMapper
            .selectByExample(lSceneRevisionStrandExample);

    if (lSceneRevisionStrandsKeyList != null && lSceneRevisionStrandsKeyList.size() > 0) {
        lBlnResult = true;/*w  ww  .  j  a  v a 2 s  . c om*/
    } else {
        lBlnResult = false;
    }

    mLog.debug("End checkIfReferenced(Integer, SqlSession): return " + lBlnResult);

    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 {//  ww w .  j  a  v  a2s  .co  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 w  w  . j av a  2  s  . c o 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 {//www . ja  v a 2  s.  c  om
        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 ww  w  .  j a  v a  2s  .c o  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;
    }/* ww  w .  jav a 2 s .  c  om*/

    // 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;
        }
    }
}

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

License:GNU General Public License

public static void disableTip(String pStrTipCode) {

    mLog.debug("Start disableTip(" + pStrTipCode + ")");

    SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryBibisco();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {/* ww w  . ja v  a  2  s  .co m*/
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);

        Properties lProperties = new Properties();
        lProperties.setProperty(pStrTipCode);
        lProperties.setValue("false");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

        lSqlSession.commit();

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

    mLog.debug("End disableTip(" + pStrTipCode + ")");
}

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

License:GNU General Public License

private String initVersion() {

    String lStrVersion = null;/*from w w  w.ja  va 2 s  . c om*/

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

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

        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        Properties lProperties = lPropertiesMapper.selectByPrimaryKey("version");

        if (lProperties != null) {
            lStrVersion = lProperties.getValue();
        }

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

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

    return lStrVersion;
}