Beispiel #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;
  }
Beispiel #2
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;
  }
Beispiel #3
0
  /**
   * Inserts a message to the database using a object made in Java
   *
   * @param message the message object constructed by the application
   * @return true if the message was inserted, else false
   */
  @Override
  public boolean insert(Message message) {
    boolean success = true;

    try {
      // Set the current time for the object
      message.updateTimestamp();

      // Insert object
      this.messageData.insert(message);
      this.messageCategoriesData.insert(
          new MessageCategories(
              this.messageData.getLastInsertId(), message.getCategory().getCid()));
    } catch (Exception e) {
      success = false;
    }

    return success;
  }
Beispiel #4
0
  /**
   * Updates a message using a message object
   *
   * @param message the message object to update
   * @return true if the message was updated, else false
   */
  @Override
  public boolean update(Message message) {
    Boolean success = true;

    try {
      this.messageData.update(message.getId(), message);
    } catch (Exception e) {
      success = false;
    }

    return success;
  }
Beispiel #5
0
 /**
  * Deletes a message using a object
  *
  * @see MessageDao#delete(Object)
  * @param message the message object constructed by the application
  * @return true if the message was deleted, else false
  */
 @Override
 public boolean delete(Message message) {
   return this.delete(message.getId());
 }