forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UserTransaction should fire context lifecycle events
- such as @initialized(TransactionScoped.class) - resolves quarkusio#28709
- Loading branch information
Showing
8 changed files
with
154 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...a-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/NotifyingUserTransaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package io.quarkus.narayana.jta.runtime; | ||
|
||
import javax.transaction.HeuristicMixedException; | ||
import javax.transaction.HeuristicRollbackException; | ||
import javax.transaction.NotSupportedException; | ||
import javax.transaction.RollbackException; | ||
import javax.transaction.SystemException; | ||
import javax.transaction.UserTransaction; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
public class NotifyingUserTransaction extends TransactionScopedNotifier implements UserTransaction { | ||
|
||
private static final Logger LOG = Logger.getLogger(NotifyingUserTransaction.class); | ||
|
||
private final UserTransaction delegate; | ||
|
||
public NotifyingUserTransaction(UserTransaction delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void begin() throws NotSupportedException, SystemException { | ||
delegate.begin(); | ||
initialized(delegate); | ||
} | ||
|
||
@Override | ||
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, | ||
IllegalStateException, SystemException { | ||
beforeDestroyed(delegate); | ||
try { | ||
delegate.commit(); | ||
} finally { | ||
destroyed(delegate); | ||
} | ||
} | ||
|
||
@Override | ||
public void rollback() throws IllegalStateException, SecurityException, SystemException { | ||
try { | ||
beforeDestroyed(delegate); | ||
} catch (Throwable t) { | ||
LOG.error("Failed to fire @BeforeDestroyed(TransactionScoped.class)", t); | ||
} | ||
try { | ||
delegate.rollback(); | ||
} finally { | ||
destroyed(delegate); | ||
} | ||
} | ||
|
||
@Override | ||
public void setRollbackOnly() throws IllegalStateException, SystemException { | ||
delegate.setRollbackOnly(); | ||
} | ||
|
||
@Override | ||
public int getStatus() throws SystemException { | ||
return delegate.getStatus(); | ||
} | ||
|
||
@Override | ||
public void setTransactionTimeout(int seconds) throws SystemException { | ||
delegate.setTransactionTimeout(seconds); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/TransactionScopedNotifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.quarkus.narayana.jta.runtime; | ||
|
||
import javax.enterprise.context.BeforeDestroyed; | ||
import javax.enterprise.context.Destroyed; | ||
import javax.enterprise.context.Initialized; | ||
import javax.enterprise.event.Event; | ||
import javax.transaction.TransactionScoped; | ||
|
||
import io.quarkus.arc.Arc; | ||
|
||
abstract class TransactionScopedNotifier { | ||
|
||
private transient Event<Object> initialized; | ||
private transient Event<Object> beforeDestroyed; | ||
private transient Event<Object> destroyed; | ||
|
||
void initialized(Object payload) { | ||
if (initialized == null) { | ||
initialized = Arc.container().beanManager().getEvent() | ||
.select(Initialized.Literal.of(TransactionScoped.class)); | ||
} | ||
initialized.fire(payload); | ||
} | ||
|
||
void beforeDestroyed(Object payload) { | ||
if (beforeDestroyed == null) { | ||
beforeDestroyed = Arc.container().beanManager().getEvent() | ||
.select(BeforeDestroyed.Literal.of(TransactionScoped.class)); | ||
} | ||
beforeDestroyed.fire(payload); | ||
} | ||
|
||
void destroyed(Object payload) { | ||
if (destroyed == null) { | ||
destroyed = Arc.container().beanManager().getEvent() | ||
.select(Destroyed.Literal.of(TransactionScoped.class)); | ||
} | ||
destroyed.fire(payload); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters