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.salgroup.dao; 017 018 import org.apache.ojb.broker.query.Criteria; 019 import org.apache.ojb.broker.query.Query; 020 import org.apache.ojb.broker.query.QueryFactory; 021 import org.apache.ojb.broker.query.ReportQueryByCriteria; 022 import org.kuali.hr.time.salgroup.SalGroup; 023 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb; 024 025 import java.sql.Date; 026 027 public class SalGroupDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements SalGroupDao { 028 029 @Override 030 public void saveOrUpdate(SalGroup salGroup) { 031 this.getPersistenceBrokerTemplate().store(salGroup); 032 } 033 034 @Override 035 public SalGroup getSalGroup(String salGroup, Date asOfDate) { 036 Criteria root = new Criteria(); 037 Criteria effdt = new Criteria(); 038 Criteria timestamp = new Criteria(); 039 040 effdt.addEqualToField("hrSalGroup", Criteria.PARENT_QUERY_PREFIX + "hrSalGroup"); 041 effdt.addLessOrEqualThan("effectiveDate", asOfDate); 042 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(SalGroup.class, effdt); 043 effdtSubQuery.setAttributes(new String[] { "max(effdt)" }); 044 045 timestamp.addEqualToField("hrSalGroup", Criteria.PARENT_QUERY_PREFIX + "hrSalGroup"); 046 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate"); 047 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(SalGroup.class, timestamp); 048 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" }); 049 050 root.addEqualTo("hrSalGroup", salGroup); 051 root.addEqualTo("effectiveDate", effdtSubQuery); 052 root.addEqualTo("timestamp", timestampSubQuery); 053 Criteria activeFilter = new Criteria(); // Inner Join For Activity 054 activeFilter.addEqualTo("active", true); 055 root.addAndCriteria(activeFilter); 056 057 Query query = QueryFactory.newQuery(SalGroup.class, root); 058 SalGroup s = (SalGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query); 059 060 return s; 061 } 062 063 @Override 064 public SalGroup getSalGroup(String hrSalGroupId) { 065 Criteria crit = new Criteria(); 066 crit.addEqualTo("hrSalGroupId", hrSalGroupId); 067 068 Query query = QueryFactory.newQuery(SalGroup.class, crit); 069 return (SalGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query); 070 } 071 @Override 072 public int getSalGroupCount(String salGroup) { 073 Criteria crit = new Criteria(); 074 crit.addEqualTo("hrSalGroup", salGroup); 075 Query query = QueryFactory.newQuery(SalGroup.class, crit); 076 return this.getPersistenceBrokerTemplate().getCount(query); 077 } 078 079 }