1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.timeblock.dao;
17
18 import java.sql.Date;
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.LinkedList;
22 import java.util.List;
23
24 import org.apache.log4j.Logger;
25 import org.apache.ojb.broker.query.Criteria;
26 import org.apache.ojb.broker.query.Query;
27 import org.apache.ojb.broker.query.QueryFactory;
28 import org.apache.ojb.broker.query.ReportQueryByCriteria;
29 import org.kuali.hr.time.assignment.Assignment;
30 import org.kuali.hr.time.timeblock.TimeBlock;
31 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
32
33 public class TimeBlockDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements TimeBlockDao {
34
35 @SuppressWarnings("unused")
36 private static final Logger LOG = Logger.getLogger(TimeBlockDaoSpringOjbImpl.class);
37
38 public void saveOrUpdate(TimeBlock timeBlock) {
39 this.getPersistenceBrokerTemplate().store(timeBlock);
40 }
41
42 public void saveOrUpdate(List<TimeBlock> timeBlockList) {
43 if (timeBlockList != null) {
44 for (TimeBlock timeBlock : timeBlockList) {
45 this.getPersistenceBrokerTemplate().store(timeBlock);
46 }
47 }
48 }
49
50 public TimeBlock getTimeBlock(String tkTimeBlockId) {
51 Criteria currentRecordCriteria = new Criteria();
52 currentRecordCriteria.addEqualTo("tkTimeBlockId", tkTimeBlockId);
53
54 return (TimeBlock) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(TimeBlock.class, currentRecordCriteria));
55 }
56
57 @SuppressWarnings("unchecked")
58 public List<TimeBlock> getTimeBlocks(String documentId) {
59 Criteria currentRecordCriteria = new Criteria();
60 currentRecordCriteria.addEqualTo("documentId", documentId);
61 Query query = QueryFactory.newQuery(TimeBlock.class, currentRecordCriteria);
62 List<TimeBlock> timeBlocks = (List<TimeBlock>) this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
63 return timeBlocks == null || timeBlocks.size() == 0 ? new LinkedList<TimeBlock>() : timeBlocks;
64 }
65
66 @SuppressWarnings("unchecked")
67 public List<TimeBlock> getTimeBlocksForAssignment(Assignment assign) {
68 Criteria rootCriteria = new Criteria();
69 rootCriteria.addEqualTo("principalId", assign.getPrincipalId());
70 rootCriteria.addEqualTo("jobNumber", assign.getJobNumber());
71 rootCriteria.addEqualTo("task", assign.getTask());
72 rootCriteria.addEqualTo("workArea", assign.getWorkArea());
73 Query query = QueryFactory.newQuery(TimeBlock.class, rootCriteria);
74 List<TimeBlock> timeBlocks = (List<TimeBlock>) this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
75 return timeBlocks == null || timeBlocks.isEmpty() ? new ArrayList<TimeBlock>() : timeBlocks;
76 }
77
78 public void deleteTimeBlock(TimeBlock timeBlock) {
79 this.getPersistenceBrokerTemplate().delete(timeBlock);
80 }
81
82
83 public void deleteTimeBlocksAssociatedWithDocumentId(String documentId) {
84 Criteria crit = new Criteria();
85 crit.addEqualTo("documentId", documentId);
86 this.getPersistenceBrokerTemplate().deleteByQuery(QueryFactory.newQuery(TimeBlock.class, crit));
87
88 }
89
90 @SuppressWarnings("unchecked")
91 @Override
92 public List<TimeBlock> getTimeBlocksForClockLogEndId(String tkClockLogId) {
93 Criteria crit = new Criteria();
94 crit.addEqualTo("clockLogEndId", tkClockLogId);
95 return (List<TimeBlock>) this.getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(TimeBlock.class, crit));
96 }
97
98 @SuppressWarnings("unchecked")
99 @Override
100 public List<TimeBlock> getTimeBlocksForClockLogBeginId(String tkClockLogId) {
101 Criteria crit = new Criteria();
102 crit.addEqualTo("clockLogBeginId", tkClockLogId);
103 return (List<TimeBlock>) this.getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(TimeBlock.class, crit));
104 }
105
106 public List<TimeBlock> getTimeBlocks() {
107 List<TimeBlock> timeBlocks = new ArrayList<TimeBlock>();
108 Criteria crit = new Criteria();
109
110 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(TimeBlock.class, crit));
111
112 if (c != null) {
113 timeBlocks.addAll(c);
114 }
115
116 return timeBlocks;
117 }
118
119 @Override
120 public List<TimeBlock> getLatestEndTimestamp() {
121 List<TimeBlock> timeBlocks = new ArrayList<TimeBlock>();
122 Criteria root = new Criteria();
123 Criteria crit = new Criteria();
124
125 ReportQueryByCriteria endTimestampSubQuery = QueryFactory.newReportQuery(TimeBlock.class, crit);
126 endTimestampSubQuery.setAttributes(new String[]{"max(endTimestamp)"});
127
128 root.addEqualTo("endTimestamp", endTimestampSubQuery);
129
130 Query query = QueryFactory.newQuery(TimeBlock.class, root);
131 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
132
133 if (c != null) {
134 timeBlocks.addAll(c);
135 }
136
137 return timeBlocks;
138 }
139
140 @Override
141 public List<TimeBlock> getOvernightTimeBlocks(String clockLogEndId) {
142 List<TimeBlock> timeBlocks = new ArrayList<TimeBlock>();
143 Criteria root = new Criteria();
144
145 root.addEqualTo("clockLogEndId", clockLogEndId);
146
147 Query query = QueryFactory.newQuery(TimeBlock.class, root);
148 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
149
150 if (c != null) {
151 timeBlocks.addAll(c);
152 }
153
154 return timeBlocks;
155 }
156
157 @SuppressWarnings("unchecked")
158 @Override
159 public List<TimeBlock> getTimeBlocksWithEarnCode(String earnCode, Date effDate) {
160 Criteria root = new Criteria();
161 root.addEqualTo("earnCode", earnCode);
162 root.addGreaterOrEqualThan("beginTimestamp", effDate);
163 return (List<TimeBlock>) this.getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(TimeBlock.class, root));
164 }
165
166 }