001 /** 002 * Copyright 2004-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.hr.paygrade.dao; 017 018 import java.sql.Date; 019 import java.util.ArrayList; 020 import java.util.List; 021 022 import com.google.common.collect.ImmutableList; 023 import org.apache.commons.lang.StringUtils; 024 import org.apache.ojb.broker.query.Criteria; 025 import org.apache.ojb.broker.query.Query; 026 import org.apache.ojb.broker.query.QueryFactory; 027 import org.apache.ojb.broker.query.ReportQueryByCriteria; 028 import org.kuali.hr.core.util.OjbSubQueryUtil; 029 import org.kuali.hr.paygrade.PayGrade; 030 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb; 031 032 public class PayGradeDaoSpringObjImpl extends PlatformAwareDaoBaseOjb implements PayGradeDao { 033 private static final ImmutableList<String> EQUAL_TO_FIELDS = new ImmutableList.Builder<String>() 034 .add("payGrade") 035 .build(); 036 037 @Override 038 public PayGrade getPayGrade(String payGrade, Date asOfDate) { 039 Criteria root = new Criteria(); 040 041 root.addEqualTo("payGrade", payGrade); 042 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(PayGrade.class, new java.sql.Date(asOfDate.getTime()), EQUAL_TO_FIELDS, false)); 043 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PayGrade.class, EQUAL_TO_FIELDS, false)); 044 045 Criteria activeFilter = new Criteria(); // Inner Join For Activity 046 activeFilter.addEqualTo("active", true); 047 root.addAndCriteria(activeFilter); 048 049 050 Query query = QueryFactory.newQuery(PayGrade.class, root); 051 052 PayGrade pg = (PayGrade)this.getPersistenceBrokerTemplate().getObjectByQuery(query); 053 054 return pg; 055 } 056 057 @Override 058 public PayGrade getPayGrade(String hrPayGradeId) { 059 Criteria crit = new Criteria(); 060 crit.addEqualTo("hrPayGradeId", hrPayGradeId); 061 062 Query query = QueryFactory.newQuery(PayGrade.class, crit); 063 064 return (PayGrade)this.getPersistenceBrokerTemplate().getObjectByQuery(query); 065 } 066 067 public int getPayGradeCount(String payGrade) { 068 Criteria crit = new Criteria(); 069 crit.addEqualTo("payGrade", payGrade); 070 Query query = QueryFactory.newQuery(PayGrade.class, crit); 071 return this.getPersistenceBrokerTemplate().getCount(query); 072 } 073 074 @Override 075 @SuppressWarnings("unchecked") 076 public List<PayGrade> getPayGrades(String payGrade, String payGradeDescr, String active) { 077 List<PayGrade> results = new ArrayList<PayGrade>(); 078 079 Criteria root = new Criteria(); 080 081 if (StringUtils.isNotBlank(payGrade)) { 082 root.addLike("payGrade", payGrade); 083 } 084 085 if (StringUtils.isNotBlank(payGradeDescr)) { 086 root.addLike("description", payGradeDescr); 087 } 088 089 if (StringUtils.isNotBlank(active)) { 090 Criteria activeFilter = new Criteria(); 091 if (StringUtils.equals(active, "Y")) { 092 activeFilter.addEqualTo("active", true); 093 } else if (StringUtils.equals(active, "N")) { 094 activeFilter.addEqualTo("active", false); 095 } 096 root.addAndCriteria(activeFilter); 097 } 098 099 Query query = QueryFactory.newQuery(PayGrade.class, root); 100 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query)); 101 102 return results; 103 } 104 105 }