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: 21
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
equals(Object)
M: 28 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
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: 19 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
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%

Coverage

1: /**
2: * Copyright (C) 2016 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.sesame;
16:
17: import static cz.cvut.kbss.ontodriver.sesame.TransactionState.ABORTED;
18: import static cz.cvut.kbss.ontodriver.sesame.TransactionState.ACTIVE;
19: import static cz.cvut.kbss.ontodriver.sesame.TransactionState.COMMITTED;
20: import static cz.cvut.kbss.ontodriver.sesame.TransactionState.FAILED;
21: import static cz.cvut.kbss.ontodriver.sesame.TransactionState.PARTIALLY_COMMITTED;
22:
23: public final class Transaction {
24:
25:         private TransactionState state;
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:         public void commit() {
35:•                if (state != ACTIVE) {
36:                         throw new IllegalStateException("Cannot commit transaction. Current state is " + state);
37:                 }
38:                 this.state = PARTIALLY_COMMITTED;
39:         }
40:
41:         public void afterCommit() {
42:•                if (state != PARTIALLY_COMMITTED) {
43:                         throw new IllegalStateException("Cannot finish commit. Current state is " + state);
44:                 }
45:                 this.state = COMMITTED;
46:         }
47:
48:         public void rollback() {
49:•                if (state != ACTIVE && state != PARTIALLY_COMMITTED && state != FAILED) {
50:                         throw new IllegalStateException("Cannot rollback transaction. Current state is "
51:                                         + state);
52:                 }
53:                 this.state = FAILED;
54:         }
55:
56:         public void afterRollback() {
57:•                if (state != FAILED) {
58:                         throw new IllegalStateException("Cannot finish rollback. Current state is " + state);
59:                 }
60:                 this.state = ABORTED;
61:         }
62:
63:         public boolean isActive() {
64:•                return state == ACTIVE;
65:         }
66:
67:         public TransactionState getState() {
68:                 return state;
69:         }
70:
71:         @Override
72:         public int hashCode() {
73:                 final int prime = 31;
74:                 int result = 1;
75:•                result = prime * result + ((state == null) ? 0 : state.hashCode());
76:                 return result;
77:         }
78:
79:         @Override
80:         public boolean equals(Object obj) {
81:•                if (this == obj)
82:                         return true;
83:•                if (obj == null)
84:                         return false;
85:•                if (getClass() != obj.getClass())
86:                         return false;
87:                 Transaction other = (Transaction) obj;
88:•                if (state != other.state)
89:                         return false;
90:                 return true;
91:         }
92:
93:         @Override
94:         public String toString() {
95:•                return (state != null ? state.toString() : "null");
96:         }
97: }