01: package com.technoetic.xplanner.db;
02:
03: import com.technoetic.xplanner.db.hibernate.ThreadSession;
04:
05: import java.util.Collection;
06: import java.util.Date;
07:
08: import net.sf.hibernate.HibernateException;
09:
10: /**
11: * TODO move to story repository.
12: *
13: * @see com.technoetic.xplanner.domain.repository.StoryRepositoryHibernate
14: */
15: public class StoryQueryHelper {
16: private int personId;
17:
18: public StoryQueryHelper() {
19: }
20:
21: public StoryQueryHelper(int personId) {
22: this .personId = personId;
23: }
24:
25: public void setPersonId(int personId) {
26: this .personId = personId;
27: }
28:
29: public Collection getStoriesForCustomer() throws QueryException {
30: return bindAndExecuteQuery("stories.customer");
31: }
32:
33: public Collection getStoriesForTracker() throws QueryException {
34: return bindAndExecuteQuery("stories.tracker");
35: }
36:
37: private Collection bindAndExecuteQuery(String queryName)
38: throws QueryException {
39: try {
40: return ThreadSession.get().getNamedQuery(queryName)
41: .setInteger("personId", personId).setDate("date",
42: new Date()).list();
43: } catch (HibernateException e) {
44: throw new QueryException(e);
45: }
46: }
47: }
|