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 import java.util.ArrayList;
20 import java.util.List;
21
22 import com.google.common.collect.ImmutableList;
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.apache.ojb.broker.query.ReportQueryByCriteria;
28 import org.kuali.hr.core.util.OjbSubQueryUtil;
29 import org.kuali.hr.location.Location;
30 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
31
32 public class LocationDaoSpringObjImpl extends PlatformAwareDaoBaseOjb implements LocationDao {
33 private static final ImmutableList<String> EQUAL_TO_FIELDS = new ImmutableList.Builder<String>()
34 .add("location")
35 .build();
36 @Override
37 public Location getLocation(String location, Date asOfDate) {
38 Criteria root = new Criteria();
39
40 root.addEqualTo("location", location);
41 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(Location.class, new java.sql.Date(asOfDate.getTime()), EQUAL_TO_FIELDS, false));
42 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(Location.class, EQUAL_TO_FIELDS, false));
43 Criteria activeFilter = new Criteria();
44 activeFilter.addEqualTo("active", true);
45 root.addAndCriteria(activeFilter);
46
47
48 Query query = QueryFactory.newQuery(Location.class, root);
49
50 Location l = (Location)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
51
52 return l;
53 }
54
55 @Override
56 public Location getLocation(String hrLocationId) {
57 Criteria crit = new Criteria();
58 crit.addEqualTo("hrLocationId", hrLocationId);
59
60 Query query = QueryFactory.newQuery(Location.class, crit);
61 return (Location)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
62 }
63
64 @Override
65 public int getLocationCount(String location) {
66 Criteria crit = new Criteria();
67 crit.addEqualTo("location", location);
68 Query query = QueryFactory.newQuery(Location.class, crit);
69 return this.getPersistenceBrokerTemplate().getCount(query);
70 }
71
72 @Override
73 @SuppressWarnings("unchecked")
74 public List<Location> searchLocations(String location, String locationDescr, String active, String showHistory) {
75 List<Location> results = new ArrayList<Location>();
76
77 Criteria root = new Criteria();
78
79 if (StringUtils.isNotBlank(location)) {
80 root.addLike("location", location);
81 }
82
83 if (StringUtils.isNotBlank(locationDescr)) {
84 root.addLike("description", locationDescr);
85 }
86
87 if (StringUtils.isNotBlank(active)) {
88 Criteria activeFilter = new Criteria();
89 if (StringUtils.equals(active, "Y")) {
90 activeFilter.addEqualTo("active", true);
91 } else if (StringUtils.equals(active, "N")) {
92 activeFilter.addEqualTo("active", false);
93 }
94 root.addAndCriteria(activeFilter);
95 }
96
97 Query query = QueryFactory.newQuery(Location.class, root);
98 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
99
100 return results;
101 }
102
103 }