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

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

Introduction

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

Prototype

void commit();

Source Link

Document

Flushes batch statements and commits database connection.

Usage

From source file:net.landora.video.preferences.PreferencesDBA.java

License:Open Source License

public static void setPreferenceValue(String content, String prefName, String prefValue) {
    SqlSession session = null;

    try {/*w  ww  .j  a  v a  2 s. c  o  m*/
        session = PreferencesDataManager.getInstance().openSession();
        PreferencesMapper mapper = session.getMapper(PreferencesMapper.class);

        if (mapper.updatePreference(content, prefName, prefValue) == 0) {
            mapper.insertPreference(content, prefName, prefValue);
        }

        session.commit();
    } catch (Exception e) {
        log.error("Error saving preferences.", e);
        session.rollback();
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:net.nexxus.db.DBManagerImpl.java

License:Open Source License

public void updateHeader(NntpArticleHeader header) {
    try {//from w  ww. j a  v  a2  s .  co m
        SqlSession session = sqlFactory.openSession();
        HashMap map = DBUtils.mapHeaderForUpdate(header);
        session.update("updateStatus", map);
        session.commit();
        session.close();
    } catch (Exception e) {
        log.error("could not update header in database: " + e.getMessage());
    }

}

From source file:net.nexxus.db.DBManagerImpl.java

License:Open Source License

/**
 * create the NntpGroup List table to keep track of groups
 * that are being used//  w  w w.  ja v  a2 s . c  o m
 */
public void createServerGroups() throws Exception {
    SqlSession session = sqlFactory.openSession();
    session.insert("createGroupsTable", groupsTable);
    session.commit();
    session.close();
}

From source file:net.nexxus.db.DBManagerImpl.java

License:Open Source License

/**
 * add an NntpGroup to our groups list// w ww  . ja  v  a2  s  .  c  om
 */
public void addGroup(NntpGroup group) throws Exception {
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("table", groupsTable);
    map.put("server", group.getServer());
    map.put("name", group.getName());
    map.put("hi", group.getHighID());
    map.put("low", group.getLowID());

    SqlSession session = sqlFactory.openSession();
    session.insert("addGroup", map);

    // now ensure there is an ArticleHeader table for it
    session.insert("createHeaderTable", DBUtils.convertGroup(group.getName()));

    session.commit();
    session.close();
}

From source file:net.nexxus.db.DBManagerImpl.java

License:Open Source License

/**
 * update an NntpGroup in our groups list
 *///  w w w  .  j  a va 2s . c o m
public void updateGroup(NntpGroup group) throws Exception {
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("table", groupsTable);
    map.put("name", group.getName());
    map.put("auto_update", group.isAutoUpdate());
    map.put("hi", group.getHighID());
    map.put("low", group.getLowID());

    SqlSession session = sqlFactory.openSession();
    session.update("updateGroup", map);

    session.commit();
    session.close();
}

From source file:net.nexxus.db.DBManagerImpl.java

License:Open Source License

/**
 * remove an NntpGroup from our groups list
 */// ww  w.  j a  va2  s. co  m
public void removeGroup(NntpGroup group) throws Exception {
    HashMap<String, String> map = new HashMap<String, String>();
    map.put("table", groupsTable);
    map.put("name", group.getName());

    SqlSession session = sqlFactory.openSession();
    session.insert("removeGroup", map);
    session.commit();
    session.close();
}

From source file:net.nexxus.db.DBManagerImpl.java

License:Open Source License

/**
 * create Server group list table/*from  w ww . j a v a2  s. c  o m*/
 * @throws Exception
 */
public void createServerGroupList() throws Exception {
    SqlSession session = sqlFactory.openSession();
    session.insert("createGroupListTable");
    session.commit();
    session.close();
}

From source file:net.nexxus.db.DBManagerImpl.java

License:Open Source License

/**
 * add an NntpGroup to an NntpServers group listing
 * @param group//from w w  w  . j a va 2 s .  c o m
 * @throws Exception
 */
public void addServerGroup(NntpGroup group) throws Exception {
    HashMap map = new HashMap();
    map.put("name", group.getName());
    map.put("hi", group.getHighID());
    map.put("low", group.getLowID());

    SqlSession session = sqlFactory.openSession();
    session.insert("addGroupToGroupList", map);
    session.commit();
    session.close();
}

From source file:net.nexxus.db.DBManagerImpl.java

License:Open Source License

public void addServerGroups(List<NntpGroup> groups) throws Exception {
    HashMap map = new HashMap();
    SqlSession session = sqlFactory.openSession();
    Iterator<NntpGroup> iter = groups.iterator();
    while (iter.hasNext()) {
        NntpGroup group = iter.next();// w w w  .  ja v  a 2  s .  co  m
        map.put("name", group.getName());
        map.put("hi", group.getHighID());
        map.put("low", group.getLowID());
        session.insert("addGroupToGroupList", map);
    }
    session.commit();
    session.close();
}

From source file:net.nexxus.db.DBManagerImpl.java

License:Open Source License

/**
 * create the needed DB table to hold our 
 * NntpServer entities /*from  www  . j  a  va  2  s .c  o  m*/
 */
public void createServerTable() throws Exception {
    SqlSession session = sqlFactory.openSession();
    session.insert("createServerTable", serverTable);
    session.commit();
    session.close();
}