1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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 }