-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a common test util for transactions in Hibernate ORM unit t…
…ests
- Loading branch information
Showing
4 changed files
with
41 additions
and
39 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/TransactionTestUtils.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,32 @@ | ||
package io.quarkus.hibernate.orm; | ||
|
||
import javax.transaction.HeuristicMixedException; | ||
import javax.transaction.HeuristicRollbackException; | ||
import javax.transaction.NotSupportedException; | ||
import javax.transaction.RollbackException; | ||
import javax.transaction.SystemException; | ||
import javax.transaction.UserTransaction; | ||
|
||
public class TransactionTestUtils { | ||
|
||
public static void inTransaction(UserTransaction transaction, Runnable runnable) { | ||
try { | ||
transaction.begin(); | ||
try { | ||
runnable.run(); | ||
transaction.commit(); | ||
} catch (Throwable t) { | ||
try { | ||
transaction.rollback(); | ||
} catch (Throwable t2) { | ||
t.addSuppressed(t2); | ||
} | ||
throw t; | ||
} | ||
} catch (SystemException | NotSupportedException | RollbackException | HeuristicMixedException | ||
| HeuristicRollbackException e) { | ||
throw new IllegalStateException("Transaction exception", e); | ||
} | ||
} | ||
|
||
} |
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