1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.pm.positionreportsubcat.dao;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
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.joda.time.LocalDate;
27 import org.kuali.kpme.core.util.OjbSubQueryUtil;
28 import org.kuali.kpme.core.util.ValidationUtils;
29 import org.kuali.kpme.pm.positionreportsubcat.PositionReportSubCategoryBo;
30 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
31
32 public class PositionReportSubCatDaoObjImpl extends PlatformAwareDaoBaseOjb implements PositionReportSubCatDao {
33 public PositionReportSubCategoryBo getPositionReportSubCatById(
34 String pmPositionReportSubCatId) {
35 Criteria crit = new Criteria();
36 crit.addEqualTo("pmPositionReportSubCatId", pmPositionReportSubCatId);
37
38 Query query = QueryFactory.newQuery(PositionReportSubCategoryBo.class, crit);
39 return (PositionReportSubCategoryBo) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
40 }
41
42 public List<PositionReportSubCategoryBo> getPositionReportSubCat(String pstnRptSubCat,LocalDate asOfDate) {
43 List<PositionReportSubCategoryBo> prscList = new ArrayList<PositionReportSubCategoryBo>();
44 Criteria root = new Criteria();
45 if(StringUtils.isNotEmpty(pstnRptSubCat)
46 && !ValidationUtils.isWildCard(pstnRptSubCat)) {
47 root.addEqualTo("positionReportSubCat", pstnRptSubCat);
48 }
49 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(PositionReportSubCategoryBo.class, asOfDate, PositionReportSubCategoryBo.BUSINESS_KEYS, false));
50 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PositionReportSubCategoryBo.class, PositionReportSubCategoryBo.BUSINESS_KEYS, false));
51
52 Criteria activeFilter = new Criteria();
53 activeFilter.addEqualTo("active", true);
54 root.addAndCriteria(activeFilter);
55 Query query = QueryFactory.newQuery(PositionReportSubCategoryBo.class, root);
56
57 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
58 if(!c.isEmpty())
59 prscList.addAll(c);
60
61 return prscList;
62 }
63
64 @Override
65 public PositionReportSubCategoryBo getActivePositionReportSubCat(String pstnRptSubCat, LocalDate asOfDate) {
66 Criteria root = new Criteria();
67 root.addEqualTo("positionReportSubCat", pstnRptSubCat);
68 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(PositionReportSubCategoryBo.class, asOfDate, PositionReportSubCategoryBo.BUSINESS_KEYS, false));
69 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PositionReportSubCategoryBo.class, PositionReportSubCategoryBo.BUSINESS_KEYS, false));
70 Criteria activeFilter = new Criteria();
71 activeFilter.addEqualTo("active", true);
72 root.addAndCriteria(activeFilter);
73
74 Query query = QueryFactory.newQuery(PositionReportSubCategoryBo.class, root);
75 return (PositionReportSubCategoryBo) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
76 }
77
78 }