Skip to content

Package: Transaction

Transaction

nameinstructionbranchcomplexitylinemethod
Transaction()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
afterCommit()
M: 0 C: 21
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
afterRollback()
M: 0 C: 21
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
begin()
M: 0 C: 28
100%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 4
100%
M: 0 C: 1
100%
commit()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
equals(Object)
M: 6 C: 22
79%
M: 3 C: 5
63%
M: 3 C: 2
40%
M: 3 C: 5
63%
M: 0 C: 1
100%
getState()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hashCode()
M: 2 C: 17
89%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 4
100%
M: 0 C: 1
100%
isActive()
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
rollback()
M: 0 C: 29
100%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 4
100%
M: 0 C: 1
100%
toString()
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
verifyActive()
M: 0 C: 17
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2020 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.ontodriver.util;
16:
17:
18: import static cz.cvut.kbss.ontodriver.util.TransactionState.*;
19:
20: public final class Transaction {
21:
22: private TransactionState state;
23:
24: /**
25: * Begins a transaction.
26: */
27: public void begin() {
28:• if (state != null && state != ABORTED && state != COMMITTED) {
29: throw new IllegalStateException("Cannot begin transaction. Current state is " + state);
30: }
31: this.state = ACTIVE;
32: }
33:
34: /**
35: * Marks the beginning of transaction commit.
36: *
37: * @see #afterCommit()
38: */
39: public void commit() {
40: verifyActive();
41: this.state = PARTIALLY_COMMITTED;
42: }
43:
44: /**
45: * Marks successful completion of transaction commit.
46: *
47: * @see #commit()
48: */
49: public void afterCommit() {
50:• if (state != PARTIALLY_COMMITTED) {
51: throw new IllegalStateException("Cannot finish commit. Current state is " + state);
52: }
53: this.state = COMMITTED;
54: }
55:
56: /**
57: * Commences transaction rollback.
58: *
59: * @see #afterRollback()
60: */
61: public void rollback() {
62:• if (state != ACTIVE && state != PARTIALLY_COMMITTED && state != FAILED) {
63: throw new IllegalStateException("Cannot rollback transaction. Current state is "
64: + state);
65: }
66: this.state = FAILED;
67: }
68:
69: /**
70: * Marks successful finish of transaction rollback.
71: *
72: * @see #rollback()
73: */
74: public void afterRollback() {
75:• if (state != FAILED) {
76: throw new IllegalStateException("Cannot finish rollback. Current state is " + state);
77: }
78: this.state = ABORTED;
79: }
80:
81: public boolean isActive() {
82:• return state == ACTIVE;
83: }
84:
85: public TransactionState getState() {
86: return state;
87: }
88:
89: /**
90: * Verifies that the transaction is active.
91: *
92: * @throws IllegalStateException When transaction is not active
93: */
94: public void verifyActive() {
95:• if (!isActive()) {
96: throw new IllegalStateException("Transaction is not active. Current state is " + state);
97: }
98: }
99:
100: @Override
101: public int hashCode() {
102: final int prime = 31;
103: int result = 1;
104:• result = prime * result + ((state == null) ? 0 : state.hashCode());
105: return result;
106: }
107:
108: @Override
109: public boolean equals(Object obj) {
110:• if (this == obj)
111: return true;
112:• if (obj == null)
113: return false;
114:• if (getClass() != obj.getClass())
115: return false;
116: Transaction other = (Transaction) obj;
117:• return state == other.state;
118: }
119:
120: @Override
121: public String toString() {
122:• return state != null ? state.toString() : "null";
123: }
124: }