Rev 31 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 31 | Rev 33 | ||
---|---|---|---|
Line 40... | Line 40... | ||
40 | public List<Term> listTerm() |
40 | public List<Term> listTerm() |
41 | {
|
41 | {
|
42 | List<Term> term = null; |
42 | List<Term> term = null; |
43 | try
|
43 | try
|
44 | {
|
44 | {
|
45 | term = this.session.createQuery("FROM term").list(); //$NON-NLS-1$ |
45 | term = this.session.createQuery("from Term").list(); //$NON-NLS-1$ |
46 | }
|
46 | }
|
47 | catch (Exception e) |
47 | catch (Exception e) |
48 | {
|
48 | {
|
49 | e.printStackTrace(); |
49 | e.printStackTrace(); |
50 | }
|
50 | }
|
Line 55... | Line 55... | ||
55 | */
|
55 | */
|
56 | if (term == null) |
56 | if (term == null) |
57 | {
|
57 | {
|
58 | term = new ArrayList<Term>(); |
58 | term = new ArrayList<Term>(); |
59 | }
|
59 | }
|
- | 60 | ||
60 | return term; |
61 | return term; |
61 | }
|
62 | }
|
62 | 63 | ||
63 | /*
|
64 | /*
|
64 | * (non-Javadoc)
|
65 | * (non-Javadoc)
|
65 | *
|
66 | *
|
66 | * @see ch.ffhs.webE.dao.TermDAO#saveOrUpdate(ch.ffhs.webE.domain.Term)
|
67 | * @see ch.ffhs.webE.dao.TermDAO#saveOrUpdate(ch.ffhs.webE.domain.Term)
|
67 | */
|
68 | */
|
68 | public void saveOrUpdate(Term term) |
69 | public boolean saveOrUpdate(Term term) |
69 | {
|
70 | {
|
70 | try
|
71 | try
|
71 | {
|
72 | {
|
- | 73 | term.setObjectId(term.getObjectId()); |
|
72 | this.session.saveOrUpdate(term); |
74 | this.session.saveOrUpdate(term); |
- | 75 | return true; |
|
73 | }
|
76 | }
|
74 | catch (Exception e) |
77 | catch (Exception e) |
75 | {
|
78 | {
|
76 | this.transaction.rollback(); |
79 | this.transaction.rollback(); |
77 | e.printStackTrace(); |
80 | e.printStackTrace(); |
- | 81 | return false; |
|
78 | }
|
82 | }
|
79 | }
|
83 | }
|
80 | 84 | ||
81 | /*
|
85 | /*
|
82 | * (non-Javadoc)
|
86 | * (non-Javadoc)
|
Line 85... | Line 89... | ||
85 | */
|
89 | */
|
86 | public void deleteTerm(int termId) |
90 | public void deleteTerm(int termId) |
87 | {
|
91 | {
|
88 | try
|
92 | try
|
89 | {
|
93 | {
|
90 | Term user = (Term) this.session.get(Term.class, termId); |
94 | Term term = (Term) this.session.get(Term.class, termId); |
91 | this.session.delete(user); |
95 | this.session.delete(term); |
92 | }
|
96 | }
|
93 | catch (Exception e) |
97 | catch (Exception e) |
94 | {
|
98 | {
|
95 | this.transaction.rollback(); |
99 | this.transaction.rollback(); |
96 | e.printStackTrace(); |
100 | e.printStackTrace(); |
97 | }
|
101 | }
|
98 | }
|
102 | }
|
99 | 103 | ||
100 | /**
|
104 | /*
|
101 | * Returns a single user with this user name (used for login)
|
105 | * (non-Javadoc)
|
102 | *
|
106 | *
|
103 | * @param termName
|
- | |
104 | * Term name
|
- | |
105 | * @return User: Returns a user object if something is found. If not, null is
|
107 | * @see ch.ffhs.webE.dao.TermDAO#getTermById(int)
|
106 | * returned
|
- | |
107 | */
|
108 | */
|
108 | public Term searchTerm(String termName) |
109 | public Term getTermById(int termId) |
109 | {
|
110 | {
|
110 | Term term = null; |
111 | Term term = null; |
111 | 112 | ||
112 | /* Exec query */
|
- | |
113 | try
|
- | |
114 | {
|
- | |
115 | term = (Term) this.session |
- | |
116 | .createQuery("FROM User " + "WHERE username = :username") //$NON-NLS-1$ //$NON-NLS-2$ |
- | |
117 | .setParameter("username", termName).uniqueResult(); //$NON-NLS-1$ |
- | |
118 | }
|
- | |
119 | catch (Exception e) |
- | |
120 | {
|
- | |
121 | /* TODO: Log error */
|
- | |
122 | }
|
- | |
123 | return term; |
- | |
124 | }
|
- | |
125 | - | ||
126 | /**
|
- | |
127 | * List a term by ID
|
- | |
128 | *
|
- | |
129 | * @param termId
|
- | |
130 | * @return
|
- | |
131 | */
|
- | |
132 | public Term listTermById(int termId) |
- | |
133 | {
|
- | |
134 | Term term = null; |
- | |
135 | try
|
113 | try
|
136 | {
|
114 | {
|
137 | term = (Term) this.session.get(Term.class, termId); |
115 | term = (Term) this.session.get(Term.class, termId); |
138 | }
|
116 | }
|
139 | catch (Exception e) |
117 | catch (Exception e) |
140 | {
|
118 | {
|
141 | e.printStackTrace(); |
119 | e.printStackTrace(); |
142 | }
|
120 | }
|
- | 121 | ||
143 | return term; |
122 | return term; |
144 | }
|
123 | }
|
145 | }
|
124 | }
|
146 | 125 |