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 org.apache.ojb.broker.query.Criteria;
19 import org.apache.ojb.broker.query.Query;
20 import org.apache.ojb.broker.query.QueryFactory;
21 import org.apache.ojb.broker.query.ReportQueryByCriteria;
22 import org.kuali.hr.time.salgroup.SalGroup;
23 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
24
25 import java.sql.Date;
26
27 public class SalGroupDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements SalGroupDao {
28
29 @Override
30 public void saveOrUpdate(SalGroup salGroup) {
31 this.getPersistenceBrokerTemplate().store(salGroup);
32 }
33
34 @Override
35 public SalGroup getSalGroup(String salGroup, Date asOfDate) {
36 Criteria root = new Criteria();
37 Criteria effdt = new Criteria();
38 Criteria timestamp = new Criteria();
39
40 effdt.addEqualToField("hrSalGroup", Criteria.PARENT_QUERY_PREFIX + "hrSalGroup");
41 effdt.addLessOrEqualThan("effectiveDate", asOfDate);
42 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(SalGroup.class, effdt);
43 effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
44
45 timestamp.addEqualToField("hrSalGroup", Criteria.PARENT_QUERY_PREFIX + "hrSalGroup");
46 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
47 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(SalGroup.class, timestamp);
48 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
49
50 root.addEqualTo("hrSalGroup", salGroup);
51 root.addEqualTo("effectiveDate", effdtSubQuery);
52 root.addEqualTo("timestamp", timestampSubQuery);
53 Criteria activeFilter = new Criteria();
54 activeFilter.addEqualTo("active", true);
55 root.addAndCriteria(activeFilter);
56
57 Query query = QueryFactory.newQuery(SalGroup.class, root);
58 SalGroup s = (SalGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
59
60 return s;
61 }
62
63 @Override
64 public SalGroup getSalGroup(String hrSalGroupId) {
65 Criteria crit = new Criteria();
66 crit.addEqualTo("hrSalGroupId", hrSalGroupId);
67
68 Query query = QueryFactory.newQuery(SalGroup.class, crit);
69 return (SalGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
70 }
71 @Override
72 public int getSalGroupCount(String salGroup) {
73 Criteria crit = new Criteria();
74 crit.addEqualTo("hrSalGroup", salGroup);
75 Query query = QueryFactory.newQuery(SalGroup.class, crit);
76 return this.getPersistenceBrokerTemplate().getCount(query);
77 }
78
79 }