ResourcePeerImpl.java
3.62 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.transaction.Synchronization
* javax.transaction.SystemException
* javax.transaction.Transaction
* javax.transaction.TransactionManager
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.service;
import com.adobe.aemds.bedrock.internal.OSGiUtils;
import com.adobe.service.Resource;
import com.adobe.service.ResourcePeer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import java.lang.reflect.UndeclaredThrowableException;
class ResourcePeerImpl
extends ResourcePeer
implements Synchronization {
private final Logger logger = LoggerFactory.getLogger(ResourcePeerImpl.class);
private Transaction savedTx;
private boolean didRollback = false;
ResourcePeerImpl(Resource resource) {
super(resource);
}
private static TransactionManager getTransactionManager() {
return OSGiUtils.getTransactionManager();
}
public void resumeTx() {
if (this.getSavedTx() == null) {
return;
}
TransactionManager tm = ResourcePeerImpl.getTransactionManager();
try {
Transaction trans = tm.getTransaction();
if (trans != null) {
throw new IllegalStateException("Unexpected Transaction " + (Object)trans);
}
tm.resume(this.getSavedTx());
trans = tm.getTransaction();
if (trans != this.getSavedTx()) {
throw new IllegalStateException("Transaction not resumed " + (Object)trans);
}
}
catch (Exception e) {
this.logger.error("Unexpected exception while resuming transaction", (Throwable)e);
throw new UndeclaredThrowableException(e);
}
}
public void suspendTx() {
if (this.getSavedTx() == null) {
return;
}
TransactionManager tm = ResourcePeerImpl.getTransactionManager();
try {
Transaction trans = tm.getTransaction();
if (trans != this.getSavedTx()) {
throw new IllegalStateException("Wrong transaction " + (Object)trans);
}
tm.suspend();
trans = tm.getTransaction();
if (trans != null) {
throw new IllegalStateException("Not suspended " + (Object)trans);
}
}
catch (SystemException e) {
this.logger.error("Unexpected exception while suspending transaction", (Throwable)e);
throw new UndeclaredThrowableException((Throwable)e, "System exception");
}
}
void setSavedTx(Transaction tx) {
this.savedTx = tx;
}
Transaction getSavedTx() {
return this.savedTx;
}
public void afterCompletion(int status) {
if (status == 4) {
this.invokeRollback();
} else if (!this.didRollback) {
this.invokeCommit();
}
this.didRollback = false;
}
public void beforeCompletion() {
try {
this.invokePrepare();
}
catch (Resource.Rollback e) {
this.logger.warn("Rollback error encountered while preparing resource for tx completion", (Throwable)e);
this.didRollback = true;
this.invokeRollback();
}
}
public static class Factory
implements ResourcePeer.Factory {
public ResourcePeer create(Resource resource) {
return new ResourcePeerImpl(resource);
}
}
}