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

COVERAGE SUMMARY FOR SOURCE FILE [ResourcelessTransactionManager.java]

nameclass, %method, %block, %line, %
ResourcelessTransactionManager.java67%  (2/3)92%  (12/13)94%  (113/120)94%  (31/33)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ResourcelessTransactionManager$ResourcelessTransaction100% (1/1)80%  (4/5)85%  (17/20)86%  (6/7)
isActive (): boolean 0%   (0/1)0%   (0/3)0%   (0/1)
ResourcelessTransactionManager$ResourcelessTransaction (): void 100% (1/1)100% (6/6)100% (2/2)
ResourcelessTransactionManager$ResourcelessTransaction (ResourcelessTransacti... 100% (1/1)100% (3/3)100% (1/1)
begin (): void 100% (1/1)100% (4/4)100% (2/2)
clear (): void 100% (1/1)100% (4/4)100% (2/2)
     
class ResourcelessTransactionManager100% (1/1)100% (8/8)96%  (96/100)96%  (26/27)
isExistingTransaction (Object): boolean 100% (1/1)79%  (15/19)75%  (3/4)
ResourcelessTransactionManager (): void 100% (1/1)100% (3/3)100% (2/2)
doBegin (Object, TransactionDefinition): void 100% (1/1)100% (4/4)100% (2/2)
doCleanupAfterCompletion (Object): void 100% (1/1)100% (15/15)100% (6/6)
doCommit (DefaultTransactionStatus): void 100% (1/1)100% (15/15)100% (2/2)
doGetTransaction (): Object 100% (1/1)100% (28/28)100% (8/8)
doRollback (DefaultTransactionStatus): void 100% (1/1)100% (15/15)100% (2/2)
doSetRollbackOnly (DefaultTransactionStatus): void 100% (1/1)100% (1/1)100% (1/1)
     
class ResourcelessTransactionManager$10%   (0/1)100% (0/0)100% (0/0)100% (0/0)

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.support.transaction;
18 
19import java.util.Stack;
20 
21import org.springframework.transaction.TransactionDefinition;
22import org.springframework.transaction.TransactionException;
23import org.springframework.transaction.support.AbstractPlatformTransactionManager;
24import org.springframework.transaction.support.DefaultTransactionStatus;
25import org.springframework.transaction.support.TransactionSynchronizationManager;
26 
27public class ResourcelessTransactionManager extends AbstractPlatformTransactionManager {
28 
29    @Override
30        protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException {
31                ((ResourcelessTransaction) transaction).begin();
32        }
33 
34    @Override
35        protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
36                logger.debug("Committing resourceless transaction on [" + status.getTransaction() + "]");
37        }
38 
39    @Override
40        protected Object doGetTransaction() throws TransactionException {
41                Object transaction = new ResourcelessTransaction();
42                Stack<Object> resources;
43                if (!TransactionSynchronizationManager.hasResource(this)) {
44                        resources = new Stack<Object>();
45                        TransactionSynchronizationManager.bindResource(this, resources);
46                }
47                else {
48                        @SuppressWarnings("unchecked")
49                        Stack<Object> stack = (Stack<Object>) TransactionSynchronizationManager.getResource(this);
50                        resources = stack;
51                }
52                resources.push(transaction);
53                return transaction;
54        }
55 
56    @Override
57        protected void doRollback(DefaultTransactionStatus status) throws TransactionException {
58                logger.debug("Rolling back resourceless transaction on [" + status.getTransaction() + "]");
59        }
60 
61    @Override
62        protected boolean isExistingTransaction(Object transaction) throws TransactionException {
63                if (TransactionSynchronizationManager.hasResource(this)) {
64                        @SuppressWarnings("unchecked")
65                        Stack<Object> stack = (Stack<Object>) TransactionSynchronizationManager.getResource(this);
66                        return stack.size() > 1;
67                }
68                return ((ResourcelessTransaction) transaction).isActive();
69        }
70 
71    @Override
72        protected void doSetRollbackOnly(DefaultTransactionStatus status) throws TransactionException {
73        }
74 
75    @Override
76        protected void doCleanupAfterCompletion(Object transaction) {
77                @SuppressWarnings("unchecked")
78                Stack<Object> list = (Stack<Object>) TransactionSynchronizationManager.getResource(this);
79                Stack<Object> resources = list;
80                resources.clear();
81                TransactionSynchronizationManager.unbindResource(this);
82                ((ResourcelessTransaction) transaction).clear();
83        }
84 
85        private static class ResourcelessTransaction {
86 
87                private boolean active = false;
88 
89                public boolean isActive() {
90                        return active;
91                }
92 
93                public void begin() {
94                        active = true;
95                }
96 
97                public void clear() {
98                        active = false;
99                }
100 
101        }
102 
103}

[all classes][org.springframework.batch.support.transaction]
EMMA 2.0.5312 (C) Vladimir Roubtsov