1
2
3
4
5
6 package org.andromda.timetracker.domain;
7
8 import java.util.List;
9 import org.andromda.timetracker.vo.TimecardSearchCriteriaVO;
10 import org.andromda.timetracker.vo.TimecardSummaryVO;
11 import org.apache.commons.logging.Log;
12 import org.apache.commons.logging.LogFactory;
13 import org.hibernate.Criteria;
14 import org.hibernate.FetchMode;
15 import org.hibernate.criterion.Restrictions;
16
17
18
19
20 public class TimecardDaoImpl
21 extends TimecardDaoBase
22 {
23 private Log logger = LogFactory.getLog(TimecardDaoImpl.class);
24
25
26
27
28 @Override
29 protected List handleFindByCriteria(TimecardSearchCriteriaVO criteria)
30 {
31
32 Criteria timecardCriteria = this.hibernateSession.createCriteria(Timecard.class);
33 timecardCriteria.setFetchMode("submitter", FetchMode.JOIN);
34 timecardCriteria.setFetchMode("approver", FetchMode.JOIN);
35
36
37 if (criteria.getSubmitterId() != null)
38 {
39 timecardCriteria.createCriteria("submitter").add(Restrictions.idEq(criteria.getSubmitterId()));
40 }
41
42
43 if (criteria.getApproverId() != null)
44 {
45 timecardCriteria.createCriteria("approver").add(Restrictions.idEq(criteria.getApproverId()));
46 }
47
48
49 if (criteria.getStatus() != null)
50 {
51 timecardCriteria.add(Restrictions.eq("status", criteria.getStatus()));
52 }
53
54
55 if (criteria.getStartDateMin() != null)
56 {
57 timecardCriteria.add(Restrictions.ge("startDate", criteria.getStartDateMin()));
58 }
59
60
61 if (criteria.getStartDateMax() != null)
62 {
63 timecardCriteria.add(Restrictions.le("startDate", criteria.getStartDateMax()));
64 }
65
66 List timecards = timecardCriteria.list();
67 if (this.logger.isDebugEnabled())
68 {
69 this.logger.debug(timecards.size() + " timecards found");
70 }
71 return timecards;
72 }
73
74
75
76
77 @Override
78 public void toTimecardSummaryVO(
79 Timecard sourceEntity,
80 TimecardSummaryVO targetVO)
81 {
82
83 super.toTimecardSummaryVO(sourceEntity, targetVO);
84
85
86 targetVO.setSubmitterName(sourceEntity.getSubmitter().getUsername());
87 if (sourceEntity.getApprover() != null)
88 {
89 targetVO.setApproverName(sourceEntity.getApprover().getUsername());
90 }
91 }
92
93
94
95
96 @Override
97 public TimecardSummaryVO toTimecardSummaryVO(final Timecard entity)
98 {
99
100 return super.toTimecardSummaryVO(entity);
101 }
102
103
104
105
106
107
108 @SuppressWarnings("static-method")
109 private Timecard loadTimecardFromTimecardSummaryVO(TimecardSummaryVO timecardSummaryVO)
110 {
111
112 throw new java.lang.UnsupportedOperationException("loadTimecardFromTimecardSummaryVO(TimecardSummaryVO) not yet implemented.");
113
114
115
116
117
118
119
120
121
122 }
123
124
125
126
127 @Override
128 public Timecard timecardSummaryVOToEntity(TimecardSummaryVO timecardSummaryVO)
129 {
130
131 Timecard entity = this.loadTimecardFromTimecardSummaryVO(timecardSummaryVO);
132 this.timecardSummaryVOToEntity(timecardSummaryVO, entity, true);
133 return entity;
134 }
135
136
137
138
139 @Override
140 public void timecardSummaryVOToEntity(
141 TimecardSummaryVO sourceVO,
142 Timecard targetEntity,
143 boolean copyIfNull)
144 {
145
146 super.timecardSummaryVOToEntity(sourceVO, targetEntity, copyIfNull);
147 }
148 }