EMMA Coverage Report (generated Fri Aug 21 15:59:46 BST 2009)
[all classes][org.springframework.batch.core.repository.dao]

COVERAGE SUMMARY FOR SOURCE FILE [MapJobInstanceDao.java]

nameclass, %method, %block, %line, %
MapJobInstanceDao.java100% (2/2)100% (11/11)100% (180/180)100% (36/36)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapJobInstanceDao100% (1/1)100% (9/9)100% (165/165)100% (34/34)
<static initializer> 100% (1/1)100% (6/6)100% (3/3)
MapJobInstanceDao (): void 100% (1/1)100% (3/3)100% (1/1)
clear (): void 100% (1/1)100% (3/3)100% (2/2)
createJobInstance (String, JobParameters): JobInstance 100% (1/1)100% (30/30)100% (5/5)
getJobInstance (JobExecution): JobInstance 100% (1/1)100% (3/3)100% (1/1)
getJobInstance (Long): JobInstance 100% (1/1)100% (20/20)100% (4/4)
getJobInstance (String, JobParameters): JobInstance 100% (1/1)100% (25/25)100% (4/4)
getJobInstances (String, int, int): List 100% (1/1)100% (51/51)100% (10/10)
getJobNames (): List 100% (1/1)100% (24/24)100% (5/5)
     
class MapJobInstanceDao$1100% (1/1)100% (2/2)100% (15/15)100% (3/3)
MapJobInstanceDao$1 (MapJobInstanceDao): void 100% (1/1)100% (6/6)100% (2/2)
compare (JobInstance, JobInstance): int 100% (1/1)100% (9/9)100% (1/1)

1/*
2 * Copyright 2006-2007 the original author or authors.
3 *
4 * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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 
17package org.springframework.batch.core.repository.dao;
18 
19import java.util.ArrayList;
20import java.util.Collection;
21import java.util.Collections;
22import java.util.Comparator;
23import java.util.List;
24 
25import org.springframework.batch.core.JobExecution;
26import org.springframework.batch.core.JobInstance;
27import org.springframework.batch.core.JobParameters;
28import org.springframework.batch.support.transaction.TransactionAwareProxyFactory;
29import org.springframework.util.Assert;
30 
31/**
32 * In-memory implementation of {@link JobInstanceDao}.
33 */
34public class MapJobInstanceDao implements JobInstanceDao {
35 
36        private static Collection<JobInstance> jobInstances = TransactionAwareProxyFactory.createTransactionalSet();
37 
38        private static long currentId = 0;
39 
40        public static void clear() {
41                jobInstances.clear();
42        }
43 
44        public JobInstance createJobInstance(String jobName, JobParameters jobParameters) {
45 
46                Assert.state(getJobInstance(jobName, jobParameters) == null, "JobInstance must not already exist");
47 
48                JobInstance jobInstance = new JobInstance(currentId++, jobParameters, jobName);
49                jobInstance.incrementVersion();
50                jobInstances.add(jobInstance);
51 
52                return jobInstance;
53        }
54 
55        public JobInstance getJobInstance(String jobName, JobParameters jobParameters) {
56 
57                for (JobInstance instance : jobInstances) {
58                        if (instance.getJobName().equals(jobName) && instance.getJobParameters().equals(jobParameters)) {
59                                return instance;
60                        }
61                }
62                return null;
63 
64        }
65 
66        public JobInstance getJobInstance(Long instanceId) {
67                for (JobInstance instance : jobInstances) {
68                        if (instance.getId().equals(instanceId)) {
69                                return instance;
70                        }
71                }
72                return null;
73        }
74 
75        public List<String> getJobNames() {
76                List<String> result = new ArrayList<String>();
77                for (JobInstance instance : jobInstances) {
78                        result.add(instance.getJobName());
79                }
80                Collections.sort(result);
81                return result;
82        }
83 
84        public List<JobInstance> getJobInstances(String jobName, int start, int count) {
85                List<JobInstance> result = new ArrayList<JobInstance>();
86                for (JobInstance instance : jobInstances) {
87                        if (instance.getJobName().equals(jobName)) {
88                                result.add(instance);
89                        }
90                }
91                Collections.sort(result, new Comparator<JobInstance>() {
92                        // sort by ID descending
93                        public int compare(JobInstance o1, JobInstance o2) {
94                                return Long.signum(o2.getId() - o1.getId());
95                        }
96                });
97                if (start>=result.size()) {
98                        start = result.size();
99                }
100                if (start + count >=result.size()) {
101                        count = result.size();
102                }
103                return result.subList(start, count);
104        }
105 
106        public JobInstance getJobInstance(JobExecution jobExecution) {
107                return jobExecution.getJobInstance();
108        }
109 
110}

[all classes][org.springframework.batch.core.repository.dao]
EMMA 2.0.5312 (C) Vladimir Roubtsov