List of usage examples for org.apache.commons.dbutils DbUtils rollbackAndCloseQuietly
public static void rollbackAndCloseQuietly(Connection conn)
Connection
then closes it, avoid closing if null and hide any SQLExceptions that occur. From source file:org.gaixie.jibu.security.service.impl.LoginServiceImpl.java
public void resetPassword(String tokenValue, String password) throws JibuException { Connection conn = null;//from w ww . j av a 2 s . c o m 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); } }
From source file:org.gaixie.jibu.security.service.impl.RoleServiceImpl.java
public void add(Role role, Role parent) throws JibuException { Connection conn = null;/*from www. j a va 2 s. c o m*/ try { conn = ConnectionUtils.getConnection(); roleDAO.save(conn, role, parent); DbUtils.commitAndClose(conn); } catch (SQLException e) { DbUtils.rollbackAndCloseQuietly(conn); throw new JibuException(e.getMessage()); } }
From source file:org.gaixie.jibu.security.service.impl.RoleServiceImpl.java
public void delete(Role role) throws JibuException { Connection conn = null;//from w w w. j a v a 2 s .co m 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); } }
From source file:org.gaixie.jibu.security.service.impl.RoleServiceImpl.java
/** * {@inheritDoc}/*from ww w . j ava 2 s . c o m*/ * <p> * Role??? Cache ?? */ public void update(Role role) throws JibuException { Connection conn = null; try { conn = ConnectionUtils.getConnection(); // ? role.setLft(null); role.setRgt(null); roleDAO.update(conn, role); DbUtils.commitAndClose(conn); CacheUtils.getAuthCache().clear(); CacheUtils.getUserCache().clear(); } catch (SQLException e) { DbUtils.rollbackAndCloseQuietly(conn); throw new JibuException(e.getMessage()); } }
From source file:org.gaixie.jibu.security.service.impl.RoleServiceImpl.java
/** * {@inheritDoc}/* w w w.jav a 2 s.co m*/ * <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()); } }
From source file:org.gaixie.jibu.security.service.impl.RoleServiceImpl.java
/** * {@inheritDoc}/*from w ww . j a v a 2s . co m*/ * <p> * cache User roles? */ public void bind(Role role, User user) throws JibuException { Connection conn = null; try { conn = ConnectionUtils.getConnection(); User u = userDAO.get(conn, user.getId()); roleDAO.bind(conn, role, u); DbUtils.commitAndClose(conn); Cache cache = CacheUtils.getUserCache(); cache.remove(u.getUsername()); } catch (SQLException e) { DbUtils.rollbackAndCloseQuietly(conn); throw new JibuException(e.getMessage()); } }
From source file:org.gaixie.jibu.security.service.impl.RoleServiceImpl.java
/** * {@inheritDoc}// w w w. j a v a2 s. co m * <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()); } }
From source file:org.gaixie.jibu.security.service.impl.RoleServiceImpl.java
/** * {@inheritDoc}//from ww w .j a va2s. co m * <p> * cache User roles */ public void unbind(Role role, User user) throws JibuException { Connection conn = null; try { conn = ConnectionUtils.getConnection(); User u = userDAO.get(conn, user.getId()); roleDAO.unbind(conn, role, u); DbUtils.commitAndClose(conn); Cache cache = CacheUtils.getUserCache(); cache.remove(u.getUsername()); } catch (SQLException e) { DbUtils.rollbackAndCloseQuietly(conn); throw new JibuException(e.getMessage()); } }
From source file:org.gaixie.jibu.security.service.impl.SettingServiceImpl.java
public void add(Setting setting) throws JibuException { Connection conn = null;/*from w w w .ja v a 2s. c o m*/ try { conn = ConnectionUtils.getConnection(); settingDAO.save(conn, setting); DbUtils.commitAndClose(conn); } catch (SQLException e) { DbUtils.rollbackAndCloseQuietly(conn); throw new JibuException(e.getMessage()); } }
From source file:org.gaixie.jibu.security.service.impl.SettingServiceImpl.java
public void update(Setting setting) throws JibuException { Connection conn = null;/*from ww w . j a va 2 s .co m*/ try { conn = ConnectionUtils.getConnection(); settingDAO.update(conn, setting); DbUtils.commitAndClose(conn); } catch (SQLException e) { DbUtils.rollbackAndCloseQuietly(conn); throw new JibuException(e.getMessage()); } }