View Javadoc
1   /**
2    * Copyright 2004-2014 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.kpme.tklm.time.timehourdetail.dao;
17  
18  import java.util.List;
19  
20  import org.apache.commons.collections.CollectionUtils;
21  import org.apache.log4j.Logger;
22  import org.apache.ojb.broker.query.Criteria;
23  import org.apache.ojb.broker.query.Query;
24  import org.apache.ojb.broker.query.QueryFactory;
25  import org.kuali.kpme.tklm.time.timehourdetail.TimeHourDetailBo;
26  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
27  import org.kuali.rice.krad.service.KRADServiceLocator;
28  
29  public class TimeHourDetailDaoOjbImpl extends PlatformAwareDaoBaseOjb implements TimeHourDetailDao {
30  
31      private static final Logger LOG = Logger.getLogger(TimeHourDetailDaoOjbImpl.class);
32  
33      @Override
34      public void saveOrUpdate(TimeHourDetailBo timeHourDetail) {
35          this.getPersistenceBrokerTemplate().store(timeHourDetail);
36      }
37  
38      @Override
39      public void saveOrUpdate(List<TimeHourDetailBo> timeHourDetails) {
40          if (timeHourDetails != null) {
41              for (TimeHourDetailBo timeHourDetail : timeHourDetails) {
42                  this.getPersistenceBrokerTemplate().store(timeHourDetail);
43              }
44          }
45      }
46  
47      @Override
48      public TimeHourDetailBo getTimeHourDetail(String timeHourDetailId) {
49          Criteria currentRecordCriteria = new Criteria();
50          currentRecordCriteria.addEqualTo("tkTimeHourDetailId", timeHourDetailId);
51  
52          return (TimeHourDetailBo) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(TimeHourDetailBo.class, currentRecordCriteria));
53      }
54  
55      @SuppressWarnings("unchecked")
56      @Override
57      public List<TimeHourDetailBo> getTimeHourDetailsForTimeBlock(String timeBlockId) {
58          Criteria currentRecordCriteria = new Criteria();
59          currentRecordCriteria.addEqualTo("tkTimeBlockId", timeBlockId);
60          Query query = QueryFactory.newQuery(TimeHourDetailBo.class, currentRecordCriteria);
61          return (List<TimeHourDetailBo>) this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
62      }
63  
64      public void remove(String timeBlockId) {
65          Criteria removalCriteria = new Criteria();
66          removalCriteria.addEqualTo("tkTimeBlockId", timeBlockId);
67          Query query = QueryFactory.newQuery(TimeHourDetailBo.class, removalCriteria);
68          List<TimeHourDetailBo> deleteList = (List<TimeHourDetailBo>) this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
69          if(CollectionUtils.isNotEmpty(deleteList)) {
70          	KRADServiceLocator.getBusinessObjectService().delete(deleteList);
71          }
72  //        this.getPersistenceBrokerTemplate().deleteByQuery(QueryFactory.newQuery(TimeHourDetailBo.class, removalCriteria));
73      }
74  
75      @Override
76      public void removeById(String timeHourDetailId) {
77          Criteria removalCriteria = new Criteria();
78          removalCriteria.addEqualTo("tkTimeHourDetailId", timeHourDetailId);
79  
80          this.getPersistenceBrokerTemplate().deleteByQuery(QueryFactory.newQuery(TimeHourDetailBo.class, removalCriteria));
81      }
82  }