DefaultTransactionDefinition.java
7.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.pdfg.transaction;
import com.adobe.pdfg.transaction.TransactionDefinition;
import java.io.Serializable;
public class DefaultTransactionDefinition
implements TransactionDefinition,
Serializable {
public static final String PREFIX_PROPAGATION = "PROPAGATION_";
public static final String PROPAGATION_REQUIRED = "PROPAGATION_REQUIRED";
public static final String PROPAGATION_SUPPORTS = "PROPAGATION_SUPPORTS";
public static final String PROPAGATION_MANDATORY = "PROPAGATION_MANDATORY";
public static final String PROPAGATION_REQUIRES_NEW = "PROPAGATION_REQUIRES_NEW";
public static final String PROPAGATION_NOT_SUPPORTED = "PROPAGATION_NOT_SUPPORTED";
public static final String PROPAGATION_NEVER = "PROPAGATION_NEVER";
public static final String PROPAGATION_NESTED = "PROPAGATION_NESTED";
public static final String ISOLATION_DEFAULT = "ISOLATION_DEFAULT";
public static final String ISOLATION_READ_UNCOMMITTED = "ISOLATION_READ_UNCOMMITTED";
public static final String ISOLATION_READ_COMMITTED = "ISOLATION_READ_COMMITTED";
public static final String ISOLATION_REPEATABLE_READ = "ISOLATION_REPEATABLE_READ";
public static final String ISOLATION_SERIALIZABLE = "ISOLATION_SERIALIZABLE";
public static final String PREFIX_ISOLATION = "ISOLATION_";
public static final String PREFIX_TIMEOUT = "timeout_";
public static final String READ_ONLY_MARKER = "readOnly";
private int propagationBehavior = 0;
private int isolationLevel = -1;
private int timeout = -1;
private boolean readOnly = false;
private String name;
public DefaultTransactionDefinition() {
}
public DefaultTransactionDefinition(TransactionDefinition other) {
this.propagationBehavior = other.getPropagationBehavior();
this.isolationLevel = other.getIsolationLevel();
this.timeout = other.getTimeout();
this.readOnly = other.isReadOnly();
this.name = other.getName();
}
public DefaultTransactionDefinition(int propagationBehavior) {
this.propagationBehavior = propagationBehavior;
}
public final void setPropagationBehaviorName(String constantName) throws IllegalArgumentException {
if (constantName == null || !constantName.startsWith("PROPAGATION_")) {
throw new IllegalArgumentException("Only propagation constants allowed");
}
this.setPropagationBehavior(DefaultTransactionDefinition.getPropagationBehaviorVal(constantName));
}
public final void setPropagationBehavior(int propagationBehavior) {
this.propagationBehavior = propagationBehavior;
}
public final int getPropagationBehavior() {
return this.propagationBehavior;
}
public final void setIsolationLevelName(String constantName) throws IllegalArgumentException {
if (constantName == null || !constantName.startsWith("ISOLATION_")) {
throw new IllegalArgumentException("Only isolation constants allowed");
}
this.setIsolationLevel(DefaultTransactionDefinition.getIsolationLevelVal(constantName));
}
public final void setIsolationLevel(int isolationLevel) {
this.isolationLevel = isolationLevel;
}
public final int getIsolationLevel() {
return this.isolationLevel;
}
public final void setTimeout(int timeout) {
if (timeout < -1) {
throw new IllegalArgumentException("Timeout must be a positive integer or TIMEOUT_DEFAULT");
}
this.timeout = timeout;
}
public final int getTimeout() {
return this.timeout;
}
public final void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
public final boolean isReadOnly() {
return this.readOnly;
}
public final void setName(String name) {
this.name = name;
}
public final String getName() {
return this.name;
}
public boolean equals(Object other) {
return other instanceof TransactionDefinition && this.toString().equals(other.toString());
}
public int hashCode() {
return this.toString().hashCode();
}
public String toString() {
return this.getDefinitionDescription().toString();
}
protected final StringBuilder getDefinitionDescription() {
StringBuilder result = new StringBuilder();
result.append(DefaultTransactionDefinition.getPropagationBehaviorStr(this.propagationBehavior));
result.append(',');
result.append(DefaultTransactionDefinition.getIsolationLevelStr(this.isolationLevel));
if (this.timeout != -1) {
result.append(',');
result.append("timeout_").append(this.timeout);
}
if (this.readOnly) {
result.append(',');
result.append("readOnly");
}
return result;
}
private static String getPropagationBehaviorStr(int propagationBehavior) {
switch (propagationBehavior) {
case 0: {
return "PROPAGATION_REQUIRED";
}
case 1: {
return "PROPAGATION_SUPPORTS";
}
case 2: {
return "PROPAGATION_MANDATORY";
}
case 3: {
return "PROPAGATION_REQUIRES_NEW";
}
case 4: {
return "PROPAGATION_NOT_SUPPORTED";
}
case 5: {
return "PROPAGATION_NEVER";
}
case 6: {
return "PROPAGATION_NESTED";
}
}
return "PROPAGATION_REQUIRED";
}
private static int getPropagationBehaviorVal(String propagationBehavior) {
if (propagationBehavior != null && propagationBehavior.trim().equals("PROPAGATION_REQUIRED")) {
return 0;
}
if (propagationBehavior != null && propagationBehavior.trim().equals("PROPAGATION_SUPPORTS")) {
return 1;
}
if (propagationBehavior != null && propagationBehavior.trim().equals("PROPAGATION_MANDATORY")) {
return 2;
}
if (propagationBehavior != null && propagationBehavior.trim().equals("PROPAGATION_REQUIRES_NEW")) {
return 3;
}
if (propagationBehavior != null && propagationBehavior.trim().equals("PROPAGATION_NOT_SUPPORTED")) {
return 4;
}
if (propagationBehavior != null && propagationBehavior.trim().equals("PROPAGATION_NEVER")) {
return 5;
}
if (propagationBehavior != null && propagationBehavior.trim().equals("PROPAGATION_NESTED")) {
return 6;
}
return 0;
}
private static String getIsolationLevelStr(int isolationLevel) {
switch (isolationLevel) {
case -1: {
return "ISOLATION_DEFAULT";
}
case 1: {
return "ISOLATION_READ_UNCOMMITTED";
}
case 2: {
return "ISOLATION_READ_COMMITTED";
}
case 4: {
return "ISOLATION_REPEATABLE_READ";
}
case 8: {
return "ISOLATION_SERIALIZABLE";
}
}
return "ISOLATION_DEFAULT";
}
private static int getIsolationLevelVal(String isolationLevel) {
if (isolationLevel != null && isolationLevel.trim().equals("ISOLATION_DEFAULT")) {
return -1;
}
if (isolationLevel != null && isolationLevel.trim().equals("ISOLATION_READ_UNCOMMITTED")) {
return 1;
}
if (isolationLevel != null && isolationLevel.trim().equals("ISOLATION_READ_COMMITTED")) {
return 2;
}
if (isolationLevel != null && isolationLevel.trim().equals("ISOLATION_REPEATABLE_READ")) {
return 4;
}
if (isolationLevel != null && isolationLevel.trim().equals("ISOLATION_SERIALIZABLE")) {
return 8;
}
return -1;
}
}