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.salgroup.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.time.salgroup.SalGroup;
30  import org.kuali.hr.time.util.TKUtils;
31  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
32  
33  public class SalGroupDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements SalGroupDao {
34      private static final ImmutableList<String> EQUAL_TO_FIELDS = new ImmutableList.Builder<String>()
35              .add("hrSalGroup")
36              .build();
37  
38  	@Override
39  	public void saveOrUpdate(SalGroup salGroup) {
40  		this.getPersistenceBrokerTemplate().store(salGroup);		
41  	}
42  
43  	@Override
44  	public SalGroup getSalGroup(String salGroup, Date asOfDate) {
45  		Criteria root = new Criteria();
46  
47  		root.addEqualTo("hrSalGroup", salGroup);
48          root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(SalGroup.class, asOfDate, EQUAL_TO_FIELDS, false));
49          root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(SalGroup.class, EQUAL_TO_FIELDS, false));
50  		Criteria activeFilter = new Criteria(); // Inner Join For Activity
51  		activeFilter.addEqualTo("active", true);
52  		root.addAndCriteria(activeFilter);
53  		
54  		Query query = QueryFactory.newQuery(SalGroup.class, root);
55  		SalGroup s = (SalGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
56  		
57  		return s;
58  	}
59  
60  	@Override
61  	public SalGroup getSalGroup(String hrSalGroupId) {
62  		Criteria crit = new Criteria();
63  		crit.addEqualTo("hrSalGroupId", hrSalGroupId);
64  		
65  		Query query = QueryFactory.newQuery(SalGroup.class, crit);
66  		return (SalGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
67  	}
68  	@Override
69  	public int getSalGroupCount(String salGroup) {
70  		Criteria crit = new Criteria();
71  		crit.addEqualTo("hrSalGroup", salGroup);
72  		Query query = QueryFactory.newQuery(SalGroup.class, crit);
73  		return this.getPersistenceBrokerTemplate().getCount(query);
74  	}
75  
76  	@Override
77      @SuppressWarnings("unchecked")
78      public List<SalGroup> getSalGroups(String hrSalGroup, String descr, Date fromEffdt, Date toEffdt, String active, String showHistory) {
79          List<SalGroup> results = new ArrayList<SalGroup>();
80      	
81      	Criteria root = new Criteria();
82  
83          if (StringUtils.isNotBlank(hrSalGroup)) {
84              root.addLike("hrSalGroup", hrSalGroup);
85          }
86          
87          if (StringUtils.isNotBlank(descr)) {
88              root.addLike("descr", descr);
89          }
90          
91          Criteria effectiveDateFilter = new Criteria();
92          if (fromEffdt != null) {
93              effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt);
94          }
95          if (toEffdt != null) {
96              effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt);
97          }
98          if (fromEffdt == null && toEffdt == null) {
99              effectiveDateFilter.addLessOrEqualThan("effectiveDate", TKUtils.getCurrentDate());
100         }
101         root.addAndCriteria(effectiveDateFilter);
102 
103         if (StringUtils.equals(showHistory, "N")) {
104             root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(SalGroup.class, effectiveDateFilter, EQUAL_TO_FIELDS, false));
105             root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(SalGroup.class, EQUAL_TO_FIELDS, false));
106         }
107 
108         Query query = QueryFactory.newQuery(SalGroup.class, root);
109         results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
110         
111         return results;
112     }
113 	
114 }