Example #1
0
 // ----------------------------------------------My SQL
 // Functions------------------------------------------------
 private static void Create_Event_MySQL() {
   // create event.
   sqlHelper.insert(Table_Events.Table_Name, Event_Helper.details);
   // Add My user.
   sqlHelper.insert(
       Table_Events_Users.Table_Name,
       new String[] {
         Event_Helper.details[Table_Events.Event_ID_num],
         Constants.MY_User_ID,
         Constants.Yes,
         Constants.Owner
       });
   // Add all friends.
   for (String User_ID : Event_Helper.friends.keySet()) {
     Friend_Helper friend_helper = Event_Helper.friends.get(User_ID);
     add_newFriend_MySQL(friend_helper, User_ID);
   }
   // Add tasks.
   for (int task_id : Event_Helper.task.keySet()) {
     Task_Helper task_helper = Event_Helper.task.get(task_id);
     add_newTask_MySQL(task_helper, task_id, 0);
     // Add all subTasks.
     for (int subTask_id : task_helper.getSubTasks().keySet()) {
       add_newTask_MySQL(task_helper, task_id, subTask_id);
     }
   }
   // Create Chat table.
   String Chat_ID =
       Table_Chat.Table_Name
           + Helper.Clean_Event_ID(Event_Helper.details[Table_Events.Event_ID_num]);
   sqlHelper.Create_Table(Chat_ID, Table_Chat.getAllFields(), Table_Chat.getAllSqlParams());
   // Add vote_date.
   for (int vote_id : Event_Helper.vote_date.keySet()) {
     Vote_Date_Helper vote_date_helper = Event_Helper.vote_date.get(vote_id);
     add_newVote_Date_Option_MySQL(vote_date_helper, vote_id);
   }
   // Add vote_location.
   for (int vote_id : Event_Helper.vote_location.keySet()) {
     Vote_Location_Helper vote_location_helper = Event_Helper.vote_location.get(vote_id);
     add_newVote_Location_Option_MySQL(vote_location_helper, vote_id);
   }
 }
Example #2
0
  private static void Update_Event_MySQL(String Event_ID) {
    Update_Users = new ArrayList<>();
    update_section =
        new String[] {Constants.Yes, Constants.No, Constants.No, Constants.No, Constants.No};
    // Update event (delete and then insert).
    sqlHelper.delete(
        Table_Events.Table_Name,
        new String[] {Table_Events.Event_ID},
        new String[] {Event_ID},
        new int[] {1});
    sqlHelper.insert(Table_Events.Table_Name, Event_Helper.details);
    // Update Friends list invention.
    Friend_Helper friend_helper;
    for (String User_ID : Event_Helper.friends_tmp.keySet()) {
      friend_helper = Event_Helper.friends_tmp.get(User_ID);
      if (Event_Helper.friends.get(User_ID) == null) { // Add new friends.
        update_section[users_num] = Constants.Yes;
        add_newFriend_MySQL(friend_helper, User_ID);
        Update_Users.add(new String[] {User_ID, Constants.New_Event});
      } else { // Change permission.
        if (!User_ID.equals(Constants.MY_User_ID)) // No need to send update message to myself.
        Update_Users.add(new String[] {User_ID, Constants.Update_Event});
        if (!friend_helper
            .getPermission()
            .equals(Event_Helper.friends.get(User_ID).getPermission())) {
          update_section[users_num] = Constants.Yes;
          sqlHelper.update(
              Table_Events_Users.Table_Name,
              new String[] {Table_Events_Users.Permission},
              new String[] {friend_helper.getPermission()},
              new String[] {Table_Events_Users.Event_ID, Table_Events_Users.User_ID},
              new String[] {Event_ID, User_ID});
        }
      }
    }
    // Delete friends.
    for (String User_ID : Event_Helper.friends.keySet()) {
      if (Event_Helper.friends_tmp.get(User_ID) == null) {
        update_section[users_num] = Constants.Yes;
        Update_Users.add(new String[] {User_ID, Constants.Delete_Event});
        sqlHelper.delete(
            Table_Events_Users.Table_Name,
            new String[] {Table_Events_Users.Event_ID, Table_Events_Users.User_ID},
            new String[] {Event_Helper.details[Table_Events.Event_ID_num], User_ID},
            new int[] {1});
      }
    }
    // Update Tasks.
    boolean new_task, new_subTask;
    Task_Helper task_helper;
    for (int task_id : Event_Helper.task_tmp.keySet()) {
      task_helper = Event_Helper.task_tmp.get(task_id);
      new_task = Event_Helper.task.get(task_id) == null;
      if (new_task) { // Add new tasks.
        update_section[tasks_num] = Constants.Yes;
        add_newTask_MySQL(task_helper, task_id, 0);
      } else { // Update task description.
        if (!task_helper.getDescription().equals(Event_Helper.task.get(task_id).getDescription())) {
          update_section[tasks_num] = Constants.Yes;
          sqlHelper.update(
              Table_Tasks.Table_Name,
              new String[] {Table_Tasks.Description},
              new String[] {task_helper.getDescription()},
              new String[] {
                Table_Tasks.Event_ID, Table_Tasks.Task_ID_Number, Table_Tasks.subTask_ID_Number
              },
              new String[] {Event_ID, task_id + "", 0 + ""});
        }
      }
      for (int subTask_id : task_helper.getSubTasks().keySet()) {
        new_subTask =
            (new_task || Event_Helper.task.get(task_id).getSubTasks().get(subTask_id) == null);
        if (new_subTask) { // Add new subTasks.
          update_section[tasks_num] = Constants.Yes;
          add_newTask_MySQL(task_helper, task_id, subTask_id);
        } else { // Update subTask description.
          if (!task_helper
              .getSubTasks()
              .get(subTask_id)[0]
              .equals(Event_Helper.task.get(task_id).getSubTasks().get(subTask_id)[0])) {
            update_section[tasks_num] = Constants.Yes;
            sqlHelper.update(
                Table_Tasks.Table_Name,
                new String[] {Table_Tasks.Description},
                new String[] {task_helper.getSubTasks().get(subTask_id)[0]},
                new String[] {
                  Table_Tasks.Event_ID, Table_Tasks.Task_ID_Number, Table_Tasks.subTask_ID_Number
                },
                new String[] {Event_ID, task_id + "", subTask_id + ""});
          }
        }
      }
    }
    // Delete Tasks.
    for (int task_id : Event_Helper.task.keySet()) {
      task_helper = Event_Helper.task.get(task_id);
      if (Event_Helper.task_tmp.get(task_id) == null) {
        update_section[tasks_num] = Constants.Yes;
        sqlHelper.delete(
            Table_Tasks.Table_Name,
            new String[] {Table_Tasks.Event_ID, Table_Tasks.Task_ID_Number},
            new String[] {Event_Helper.details[Table_Events.Event_ID_num], task_id + ""},
            null);
      } else {
        for (int subTask_id : task_helper.getSubTasks().keySet()) {
          if (Event_Helper.task_tmp.get(task_id).getSubTasks().get(subTask_id) == null) {
            update_section[tasks_num] = Constants.Yes;
            sqlHelper.delete(
                Table_Tasks.Table_Name,
                new String[] {
                  Table_Tasks.Event_ID, Table_Tasks.Task_ID_Number, Table_Tasks.subTask_ID_Number
                },
                new String[] {
                  Event_Helper.details[Table_Events.Event_ID_num], task_id + "", subTask_id + ""
                },
                null);
          }
        }
      }
    }
    // Update Vote_date.
    // Update vote will reset the votes users.
    boolean new_vote_date;
    Vote_Date_Helper vote_date_helper_tmp;
    Vote_Date_Helper vote_date_helper;
    for (int vote_id : Event_Helper.vote_date_tmp.keySet()) {
      vote_date_helper_tmp = Event_Helper.vote_date_tmp.get(vote_id);
      vote_date_helper = Event_Helper.vote_date.get(vote_id);
      new_vote_date = vote_date_helper == null;
      if (new_vote_date) { // Add new vote.
        update_section[vote_date_num] = Constants.Yes;
        add_newVote_Date_Option_MySQL(vote_date_helper_tmp, vote_id);
      } else { // Update vote date.
        if (!vote_date_helper_tmp.getStart_Date().equals(vote_date_helper.getStart_Date())
            || !vote_date_helper_tmp.getEnd_Date().equals(vote_date_helper.getEnd_Date())
            || !vote_date_helper_tmp.getAll_Day().equals(vote_date_helper.getAll_Day())
            || !vote_date_helper_tmp.getStart_Time().equals(vote_date_helper.getStart_Time())
            || !vote_date_helper_tmp.getEnd_Time().equals(vote_date_helper.getStart_Time())) {
          update_section[vote_date_num] = Constants.Yes;
          // reset the votes users.
          sqlHelper.delete(
              Table_Vote_Date.Table_Name,
              new String[] {Table_Vote_Date.Event_ID, Table_Vote_Date.Vote_ID},
              new String[] {Event_ID, vote_id + ""},
              null);
          add_newVote_Date_Option_MySQL(vote_date_helper_tmp, vote_id);
        }
      }
    }
    // Delete Vote_date.
    for (int vote_id : Event_Helper.vote_date.keySet()) {
      vote_date_helper = Event_Helper.vote_date.get(vote_id);
      if (Event_Helper.vote_date_tmp.get(vote_id) == null) {
        update_section[vote_date_num] = Constants.Yes;
        sqlHelper.delete(
            Table_Vote_Date.Table_Name,
            new String[] {Table_Vote_Date.Event_ID, Table_Vote_Date.Vote_ID},
            new String[] {Event_ID, vote_id + ""},
            null);
      }
    }

    // Update Vote_location.
    // Update vote will reset the votes users.
    boolean new_vote_location;
    Vote_Location_Helper vote_location_helper_tmp;
    Vote_Location_Helper vote_location_helper;
    for (int vote_id : Event_Helper.vote_location_tmp.keySet()) {
      vote_location_helper_tmp = Event_Helper.vote_location_tmp.get(vote_id);
      vote_location_helper = Event_Helper.vote_location.get(vote_id);
      new_vote_location = vote_location_helper == null;
      if (new_vote_location) { // Add new vote.
        update_section[vote_location_num] = Constants.Yes;
        add_newVote_Location_Option_MySQL(vote_location_helper_tmp, vote_id);
      } else { // Update vote date.
        if (!vote_location_helper_tmp
            .getDescription()
            .equals(vote_location_helper.getDescription())) {
          update_section[vote_location_num] = Constants.Yes;
          // reset the votes users.
          sqlHelper.delete(
              Table_Vote_Location.Table_Name,
              new String[] {Table_Vote_Location.Event_ID, Table_Vote_Location.Vote_ID},
              new String[] {Event_ID, vote_id + ""},
              null);
          add_newVote_Location_Option_MySQL(vote_location_helper_tmp, vote_id);
        }
      }
    }
    // Delete Vote_location.
    for (int vote_id : Event_Helper.vote_location.keySet()) {
      vote_location_helper = Event_Helper.vote_location.get(vote_id);
      if (Event_Helper.vote_location_tmp.get(vote_id) == null) {
        update_section[vote_location_num] = Constants.Yes;
        sqlHelper.delete(
            Table_Vote_Location.Table_Name,
            new String[] {Table_Vote_Location.Event_ID, Table_Vote_Location.Vote_ID},
            new String[] {Event_ID, vote_id + ""},
            null);
      }
    }
  }