File tree Expand file tree Collapse file tree 2 files changed +26
-5
lines changed
hibernate-core/src/main/java/org/hibernate
engine/transaction/internal Expand file tree Collapse file tree 2 files changed +26
-5
lines changed Original file line number Diff line number Diff line change 8
8
9
9
import javax .transaction .Synchronization ;
10
10
11
- import org .jboss .logging .Logger ;
12
-
13
11
import org .hibernate .HibernateException ;
14
12
import org .hibernate .Transaction ;
15
13
import org .hibernate .TransactionException ;
16
14
import org .hibernate .internal .CoreLogging ;
17
15
import org .hibernate .resource .transaction .TransactionCoordinator ;
18
16
import org .hibernate .resource .transaction .spi .TransactionStatus ;
19
17
18
+ import org .jboss .logging .Logger ;
19
+
20
20
import static org .hibernate .resource .transaction .TransactionCoordinator .TransactionDriver ;
21
21
22
22
/**
@@ -71,8 +71,8 @@ public void commit() {
71
71
@ Override
72
72
public void rollback () {
73
73
TransactionStatus status = transactionDriverControl .getStatus ();
74
- if ( status != TransactionStatus . ACTIVE && status != TransactionStatus . FAILED_COMMIT ) {
75
- throw new TransactionException ( "Transaction not successfully started " );
74
+ if ( ! status . canRollback () ) {
75
+ throw new TransactionException ( "Cannot rollback transaction in current status [" + status . name () + "] " );
76
76
}
77
77
78
78
LOG .debug ( "rolling back" );
Original file line number Diff line number Diff line change @@ -46,5 +46,26 @@ public enum TransactionStatus {
46
46
* Status code indicating a transaction that is in the process of
47
47
* rolling back.
48
48
*/
49
- ROLLING_BACK
49
+ ROLLING_BACK ;
50
+
51
+ public boolean isOneOf (TransactionStatus ... statuses ) {
52
+ for ( TransactionStatus status : statuses ) {
53
+ if ( this == status ) {
54
+ return true ;
55
+ }
56
+ }
57
+ return false ;
58
+ }
59
+
60
+ public boolean isNotOneOf (TransactionStatus ... statuses ) {
61
+ return !isOneOf ( statuses );
62
+ }
63
+
64
+ public boolean canRollback () {
65
+ return isOneOf (
66
+ TransactionStatus .ACTIVE ,
67
+ TransactionStatus .FAILED_COMMIT ,
68
+ TransactionStatus .MARKED_ROLLBACK
69
+ );
70
+ }
50
71
}
You can’t perform that action at this time.
0 commit comments