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.lm.leaveadjustment.dao; 017 018 import java.sql.Date; 019 import java.util.ArrayList; 020 import java.util.Collection; 021 import java.util.List; 022 023 import edu.emory.mathcs.backport.java.util.Collections; 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.lm.leaveadjustment.LeaveAdjustment; 030 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb; 031 032 public class LeaveAdjustmentDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements LeaveAdjustmentDao{ 033 034 @SuppressWarnings("unchecked") 035 @Override 036 public List<LeaveAdjustment> getLeaveAdjustments(String principalId, Date asOfDate) { 037 List<LeaveAdjustment> leaveAdjustments = new ArrayList<LeaveAdjustment>(); 038 Criteria root = new Criteria(); 039 040 java.sql.Date effDate = asOfDate == null ? null : new java.sql.Date(asOfDate.getTime()); 041 root.addEqualTo("principalId", principalId); 042 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(LeaveAdjustment.class, effDate, Collections.singletonList("principalId"), false)); 043 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(LeaveAdjustment.class, Collections.singletonList("principalId"), false)); 044 045 Criteria activeFilter = new Criteria(); // Inner Join For Activity 046 activeFilter.addEqualTo("active", true); 047 root.addAndCriteria(activeFilter); 048 049 Query query = QueryFactory.newQuery(LeaveAdjustment.class, root); 050 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query); 051 052 if (c != null) { 053 leaveAdjustments.addAll(c); 054 } 055 return leaveAdjustments; 056 } 057 058 @Override 059 public LeaveAdjustment getLeaveAdjustment(String lmLeaveAdjustmentId) { 060 Criteria crit = new Criteria(); 061 crit.addEqualTo("lmLeaveAdjustmentId", lmLeaveAdjustmentId); 062 Query query = QueryFactory.newQuery(LeaveAdjustment.class, crit); 063 return (LeaveAdjustment) this.getPersistenceBrokerTemplate().getObjectByQuery(query); 064 } 065 066 }