View Javadoc

1   /**
2    * Copyright 2004-2012 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.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(); // Inner Join For Activity
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  }