當前位置: 首頁>>代碼示例>>Java>>正文


Java DbUtils.commitAndClose方法代碼示例

本文整理匯總了Java中org.apache.commons.dbutils.DbUtils.commitAndClose方法的典型用法代碼示例。如果您正苦於以下問題:Java DbUtils.commitAndClose方法的具體用法?Java DbUtils.commitAndClose怎麽用?Java DbUtils.commitAndClose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.dbutils.DbUtils的用法示例。


在下文中一共展示了DbUtils.commitAndClose方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testTokenExpired

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
@Test (expected = TokenException.class)
public void testTokenExpired() throws Exception {
    Token token = loginService.generateToken("admin");
    Assert.assertNotNull(token);

    // 修改token的有效期(設置為當前時間),讓token過期。
    long time = Calendar.getInstance().getTimeInMillis();
    Timestamp ts = new Timestamp(time);

    Token tk = new Token();
    tk.setExpiration(ts);
    Connection conn = ConnectionUtils.getConnection();
    QueryRunner run = new QueryRunner();
    String s = SQLBuilder.beanToSQLClause(tk,",");
    String sql = "Update tokens "+SQLBuilder.getSetClause(s)+" where value = '"+token.getValue()+"'";
    run.update(conn, sql);
    DbUtils.commitAndClose(conn);

    loginService.resetPassword(token.getValue(),"654321");
}
 
開發者ID:geekcheng,項目名稱:jibu,代碼行數:21,代碼來源:LoginServiceTest.java

示例2: update

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public void update(User user) throws JibuException {
    Connection conn = null;
    if (null != user.getPassword()) {
        String cryptpassword = MD5.encodeString(user.getPassword(),null);
        user.setPassword(cryptpassword);
    }

    try {
        conn = ConnectionUtils.getConnection();
        userDAO.update(conn,user);
        DbUtils.commitAndClose(conn);
    } catch(SQLException e) {
        DbUtils.rollbackAndCloseQuietly(conn);
        throw new JibuException(e.getMessage());
    }
}
 
開發者ID:geekcheng,項目名稱:jibu,代碼行數:17,代碼來源:UserServiceImpl.java

示例3: updateMe

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public void updateMe(List<Integer> ids, User user) throws JibuException {
    Connection conn = null;
    try {
        conn = ConnectionUtils.getConnection();
        if (null != user.getPassword()) {
            String cryptpassword = MD5.encodeString(user.getPassword(),null);
            user.setPassword(cryptpassword);
        }

        int uid = user.getId();
        userDAO.update(conn,user);
        settingDAO.unbindAll(conn,uid);
        Setting setting = null;
        for(Integer id:ids) {
            setting = settingDAO.get(conn,id);
            if(setting.getSortindex()!=0) {
                settingDAO.bind(conn,id,uid);
            }
        }
        // 如果選擇的是一個默認配置,不用bind
        DbUtils.commitAndClose(conn);
    } catch(SQLException e) {
        DbUtils.rollbackAndCloseQuietly(conn);
        throw new JibuException(e.getMessage());
    }
}
 
開發者ID:geekcheng,項目名稱:jibu,代碼行數:27,代碼來源:SettingServiceImpl.java

示例4: delete

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public void delete(Role role) throws JibuException {
    Connection conn = null;
    try {
        conn = ConnectionUtils.getConnection();
        role = roleDAO.get(conn,role.getId());
        if ((role.getRgt()-role.getLft()) > 1)
            throw new RoleException("The role is not leaf node.");
 roleDAO.delete(conn,role);
        DbUtils.commitAndClose(conn);
    } catch(SQLException e) {
        DbUtils.rollbackAndCloseQuietly(conn);
        throw new JibuException(e.getMessage());
    } finally {
        DbUtils.closeQuietly(conn);
    }

}
 
開發者ID:geekcheng,項目名稱:jibu,代碼行數:18,代碼來源:RoleServiceImpl.java

示例5: delete

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public void delete(Setting setting) throws JibuException {
    Connection conn = null;
    try {
        conn = ConnectionUtils.getConnection();
        if (setting.getId() == null) {
            setting = settingDAO.get(conn
                                     ,setting.getName()
                                     ,setting.getValue());
        }
        settingDAO.delete(conn,setting);
        DbUtils.commitAndClose(conn);
    } catch(SQLException e) {
        DbUtils.rollbackAndCloseQuietly(conn);
        throw new JibuException(e.getMessage());
    }
}
 
開發者ID:geekcheng,項目名稱:jibu,代碼行數:17,代碼來源:SettingServiceImpl.java

示例6: bind

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public void bind(int sid, String username) throws JibuException {
    Connection conn = null;
    try {
        conn = ConnectionUtils.getConnection();
        // 得到之前選擇的配置
        Setting setting = settingDAO.get(conn,sid);
        Setting oldSetting = settingDAO.getByUsername(conn
                                                      ,setting.getName()
                                                      ,username);
        User user = userDAO.get(conn,username);
        if(oldSetting !=null) {
            settingDAO.unbind(conn,oldSetting.getId(),user.getId());
        }

        // 如果選擇的是一個默認配置,不用bind
        if(setting.getSortindex()!=0) {
            settingDAO.bind(conn,setting.getId(),user.getId());
        }
        DbUtils.commitAndClose(conn);
    } catch(SQLException e) {
        DbUtils.rollbackAndCloseQuietly(conn);
        throw new JibuException(e.getMessage());
    }
}
 
開發者ID:geekcheng,項目名稱:jibu,代碼行數:25,代碼來源:SettingServiceImpl.java

示例7: delete

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 * <p>
 * 此操作會清空 Cache 中 authorities 對應的 value,下次請求時裝載。
 * @see #getAll()
 */
public void delete(Authority auth) throws JibuException {
    Connection conn = null;
    try {
        conn = ConnectionUtils.getConnection();
 authDAO.delete(conn,auth);
        DbUtils.commitAndClose(conn);
 Cache cache = CacheUtils.getAuthCache();
 cache.remove("authorities");
    } catch(SQLException e) {
        DbUtils.rollbackAndCloseQuietly(conn);
        throw new JibuException(e.getMessage());
    }
}
 
開發者ID:geekcheng,項目名稱:jibu,代碼行數:20,代碼來源:AuthorityServiceImpl.java

示例8: generateToken

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public Token generateToken(String username) {
    Connection conn = null;
    Token token = null;
    try {
        conn = ConnectionUtils.getConnection();
        User user = userDAO.get(conn,username);
        if (user == null) return null;

        Random randomGenerator = new Random();
        long randomLong = randomGenerator.nextLong();

        //            Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        //calendar.setTime(date);
        calendar.add(calendar.DAY_OF_MONTH, +1);
        long time = calendar.getTimeInMillis();
        Timestamp ts = new Timestamp(time);
        String key = MD5.encodeString(Long.toString(randomLong) + time, null);
        token = new Token(key,"password",ts,user.getId());

        tokenDAO.save(conn,token);
        DbUtils.commitAndClose(conn);
    } catch(SQLException e) {
        DbUtils.rollbackAndCloseQuietly(conn);
        logger.error(e.getMessage());
        return null;
    } finally {
        DbUtils.closeQuietly(conn);
    }
    return token;
}
 
開發者ID:geekcheng,項目名稱:jibu,代碼行數:32,代碼來源:LoginServiceImpl.java

示例9: resetPassword

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public void resetPassword(String tokenValue, String password) throws JibuException {
    Connection conn = null;
    try {
        conn = ConnectionUtils.getConnection();
        Token token = tokenDAO.get(conn,tokenValue);

        if (token == null) throw new TokenException("Token is null");
        Calendar calendar = Calendar.getInstance();
        long time = calendar.getTimeInMillis();
        Timestamp ts = new Timestamp(time);
        if(ts.after(token.getExpiration())) throw new TokenException("Token expired.");
        if (password == null || password.isEmpty()) {
            throw new JibuException("Password is invalid.");
        }

        User user = new User();
        String cryptpassword = MD5.encodeString(password,null);
        user.setPassword(cryptpassword);
        user.setId(token.getUser_id());
        userDAO.update(conn,user);
        DbUtils.commitAndClose(conn);
    } catch(SQLException e) {
        DbUtils.rollbackAndCloseQuietly(conn);
        throw new JibuException(e.getMessage());
    } finally {
        DbUtils.closeQuietly(conn);
    }

}
 
開發者ID:geekcheng,項目名稱:jibu,代碼行數:30,代碼來源:LoginServiceImpl.java

示例10: add

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public void add(User user) throws JibuException {
    Connection conn = null;
    if (null != user.getPassword()) {
        String cryptpassword = MD5.encodeString(user.getPassword(),null);
        user.setPassword(cryptpassword);
    }
    try {
        conn = ConnectionUtils.getConnection();
        userDAO.save(conn,user);
        DbUtils.commitAndClose(conn);
    } catch(SQLException e) {
        DbUtils.rollbackAndCloseQuietly(conn);
        throw new JibuException(e.getMessage());
    }
}
 
開發者ID:geekcheng,項目名稱:jibu,代碼行數:16,代碼來源:UserServiceImpl.java

示例11: setup

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
@Before
   public void setup() throws Exception {
clearTable();
       roleService = getInjector().getInstance(RoleService.class);
       Connection conn = ConnectionUtils.getConnection();
       QueryRunner run = new QueryRunner();
       run.update(conn, "INSERT INTO roles (name,description,lft,rgt) values ('ROLE_BASE','ROLE_BASE',1,2)");
       DbUtils.commitAndClose(conn);
   }
 
開發者ID:geekcheng,項目名稱:jibu,代碼行數:10,代碼來源:RoleServiceTest.java

示例12: reset

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public void reset(String username) throws JibuException{
    Connection conn = null;
    try {
        conn = ConnectionUtils.getConnection();
        User user = userDAO.get(conn,username);
        settingDAO.unbindAll(conn,user.getId());
        DbUtils.commitAndClose(conn);
    } catch(SQLException e) {
        DbUtils.rollbackAndCloseQuietly(conn);
        throw new JibuException(e.getMessage());
    }
}
 
開發者ID:geekcheng,項目名稱:jibu,代碼行數:13,代碼來源:SettingServiceImpl.java

示例13: bind

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 * <p>
 * 從 cache 中刪除此 auth 對應的 roles。下次條用時裝載。
 */
public void bind(Role role, Authority auth) throws JibuException {
    Connection conn = null;
    try {
        conn = ConnectionUtils.getConnection();
        Authority a = authDAO.get(conn,auth.getId());
 roleDAO.bind(conn, role, a);
        DbUtils.commitAndClose(conn);
 Cache cache = CacheUtils.getAuthCache();
 cache.remove(a.getValue());
    } catch(SQLException e) {
        DbUtils.rollbackAndCloseQuietly(conn);
        throw new JibuException(e.getMessage());
    }
}
 
開發者ID:geekcheng,項目名稱:jibu,代碼行數:20,代碼來源:RoleServiceImpl.java

示例14: unbind

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 * <p>
 * 從 cache 中刪除此 auth 對應的 roles。
 */
public void unbind(Role role, Authority auth) throws JibuException {
    Connection conn = null;
    try {
        conn = ConnectionUtils.getConnection();
        Authority a = authDAO.get(conn,auth.getId());
 roleDAO.unbind(conn, role, a);
        DbUtils.commitAndClose(conn);
 Cache cache = CacheUtils.getAuthCache();
 cache.remove(a.getValue());
    } catch(SQLException e) {
        DbUtils.rollbackAndCloseQuietly(conn);
        throw new JibuException(e.getMessage());
    }
}
 
開發者ID:geekcheng,項目名稱:jibu,代碼行數:20,代碼來源:RoleServiceImpl.java

示例15: add

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public void add(Setting setting) throws JibuException {
    Connection conn = null;
    try {
        conn = ConnectionUtils.getConnection();
        settingDAO.save(conn,setting);
        DbUtils.commitAndClose(conn);
    } catch(SQLException e) {
        DbUtils.rollbackAndCloseQuietly(conn);
        throw new JibuException(e.getMessage());
    }
}
 
開發者ID:geekcheng,項目名稱:jibu,代碼行數:12,代碼來源:SettingServiceImpl.java


注:本文中的org.apache.commons.dbutils.DbUtils.commitAndClose方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。