001 /**
002 * Copyright 2004-2012 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 import java.util.Map;
022
023 import org.apache.commons.lang.StringUtils;
024 import org.apache.ojb.broker.query.Criteria;
025 import org.apache.ojb.broker.query.Query;
026 import org.apache.ojb.broker.query.QueryFactory;
027 import org.kuali.hr.time.batch.BatchJobEntry;
028 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
029
030 public class BatchJobEntryDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements BatchJobEntryDao {
031
032 @Override
033 public void saveOrUpdate(BatchJobEntry batchJobEntry) {
034 this.getPersistenceBrokerTemplate().store(batchJobEntry);
035 }
036
037 @Override
038 public BatchJobEntry getBatchJobEntry(Long batchJobEntryId) {
039 Criteria currentRecordCriteria = new Criteria();
040 currentRecordCriteria.addEqualTo("tkBatchJobEntryId", batchJobEntryId);
041
042 return (BatchJobEntry) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(BatchJobEntry.class, currentRecordCriteria));
043 }
044
045 @Override
046 public List<BatchJobEntry> getBatchJobEntries(Long batchJobEntryId) {
047 Criteria root = new Criteria();
048 root.addEqualTo("tkBatchJobId", batchJobEntryId);
049 Query query = QueryFactory.newQuery(BatchJobEntry.class, root);
050
051 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
052 List<BatchJobEntry> entries = new ArrayList<BatchJobEntry>();
053 entries.addAll(c);
054
055 return entries;
056 }
057
058 @Override
059 public List<BatchJobEntry> getBatchJobEntries(String ip, String status) {
060 Criteria root = new Criteria();
061 root.addEqualTo("ipAddress", ip);
062 root.addEqualTo("batchJobEntryStatus", status);
063 Query query = QueryFactory.newQuery(BatchJobEntry.class, root);
064
065 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
066 List<BatchJobEntry> entries = new ArrayList<BatchJobEntry>();
067 entries.addAll(c);
068
069 return entries;
070 }
071
072 @Override
073 public List<BatchJobEntry> getBatchJobEntries(Map<String, Object> criteria) {
074 Criteria root = new Criteria();
075 for (Map.Entry<String, Object> crit : criteria.entrySet()) {
076 if(crit.getValue() != null){
077 if(StringUtils.equals("ipAddress", crit.getKey()) || StringUtils.equals("batchJobName", crit.getKey())) {
078 root.addLike(crit.getKey(), "%" + crit.getValue() + "%");
079 }
080 else {
081 root.addEqualTo(crit.getKey(), crit.getValue());
082 }
083 }
084 }
085
086 Query query = QueryFactory.newQuery(BatchJobEntry.class, root);
087
088 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
089 List<BatchJobEntry> entries = new ArrayList<BatchJobEntry>();
090 entries.addAll(c);
091
092 return entries;
093 }
094 }