001 /** 002 * Copyright 2004-2012 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.time.graceperiod.dao; 017 018 import java.sql.Date; 019 020 import org.apache.ojb.broker.query.Criteria; 021 import org.apache.ojb.broker.query.Query; 022 import org.apache.ojb.broker.query.QueryFactory; 023 import org.apache.ojb.broker.query.ReportQueryByCriteria; 024 import org.kuali.hr.time.graceperiod.rule.GracePeriodRule; 025 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb; 026 027 public class GracePeriodDaoImpl extends PlatformAwareDaoBaseOjb implements GracePeriodDao { 028 public GracePeriodRule getGracePeriodRule(Date asOfDate){ 029 GracePeriodRule gracePeriodRule = null; 030 031 Criteria root = new Criteria(); 032 Criteria effdt = new Criteria(); 033 Criteria timestamp = new Criteria(); 034 035 // OJB's awesome sub query setup part 1 036 effdt.addLessOrEqualThan("effectiveDate", asOfDate); 037 // effdt.addEqualTo("active", true); 038 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(GracePeriodRule.class, effdt); 039 effdtSubQuery.setAttributes(new String[] { "max(effdt)" }); 040 041 // OJB's awesome sub query setup part 2 042 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate"); 043 // timestamp.addEqualTo("active", true); 044 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(GracePeriodRule.class, timestamp); 045 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" }); 046 047 root.addEqualTo("effectiveDate", effdtSubQuery); 048 root.addEqualTo("timestamp", timestampSubQuery); 049 050 Criteria activeFilter = new Criteria(); // Inner Join For Activity 051 activeFilter.addEqualTo("active", true); 052 root.addAndCriteria(activeFilter); 053 054 055 Query query = QueryFactory.newQuery(GracePeriodRule.class, root); 056 Object obj = this.getPersistenceBrokerTemplate().getObjectByQuery(query); 057 058 if (obj != null) { 059 gracePeriodRule = (GracePeriodRule) obj; 060 } 061 062 return gracePeriodRule; 063 } 064 065 @Override 066 public GracePeriodRule getGracePeriodRule(String tkGracePeriodId) { 067 Criteria crit = new Criteria(); 068 crit.addEqualTo("tkGracePeriodRuleId", tkGracePeriodId); 069 070 Query query = QueryFactory.newQuery(GracePeriodRule.class, crit); 071 return (GracePeriodRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query); 072 } 073 }