EMMA Coverage Report (generated Tue May 06 07:29:23 PDT 2008)
[all classes][org.springframework.batch.core.repository.dao]

COVERAGE SUMMARY FOR SOURCE FILE [MapStepExecutionDao.java]

nameclass, %method, %block, %line, %
MapStepExecutionDao.java100% (1/1)100% (8/8)100% (167/167)100% (37/37)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapStepExecutionDao100% (1/1)100% (8/8)100% (167/167)100% (37/37)
<static initializer> 100% (1/1)100% (7/7)100% (4/4)
MapStepExecutionDao (): void 100% (1/1)100% (3/3)100% (1/1)
clear (): void 100% (1/1)100% (3/3)100% (2/2)
findExecutionContext (StepExecution): ExecutionContext 100% (1/1)100% (6/6)100% (1/1)
getStepExecution (JobExecution, Step): StepExecution 100% (1/1)100% (16/16)100% (4/4)
saveOrUpdateExecutionContext (StepExecution): void 100% (1/1)100% (8/8)100% (2/2)
saveStepExecution (StepExecution): void 100% (1/1)100% (53/53)100% (11/11)
updateStepExecution (StepExecution): void 100% (1/1)100% (71/71)100% (12/12)

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.Map;
20 
21import org.springframework.batch.core.JobExecution;
22import org.springframework.batch.core.Step;
23import org.springframework.batch.core.StepExecution;
24import org.springframework.batch.item.ExecutionContext;
25import org.springframework.batch.support.transaction.TransactionAwareProxyFactory;
26import org.springframework.dao.OptimisticLockingFailureException;
27import org.springframework.util.Assert;
28 
29/**
30 * In-memory implementation of {@link StepExecutionDao}.
31 */
32public class MapStepExecutionDao implements StepExecutionDao {
33 
34        private static Map executionsByJobExecutionId;
35 
36        private static Map contextsByStepExecutionId;
37 
38        private static long currentId = 0;
39 
40        static {
41                executionsByJobExecutionId = TransactionAwareProxyFactory.createTransactionalMap();
42                contextsByStepExecutionId = TransactionAwareProxyFactory.createTransactionalMap();
43        }
44 
45        public static void clear() {
46                executionsByJobExecutionId.clear();
47        }
48 
49        public ExecutionContext findExecutionContext(StepExecution stepExecution) {
50                return (ExecutionContext) contextsByStepExecutionId.get(stepExecution.getId());
51        }
52 
53        public void saveStepExecution(StepExecution stepExecution) {
54                Assert.isTrue(stepExecution.getId() == null);
55                Assert.isTrue(stepExecution.getVersion() == null);
56                Assert.notNull(stepExecution.getJobExecutionId(), "JobExecution must be saved already.");
57 
58                Map executions = (Map) executionsByJobExecutionId.get(stepExecution.getJobExecutionId());
59                if (executions == null) {
60                        executions = TransactionAwareProxyFactory.createTransactionalMap();
61                        executionsByJobExecutionId.put(stepExecution.getJobExecutionId(), executions);
62                }
63                stepExecution.setId(new Long(currentId++));
64                stepExecution.incrementVersion();
65                executions.put(stepExecution.getStepName(), stepExecution);
66        }
67 
68        public void updateStepExecution(StepExecution stepExecution) {
69 
70                Assert.notNull(stepExecution.getJobExecutionId());
71 
72                Map executions = (Map) executionsByJobExecutionId.get(stepExecution.getJobExecutionId());
73                Assert.notNull(executions, "step executions for given job execution are expected to be already saved");
74 
75                StepExecution persistedExecution = (StepExecution) executions.get(stepExecution.getStepName());
76                Assert.notNull(persistedExecution, "step execution is expected to be already saved");
77 
78                synchronized (stepExecution) {
79                        if (!persistedExecution.getVersion().equals(stepExecution.getVersion())) {
80                                throw new OptimisticLockingFailureException("Attempt to update step execution id="
81                                                + stepExecution.getId() + " with wrong version (" + stepExecution.getVersion()
82                                                + "), where current version is " + persistedExecution.getVersion());
83                        }
84 
85                        stepExecution.incrementVersion();
86                        executions.put(stepExecution.getStepName(), stepExecution);
87                }
88        }
89 
90        public StepExecution getStepExecution(JobExecution jobExecution, Step step) {
91                Map executions = (Map) executionsByJobExecutionId.get(jobExecution.getId());
92                if (executions == null) {
93                        return null;
94                }
95 
96                return (StepExecution) executions.get(step.getName());
97        }
98 
99        public void saveOrUpdateExecutionContext(StepExecution stepExecution) {
100                contextsByStepExecutionId.put(stepExecution.getId(), stepExecution.getExecutionContext());
101        }
102 
103}

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