EMMA Coverage Report (generated Thu Jan 24 13:37:04 CST 2013)
[all classes][org.springframework.batch.core.repository.dao]

COVERAGE SUMMARY FOR SOURCE FILE [MapExecutionContextDao.java]

nameclass, %method, %block, %line, %
MapExecutionContextDao.java100% (4/4)90%  (19/21)75%  (196/260)78%  (34.2/44)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapExecutionContextDao$ContextKey100% (1/1)86%  (6/7)55%  (71/128)58%  (13.4/23)
compareTo (MapExecutionContextDao$ContextKey): int 0%   (0/1)0%   (0/32)0%   (0/6)
hashCode (): int 100% (1/1)62%  (21/34)80%  (4/5)
MapExecutionContextDao$ContextKey (MapExecutionContextDao$ContextKey$Type, lo... 100% (1/1)69%  (11/16)89%  (4.4/5)
equals (Object): boolean 100% (1/1)71%  (10/14)50%  (1.5/3)
equals (MapExecutionContextDao$ContextKey): boolean 100% (1/1)85%  (17/20)72%  (1.4/2)
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% (9/9)100% (75/75)100% (20/20)
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)
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-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.io.Serializable;
20import java.util.concurrent.ConcurrentMap;
21 
22import org.springframework.batch.core.JobExecution;
23import org.springframework.batch.core.StepExecution;
24import org.springframework.batch.item.ExecutionContext;
25import org.springframework.batch.support.SerializationUtils;
26import org.springframework.batch.support.transaction.TransactionAwareProxyFactory;
27 
28/**
29 * In-memory implementation of {@link ExecutionContextDao} backed by maps.
30 * 
31 * @author Robert Kasanicky
32 * @author Dave Syer
33 */
34public class MapExecutionContextDao implements ExecutionContextDao {
35 
36        private final ConcurrentMap<ContextKey, ExecutionContext> contexts = TransactionAwareProxyFactory
37                        .createAppendOnlyTransactionalMap();
38 
39        private static final class ContextKey implements Comparable<ContextKey>, Serializable {
40 
41                private static enum Type { STEP, JOB; }
42 
43                private final Type type;
44                private final long id;
45 
46                private ContextKey(Type type, long id) {
47                        if(type == null) throw new IllegalStateException("Need a non-null type for a context");
48                        this.type = type;
49                        this.id = id;
50                }
51 
52                public int compareTo(ContextKey them) {
53                        if(them == null) return 1;
54                        final int idCompare = new Long(this.id).compareTo(new Long(them.id)); // JDK6 Make this Long.compare(x,y)
55                        if(idCompare != 0) return idCompare;
56                        final int typeCompare = this.type.compareTo(them.type);
57                        if(typeCompare != 0) return typeCompare;
58                        return 0;
59                }
60 
61                @Override
62                public boolean equals(Object them) {
63                        if(them == null) return false;
64                        if(them instanceof ContextKey) return this.equals((ContextKey)them);
65                        return false;
66                }
67 
68                public boolean equals(ContextKey them) {
69                        if(them == null) return false;
70                        return this.id == them.id && this.type.equals(them.type);
71                }
72 
73                @Override
74                public int hashCode() {
75                        int value = (int)(id^(id>>>32));
76                        switch(type) {
77                                case STEP: return value;
78                                case JOB: return ~value;
79                                default: throw new IllegalStateException("Unknown type encountered in switch: " + type);
80                        }
81                }
82 
83                public static ContextKey step(long id) { return new ContextKey(Type.STEP, id); }
84 
85                public static ContextKey job(long id) { return new ContextKey(Type.JOB, id); }
86        }
87 
88        public void clear() {        
89                contexts.clear();
90        }
91 
92        private static ExecutionContext copy(ExecutionContext original) {
93                return (ExecutionContext) SerializationUtils.deserialize(SerializationUtils.serialize(original));
94        }
95 
96        public ExecutionContext getExecutionContext(StepExecution stepExecution) {
97                return copy(contexts.get(ContextKey.step(stepExecution.getId())));
98        }
99 
100        public void updateExecutionContext(StepExecution stepExecution) {
101                ExecutionContext executionContext = stepExecution.getExecutionContext();
102                if (executionContext != null) {
103                        contexts.put(ContextKey.step(stepExecution.getId()), copy(executionContext));
104                }
105        }
106 
107        public ExecutionContext getExecutionContext(JobExecution jobExecution) {
108                return copy(contexts.get(ContextKey.job(jobExecution.getId())));
109        }
110 
111        public void updateExecutionContext(JobExecution jobExecution) {
112                ExecutionContext executionContext = jobExecution.getExecutionContext();
113                if (executionContext != null) {
114                        contexts.put(ContextKey.job(jobExecution.getId()), copy(executionContext));
115                }
116        }
117 
118        public void saveExecutionContext(JobExecution jobExecution) {
119                updateExecutionContext(jobExecution);
120        }
121 
122        public void saveExecutionContext(StepExecution stepExecution) {
123                updateExecutionContext(stepExecution);
124        }
125 
126}

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