-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
SynchronizationRegistryBasedSynchronizationStrategy.java
39 lines (33 loc) · 1.48 KB
/
SynchronizationRegistryBasedSynchronizationStrategy.java
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
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.engine.transaction.jta.platform.internal;
import jakarta.transaction.Synchronization;
import jakarta.transaction.TransactionSynchronizationRegistry;
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
/**
* Implementation of the {@link JtaSynchronizationStrategy} contract based on using a
* {@link TransactionSynchronizationRegistry}
*
* @author Steve Ebersole
*/
public class SynchronizationRegistryBasedSynchronizationStrategy implements JtaSynchronizationStrategy {
private final SynchronizationRegistryAccess synchronizationRegistryAccess;
public SynchronizationRegistryBasedSynchronizationStrategy(SynchronizationRegistryAccess synchronizationRegistryAccess) {
this.synchronizationRegistryAccess = synchronizationRegistryAccess;
}
@Override
public void registerSynchronization(Synchronization synchronization) {
synchronizationRegistryAccess.getSynchronizationRegistry().registerInterposedSynchronization(
synchronization
);
}
@Override
public boolean canRegisterSynchronization() {
final TransactionSynchronizationRegistry registry = synchronizationRegistryAccess.getSynchronizationRegistry();
return JtaStatusHelper.isActive( registry.getTransactionStatus() ) && ! registry.getRollbackOnly();
}
}