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 org.apache.commons.lang.StringUtils; 023 import org.apache.ojb.broker.query.Criteria; 024 import org.apache.ojb.broker.query.Query; 025 import org.apache.ojb.broker.query.QueryFactory; 026 import org.apache.ojb.broker.query.ReportQueryByCriteria; 027 import org.kuali.hr.paygrade.PayGrade; 028 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb; 029 030 public class PayGradeDaoSpringObjImpl extends PlatformAwareDaoBaseOjb implements PayGradeDao { 031 032 @Override 033 public PayGrade getPayGrade(String payGrade, Date asOfDate) { 034 Criteria root = new Criteria(); 035 Criteria effdt = new Criteria(); 036 Criteria timestamp = new Criteria(); 037 038 effdt.addEqualToField("payGrade", Criteria.PARENT_QUERY_PREFIX + "payGrade"); 039 effdt.addLessOrEqualThan("effectiveDate", asOfDate); 040 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(PayGrade.class, effdt); 041 effdtSubQuery.setAttributes(new String[] { "max(effdt)" }); 042 043 timestamp.addEqualToField("payGrade", Criteria.PARENT_QUERY_PREFIX + "payGrade"); 044 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate"); 045 046 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(PayGrade.class, timestamp); 047 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" }); 048 049 root.addEqualTo("payGrade", payGrade); 050 root.addEqualTo("effectiveDate", effdtSubQuery); 051 root.addEqualTo("timestamp", timestampSubQuery); 052 053 Criteria activeFilter = new Criteria(); // Inner Join For Activity 054 activeFilter.addEqualTo("active", true); 055 root.addAndCriteria(activeFilter); 056 057 058 Query query = QueryFactory.newQuery(PayGrade.class, root); 059 060 PayGrade pg = (PayGrade)this.getPersistenceBrokerTemplate().getObjectByQuery(query); 061 062 return pg; 063 } 064 065 @Override 066 public PayGrade getPayGrade(String hrPayGradeId) { 067 Criteria crit = new Criteria(); 068 crit.addEqualTo("hrPayGradeId", hrPayGradeId); 069 070 Query query = QueryFactory.newQuery(PayGrade.class, crit); 071 072 return (PayGrade)this.getPersistenceBrokerTemplate().getObjectByQuery(query); 073 } 074 075 public int getPayGradeCount(String payGrade) { 076 Criteria crit = new Criteria(); 077 crit.addEqualTo("payGrade", payGrade); 078 Query query = QueryFactory.newQuery(PayGrade.class, crit); 079 return this.getPersistenceBrokerTemplate().getCount(query); 080 } 081 082 @Override 083 @SuppressWarnings("unchecked") 084 public List<PayGrade> getPayGrades(String payGrade, String payGradeDescr, String active) { 085 List<PayGrade> results = new ArrayList<PayGrade>(); 086 087 Criteria root = new Criteria(); 088 089 if (StringUtils.isNotBlank(payGrade)) { 090 root.addLike("payGrade", payGrade); 091 } 092 093 if (StringUtils.isNotBlank(payGradeDescr)) { 094 root.addLike("description", payGradeDescr); 095 } 096 097 if (StringUtils.isNotBlank(active)) { 098 Criteria activeFilter = new Criteria(); 099 if (StringUtils.equals(active, "Y")) { 100 activeFilter.addEqualTo("active", true); 101 } else if (StringUtils.equals(active, "N")) { 102 activeFilter.addEqualTo("active", false); 103 } 104 root.addAndCriteria(activeFilter); 105 } 106 107 Query query = QueryFactory.newQuery(PayGrade.class, root); 108 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query)); 109 110 return results; 111 } 112 113 }