protected boolean haveRecords(String table) { boolean rv = false; String countQuery = "SELECT COUNT(*) FROM " + table; logsql(countQuery); Result dbr = db.executeCountQuery(countQuery); if (dbr.isSuccessful()) { rv = ((Integer) dbr.objectValue()) > 0; } else { log("haveRecords(" + table + ")" + dbr.name()); } return rv; }
private Result getRoleList(Screen.Button button) { Result result; Screen next; List<Role> roleList = new ArrayList<Role>(); result = listAllRoles(roleList); if (result.isSuccessful()) { next = new Screen(this, button.destination()); next.setValue(Screen.AVAILABLE_ROLES, roleList); result.objectValue(next); } else { log(result.getReason().name()); log(result.allMessages()); } return result; }
private Result getUserList(Screen.Button button) { Result result; Screen next; List<User> userList = new ArrayList<User>(); result = listUsers(userList); if (result.isSuccessful()) { next = new Screen(this, button.destination()); next.setValue(Screen.USERS_LIST, userList); result.objectValue(next); } else { log(result.getReason().name()); log(result.allMessages()); } return result; }
/** * DOC * * @param role * @param manager * @param privilege * @return */ @SuppressWarnings("rawtypes") public boolean denyAccess(Role role, Manager manager, Privilege privilege) { boolean rv = true; String countSql = "SELECT count(*) FROM " + Role.AUX_ROLE_PRIV + " WHERE role_id = ? and manager_id = ? and priv_id = ? "; Result r = db.executeCountQuery(countSql); if (r.isSuccessful()) { Integer count = (Integer) r.objectValue(); rv = (count == Base.ZERO); } else { log("Deny access query:" + countSql + " failed:" + r.name()); } return rv; }
public Result findRole(String roleId) { Result r = new Result(); if (!loggedIn) { r = r.notAuthorized(); return r; } Role role = new Role(); String selectRoleSql = "SELECT * FROM " + Role.AUX_ROLE + " WHERE " + "ID = " + roleId + " "; r = db.executeSingleSelectQuery(selectRoleSql, role); if (!role.isValid()) { r.error("User object not valid."); } else { if (r.isSuccessful()) { r.objectValue(role); } } return r; }
@Override public Result findUser(String userId) { Result r = new Result(); if (!loggedIn) { r = r.notAuthorized(); return r; } User user = new User(); String selectUserSql = "SELECT * FROM " + User.AUX_USER + " WHERE " + "ID = " + userId + " "; r = db.executeSingleSelectQuery(selectUserSql, user); if (!user.isValid()) { r.error("User object not valid."); } else { if (r.isSuccessful()) { r.objectValue(user); } } return r; }