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.timehourdetail.dao;
017    
018    import java.util.List;
019    
020    import org.apache.log4j.Logger;
021    import org.apache.ojb.broker.query.Criteria;
022    import org.apache.ojb.broker.query.Query;
023    import org.apache.ojb.broker.query.QueryFactory;
024    import org.kuali.hr.time.timeblock.TimeHourDetail;
025    import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
026    
027    public class TimeHourDetailDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements TimeHourDetailDao {
028    
029        private static final Logger LOG = Logger.getLogger(TimeHourDetailDaoSpringOjbImpl.class);
030    
031        @Override
032        public void saveOrUpdate(TimeHourDetail timeHourDetail) {
033            this.getPersistenceBrokerTemplate().store(timeHourDetail);
034        }
035    
036        @Override
037        public void saveOrUpdate(List<TimeHourDetail> timeHourDetails) {
038            if (timeHourDetails != null) {
039                for (TimeHourDetail timeHourDetail : timeHourDetails) {
040                    this.getPersistenceBrokerTemplate().store(timeHourDetail);
041                }
042            }
043        }
044    
045        @Override
046        public TimeHourDetail getTimeHourDetail(String timeHourDetailId) {
047            Criteria currentRecordCriteria = new Criteria();
048            currentRecordCriteria.addEqualTo("tkTimeHourDetailId", timeHourDetailId);
049    
050            return (TimeHourDetail) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(TimeHourDetail.class, currentRecordCriteria));
051        }
052    
053        @SuppressWarnings("unchecked")
054        @Override
055        public List<TimeHourDetail> getTimeHourDetailsForTimeBlock(String timeBlockId) {
056            Criteria currentRecordCriteria = new Criteria();
057            currentRecordCriteria.addEqualTo("tkTimeBlockId", timeBlockId);
058            Query query = QueryFactory.newQuery(TimeHourDetail.class, currentRecordCriteria);
059            return (List<TimeHourDetail>) this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
060        }
061    
062        public void remove(String timeBlockId) {
063            Criteria removalCriteria = new Criteria();
064            removalCriteria.addEqualTo("tkTimeBlockId", timeBlockId);
065    
066            this.getPersistenceBrokerTemplate().deleteByQuery(QueryFactory.newQuery(TimeHourDetail.class, removalCriteria));
067        }
068    
069        @Override
070        public void removeById(String timeHourDetailId) {
071            Criteria removalCriteria = new Criteria();
072            removalCriteria.addEqualTo("tkTimeHourDetailId", timeHourDetailId);
073    
074            this.getPersistenceBrokerTemplate().deleteByQuery(QueryFactory.newQuery(TimeHourDetail.class, removalCriteria));
075        }
076    }