예제 #1
0
  private Set<UserRole> getRolesForUser(String sessID, String user)
      throws RemoteException, SQLException, SessionExpiredException {
    String database = SessionManager.getInstance().getDatabaseForSession(sessID);
    TableSchema roleTable = MedSavantDatabase.UserRoleTableSchema;
    TableSchema roleATable = MedSavantDatabase.UserRoleAssignmentTableSchema;

    SelectQuery sq = new SelectQuery();
    sq.addColumns(
        roleTable.getDBColumn(MedSavantDatabase.UserRoleTableSchema.COLUMNNAME_OF_ID),
        roleTable.getDBColumn(MedSavantDatabase.UserRoleTableSchema.COLUMNNAME_OF_ROLENAME),
        roleTable.getDBColumn(
            MedSavantDatabase.UserRoleTableSchema.COLUMNNAME_OF_ROLE_DESCRIPTION));
    Condition joinCondition =
        BinaryCondition.equalTo(
            roleTable.getDBColumn(MedSavantDatabase.UserRoleTableSchema.COLUMNNAME_OF_ID),
            roleATable.getDBColumn(
                MedSavantDatabase.UserRoleAssignmentTableSchema.COLUMNNAME_OF_ROLE_ID));
    sq.addJoin(
        SelectQuery.JoinType.INNER, roleTable.getTable(), roleATable.getTable(), joinCondition);
    sq.addCondition(
        BinaryCondition.equalTo(
            roleATable.getDBColumn(
                MedSavantDatabase.UserRoleAssignmentTableSchema.COLUMNNAME_OF_USERNAME),
            user));

    ResultSet rs = null;
    try {
      rs = ConnectionController.executeQuery(sessID, sq.toString());
      Set<UserRole> roleSet = new HashSet<UserRole>();
      while (rs.next()) {
        int roleId = rs.getInt(1);
        String roleName = rs.getString(2);
        String roleDescription = rs.getString(3);
        roleSet.add(new UserRole(roleId, roleName, roleDescription, database));
      }
      return roleSet;
    } finally {
      if (rs != null) {
        rs.close();
      }
    }
  }