01: package com.technoetic.xplanner.db;
02:
03: import com.technoetic.xplanner.db.hibernate.ThreadSession;
04: import com.technoetic.xplanner.domain.Iteration;
05: import com.technoetic.xplanner.domain.Person;
06: import com.technoetic.xplanner.domain.UserStory;
07: import net.sf.hibernate.Hibernate;
08: import net.sf.hibernate.Session;
09: import net.sf.hibernate.type.Type;
10: import org.apache.log4j.Logger;
11:
12: import java.util.Collection;
13: import java.util.Collections;
14: import java.util.Date;
15:
16: public class CustomerStoriesQuery {
17: private Logger log = Logger.getLogger(getClass());
18: private int personId;
19: private Collection stories;
20: private Collection myStories;
21: //DEBT Why static? Should the query go to either Story.xml or Person.xml?
22: private static String query;
23:
24: public void setPersonId(int personId) {
25: this .personId = personId;
26: }
27:
28: public int getPersonId() {
29: return personId;
30: }
31:
32: public Collection getMyStories() {
33: if (myStories == null) {
34: myStories = getStories();
35: }
36: return myStories;
37: }
38:
39: private Collection getStories() {
40: Session session = ThreadSession.get();
41: if (stories == null) {
42: try {
43: if (session == null) {
44: log
45: .error("no Hibernate session provided, ignoring "
46: + this );
47: return Collections.EMPTY_LIST;
48: }
49: try {
50: if (query == null) {
51: query = "select distinct story from "
52: + "story in "
53: + UserStory.class
54: + ","
55: + "iteration in "
56: + Iteration.class
57: + ","
58: + "person in "
59: + Person.class
60: + " where iteration.id = story.iterationId and iteration.endDate > ? and "
61: + "person.id = story.customer.id and person.id = ?";
62: }
63: stories = session.find(query, new Object[] {
64: new Date(), new Integer(personId) },
65: new Type[] { Hibernate.DATE,
66: Hibernate.INTEGER });
67: } catch (Exception ex) {
68: log.error("query error", ex);
69: } finally {
70: session.connection().rollback();
71: }
72: } catch (Exception e) {
73: log.error("error in CustomerStoriesQuery", e);
74: }
75:
76: }
77: return stories;
78: }
79: }
|