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.batch.dao;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.List;
21  
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.hr.time.batch.BatchJob;
26  import org.kuali.hr.time.service.base.TkServiceLocator;
27  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
28  import org.springframework.transaction.TransactionStatus;
29  import org.springframework.transaction.support.TransactionCallbackWithoutResult;
30  
31  public class BatchJobDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements BatchJobDao {
32  
33      public void saveOrUpdate(final BatchJob batchJob) {
34      	TkServiceLocator.getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {
35  			@Override
36  			protected void doInTransactionWithoutResult(TransactionStatus status) {
37  				getPersistenceBrokerTemplate().store(batchJob);
38  			}
39      	});
40      }
41  
42      public BatchJob getBatchJob(Long batchJobId){
43          Criteria currentRecordCriteria = new Criteria();
44          currentRecordCriteria.addEqualTo("tkBatchJobId", batchJobId);
45  
46          return (BatchJob) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(BatchJob.class, currentRecordCriteria));
47      }
48  
49      @Override
50      public List<BatchJob> getBatchJobs(String hrPyCalendarEntryId) {
51          Criteria root = new Criteria();
52          root.addEqualTo("hrPyCalendarEntryId", hrPyCalendarEntryId);
53          Query query = QueryFactory.newQuery(BatchJob.class, root);
54  
55          Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
56          List<BatchJob> jobs = new ArrayList<BatchJob>();
57          jobs.addAll(c);
58  
59          return jobs;
60      }
61  
62      @Override
63      public List<BatchJob> getPayCalendarEntries(String hrPyCalendarEntryId, String batchJobStatus) {
64          Criteria root = new Criteria();
65          root.addEqualTo("hrPyCalendarEntryId", hrPyCalendarEntryId);
66          root.addEqualTo("batchJobStatus", batchJobStatus);
67          Query query = QueryFactory.newQuery(BatchJob.class, root);
68  
69          Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
70          List<BatchJob> jobs = new ArrayList<BatchJob>();
71          jobs.addAll(c);
72   
73          return jobs;
74      }
75  }