EMMA Coverage Report (generated Thu May 22 12:08:10 CDT 2014)
[all classes][org.springframework.batch.core.repository.dao]

COVERAGE SUMMARY FOR SOURCE FILE [MapExecutionContextDao.java]

nameclass, %method, %block, %line, %
MapExecutionContextDao.java100% (4/4)91%  (20/22)77%  (218/282)75%  (42.7/57)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapExecutionContextDao$ContextKey100% (1/1)86%  (6/7)55%  (71/128)53%  (15.9/30)
compareTo (MapExecutionContextDao$ContextKey): int 0%   (0/1)0%   (0/32)0%   (0/9)
hashCode (): int 100% (1/1)62%  (21/34)80%  (4/5)
MapExecutionContextDao$ContextKey (MapExecutionContextDao$ContextKey$Type, lo... 100% (1/1)69%  (11/16)83%  (5/6)
equals (Object): boolean 100% (1/1)71%  (10/14)60%  (3/5)
equals (MapExecutionContextDao$ContextKey): boolean 100% (1/1)85%  (17/20)64%  (1.9/3)
job (long): MapExecutionContextDao$ContextKey 100% (1/1)100% (6/6)100% (1/1)
step (long): MapExecutionContextDao$ContextKey 100% (1/1)100% (6/6)100% (1/1)
     
class MapExecutionContextDao$ContextKey$Type100% (1/1)75%  (3/4)87%  (33/38)86%  (0.9/1)
valueOf (String): MapExecutionContextDao$ContextKey$Type 0%   (0/1)0%   (0/5)0%   (0/1)
<static initializer> 100% (1/1)100% (24/24)100% (1/1)
MapExecutionContextDao$ContextKey$Type (String, int): void 100% (1/1)100% (5/5)100% (1/1)
values (): MapExecutionContextDao$ContextKey$Type [] 100% (1/1)100% (4/4)100% (1/1)
     
class MapExecutionContextDao$1100% (1/1)100% (1/1)89%  (17/19)89%  (0.9/1)
<static initializer> 100% (1/1)89%  (17/19)89%  (0.9/1)
     
class MapExecutionContextDao100% (1/1)100% (10/10)100% (97/97)100% (26/26)
MapExecutionContextDao (): void 100% (1/1)100% (6/6)100% (3/3)
clear (): void 100% (1/1)100% (4/4)100% (2/2)
copy (ExecutionContext): ExecutionContext 100% (1/1)100% (5/5)100% (1/1)
getExecutionContext (JobExecution): ExecutionContext 100% (1/1)100% (10/10)100% (1/1)
getExecutionContext (StepExecution): ExecutionContext 100% (1/1)100% (10/10)100% (1/1)
saveExecutionContext (JobExecution): void 100% (1/1)100% (4/4)100% (2/2)
saveExecutionContext (StepExecution): void 100% (1/1)100% (4/4)100% (2/2)
saveExecutionContexts (Collection): void 100% (1/1)100% (22/22)100% (6/6)
updateExecutionContext (JobExecution): void 100% (1/1)100% (16/16)100% (4/4)
updateExecutionContext (StepExecution): void 100% (1/1)100% (16/16)100% (4/4)

1/*
2 * Copyright 2006-2013 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.io.Serializable;
20import java.util.Collection;
21import java.util.concurrent.ConcurrentMap;
22 
23import org.springframework.batch.core.JobExecution;
24import org.springframework.batch.core.StepExecution;
25import org.springframework.batch.item.ExecutionContext;
26import org.springframework.batch.support.SerializationUtils;
27import org.springframework.batch.support.transaction.TransactionAwareProxyFactory;
28import org.springframework.util.Assert;
29 
30/**
31 * In-memory implementation of {@link ExecutionContextDao} backed by maps.
32 *
33 * @author Robert Kasanicky
34 * @author Dave Syer
35 * @author David Turanski
36 */
37@SuppressWarnings("serial")
38public class MapExecutionContextDao implements ExecutionContextDao {
39 
40        private final ConcurrentMap<ContextKey, ExecutionContext> contexts = TransactionAwareProxyFactory
41                        .createAppendOnlyTransactionalMap();
42 
43        private static final class ContextKey implements Comparable<ContextKey>, Serializable {
44 
45                private static enum Type { STEP, JOB; }
46 
47                private final Type type;
48                private final long id;
49 
50                private ContextKey(Type type, long id) {
51                        if(type == null) {
52                                throw new IllegalStateException("Need a non-null type for a context");
53                        }
54                        this.type = type;
55                        this.id = id;
56                }
57 
58                @Override
59                public int compareTo(ContextKey them) {
60                        if(them == null) {
61                                return 1;
62                        }
63                        final int idCompare = new Long(this.id).compareTo(new Long(them.id)); // JDK6 Make this Long.compare(x,y)
64                        if(idCompare != 0) {
65                                return idCompare;
66                        }
67                        final int typeCompare = this.type.compareTo(them.type);
68                        if(typeCompare != 0) {
69                                return typeCompare;
70                        }
71                        return 0;
72                }
73 
74                @Override
75                public boolean equals(Object them) {
76                        if(them == null) {
77                                return false;
78                        }
79                        if(them instanceof ContextKey) {
80                                return this.equals((ContextKey)them);
81                        }
82                        return false;
83                }
84 
85                public boolean equals(ContextKey them) {
86                        if(them == null) {
87                                return false;
88                        }
89                        return this.id == them.id && this.type.equals(them.type);
90                }
91 
92                @Override
93                public int hashCode() {
94                        int value = (int)(id^(id>>>32));
95                        switch(type) {
96                        case STEP: return value;
97                        case JOB: return ~value;
98                        default: throw new IllegalStateException("Unknown type encountered in switch: " + type);
99                        }
100                }
101 
102                public static ContextKey step(long id) { return new ContextKey(Type.STEP, id); }
103 
104                public static ContextKey job(long id) { return new ContextKey(Type.JOB, id); }
105        }
106 
107        public void clear() {
108                contexts.clear();
109        }
110 
111        private static ExecutionContext copy(ExecutionContext original) {
112                return (ExecutionContext) SerializationUtils.deserialize(SerializationUtils.serialize(original));
113        }
114 
115        @Override
116        public ExecutionContext getExecutionContext(StepExecution stepExecution) {
117                return copy(contexts.get(ContextKey.step(stepExecution.getId())));
118        }
119 
120        @Override
121        public void updateExecutionContext(StepExecution stepExecution) {
122                ExecutionContext executionContext = stepExecution.getExecutionContext();
123                if (executionContext != null) {
124                        contexts.put(ContextKey.step(stepExecution.getId()), copy(executionContext));
125                }
126        }
127 
128        @Override
129        public ExecutionContext getExecutionContext(JobExecution jobExecution) {
130                return copy(contexts.get(ContextKey.job(jobExecution.getId())));
131        }
132 
133        @Override
134        public void updateExecutionContext(JobExecution jobExecution) {
135                ExecutionContext executionContext = jobExecution.getExecutionContext();
136                if (executionContext != null) {
137                        contexts.put(ContextKey.job(jobExecution.getId()), copy(executionContext));
138                }
139        }
140 
141        @Override
142        public void saveExecutionContext(JobExecution jobExecution) {
143                updateExecutionContext(jobExecution);
144        }
145 
146        @Override
147        public void saveExecutionContext(StepExecution stepExecution) {
148                updateExecutionContext(stepExecution);
149        }
150 
151 
152        @Override
153        public void saveExecutionContexts(Collection<StepExecution> stepExecutions) {
154                Assert.notNull(stepExecutions,"Attempt to save a nulk collection of step executions");
155                for (StepExecution stepExecution: stepExecutions) {
156                        saveExecutionContext(stepExecution);
157                        saveExecutionContext(stepExecution.getJobExecution());
158                }
159        }
160 
161}

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