1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.gl.dataaccess.impl;
17
18 import java.sql.Date;
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.apache.ojb.broker.query.Criteria;
26 import org.apache.ojb.broker.query.QueryByCriteria;
27 import org.apache.ojb.broker.query.QueryFactory;
28 import org.apache.ojb.broker.query.ReportQueryByCriteria;
29 import org.kuali.ole.gl.businessobject.OriginEntryGroup;
30 import org.kuali.ole.gl.businessobject.OriginEntrySource;
31 import org.kuali.ole.gl.dataaccess.OriginEntryGroupDao;
32 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
33
34
35
36
37 public class OriginEntryGroupDaoOjb extends PlatformAwareDaoBaseOjb implements OriginEntryGroupDao {
38 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OriginEntryGroupDaoOjb.class);
39
40 private static final String DATE = "date";
41 private static final String ID = "id";
42 private static final String SOURCE_CODE = "sourceCode";
43 private static final String PROCESS = "process";
44 private static final String VALID = "valid";
45 private static final String SCRUB = "scrub";
46 private static final String ORIGIN_ENTRY_GRP_ID = "ORIGIN_ENTRY_GRP_ID";
47 private static final String MAX_ORIGIN_ENTRY_GRP_ID = "max(ORIGIN_ENTRY_GRP_ID)";
48
49
50
51
52
53
54
55
56
57 public OriginEntryGroup getGroupWithMaxIdFromSource(String sourceCode) {
58 LOG.debug("getGroupWithMaxIdFromSource() started");
59
60 Criteria crit = new Criteria();
61
62 Criteria subCrit = new Criteria();
63 subCrit.addEqualTo(SOURCE_CODE, sourceCode);
64 ReportQueryByCriteria subQuery = new ReportQueryByCriteria(OriginEntryGroup.class, subCrit);
65 subQuery.setAttributes(new String[]{MAX_ORIGIN_ENTRY_GRP_ID});
66
67 crit.addGreaterOrEqualThan(ORIGIN_ENTRY_GRP_ID, subQuery);
68
69 QueryByCriteria qbc = QueryFactory.newQuery(OriginEntryGroup.class, crit);
70
71 return (OriginEntryGroup) getPersistenceBrokerTemplate().getObjectByQuery(qbc);
72 }
73
74
75
76
77
78
79
80
81 public Collection<OriginEntryGroup> getOlderGroups(Date day) {
82 LOG.debug("getOlderGroups() started");
83
84 Criteria criteria = new Criteria();
85 criteria.addLessOrEqualThan(DATE, day);
86
87 return getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(OriginEntryGroup.class, criteria));
88 }
89
90
91
92
93
94
95
96
97 public void deleteGroups(Collection<OriginEntryGroup> groups) {
98 LOG.debug("deleteGroups() started");
99
100 List ids = new ArrayList();
101 for (Iterator iter = groups.iterator(); iter.hasNext();) {
102 OriginEntryGroup element = (OriginEntryGroup) iter.next();
103 ids.add(element.getId());
104 }
105 Criteria criteria = new Criteria();
106 criteria.addIn(ID, ids);
107
108 getPersistenceBrokerTemplate().deleteByQuery(QueryFactory.newQuery(OriginEntryGroup.class, criteria));
109 getPersistenceBrokerTemplate().clearCache();
110 }
111
112
113
114
115
116
117
118
119 public Collection getMatchingGroups(Map searchCriteria) {
120 LOG.debug("getMatchingGroups() started");
121
122 Criteria criteria = new Criteria();
123 for (Iterator iterator = searchCriteria.keySet().iterator(); iterator.hasNext();) {
124 String key = iterator.next().toString();
125 criteria.addEqualTo(key, searchCriteria.get(key));
126 }
127
128 QueryByCriteria qbc = QueryFactory.newQuery(OriginEntryGroup.class, criteria);
129 return getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
130 }
131
132
133
134
135
136
137
138
139 public Collection getPosterGroups(String groupSourceCode) {
140 LOG.debug("getPosterGroups() started");
141
142 Criteria criteria = new Criteria();
143 criteria.addEqualTo(SOURCE_CODE, groupSourceCode);
144 criteria.addEqualTo(PROCESS, Boolean.TRUE);
145 criteria.addEqualTo(VALID, Boolean.TRUE);
146
147 QueryByCriteria qbc = QueryFactory.newQuery(OriginEntryGroup.class, criteria);
148 return getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
149 }
150
151
152
153
154
155
156
157 public Collection<OriginEntryGroup> getAllScrubbableBackupGroups() {
158 Criteria criteria = new Criteria();
159 criteria.addEqualTo(SOURCE_CODE, OriginEntrySource.BACKUP);
160 criteria.addEqualTo(SCRUB, Boolean.TRUE);
161 criteria.addEqualTo(PROCESS, Boolean.TRUE);
162 criteria.addEqualTo(VALID, Boolean.TRUE);
163
164 QueryByCriteria qbc = QueryFactory.newQuery(OriginEntryGroup.class, criteria);
165 return getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
166 }
167
168
169
170
171
172
173
174
175 public Collection getGroupsToBackup(Date groupDate) {
176 LOG.debug("getGroupsToBackup() started");
177
178 Criteria criteria = new Criteria();
179 criteria.addLessOrEqualThan(DATE, groupDate);
180 criteria.addEqualTo(SCRUB, Boolean.TRUE);
181 criteria.addEqualTo(PROCESS, Boolean.TRUE);
182 criteria.addEqualTo(VALID, Boolean.TRUE);
183
184 QueryByCriteria qbc = QueryFactory.newQuery(OriginEntryGroup.class, criteria);
185 return getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
186 }
187
188
189
190
191
192
193
194
195
196
197
198
199 public OriginEntryGroup getExactMatchingEntryGroup(Integer id) {
200 LOG.debug("getMatchingEntries() started");
201 return (OriginEntryGroup) getPersistenceBrokerTemplate().getObjectById(OriginEntryGroup.class, id);
202 }
203
204
205
206
207
208
209
210 public Collection<OriginEntryGroup> getRecentGroups(Date day) {
211 LOG.debug("getOlderGroups() started");
212
213 Criteria criteria = new Criteria();
214 criteria.addGreaterOrEqualThan(DATE, day);
215
216 return getPersistenceBrokerTemplate().getCollectionByQuery(QueryFactory.newQuery(OriginEntryGroup.class, criteria));
217 }
218
219
220 }