コード例 #1
0
  public String insertActivity(Activity activity)
      throws DatabaseException, IllegalArgumentException {
    if (activity == null) {
      throw new IllegalArgumentException("Activity not specified!");
    }

    if (activity.getUserId() == null) {
      throw new IllegalArgumentException("userId not specified!");
    }

    String activityId = "000000000";

    synchronized (activityIdGenerator) {
      activityId += activityIdGenerator.nextInt(1000000000);
      activityId = activityId.substring(activityId.length() - 9);
      activityId = "CR_ES" + activityId;
    }

    activity.setId(activityId);

    Hashtable<String, Activity> userDB = activityDB.get(activity.getUserId());

    if (userDB == null) {
      userDB = new Hashtable<String, Activity>(0);
      activityDB.put(activity.getUserId(), userDB);
    }

    if (userDB.containsKey(activityId)) {
      throw new DatabaseException("Activity " + activityId + " already exists!");
    }

    userDB.put(activityId, activity);
    return activityId;
  }
コード例 #2
0
  public void insertActivityStatus(String activityId, ActivityStatus activityStatus)
      throws DatabaseException, IllegalArgumentException {
    if (activityStatus == null) {
      throw new IllegalArgumentException("ActivityStatus not specified!");
    }

    Activity activity = getActivity(activityId, null);

    if (activity == null) {
      throw new DatabaseException("activity not found");
    }

    activity.getStates().add(activityStatus);
  }
コード例 #3
0
  public void insertActivityCommand(String activityId, ActivityCommand activityCommand)
      throws DatabaseException, IllegalArgumentException {
    if (activityCommand == null) {
      throw new IllegalArgumentException("ActivityCommand not specified!");
    }

    Activity activity = getActivity(activityId, null);

    if (activity == null) {
      throw new DatabaseException("activity not found");
    }

    activity.getCommands().add(activityCommand);
  }
コード例 #4
0
  public void updateActivity(Activity activity) throws DatabaseException, IllegalArgumentException {
    if (activity == null) {
      throw new IllegalArgumentException("Activity not specified!");
    }

    if (activity.getId() == null) {
      throw new IllegalArgumentException("activityId not specified!");
    }

    if (activity.getUserId() == null) {
      throw new IllegalArgumentException("userId not specified!");
    }

    Hashtable<String, Activity> userDB = activityDB.get(activity.getUserId());

    if (userDB == null || !userDB.containsKey(activity.getId())) {
      throw new DatabaseException("Activity " + activity.getId() + " not found!");
    }

    userDB.put(activity.getId(), activity);
  }