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.syslunch.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.syslunch.rule.SystemLunchRule; 025 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb; 026 027 public class SystemLunchRuleDaoImpl extends PlatformAwareDaoBaseOjb implements SystemLunchRuleDao { 028 029 @Override 030 public SystemLunchRule getSystemLunchRule(Date asOfDate) { 031 Criteria root = new Criteria(); 032 Criteria effdt = new Criteria(); 033 Criteria timestamp = new Criteria(); 034 035 //effdt.addEqualToField("tkSystemLunchRuleId", Criteria.PARENT_QUERY_PREFIX + "tkSystemLunchRuleId"); 036 effdt.addLessOrEqualThan("effectiveDate", asOfDate); 037 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(SystemLunchRule.class, effdt); 038 effdtSubQuery.setAttributes(new String[] { "max(effdt)" }); 039 040 //timestamp.addEqualToField("tkSystemLunchRuleId", Criteria.PARENT_QUERY_PREFIX + "tkSystemLunchRuleId"); 041 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate"); 042 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(SystemLunchRule.class, timestamp); 043 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" }); 044 045 root.addEqualTo("effectiveDate", effdtSubQuery); 046 root.addEqualTo("timestamp", timestampSubQuery); 047 048 Criteria activeFilter = new Criteria(); // Inner Join For Activity 049 activeFilter.addEqualTo("active", true); 050 root.addAndCriteria(activeFilter); 051 052 Query query = QueryFactory.newQuery(SystemLunchRule.class, root); 053 return (SystemLunchRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query); 054 } 055 056 @Override 057 public SystemLunchRule getSystemLunchRule(String tkSystemLunchRuleId) { 058 Criteria crit = new Criteria(); 059 crit.addEqualTo("tkSystemLunchRuleId", tkSystemLunchRuleId); 060 061 Query query = QueryFactory.newQuery(SystemLunchRule.class, crit); 062 063 return (SystemLunchRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query); 064 } 065 066 }