Rev 34 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 34 | Rev 37 | ||
---|---|---|---|
1 | package ch.ffhs.webE.dao; |
1 | package ch.ffhs.webE.dao; |
2 | 2 | ||
- | 3 | import java.util.ArrayList; |
|
3 | import java.util.List; |
4 | import java.util.List; |
4 | 5 | ||
- | 6 | import org.hibernate.Session; |
|
- | 7 | import org.hibernate.Transaction; |
|
- | 8 | ||
5 | import ch.ffhs.webE.domain.Term; |
9 | import ch.ffhs.webE.domain.Term; |
6 | 10 | ||
- | 11 | import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget; |
|
- | 12 | import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget; |
|
- | 13 | ||
7 | /**
|
14 | /**
|
8 | * Defines methods all term DAO implementations must implement
|
15 | * Implements the Database Access Object for terms
|
9 | *
|
16 | *
|
10 | * @author pelinux
|
17 | * @author Thomas Lahn
|
11 | */
|
18 | */
|
12 | public interface TermDAO |
19 | public class TermDAO |
13 | {
|
20 | {
|
14 | /**
|
21 | /**
|
15 | * @return
|
22 | * Database session
|
16 | */
|
23 | */
|
- | 24 | @SessionTarget |
|
17 | List<Term> getTerms(); |
25 | Session session;
|
18 | 26 | ||
19 | /**
|
27 | /**
|
20 | * Delete a term
|
28 | * Database transaction
|
21 | *
|
- | |
22 | * @param termId
|
- | |
23 | * Term ID
|
- | |
24 | */
|
29 | */
|
- | 30 | @TransactionTarget |
|
25 | void deleteTerm(int termId); |
31 | Transaction transaction;
|
26 | 32 | ||
27 | /**
|
33 | /**
|
28 | * Retrieves a term by ID
|
34 | * Returns a list of all terms
|
29 | *
|
35 | *
|
- | 36 | * @return an ArrayList with all the terms - in case of a problem, an empty
|
|
- | 37 | * list is returned
|
|
- | 38 | */
|
|
- | 39 | @SuppressWarnings("unchecked") |
|
- | 40 | public List<Term> getList() |
|
- | 41 | {
|
|
30 | * @param termId
|
42 | List<Term> term = null; |
31 | * @return
|
43 | try
|
- | 44 | {
|
|
- | 45 | term = this.session.createQuery("from Term").list(); //$NON-NLS-1$ |
|
- | 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
|
|
32 | */
|
55 | */
|
- | 56 | if (term == null) |
|
- | 57 | {
|
|
33 | Term getTermById(int termId); |
58 | term = new ArrayList<Term>(); |
- | 59 | }
|
|
- | 60 | ||
- | 61 | return term; |
|
- | 62 | }
|
|
34 | 63 | ||
35 | /**
|
64 | /**
|
36 | * Executes the query to save the term
|
65 | * Executes the query to save the term
|
37 | *
|
66 | *
|
38 | * @param term
|
67 | * @param term
|
39 | * Domain object to be saved
|
68 | * Domain object to be saved
|
40 | * @return <code>true</code> if successful, <code>false</code> otherwise
|
69 | * @return <code>true</code> if successful, <code>false</code> otherwise
|
41 | */
|
70 | */
|
42 | boolean saveOrUpdate(Term term); |
71 | public boolean saveOrUpdate(Term term) |
- | 72 | {
|
|
- | 73 | try
|
|
- | 74 | {
|
|
- | 75 | term.setObjectId(term.getObjectId()); |
|
- | 76 | this.session.saveOrUpdate(term); |
|
- | 77 | return true; |
|
- | 78 | }
|
|
- | 79 | catch (Exception e) |
|
- | 80 | {
|
|
- | 81 | this.transaction.rollback(); |
|
- | 82 | e.printStackTrace(); |
|
- | 83 | return false; |
|
- | 84 | }
|
|
- | 85 | }
|
|
- | 86 | ||
- | 87 | /**
|
|
- | 88 | * Delete a term
|
|
- | 89 | *
|
|
- | 90 | * @param termId
|
|
- | 91 | * Term ID
|
|
- | 92 | */
|
|
- | 93 | public void delete(int termId) |
|
- | 94 | {
|
|
- | 95 | try
|
|
- | 96 | {
|
|
- | 97 | Term term = (Term) this.session.get(Term.class, termId); |
|
- | 98 | this.session.delete(term); |
|
- | 99 | }
|
|
- | 100 | catch (Exception e) |
|
- | 101 | {
|
|
- | 102 | this.transaction.rollback(); |
|
- | 103 | e.printStackTrace(); |
|
- | 104 | }
|
|
- | 105 | }
|
|
- | 106 | ||
- | 107 | /**
|
|
- | 108 | * Retrieves a term by ID
|
|
- | 109 | *
|
|
- | 110 | * @param termId
|
|
- | 111 | * @return
|
|
- | 112 | */
|
|
- | 113 | public Term getById(int termId) |
|
- | 114 | {
|
|
- | 115 | Term term = null; |
|
- | 116 | ||
- | 117 | try
|
|
- | 118 | {
|
|
- | 119 | term = (Term) this.session.get(Term.class, termId); |
|
- | 120 | }
|
|
- | 121 | catch (Exception e) |
|
- | 122 | {
|
|
- | 123 | e.printStackTrace(); |
|
- | 124 | }
|
|
- | 125 | ||
- | 126 | return term; |
|
- | 127 | }
|
|
43 | }
|
128 | }
|
44 | - |