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.SettingServiceImpl.java
public void delete(Setting setting) throws JibuException { Connection conn = null;//from w w w. j ava 2s . c o m 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()); } }
From source file:org.gaixie.jibu.security.service.impl.SettingServiceImpl.java
public void bind(int sid, String username) throws JibuException { Connection conn = null;//from w ww . j a va 2s . c o m 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()); } }
From source file:org.gaixie.jibu.security.service.impl.SettingServiceImpl.java
public void unbind(int sid, String username) throws JibuException { Connection conn = null;// w ww.j av a 2 s.co m try { conn = ConnectionUtils.getConnection(); User user = userDAO.get(conn, username); settingDAO.unbind(conn, sid, user.getId()); 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 updateMe(List<Integer> ids, User user) throws JibuException { Connection conn = null;/*from w w w . j a v a2s . com*/ 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()); } }
From source file:org.gaixie.jibu.security.service.impl.SettingServiceImpl.java
public void reset(String username) throws JibuException { Connection conn = null;/*from ww w . j a v a 2s. c om*/ 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()); } }
From source file:org.gaixie.jibu.security.service.impl.UserServiceImpl.java
public void add(User user) throws JibuException { Connection conn = null;/*from w w w.jav a 2s . c om*/ 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()); } }
From source file:org.gaixie.jibu.security.service.impl.UserServiceImpl.java
public void update(User user) throws JibuException { Connection conn = null;//from ww w. j a va 2s.c o m 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()); } }
From source file:org.gaixie.jibu.security.service.impl.UserServiceImpl.java
public void delete(User user) throws JibuException { Connection conn = null;//from w ww.j ava 2 s. c om try { conn = ConnectionUtils.getConnection(); userDAO.delete(conn, user); DbUtils.commitAndClose(conn); } catch (SQLException e) { DbUtils.rollbackAndCloseQuietly(conn); throw new JibuException(e.getMessage()); } }
From source file:org.gaixie.jibu.security.service.LoginServiceTest.java
@After public void tearDown() { Connection conn = null;//w w w.ja v a 2 s.c o m try { conn = ConnectionUtils.getConnection(); QueryRunner run = new QueryRunner(); run.update(conn, "DELETE from tokens"); run.update(conn, "DELETE from userbase"); DbUtils.commitAndClose(conn); } catch (SQLException e) { DbUtils.rollbackAndCloseQuietly(conn); System.out.println(e.getMessage()); } }
From source file:org.gaixie.jibu.security.service.RoleServiceTest.java
@After public void tearDown() { Connection conn = null;/*from ww w . j a v a 2s .c o m*/ try { conn = ConnectionUtils.getConnection(); QueryRunner run = new QueryRunner(); run.update(conn, "DELETE from roles"); DbUtils.commitAndClose(conn); } catch (SQLException e) { DbUtils.rollbackAndCloseQuietly(conn); System.out.println(e.getMessage()); } }