示例#1
0
  public ArrayList<Reward> getProjectRewards(int projectId)
      throws java.rmi.RemoteException, SQLException {
    ResultSet result =
        connection
            .createStatement()
            .executeQuery("Select * from Rewards where ProjectId = " + projectId);
    ArrayList<Reward> rewards = new ArrayList<Reward>();

    while (result.next()) {
      Reward r = new Reward(result.getDouble(2), result.getString(3), result.getString(4));
      r.setId(result.getInt(1));
      rewards.add(r);
    }
    System.out.println("Get Project Rewards executed");
    return rewards;
  }
示例#2
0
  public ArrayList<Reward> getUserRewards(int userId)
      throws java.rmi.RemoteException, SQLException {
    ResultSet result =
        connection
            .createStatement()
            .executeQuery(
                "SELECT Rewards_Users.flag, Rewards_Users.id, Rewards.* from Rewards_Users INNER JOIN Rewards ON Rewards.id=Rewards_Users.rewardId where Rewards_Users.OwnerUserId = "
                    + userId);
    ArrayList<Reward> rewards = new ArrayList<Reward>();

    while (result.next()) {
      Reward r = new Reward(result.getDouble(4), result.getString(5), result.getString(6));
      r.setFlag(result.getBoolean(1));
      r.setId(result.getInt(2));
      rewards.add(r);
    }
    System.out.println("Get User Rewards executed");
    return rewards;
  }
示例#3
0
  public boolean createReward(Reward reward, int requestId, int projectId, int userId)
      throws RemoteException, SQLException {
    System.out.println(reward + " " + requestId + " " + projectId + " " + userId);
    ResultSet result =
        connection
            .createStatement()
            .executeQuery(
                "select count(*) from logs where requestId = "
                    + requestId
                    + " and userId = "
                    + userId);
    if (result.getInt(1) == 0 || requestId == 0) {
      result =
          connection
              .createStatement()
              .executeQuery(
                  "select id from rewards where Name = \""
                      + reward.getName()
                      + "\" and projectId = "
                      + projectId);
      if (result.next()) return false;

      result =
          connection
              .createStatement()
              .executeQuery(
                  "select * from administrators where userId = "
                      + userId
                      + " and projectId= "
                      + projectId);
      if (!result.next()) return false;
      connection.setAutoCommit(false);
      connection
          .createStatement()
          .execute(
              "insert into rewards (MinValue, Name, Description, ProjectId) values ("
                  + reward.getMinValue()
                  + ",\""
                  + reward.getName()
                  + "\", \""
                  + reward.getDescription()
                  + "\", "
                  + projectId
                  + ")");
      connection
          .createStatement()
          .execute(
              "insert into logs (UserId, RequestId, Response) values ("
                  + userId
                  + ", "
                  + requestId
                  + ", 1)");
      connection.commit();
      return true;
    } else {
      result =
          connection
              .createStatement()
              .executeQuery(
                  "select response from logs where requestId = "
                      + requestId
                      + " and userId = "
                      + userId);
      return result.getBoolean(1);
    }
  }