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.calendar.dao;
017    
018    import java.util.Date;
019    import java.util.List;
020    
021    import org.apache.log4j.Logger;
022    import org.apache.ojb.broker.query.Criteria;
023    import org.apache.ojb.broker.query.QueryFactory;
024    import org.kuali.hr.time.calendar.Calendar;
025    import org.kuali.hr.time.calendar.CalendarEntries;
026    import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
027    
028    public class CalendarDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb  implements CalendarDao {
029    
030            private static final Logger LOG = Logger.getLogger(CalendarDaoSpringOjbImpl.class);
031    
032            public void saveOrUpdate(Calendar calendar) {
033                    this.getPersistenceBrokerTemplate().store(calendar);
034            }
035    
036            public void saveOrUpdate(List<Calendar> calendarList) {
037                    if (calendarList != null) {
038                            for (Calendar calendar : calendarList) {
039                                    this.getPersistenceBrokerTemplate().store(calendar);
040                            }
041                    }
042            }
043    
044            public Calendar getCalendar(String hrPyCalendarId) {
045                    Criteria currentRecordCriteria = new Criteria();
046                    currentRecordCriteria.addEqualTo("hrCalendarId", hrPyCalendarId);
047    
048                    return (Calendar) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(Calendar.class, currentRecordCriteria));
049            }
050    
051            // Is pay clendar groups alwasy unique?
052            public Calendar getCalendarByGroup(String pyCalendarGroup) {
053                    Criteria currentRecordCriteria = new Criteria();
054                    currentRecordCriteria.addEqualTo("calendarName", pyCalendarGroup);
055    
056                    return (Calendar) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(Calendar.class, currentRecordCriteria));
057            }
058            
059            public CalendarEntries getPreviousCalendarEntry(String tkCalendarId, Date beginDateCurrentCalendar){
060            Criteria payEndDateCriteria = new Criteria();
061            payEndDateCriteria.addEqualTo("hr_py_calendar_id", tkCalendarId);
062            payEndDateCriteria.addLessOrEqualThan("end_period_date", beginDateCurrentCalendar);
063            
064            return (CalendarEntries) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(CalendarEntries.class,payEndDateCriteria));
065            
066            }
067    }