Ejemplo n.º 1
0
  /** @return a collection of message objects */
  public Collection<Message> getCollection() {
    Collection<Message> messages = new ArrayList<>();

    for (Message message : messageData.getCollection()) messages.add(this.get(message.getId()));

    return messages;
  }
Ejemplo n.º 2
0
  /**
   * Deletes a message using a unique key (used by {@link MessageDao#delete(Message)})
   *
   * @param id the unique key
   * @return true if the message was deleted, else false
   */
  public boolean delete(int id) {
    Boolean success = true;

    if (id > 0) {
      try {
        messageData.delete(id);
        messageCategoriesData.delete(id);
      } catch (Exception e) {
        success = false;
      }
    } else {
      success = false;
    }

    return success;
  }
Ejemplo n.º 3
0
  /**
   * Retrieve a message from the database using a unique key
   *
   * @param key the unique key
   * @return a message object associated with the unique key in the database
   */
  @Override
  public Message get(Object key) {
    Message message = null;

    if (messageData.count() > 0) {
      Integer primaryKey = (Integer) key;

      message = messageData.getUsingPrimaryKey(primaryKey);
      MessageCategory category =
          messageCategoryData.getUsingPrimaryKey(
              messageCategoriesData.getUsingPrimaryKey(primaryKey).getCid());

      message.setCategory(category);
    }

    return message;
  }