| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.store; |
| 21 |
|
|
| 22 |
|
import java.io.PrintStream; |
| 23 |
|
import java.io.PrintWriter; |
| 24 |
|
import java.io.StringWriter; |
| 25 |
|
import java.io.Writer; |
| 26 |
|
import java.util.ArrayList; |
| 27 |
|
import java.util.List; |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
@version |
| 35 |
|
@since |
| 36 |
|
|
| |
|
| 72.7% |
Uncovered Elements: 18 (66) |
Complexity: 17 |
Complexity Density: 0.39 |
|
| 37 |
|
public class TransactionException extends Exception |
| 38 |
|
{ |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
private static final String NEWLINE = System.getProperty("line.separator"); |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
private static final String TAB = "\t"; |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
private final List<Throwable> causes; |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
private final boolean isNonRecoverable; |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
private final int exceptionCount; |
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
@param |
| 68 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 69 |
4 |
public TransactionException(final List<Throwable> causes)... |
| 70 |
|
{ |
| 71 |
4 |
this(null, causes); |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
@param |
| 78 |
|
@param |
| 79 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 80 |
4 |
public TransactionException(final String message, final List<Throwable> causes)... |
| 81 |
|
{ |
| 82 |
4 |
this(message, causes, false); |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
@param |
| 89 |
|
@param |
| 90 |
|
@param |
| 91 |
|
|
| 92 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 3 |
Complexity Density: 0.23 |
|
| 93 |
27 |
public TransactionException(final String message,... |
| 94 |
|
final List<Throwable> causes, |
| 95 |
|
final boolean isNonRecoverable) |
| 96 |
|
{ |
| 97 |
27 |
super(message); |
| 98 |
27 |
this.causes = new ArrayList<Throwable>(causes); |
| 99 |
27 |
boolean nonRecoverable = isNonRecoverable; |
| 100 |
|
|
| 101 |
27 |
int total = 0; |
| 102 |
27 |
for (Throwable cause : this.causes) { |
| 103 |
36 |
if (cause instanceof TransactionException) { |
| 104 |
3 |
final TransactionException teCause = (TransactionException) cause; |
| 105 |
|
|
| 106 |
3 |
total += teCause.exceptionCount(); |
| 107 |
3 |
if (teCause.isNonRecoverable()) { |
| 108 |
2 |
nonRecoverable = true; |
| 109 |
|
} |
| 110 |
|
} else { |
| 111 |
33 |
total++; |
| 112 |
|
} |
| 113 |
|
} |
| 114 |
27 |
this.exceptionCount = total; |
| 115 |
27 |
this.isNonRecoverable = nonRecoverable; |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
|
| 119 |
|
@return |
| 120 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 121 |
12 |
public List<Throwable> getCauses()... |
| 122 |
|
{ |
| 123 |
12 |
return new ArrayList<Throwable>(this.causes); |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
|
| 127 |
|
@return |
| 128 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 129 |
8 |
public int exceptionCount()... |
| 130 |
|
{ |
| 131 |
8 |
return this.exceptionCount; |
| 132 |
|
} |
| 133 |
|
|
| 134 |
|
|
| 135 |
|
@return |
| 136 |
|
|
| 137 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 138 |
11 |
public boolean isNonRecoverable()... |
| 139 |
|
{ |
| 140 |
11 |
return this.isNonRecoverable; |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
|
| 144 |
|
@inheritDoc |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
| 150 |
|
@see |
| 151 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 152 |
5 |
public String getMessage()... |
| 153 |
|
{ |
| 154 |
5 |
final Writer writer = new StringWriter(); |
| 155 |
5 |
final PrintWriter printer = new PrintWriter(writer); |
| 156 |
5 |
printInfo(printer, false); |
| 157 |
5 |
return writer.toString(); |
| 158 |
|
} |
| 159 |
|
|
| 160 |
|
|
| 161 |
|
|
| 162 |
|
|
| 163 |
|
@return@link |
| 164 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 165 |
0 |
public String getStackTraceString()... |
| 166 |
|
{ |
| 167 |
0 |
final Writer writer = new StringWriter(); |
| 168 |
0 |
final PrintWriter printer = new PrintWriter(writer); |
| 169 |
0 |
this.printStackTrace(printer); |
| 170 |
0 |
return writer.toString(); |
| 171 |
|
} |
| 172 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 173 |
0 |
@Override... |
| 174 |
|
public void printStackTrace() |
| 175 |
|
{ |
| 176 |
0 |
this.printStackTrace(System.err); |
| 177 |
|
} |
| 178 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 179 |
0 |
@Override... |
| 180 |
|
public void printStackTrace(final PrintStream writeTo) |
| 181 |
|
{ |
| 182 |
0 |
this.printStackTrace(new PrintWriter(writeTo)); |
| 183 |
|
} |
| 184 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 185 |
0 |
@Override... |
| 186 |
|
public void printStackTrace(final PrintWriter writeTo) |
| 187 |
|
{ |
| 188 |
0 |
this.printInfo(writeTo, true); |
| 189 |
|
} |
| 190 |
|
|
| 191 |
|
|
| 192 |
|
|
| 193 |
|
|
| 194 |
|
@param |
| 195 |
|
@param |
| 196 |
|
|
| |
|
| 66.7% |
Uncovered Elements: 7 (21) |
Complexity: 4 |
Complexity Density: 0.27 |
|
| 197 |
5 |
private void printInfo(final PrintWriter writeTo, final boolean includeStackTrace)... |
| 198 |
|
{ |
| 199 |
5 |
if (super.getMessage() != null) { |
| 200 |
1 |
writeTo.println(super.getMessage()); |
| 201 |
|
} |
| 202 |
5 |
writeTo.println("Caused by:"); |
| 203 |
|
|
| 204 |
5 |
for (Throwable cause : causes) { |
| 205 |
|
|
| 206 |
13 |
writeTo.println(cause.getClass().getName()); |
| 207 |
13 |
writeTo.print(TAB); |
| 208 |
13 |
writeTo.print(("" + cause.getMessage()).replaceAll(NEWLINE, NEWLINE + TAB)); |
| 209 |
13 |
writeTo.print(NEWLINE); |
| 210 |
|
|
| 211 |
13 |
if (includeStackTrace) { |
| 212 |
|
|
| 213 |
|
|
| 214 |
0 |
final Writer stw = new StringWriter(); |
| 215 |
0 |
final PrintWriter stpw = new PrintWriter(stw); |
| 216 |
0 |
cause.printStackTrace(stpw); |
| 217 |
0 |
writeTo.print(stw.toString().replaceAll(NEWLINE, NEWLINE + TAB)); |
| 218 |
|
} |
| 219 |
|
} |
| 220 |
5 |
if (includeStackTrace) { |
| 221 |
0 |
super.printStackTrace(writeTo); |
| 222 |
|
} |
| 223 |
|
} |
| 224 |
|
} |