@Override public void saveOrUpdateAll(List<Role> entities) throws SQLException { ResultSet rs = null; try { con = new DBConnection(); if (con.connect()) { Iterator<Role> iterator = entities.iterator(); while (iterator.hasNext()) { Role entity = iterator.next(); if (entity.getRolename() != null) { cstmt = (CallableStatement) con.getConnection().prepareCall("{call sp_upd_role(?)}"); } else { cstmt = (CallableStatement) con.getConnection().prepareCall("{call sp_ins_role(?,?)}"); } cstmt.setString("p_rolename", entity.getRolename()); cstmt.setString("p_description", entity.getDescription()); rs = con.saveOrUpdate(cstmt); } } } catch (ClassNotFoundException ex) { logger.log(Priority.ERROR, ex.toString()); } catch (SQLException e) { throw e; } finally { cstmt.close(); con.disconnect(); } }
@Override public String saveOrUpdate(Role entity) throws SQLException { ResultSet rs = null; String retval = null; try { con = new DBConnection(); if (con.connect()) { if (entity.getRolename() != null) { cstmt = (CallableStatement) con.getConnection().prepareCall("{call sp_upd_role(?)}"); } else { cstmt = (CallableStatement) con.getConnection().prepareCall("{call sp_ins_role(?,?)}"); } cstmt.setString("p_rolename", entity.getRolename()); cstmt.setString("p_description", entity.getDescription()); rs = con.saveOrUpdate(cstmt); } } catch (ClassNotFoundException ex) { logger.log(Priority.ERROR, ex.toString()); } catch (SQLException e) { throw e; } finally { cstmt.close(); con.disconnect(); } return entity.getRolename(); }
@Override public boolean assignRole(String rolename, Integer userid) throws SQLException { boolean retval = false; ResultSet rs = null; try { con = new DBConnection(); if (con.connect()) { cstmt = (CallableStatement) con.getConnection().prepareCall("{call sp_ins_userrole(?,?,?)}"); cstmt.setString("p_rolename", rolename); cstmt.setInt("p_userid", userid); UserDAOImpl userDao = new UserDAOImpl(); cstmt.setString("p_username", userDao.findById(userid).getUsername()); rs = con.saveOrUpdate(cstmt); } retval = true; } catch (ClassNotFoundException ex) { logger.log(Priority.ERROR, ex.toString()); } catch (SQLException ex) { throw ex; } finally { con.disconnect(); } return retval; }