1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.salgroup.dao;
17
18 import java.sql.Date;
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.apache.ojb.broker.query.Criteria;
24 import org.apache.ojb.broker.query.Query;
25 import org.apache.ojb.broker.query.QueryFactory;
26 import org.apache.ojb.broker.query.ReportQueryByCriteria;
27 import org.kuali.hr.time.salgroup.SalGroup;
28 import org.kuali.hr.time.util.TKUtils;
29 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30
31 public class SalGroupDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements SalGroupDao {
32
33 @Override
34 public void saveOrUpdate(SalGroup salGroup) {
35 this.getPersistenceBrokerTemplate().store(salGroup);
36 }
37
38 @Override
39 public SalGroup getSalGroup(String salGroup, Date asOfDate) {
40 Criteria root = new Criteria();
41 Criteria effdt = new Criteria();
42 Criteria timestamp = new Criteria();
43
44 effdt.addEqualToField("hrSalGroup", Criteria.PARENT_QUERY_PREFIX + "hrSalGroup");
45 effdt.addLessOrEqualThan("effectiveDate", asOfDate);
46 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(SalGroup.class, effdt);
47 effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
48
49 timestamp.addEqualToField("hrSalGroup", Criteria.PARENT_QUERY_PREFIX + "hrSalGroup");
50 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
51 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(SalGroup.class, timestamp);
52 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
53
54 root.addEqualTo("hrSalGroup", salGroup);
55 root.addEqualTo("effectiveDate", effdtSubQuery);
56 root.addEqualTo("timestamp", timestampSubQuery);
57 Criteria activeFilter = new Criteria();
58 activeFilter.addEqualTo("active", true);
59 root.addAndCriteria(activeFilter);
60
61 Query query = QueryFactory.newQuery(SalGroup.class, root);
62 SalGroup s = (SalGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
63
64 return s;
65 }
66
67 @Override
68 public SalGroup getSalGroup(String hrSalGroupId) {
69 Criteria crit = new Criteria();
70 crit.addEqualTo("hrSalGroupId", hrSalGroupId);
71
72 Query query = QueryFactory.newQuery(SalGroup.class, crit);
73 return (SalGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
74 }
75 @Override
76 public int getSalGroupCount(String salGroup) {
77 Criteria crit = new Criteria();
78 crit.addEqualTo("hrSalGroup", salGroup);
79 Query query = QueryFactory.newQuery(SalGroup.class, crit);
80 return this.getPersistenceBrokerTemplate().getCount(query);
81 }
82
83 @Override
84 @SuppressWarnings("unchecked")
85 public List<SalGroup> getSalGroups(String hrSalGroup, String descr, Date fromEffdt, Date toEffdt, String active, String showHistory) {
86 List<SalGroup> results = new ArrayList<SalGroup>();
87
88 Criteria root = new Criteria();
89
90 if (StringUtils.isNotBlank(hrSalGroup)) {
91 root.addLike("hrSalGroup", hrSalGroup);
92 }
93
94 if (StringUtils.isNotBlank(descr)) {
95 root.addLike("descr", descr);
96 }
97
98 Criteria effectiveDateFilter = new Criteria();
99 if (fromEffdt != null) {
100 effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt);
101 }
102 if (toEffdt != null) {
103 effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt);
104 }
105 if (fromEffdt == null && toEffdt == null) {
106 effectiveDateFilter.addLessOrEqualThan("effectiveDate", TKUtils.getCurrentDate());
107 }
108 root.addAndCriteria(effectiveDateFilter);
109
110 if (StringUtils.equals(showHistory, "N")) {
111 Criteria effdt = new Criteria();
112 effdt.addEqualToField("hrSalGroup", Criteria.PARENT_QUERY_PREFIX + "hrSalGroup");
113 effdt.addAndCriteria(effectiveDateFilter);
114 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(SalGroup.class, effdt);
115 effdtSubQuery.setAttributes(new String[]{"max(effectiveDate)"});
116 root.addEqualTo("effectiveDate", effdtSubQuery);
117
118 Criteria timestamp = new Criteria();
119 timestamp.addEqualToField("hrSalGroup", Criteria.PARENT_QUERY_PREFIX + "hrSalGroup");
120 timestamp.addAndCriteria(effectiveDateFilter);
121 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(SalGroup.class, timestamp);
122 timestampSubQuery.setAttributes(new String[]{"max(timestamp)"});
123 root.addEqualTo("timestamp", timestampSubQuery);
124 }
125
126 Query query = QueryFactory.newQuery(SalGroup.class, root);
127 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
128
129 return results;
130 }
131
132 }