View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.hr.time.earngroup.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.earngroup.EarnGroup;
23  import org.kuali.hr.time.earngroup.EarnGroupDefinition;
24  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
25  import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
26  
27  import java.sql.Date;
28  
29  public class EarnGroupDaoServiceImpl extends PlatformAwareDaoBaseOjb implements EarnGroupDaoService {
30  
31  	@Override
32  	public EarnGroup getEarnGroup(String earnGroup, Date asOfDate) {
33  		Criteria root = new Criteria();
34  		Criteria effdt = new Criteria();
35  		Criteria timestamp = new Criteria();
36  
37  		effdt.addEqualToField("earnGroup", Criteria.PARENT_QUERY_PREFIX + "earnGroup");
38  		effdt.addLessOrEqualThan("effectiveDate", asOfDate);
39  //		effdt.addEqualTo("active", true);
40  		ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(EarnGroup.class, effdt);
41  		effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
42  
43  		timestamp.addEqualToField("earnGroup", Criteria.PARENT_QUERY_PREFIX + "earnGroup");
44  		timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
45  //		timestamp.addEqualTo("active", true);
46  		ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(EarnGroup.class, timestamp);
47  		timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
48  
49  		root.addEqualTo("earnGroup", earnGroup);
50  		root.addEqualTo("effectiveDate", effdtSubQuery);
51  		root.addEqualTo("timestamp", timestampSubQuery);
52  //		root.addEqualTo("active", true);
53  		//do not include the summary setup earn groups
54  
55  		Criteria activeFilter = new Criteria(); // Inner Join For Activity
56  		activeFilter.addEqualTo("active", true);
57  		root.addAndCriteria(activeFilter);
58  				
59  		Query query = QueryFactory.newQuery(EarnGroup.class, root);
60  		EarnGroup earnGroupObj  = (EarnGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
61  		return earnGroupObj;
62  	}
63  
64  	@Override
65  	public EarnGroup getEarnGroupSummaryForEarnCode(String earnCode, Date asOfDate) {
66  		Criteria root = new Criteria();
67  		Criteria effdt = new Criteria();
68  		Criteria timestamp = new Criteria();
69  		Criteria earnCodeJoin = new Criteria();
70  		
71  		effdt.addEqualToField("earnGroup", Criteria.PARENT_QUERY_PREFIX + "earnGroup");
72  		effdt.addLessOrEqualThan("effectiveDate", asOfDate);
73  //		effdt.addEqualTo("active", true);
74  		ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(EarnGroup.class, effdt);
75  		effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
76  
77  		timestamp.addEqualToField("earnGroup", Criteria.PARENT_QUERY_PREFIX + "earnGroup");
78  		timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
79  //		timestamp.addEqualTo("active", true);
80  		ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(EarnGroup.class, timestamp);
81  		timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
82  		
83  		earnCodeJoin.addEqualToField("hrEarnGroupId", Criteria.PARENT_QUERY_PREFIX + "hrEarnGroupId");
84  		earnCodeJoin.addEqualTo("earnCode", earnCode);
85  		ReportQueryByCriteria earnCodeSubQuery = QueryFactory.newReportQuery(EarnGroupDefinition.class, earnCodeJoin);
86  		earnCodeSubQuery.setAttributes(new String[]{"hr_earn_group_id"});
87  		
88  		root.addEqualTo("hrEarnGroupId",earnCodeSubQuery);
89  		root.addEqualTo("effectiveDate", effdtSubQuery);
90  		root.addEqualTo("timestamp", timestampSubQuery);
91  //		root.addEqualTo("active", true);
92  		root.addEqualTo("showSummary", true);
93  		
94  		Criteria activeFilter = new Criteria(); // Inner Join For Activity
95  		activeFilter.addEqualTo("active", true);
96  		root.addAndCriteria(activeFilter);
97  
98  		Query query = QueryFactory.newQuery(EarnGroup.class, root);
99  		EarnGroup earnGroupObj  = (EarnGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
100 		return earnGroupObj;
101 	}
102 
103 	@Override
104 	public EarnGroup getEarnGroupForEarnCode(String earnCode, Date asOfDate) {
105 		Criteria root = new Criteria();
106 		Criteria effdt = new Criteria();
107 		Criteria timestamp = new Criteria();
108 		Criteria earnCodeJoin = new Criteria();
109 		
110 		effdt.addEqualToField("earnGroup", Criteria.PARENT_QUERY_PREFIX + "earnGroup");
111 		effdt.addLessOrEqualThan("effectiveDate", asOfDate);
112 //		effdt.addEqualTo("active", true);
113 		ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(EarnGroup.class, effdt);
114 		effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
115 
116 		timestamp.addEqualToField("earnGroup", Criteria.PARENT_QUERY_PREFIX + "earnGroup");
117 		timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
118 //		timestamp.addEqualTo("active", true);
119 		ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(EarnGroup.class, timestamp);
120 		timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
121 		
122 		earnCodeJoin.addEqualToField("hrEarnGroupId", Criteria.PARENT_QUERY_PREFIX + "hrEarnGroupId");
123 		earnCodeJoin.addEqualTo("earnCode", earnCode);
124 		ReportQueryByCriteria earnCodeSubQuery = QueryFactory.newReportQuery(EarnGroupDefinition.class, earnCodeJoin);
125 		earnCodeSubQuery.setAttributes(new String[]{"hr_earn_group_id"});
126 		
127 		root.addEqualTo("hrEarnGroupId",earnCodeSubQuery);
128 		root.addEqualTo("effectiveDate", effdtSubQuery);
129 		root.addEqualTo("timestamp", timestampSubQuery);
130 //		root.addEqualTo("active", true);
131 
132 		Criteria activeFilter = new Criteria(); // Inner Join For Activity
133 		activeFilter.addEqualTo("active", true);
134 		root.addAndCriteria(activeFilter);
135 		
136 		Query query = QueryFactory.newQuery(EarnGroup.class, root);
137 		EarnGroup earnGroupObj  = (EarnGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
138 		return earnGroupObj;
139 	}
140 
141 	@Override
142 	public EarnGroup getEarnGroup(String hrEarnGroupId) {
143 		Criteria crit = new Criteria();
144 		crit.addEqualTo("hrEarnGroupId", hrEarnGroupId);
145 		
146 		Query query = QueryFactory.newQuery(EarnGroup.class, crit);
147 		return (EarnGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
148 	}
149 	
150 	@Override
151 	public int getEarnGroupCount(String earnGroup) {
152 		Criteria crit = new Criteria();
153 	    crit.addEqualTo("earnGroup", earnGroup);
154 	    Query query = QueryFactory.newQuery(EarnGroup.class, crit);
155 	    return this.getPersistenceBrokerTemplate().getCount(query);
156 	}
157 	@Override
158 	public int getNewerEarnGroupCount(String earnGroup, Date effdt) {
159 		Criteria crit = new Criteria();
160 		crit.addEqualTo("earnGroup", earnGroup);
161 		crit.addEqualTo("active", "Y");
162 		crit.addGreaterThan("effectiveDate", effdt);
163 		Query query = QueryFactory.newQuery(EarnGroup.class, crit);
164        	return this.getPersistenceBrokerTemplate().getCount(query);
165 	}
166 }