Subversion Repositories WebE

Rev

Rev 31 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 PointedEar 1
package ch.ffhs.webE.dao;
2
 
3
import java.util.ArrayList;
4
import java.util.List;
5
 
6
import org.hibernate.Session;
7
import org.hibernate.Transaction;
8
 
9
import ch.ffhs.webE.domain.Term;
10
 
11
import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
12
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
13
 
14
/**
15
 * Implements the Database Access Object for terms
16
 *
17
 * @author Thomas Lahn
18
 */
19
public class TermDAOImpl implements TermDAO
20
{
21
  /**
22
   * Database session
23
   */
24
  @SessionTarget
25
  Session session;
26
 
27
  /**
28
   * Database transaction
29
   */
30
  @TransactionTarget
31
  Transaction transaction;
32
 
33
  /**
34
   * Creates a list of all terms
35
   *
36
   * @return an ArrayList with all the users - in case of a problem, an empty
37
   *         list is returned
38
   */
39
  @SuppressWarnings("unchecked")
40
  public List<Term> listTerm()
41
  {
42
    List<Term> term = null;
43
    try
44
    {
33 PointedEar 45
      term = this.session.createQuery("from Term").list(); //$NON-NLS-1$
31 PointedEar 46
    }
47
    catch (Exception e)
48
    {
49
      e.printStackTrace();
50
    }
51
 
52
    /*
53
     * If no term was checked, return an empty list to mitigate null pointer
54
     * exceptions
55
     */
56
    if (term == null)
57
    {
58
      term = new ArrayList<Term>();
59
    }
33 PointedEar 60
 
31 PointedEar 61
    return term;
62
  }
63
 
64
  /*
65
   * (non-Javadoc)
66
   *
67
   * @see ch.ffhs.webE.dao.TermDAO#saveOrUpdate(ch.ffhs.webE.domain.Term)
68
   */
33 PointedEar 69
  public boolean saveOrUpdate(Term term)
31 PointedEar 70
  {
71
    try
72
    {
33 PointedEar 73
      term.setObjectId(term.getObjectId());
31 PointedEar 74
      this.session.saveOrUpdate(term);
33 PointedEar 75
      return true;
31 PointedEar 76
    }
77
    catch (Exception e)
78
    {
79
      this.transaction.rollback();
80
      e.printStackTrace();
33 PointedEar 81
      return false;
31 PointedEar 82
    }
83
  }
84
 
85
  /*
86
   * (non-Javadoc)
87
   *
88
   * @see ch.ffhs.webE.dao.TermDAO#deleteTerm(int)
89
   */
90
  public void deleteTerm(int termId)
91
  {
92
    try
93
    {
33 PointedEar 94
      Term term = (Term) this.session.get(Term.class, termId);
95
      this.session.delete(term);
31 PointedEar 96
    }
97
    catch (Exception e)
98
    {
99
      this.transaction.rollback();
100
      e.printStackTrace();
101
    }
102
  }
103
 
33 PointedEar 104
  /*
105
   * (non-Javadoc)
31 PointedEar 106
   *
33 PointedEar 107
   * @see ch.ffhs.webE.dao.TermDAO#getTermById(int)
31 PointedEar 108
   */
33 PointedEar 109
  public Term getTermById(int termId)
31 PointedEar 110
  {
111
    Term term = null;
112
 
113
    try
114
    {
115
      term = (Term) this.session.get(Term.class, termId);
116
    }
117
    catch (Exception e)
118
    {
119
      e.printStackTrace();
120
    }
33 PointedEar 121
 
31 PointedEar 122
    return term;
123
  }
124
}