1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.batch.dao;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.ojb.broker.query.Criteria;
25 import org.apache.ojb.broker.query.Query;
26 import org.apache.ojb.broker.query.QueryFactory;
27 import org.kuali.hr.time.batch.BatchJobEntry;
28 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29
30 public class BatchJobEntryDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements BatchJobEntryDao {
31
32 @Override
33 public void saveOrUpdate(BatchJobEntry batchJobEntry) {
34 this.getPersistenceBrokerTemplate().store(batchJobEntry);
35 }
36
37 @Override
38 public BatchJobEntry getBatchJobEntry(Long batchJobEntryId) {
39 Criteria currentRecordCriteria = new Criteria();
40 currentRecordCriteria.addEqualTo("tkBatchJobEntryId", batchJobEntryId);
41
42 return (BatchJobEntry) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(BatchJobEntry.class, currentRecordCriteria));
43 }
44
45 @Override
46 public List<BatchJobEntry> getBatchJobEntries(Long batchJobEntryId) {
47 Criteria root = new Criteria();
48 root.addEqualTo("tkBatchJobId", batchJobEntryId);
49 Query query = QueryFactory.newQuery(BatchJobEntry.class, root);
50
51 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
52 List<BatchJobEntry> entries = new ArrayList<BatchJobEntry>();
53 entries.addAll(c);
54
55 return entries;
56 }
57
58 @Override
59 public List<BatchJobEntry> getBatchJobEntries(String ip, String status) {
60 Criteria root = new Criteria();
61 root.addEqualTo("ipAddress", ip);
62 root.addEqualTo("batchJobEntryStatus", status);
63 Query query = QueryFactory.newQuery(BatchJobEntry.class, root);
64
65 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
66 List<BatchJobEntry> entries = new ArrayList<BatchJobEntry>();
67 entries.addAll(c);
68
69 return entries;
70 }
71
72 @Override
73 public List<BatchJobEntry> getBatchJobEntries(Map<String, Object> criteria) {
74 Criteria root = new Criteria();
75 for (Map.Entry<String, Object> crit : criteria.entrySet()) {
76 if(crit.getValue() != null){
77 if(StringUtils.equals("ipAddress", crit.getKey()) || StringUtils.equals("batchJobName", crit.getKey())) {
78 root.addLike(crit.getKey(), "%" + crit.getValue() + "%");
79 }
80 else {
81 root.addEqualTo(crit.getKey(), crit.getValue());
82 }
83 }
84 }
85
86 Query query = QueryFactory.newQuery(BatchJobEntry.class, root);
87
88 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
89 List<BatchJobEntry> entries = new ArrayList<BatchJobEntry>();
90 entries.addAll(c);
91
92 return entries;
93 }
94 }