01: package com.technoetic.xplanner.domain.repository;
02:
03: import java.util.Collection;
04: import java.util.Date;
05: import java.util.List;
06:
07: import net.sf.hibernate.Hibernate;
08: import net.sf.hibernate.HibernateException;
09: import net.sf.hibernate.type.Type;
10: import org.apache.log4j.Logger;
11: import org.springframework.orm.hibernate.HibernateTemplate;
12:
13: import com.technoetic.xplanner.util.LogUtil;
14:
15: /*
16: * A Hibernate implementation of the StoryRepository interface.
17: *
18: * Implementation is based pretty heavily on (and should eventually supercede)
19: * StoryQueryHelper.
20: *
21: * @author James Beard
22: * @see com.technoetic.xplanner.db.StoryQueryHelper
23: */
24: public class StoryRepositoryHibernate extends HibernateObjectRepository
25: implements StoryRepository {
26: private static Logger log = LogUtil.getLogger();
27:
28: public StoryRepositoryHibernate() throws HibernateException {
29: super (com.technoetic.xplanner.domain.UserStory.class);
30: }
31:
32: /*
33: * Returns a collection of user stories in current and future iterations
34: * where personId is the customer.
35: *
36: * @param personId the id of the customer
37: * @return the collection of stories
38: */
39: public Collection getStoriesForPersonWhereCustomer(int personId) {
40: return queryStories("stories.customer", personId);
41: }
42:
43: /*
44: * Returns a collection of user stories in current and future iterations
45: * where personId is the tracker.
46: *
47: * @param personId the id of the tracker
48: * @return the collection of stories
49: */
50: public Collection getStoriesForPersonWhereTracker(int personId) {
51: return queryStories("stories.tracker", personId);
52: }
53:
54: private List queryStories(String queryName, int personId) {
55: HibernateTemplate template = getHibernateTemplate();
56: return template.findByNamedQueryAndNamedParam(queryName,
57: new String[] { "date", "personId" }, new Object[] {
58: new Date(), new Integer(personId) },
59: new Type[] { Hibernate.DATE, Hibernate.INTEGER });
60: }
61: }
|