Subversion Repositories WebE

Rev

Rev 34 | View as "text/plain" | Blame | Compare with Previous | 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.RelationshipType;

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

/**
 * Data Access Object class for {@link RelationshipType}s
 *
 * @author Thomas Lahn
 */

public class RelationshipTypeDAO
{

  /**
   * Hibernate session target
   */

  @SessionTarget
  Session session;

  /**
   * Hibernate transaction target
   */

  @TransactionTarget
  Transaction transaction;

  /**
   * Gets a list of all the relationshipTypes in the database.
   *
   * @return List of all the users. In case of a problem, an empty list is
   *         returned.
   */

  @SuppressWarnings("unchecked")
  public List<RelationshipType> getList()
  {

    List<RelationshipType> relType = null;

    try
    {
      relType = this.session.createQuery("from RelationshipType").list(); //$NON-NLS-1$
    }
    catch (Exception e)
    {
      // TODO: Logging
    }

    if (relType == null)
    {
      relType = new ArrayList<RelationshipType>();
    }

    return relType;
  }

  /**
   * Saves or updates a relationship type
   *
   * @param relType
   *          A filled domain object
   * @return Boolean indicating success or error in saving the relationshipType
   */

  public boolean saveOrUpdate(RelationshipType relType)
  {
    try
    {
      this.session.saveOrUpdate(relType);
      return true;
    }
    catch (Exception e)
    {
      this.transaction.rollback();
      return false;
      // TODO: Logging
    }
  }

  /**
   * Delete a relationship type
   *
   * @param relTypeId
   *          Relationship type ID
   * @return boolean indicating success or error in the query execution
   */

  public boolean delete(int relTypeId)
  {
    try
    {
      RelationshipType relType = (RelationshipType) this.session.get(
          RelationshipType.class, relTypeId);
      this.session.delete(relType);
      return true;
    }
    catch (Exception e)
    {
      this.transaction.rollback();
      // TODO: Logging
      return false;
    }
  }

  /**
   * Used to get a relationship type by ID
   *
   * @param relTypeID
   * @return
   */

  public RelationshipType getById(int relTypeID)
  {
    RelationshipType relType = null;
    try
    {
      relType = (RelationshipType) this.session.get(RelationshipType.class,
          relTypeID);
    }
    catch (Exception e)
    {
      e.printStackTrace();
      // TODO: Logging
    }
    return relType;
  }
}