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

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

Introduction

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

Prototype

int update(String statement, Object parameter);

Source Link

Document

Execute an update statement.

Usage

From source file:webim.dao.ibatis.WebimSettingDao.java

License:Apache License

/**
 * ??MySQL?: <br>/*from w  w w  .  ja  v  a 2  s.c  om*/
 * 
 * "update webim_settings set data = ?  where uid = ?" <br>
 * 
 * ??????
 * 
 * @param uid
 *            uid
 * @param data
 *            ??JSON?
 */
public void set(String uid, String data) {
    Map<String, Object> map = new HashMap<String, Object>();
    Date now = new Date();
    map.put("uid", uid);
    map.put("data", data);
    map.put("created", now);
    map.put("updated", now);
    SqlSession session = sessionFactory.openSession();
    try {
        String oldData = (String) session.selectOne("SettingMapper.getSetting", uid);
        if (oldData == null) {
            session.insert("SettingMapper.insertSetting", map);
        } else {
            session.update("SettingMapper.updateSetting", map);
        }
        session.commit();
    } finally {
        session.close();
    }
}