1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.location.dao;
17
18 import java.sql.Date;
19
20 import org.apache.ojb.broker.query.Criteria;
21 import org.apache.ojb.broker.query.Query;
22 import org.apache.ojb.broker.query.QueryFactory;
23 import org.apache.ojb.broker.query.ReportQueryByCriteria;
24 import org.kuali.hr.location.Location;
25 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
26
27 public class LocationDaoSpringObjImpl extends PlatformAwareDaoBaseOjb implements LocationDao {
28
29 @Override
30 public Location getLocation(String location, Date asOfDate) {
31 Criteria root = new Criteria();
32 Criteria effdt = new Criteria();
33 Criteria timestamp = new Criteria();
34
35 effdt.addEqualToField("location", Criteria.PARENT_QUERY_PREFIX + "location");
36
37
38 effdt.addLessOrEqualThan("effectiveDate", asOfDate);
39
40 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(Location.class, effdt);
41 effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
42
43 timestamp.addEqualToField("location", Criteria.PARENT_QUERY_PREFIX + "location");
44
45
46 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
47
48 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(Location.class, timestamp);
49 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
50
51 root.addEqualTo("location", location);
52 root.addEqualTo("effectiveDate", effdtSubQuery);
53 root.addEqualTo("timestamp", timestampSubQuery);
54
55 Criteria activeFilter = new Criteria();
56 activeFilter.addEqualTo("active", true);
57 root.addAndCriteria(activeFilter);
58
59
60 Query query = QueryFactory.newQuery(Location.class, root);
61
62 Location l = (Location)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
63
64 return l;
65 }
66
67 @Override
68 public Location getLocation(String hrLocationId) {
69 Criteria crit = new Criteria();
70 crit.addEqualTo("hrLocationId", hrLocationId);
71
72 Query query = QueryFactory.newQuery(Location.class, crit);
73 return (Location)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
74 }
75
76 @Override
77 public int getLocationCount(String location) {
78 Criteria crit = new Criteria();
79 crit.addEqualTo("location", location);
80 Query query = QueryFactory.newQuery(Location.class, crit);
81 return this.getPersistenceBrokerTemplate().getCount(query);
82 }
83
84 }