Beispiel #1
0
 public ArrayList<Path> getProjectPaths(int projectId)
     throws java.rmi.RemoteException, SQLException {
   ResultSet result =
       connection
           .createStatement()
           .executeQuery("SELECT * from paths where projectId = " + projectId);
   ArrayList<Path> paths = new ArrayList<Path>();
   while (result.next()) {
     int pathId = result.getInt(1);
     ResultSet result2 =
         connection
             .createStatement()
             .executeQuery("Select sum(value) from transactions where PathId  = " + pathId);
     Path p = new Path(result.getString(2), result.getString(4), result2.getDouble(1));
     p.setId(result.getInt(1));
     paths.add(p);
   }
   System.out.println("Get Project Paths executed");
   return paths;
 }
Beispiel #2
0
  public boolean createPath(Path path, int requestId, int userId, int projectId)
      throws RemoteException, SQLException {
    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 paths where Name = \""
                      + path.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
          .createStatement()
          .execute(
              "insert into paths (Name, Description, ProjectId) values (\""
                  + path.getName()
                  + "\", \""
                  + path.getDescription()
                  + "\", "
                  + projectId
                  + ")");
      connection
          .createStatement()
          .execute(
              "insert into logs (UserId, RequestId, Response) values ("
                  + userId
                  + ", "
                  + requestId
                  + ", 1)");

      return true;
    } else {
      result =
          connection
              .createStatement()
              .executeQuery(
                  "select response from logs where requestId = "
                      + requestId
                      + " and userId = "
                      + userId);
      return result.getBoolean(1);
    }
  }