View Javadoc

1   /**
2    * Copyright 2004-2012 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.syslunch.dao;
17  
18  import java.sql.Date;
19  
20  import org.apache.ojb.broker.query.Criteria;
21  import org.apache.ojb.broker.query.Query;
22  import org.apache.ojb.broker.query.QueryFactory;
23  import org.apache.ojb.broker.query.ReportQueryByCriteria;
24  import org.kuali.hr.time.syslunch.rule.SystemLunchRule;
25  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
26  
27  public class SystemLunchRuleDaoImpl  extends PlatformAwareDaoBaseOjb implements SystemLunchRuleDao {
28  
29  	@Override
30  	public SystemLunchRule getSystemLunchRule(Date asOfDate) {
31  		Criteria root = new Criteria();
32  		Criteria effdt = new Criteria();
33          Criteria timestamp = new Criteria();
34  
35          //effdt.addEqualToField("tkSystemLunchRuleId", Criteria.PARENT_QUERY_PREFIX + "tkSystemLunchRuleId");
36  		effdt.addLessOrEqualThan("effectiveDate", asOfDate);
37  		ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(SystemLunchRule.class, effdt);
38  		effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
39  
40          //timestamp.addEqualToField("tkSystemLunchRuleId", Criteria.PARENT_QUERY_PREFIX + "tkSystemLunchRuleId");
41          timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
42          ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(SystemLunchRule.class, timestamp);
43          timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
44  
45  		root.addEqualTo("effectiveDate", effdtSubQuery);
46          root.addEqualTo("timestamp", timestampSubQuery);
47  
48  		Criteria activeFilter = new Criteria(); // Inner Join For Activity
49  		activeFilter.addEqualTo("active", true);
50  		root.addAndCriteria(activeFilter);
51  
52  		Query query = QueryFactory.newQuery(SystemLunchRule.class, root);
53  		return (SystemLunchRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
54  	}
55  
56  	@Override
57  	public SystemLunchRule getSystemLunchRule(String tkSystemLunchRuleId) {
58  		Criteria crit = new Criteria();
59  		crit.addEqualTo("tkSystemLunchRuleId", tkSystemLunchRuleId);
60  		
61  		Query query = QueryFactory.newQuery(SystemLunchRule.class, crit);
62  		
63  		return (SystemLunchRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
64  	}
65  
66  }