|
| 1 | +package org.hibernate.engine.transaction.jta.platform.internal; |
| 2 | + |
| 3 | +import jakarta.transaction.HeuristicMixedException; |
| 4 | +import jakarta.transaction.HeuristicRollbackException; |
| 5 | +import jakarta.transaction.NotSupportedException; |
| 6 | +import jakarta.transaction.RollbackException; |
| 7 | +import jakarta.transaction.SystemException; |
| 8 | +import jakarta.transaction.Transaction; |
| 9 | +import jakarta.transaction.TransactionManager; |
| 10 | +import jakarta.transaction.TransactionSynchronizationRegistry; |
| 11 | +import jakarta.transaction.UserTransaction; |
| 12 | + |
| 13 | +import javax.transaction.xa.XAResource; |
| 14 | + |
| 15 | +/** |
| 16 | + * A {@link org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform} |
| 17 | + * that in principle is supposed to work in any Jakarta EE container. This |
| 18 | + * implementation is crippled by the fact that it is unable to suspend and |
| 19 | + * resume transactions. |
| 20 | + * @since 4.0 |
| 21 | + * @author Gavin King |
| 22 | + */ |
| 23 | +public class JakartaStandardJtaPlatform extends AbstractJtaPlatform |
| 24 | + implements TransactionManager, Transaction { |
| 25 | + |
| 26 | + public static final JakartaStandardJtaPlatform INSTANCE = new JakartaStandardJtaPlatform(); |
| 27 | + public static final String USER_TRANSACTION = "java:comp/UserTransaction"; |
| 28 | + public static final String TRANSACTION_SYNCHRONIZATION_REGISTRY = "java:comp/TransactionSynchronizationRegistry"; |
| 29 | + |
| 30 | + @Override |
| 31 | + protected TransactionManager locateTransactionManager() { |
| 32 | + return this; |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + protected UserTransaction locateUserTransaction() { |
| 37 | + return (UserTransaction) jndiService().locate( USER_TRANSACTION ); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + protected JtaSynchronizationStrategy getSynchronizationStrategy() { |
| 42 | + return new SynchronizationRegistryBasedSynchronizationStrategy( |
| 43 | + this::getTransactionSynchronizationRegistry ); |
| 44 | + } |
| 45 | + |
| 46 | + private TransactionSynchronizationRegistry getTransactionSynchronizationRegistry() { |
| 47 | + return (TransactionSynchronizationRegistry) |
| 48 | + jndiService().locate( TRANSACTION_SYNCHRONIZATION_REGISTRY ); |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public void begin() throws NotSupportedException, SystemException { |
| 53 | + locateUserTransaction().begin(); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public void commit() |
| 58 | + throws RollbackException, HeuristicMixedException, HeuristicRollbackException, |
| 59 | + SecurityException, IllegalStateException, SystemException { |
| 60 | + locateUserTransaction().commit(); |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public void rollback() throws IllegalStateException, SecurityException, SystemException { |
| 65 | + locateUserTransaction().rollback(); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public void setRollbackOnly() throws IllegalStateException, SystemException { |
| 70 | + locateUserTransaction().setRollbackOnly(); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public int getStatus() throws SystemException { |
| 75 | + return locateUserTransaction().getStatus(); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public Transaction getTransaction() throws SystemException { |
| 80 | + return this; |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public void setTransactionTimeout(int seconds) throws SystemException { |
| 85 | + locateUserTransaction().setTransactionTimeout( seconds ); |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public boolean delistResource(XAResource xaRes, int flag) { |
| 90 | + throw new UnsupportedOperationException( "JakartaStandardJtaPlatform does not have access to the TransactionManager" ); |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + public boolean enlistResource(XAResource xaRes) { |
| 95 | + throw new UnsupportedOperationException( "JakartaStandardJtaPlatform does not have access to the TransactionManager" ); |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + public Transaction suspend() throws SystemException { |
| 100 | + throw new UnsupportedOperationException( "JakartaStandardJtaPlatform does not have access to the TransactionManager" ); |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public void resume(Transaction tobj) { |
| 105 | + throw new UnsupportedOperationException( "JakartaStandardJtaPlatform does not have access to the TransactionManager" ); |
| 106 | + } |
| 107 | + |
| 108 | +} |
0 commit comments