View Javadoc

1   /**
2    * Copyright 2004-2013 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.hr.time.workschedule.dao;
17  
18  import java.sql.Date;
19  import java.util.List;
20  
21  import com.google.common.collect.ImmutableList;
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.apache.ojb.broker.query.ReportQueryByCriteria;
26  import org.kuali.hr.core.util.OjbSubQueryUtil;
27  import org.kuali.hr.time.workschedule.WorkSchedule;
28  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29  
30  public class WorkScheduleDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements WorkScheduleDao {
31  
32      @Override
33      public WorkSchedule getWorkSchedule(Long workSchedule, Date asOfDate) {
34          WorkSchedule ws = null;
35  
36          Criteria root = new Criteria();
37  
38          ImmutableList<String> fields = new ImmutableList.Builder<String>()
39                  .add("hrWorkSchedule")
40                  .build();
41          root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(WorkSchedule.class, asOfDate, fields, false));
42          root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(WorkSchedule.class, fields, false));
43  
44          root.addEqualTo("hrWorkSchedule", workSchedule);
45  
46          Criteria activeFilter = new Criteria(); // Inner Join For Activity
47          activeFilter.addEqualTo("active", true);
48          root.addAndCriteria(activeFilter);
49  
50          Query query = QueryFactory.newQuery(WorkSchedule.class, root);
51  
52          ws = (WorkSchedule) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
53  
54          return ws;
55      }
56  
57      /**
58  	 * Simple save via Spring OJB
59  	 *
60  	 * @param workSchedule
61  	 */
62  	public void saveOrUpdate(WorkSchedule workSchedule) {
63  		this.getPersistenceBrokerTemplate().store(workSchedule);
64  	}
65  
66  	/**
67  	 * This method is broken apart to allow future batch store calls if we think we need it.
68  	 * @param workSchedules
69  	 */
70  	public void saveOrUpdate(List<WorkSchedule> workSchedules) {
71  		for (WorkSchedule ws : workSchedules) {
72  			saveOrUpdate(ws);
73  		}
74  	}
75  
76  }