Subversion Repositories WebE

Rev

View as "text/plain" | Blame | Last modification | View Log | RSS feed

1
/**
 *
 */

package ch.ffhs.webE.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import ch.ffhs.webE.domain.History;

import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;

/**
 * @author pelinux
 *
 */

public class HistoryDAO
{
  /**
   * Database session
   */

  @SessionTarget
  Session session;

  /**
   * Database transaction
   */

  @TransactionTarget
  Transaction transaction;

  /**
   * Executes the query to save the history record
   *
   * @param history
   *          Domain object to be saved
   * @return <code>true</code> if successful, <code>false</code> otherwise
   */

  public boolean saveOrUpdate(History history)
  {
    try
    {
      history.setId(history.getId());
      this.session.saveOrUpdate(history);
      return true;
    }
    catch (Exception e)
    {
      this.transaction.rollback();
      e.printStackTrace();
      return false;
    }
  }

  /**
   * Returns a list of all terms
   *
   * @return an ArrayList with all the terms - in case of a problem, an empty
   *         list is returned
   */

  @SuppressWarnings("unchecked")
  public List<History> getList()
  {
    List<History> history = null;
    try
    {
      history = this.session.createQuery("from History").list(); //$NON-NLS-1$
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }

    /*
     * If no term was checked, return an empty list to mitigate null pointer
     * exceptions
     */

    if (history == null)
    {
      history = new ArrayList<History>();
    }

    return history;
  }
}