001 /** 002 * Copyright 2004-2013 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.batch.dao; 017 018 import java.util.ArrayList; 019 import java.util.Collection; 020 import java.util.List; 021 022 import org.apache.ojb.broker.query.Criteria; 023 import org.apache.ojb.broker.query.Query; 024 import org.apache.ojb.broker.query.QueryFactory; 025 import org.kuali.hr.time.batch.BatchJob; 026 import org.kuali.hr.time.service.base.TkServiceLocator; 027 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb; 028 import org.springframework.transaction.TransactionStatus; 029 import org.springframework.transaction.support.TransactionCallbackWithoutResult; 030 031 public class BatchJobDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements BatchJobDao { 032 033 public void saveOrUpdate(final BatchJob batchJob) { 034 TkServiceLocator.getTransactionTemplate().execute(new TransactionCallbackWithoutResult() { 035 @Override 036 protected void doInTransactionWithoutResult(TransactionStatus status) { 037 getPersistenceBrokerTemplate().store(batchJob); 038 } 039 }); 040 } 041 042 public BatchJob getBatchJob(Long batchJobId){ 043 Criteria currentRecordCriteria = new Criteria(); 044 currentRecordCriteria.addEqualTo("tkBatchJobId", batchJobId); 045 046 return (BatchJob) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(BatchJob.class, currentRecordCriteria)); 047 } 048 049 @Override 050 public List<BatchJob> getBatchJobs(String hrPyCalendarEntryId) { 051 Criteria root = new Criteria(); 052 root.addEqualTo("hrPyCalendarEntryId", hrPyCalendarEntryId); 053 Query query = QueryFactory.newQuery(BatchJob.class, root); 054 055 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query); 056 List<BatchJob> jobs = new ArrayList<BatchJob>(); 057 jobs.addAll(c); 058 059 return jobs; 060 } 061 062 @Override 063 public List<BatchJob> getPayCalendarEntries(String hrPyCalendarEntryId, String batchJobStatus) { 064 Criteria root = new Criteria(); 065 root.addEqualTo("hrPyCalendarEntryId", hrPyCalendarEntryId); 066 root.addEqualTo("batchJobStatus", batchJobStatus); 067 Query query = QueryFactory.newQuery(BatchJob.class, root); 068 069 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query); 070 List<BatchJob> jobs = new ArrayList<BatchJob>(); 071 jobs.addAll(c); 072 073 return jobs; 074 } 075 }