Exemplo n.º 1
0
  public ArrayList<Message> getProjectMessages(int projectId)
      throws java.rmi.RemoteException, SQLException {
    ResultSet result =
        connection
            .createStatement()
            .executeQuery(
                "select messages.id, subject, question, response, users.username from messages inner join users on fromUserId = users.id where projectId = "
                    + projectId);
    ArrayList<Message> messages = new ArrayList<Message>();
    while (result.next()) {
      String subject = result.getString(2);
      String question = result.getString(3);
      String response = result.getString(4);

      Message m = new Message(subject, question, response);
      m.setFromUserUsername(result.getString(5));
      m.setId(result.getInt(1));
      messages.add(m);
    }
    System.out.println("Get Project Messages executed");
    return messages;
  }
Exemplo n.º 2
0
 public boolean sendMessage(Message message, int projectId, int requestId)
     throws RemoteException, SQLException {
   ResultSet result =
       connection
           .createStatement()
           .executeQuery(
               "select count(*) from logs where requestId = "
                   + requestId
                   + " and userId = "
                   + message.getFromUserId());
   if (result.getInt(1) == 0) {
     connection.setAutoCommit(false);
     System.out.println("cheguei aqui");
     connection
         .createStatement()
         .execute(
             "insert into messages (ProjectId, Subject, Question, Response, FromUserId) values ("
                 + projectId
                 + ",\""
                 + message.getSubject()
                 + "\",\""
                 + message.getQuestion()
                 + "\", \"\", "
                 + message.getFromUserId()
                 + ")");
     connection
         .createStatement()
         .execute(
             "insert into logs (UserId, RequestId, Response) values ("
                 + message.getFromUserId()
                 + ", "
                 + requestId
                 + ", 1)");
     connection.commit();
     return true;
   } else {
     result =
         connection
             .createStatement()
             .executeQuery(
                 "select response from logs where requestId = "
                     + requestId
                     + " and userId = "
                     + message.getFromUserId());
     return result.getBoolean(1);
   }
 }