Skip to content

Commit

Permalink
Consistently use "transaction semantics" instead of "semantic" (no "s…
Browse files Browse the repository at this point in the history
…") in non-deprecated APIs
  • Loading branch information
yrodiere committed Nov 4, 2022
1 parent 3db2874 commit e10ebc8
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 75 deletions.
8 changes: 4 additions & 4 deletions docs/src/main/asciidoc/transaction.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ Otherwise, a new transaction is started, and follows all the normal lifecycle ru

SUSPEND_EXISTING::

If no transaction is active then this semantic is basically a no-op.
If no transaction is active then these semantics are basically a no-op.
If a transaction is active then it is suspended, and resumed after the task is run.
The exception handler will never be consulted when this semantic is in use, specifying both an exception handler and
this semantic is considered an error.
This semantic allows for code to easily be run outside the scope of a transaction.
The exception handler will never be consulted when these semantics are in use, specifying both an exception handler and
these semantics are considered an error.
These semantics allows for code to easily be run outside the scope of a transaction.



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import io.quarkus.hibernate.orm.runtime.FastBootHibernatePersistenceProvider;
import io.quarkus.narayana.jta.QuarkusTransaction;
import io.quarkus.narayana.jta.TransactionSemantic;
import io.quarkus.narayana.jta.TransactionSemantics;
import io.quarkus.test.QuarkusUnitTest;

public class UnsupportedPropertiesTest {
Expand Down Expand Up @@ -115,7 +115,7 @@ public void testPropertiesPropagatedToRuntimeInit() {
public void testInsertsOrdered() {
var listener = new BatchCountSpyingEventListener();

QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW).run(() -> {
QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW).run(() -> {
em.unwrap(Session.class).addEventListeners(listener);

ParentEntity parent1 = new ParentEntity(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.quarkus.narayana.jta.QuarkusTransaction;
import io.quarkus.narayana.jta.QuarkusTransactionException;
import io.quarkus.narayana.jta.TransactionExceptionResult;
import io.quarkus.narayana.jta.TransactionSemantic;
import io.quarkus.narayana.jta.TransactionSemantics;
import io.quarkus.test.QuarkusUnitTest;

public class TransactionRunnerTest {
Expand All @@ -38,26 +38,26 @@ public class TransactionRunnerTest {
@Test
public void commit() {
var sync = new TestSync();
QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW).run(() -> register(sync));
QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW).run(() -> register(sync));
assertEquals(Status.STATUS_COMMITTED, sync.completionStatus);

assertEquals(Status.STATUS_COMMITTED,
QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW).call(this::register).completionStatus);
QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW).call(this::register).completionStatus);
}

@Test
public void rollback() {
var sync1 = new TestSync();
assertThrows(QuarkusTransactionException.class,
() -> QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW).run(() -> {
() -> QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW).run(() -> {
register(sync1);
QuarkusTransaction.rollback();
}));
assertEquals(Status.STATUS_ROLLEDBACK, sync1.completionStatus);

var sync2 = new TestSync();
assertThrows(QuarkusTransactionException.class,
() -> QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW).call(() -> {
() -> QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW).call(() -> {
register(sync2);
QuarkusTransaction.rollback();
return null;
Expand All @@ -69,15 +69,15 @@ public void rollback() {
public void rollbackOnly() {
var sync1 = new TestSync();
assertThrows(QuarkusTransactionException.class,
() -> QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW).run(() -> {
() -> QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW).run(() -> {
register(sync1);
QuarkusTransaction.setRollbackOnly();
}));
assertEquals(Status.STATUS_ROLLEDBACK, sync1.completionStatus);

var sync2 = new TestSync();
assertThrows(QuarkusTransactionException.class,
() -> QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW).call(() -> {
() -> QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW).call(() -> {
register(sync2);
QuarkusTransaction.setRollbackOnly();
return null;
Expand All @@ -88,7 +88,7 @@ public void rollbackOnly() {
@Test
public void timeout() {
var sync1 = new TestSync();
assertThrows(QuarkusTransactionException.class, () -> QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW)
assertThrows(QuarkusTransactionException.class, () -> QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW)
.timeout(1)
.run(() -> {
register(sync1);
Expand All @@ -101,7 +101,7 @@ public void timeout() {
assertEquals(Status.STATUS_ROLLEDBACK, sync1.completionStatus);

var sync2 = new TestSync();
assertThrows(QuarkusTransactionException.class, () -> QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW)
assertThrows(QuarkusTransactionException.class, () -> QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW)
.timeout(1)
.call(() -> {
register(sync2);
Expand All @@ -118,23 +118,23 @@ public void timeout() {
@Test
public void exception() {
var sync1 = new TestSync();
assertThrows(MyRuntimeException.class, () -> QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW)
assertThrows(MyRuntimeException.class, () -> QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW)
.run(() -> {
register(sync1);
throw new MyRuntimeException();
}));
assertEquals(Status.STATUS_ROLLEDBACK, sync1.completionStatus);

var sync2 = new TestSync();
assertThrows(MyRuntimeException.class, () -> QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW)
assertThrows(MyRuntimeException.class, () -> QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW)
.call(() -> {
register(sync2);
throw new MyRuntimeException();
}));
assertEquals(Status.STATUS_ROLLEDBACK, sync2.completionStatus);

var sync3 = new TestSync();
assertThrows(QuarkusTransactionException.class, () -> QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW)
assertThrows(QuarkusTransactionException.class, () -> QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW)
.call(() -> {
register(sync3);
throw new MyCheckedException();
Expand All @@ -145,7 +145,7 @@ public void exception() {
@Test
public void exceptionHandler() {
var sync1 = new TestSync();
assertThrows(MyRuntimeException.class, () -> QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW)
assertThrows(MyRuntimeException.class, () -> QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW)
.exceptionHandler((e) -> TransactionExceptionResult.COMMIT)
.run(() -> {
register(sync1);
Expand All @@ -154,7 +154,7 @@ public void exceptionHandler() {
assertEquals(Status.STATUS_COMMITTED, sync1.completionStatus);

var sync2 = new TestSync();
assertThrows(MyRuntimeException.class, () -> QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW)
assertThrows(MyRuntimeException.class, () -> QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW)
.exceptionHandler((e) -> TransactionExceptionResult.COMMIT)
.call(() -> {
register(sync2);
Expand All @@ -163,7 +163,7 @@ public void exceptionHandler() {
assertEquals(Status.STATUS_COMMITTED, sync2.completionStatus);

var sync3 = new TestSync();
assertThrows(QuarkusTransactionException.class, () -> QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW)
assertThrows(QuarkusTransactionException.class, () -> QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW)
.exceptionHandler((e) -> TransactionExceptionResult.COMMIT)
.call(() -> {
register(sync3);
Expand All @@ -177,13 +177,13 @@ public void exceptionHandler() {
public void suspendExisting() {
QuarkusTransaction.begin();
assertTrue(QuarkusTransaction.isActive());
QuarkusTransaction.runner(TransactionSemantic.SUSPEND_EXISTING)
QuarkusTransaction.runner(TransactionSemantics.SUSPEND_EXISTING)
.run(() -> assertFalse(QuarkusTransaction.isActive()));
assertTrue(QuarkusTransaction.isActive());
QuarkusTransaction.rollback();

assertFalse(QuarkusTransaction.isActive());
QuarkusTransaction.runner(TransactionSemantic.SUSPEND_EXISTING)
QuarkusTransaction.runner(TransactionSemantics.SUSPEND_EXISTING)
.run(() -> assertFalse(QuarkusTransaction.isActive()));
assertFalse(QuarkusTransaction.isActive());
}
Expand All @@ -193,13 +193,13 @@ public void suspendExisting() {
public void disallowExisting() {
assertFalse(QuarkusTransaction.isActive());
assertEquals(Status.STATUS_COMMITTED,
QuarkusTransaction.runner(TransactionSemantic.DISALLOW_EXISTING).call(this::register).completionStatus);
QuarkusTransaction.runner(TransactionSemantics.DISALLOW_EXISTING).call(this::register).completionStatus);
assertFalse(QuarkusTransaction.isActive());

QuarkusTransaction.begin();
assertTrue(QuarkusTransaction.isActive());
assertThrows(QuarkusTransactionException.class,
() -> QuarkusTransaction.runner(TransactionSemantic.DISALLOW_EXISTING).call(this::register));
() -> QuarkusTransaction.runner(TransactionSemantics.DISALLOW_EXISTING).call(this::register));
assertTrue(QuarkusTransaction.isActive());
QuarkusTransaction.rollback();
}
Expand All @@ -209,13 +209,13 @@ public void disallowExisting() {
public void requireNew() throws SystemException {
assertFalse(QuarkusTransaction.isActive());
assertEquals(Status.STATUS_COMMITTED,
QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW).call(this::register).completionStatus);
QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW).call(this::register).completionStatus);
assertFalse(QuarkusTransaction.isActive());

QuarkusTransaction.begin();
assertTrue(QuarkusTransaction.isActive());
var tx = transactionManager.getTransaction();
assertEquals(Status.STATUS_COMMITTED, QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW).call(() -> {
assertEquals(Status.STATUS_COMMITTED, QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW).call(() -> {
assertTrue(QuarkusTransaction.isActive());
assertNotEquals(tx, transactionManager.getTransaction());
return register();
Expand All @@ -229,13 +229,13 @@ public void requireNew() throws SystemException {
public void joinExisting() throws SystemException {
assertFalse(QuarkusTransaction.isActive());
assertEquals(Status.STATUS_COMMITTED,
QuarkusTransaction.runner(TransactionSemantic.JOIN_EXISTING).call(this::register).completionStatus);
QuarkusTransaction.runner(TransactionSemantics.JOIN_EXISTING).call(this::register).completionStatus);
assertFalse(QuarkusTransaction.isActive());

QuarkusTransaction.begin();
assertTrue(QuarkusTransaction.isActive());
var tx = transactionManager.getTransaction();
QuarkusTransaction.runner(TransactionSemantic.JOIN_EXISTING).call(() -> {
QuarkusTransaction.runner(TransactionSemantics.JOIN_EXISTING).call(() -> {
assertTrue(QuarkusTransaction.isActive());
assertEquals(tx, transactionManager.getTransaction());
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,32 +111,32 @@ static void setRollbackOnly() {
* Examples of use:
*
* <pre>{@code
* QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW).run(() -> ...);
* QuarkusTransaction.runner(TransactionSemantic.JOIN_EXISTING).run(() -> ...);
* QuarkusTransaction.runner(TransactionSemantic.SUSPEND_EXISTING).run(() -> ...);
* QuarkusTransaction.runner(TransactionSemantic.DISALLOW_EXISTING).run(() -> ...);
* int value = QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW).call(() -> { ...; return 42; });
* int value = QuarkusTransaction.runner(TransactionSemantic.JOIN_EXISTING).call(() -> { ...; return 42; });
* int value = QuarkusTransaction.runner(TransactionSemantic.SUSPEND_EXISTING).call(() -> { ...; return 42; });
* int value = QuarkusTransaction.runner(TransactionSemantic.DISALLOW_EXISTING).call(() -> { ...; return 42; });
* QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW).run(() -> ...);
* QuarkusTransaction.runner(TransactionSemantics.JOIN_EXISTING).run(() -> ...);
* QuarkusTransaction.runner(TransactionSemantics.SUSPEND_EXISTING).run(() -> ...);
* QuarkusTransaction.runner(TransactionSemantics.DISALLOW_EXISTING).run(() -> ...);
* int value = QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW).call(() -> { ...; return 42; });
* int value = QuarkusTransaction.runner(TransactionSemantics.JOIN_EXISTING).call(() -> { ...; return 42; });
* int value = QuarkusTransaction.runner(TransactionSemantics.SUSPEND_EXISTING).call(() -> { ...; return 42; });
* int value = QuarkusTransaction.runner(TransactionSemantics.DISALLOW_EXISTING).call(() -> { ...; return 42; });
* }</pre>
*
* @param semantic The selected {@link TransactionSemantic}.
* @param semantics The selected {@link TransactionSemantics}.
* @return An interface that allow various options of a transaction runner to be customized,
* or a {@link Runnable}/{@link Callable} to be executed.
* @see TransactionRunnerOptions
*/
static TransactionRunnerOptions runner(TransactionSemantic semantic) {
return new TransactionRunnerImpl(semantic);
static TransactionRunnerOptions runner(TransactionSemantics semantics) {
return new TransactionRunnerImpl(semantics);
}

/**
* Runs a task in a new transaction with the default timeout. This defaults to {@link Transactional.TxType#REQUIRES_NEW}
* semantics, however alternate semantics can be requested using {@link #run(RunOptions, Runnable)}.
*
* @param task The task to run in a transaction
* @deprecated For the same semantics, use {@code QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW).run(task)}.
* {@link #runner(TransactionSemantic)} can also be used for alternate semantics and options.
* @deprecated For the same semantics, use {@code QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW).run(task)}.
* {@link #runner(TransactionSemantics)} can also be used for alternate semantics and options.
*/
@Deprecated
static void run(Runnable task) {
Expand All @@ -149,7 +149,7 @@ static void run(Runnable task) {
*
* @param options Options that apply to the new transaction
* @param task The task to run in a transaction
* @deprecated Use {@link #runner(TransactionSemantic)} instead.
* @deprecated Use {@link #runner(TransactionSemantics)} instead.
*/
@Deprecated
static void run(RunOptions options, Runnable task) {
Expand All @@ -169,8 +169,8 @@ public Object call() throws Exception {
* If the task throws a checked exception it will be wrapped with a {@link QuarkusTransactionException}
*
* @param task The task to run in a transaction
* @deprecated For the same semantics, use {@code QuarkusTransaction.runner(TransactionSemantic.REQUIRE_NEW).call(task)}.
* {@link #runner(TransactionSemantic)} can also be used for alternate semantics and options.
* @deprecated For the same semantics, use {@code QuarkusTransaction.runner(TransactionSemantics.REQUIRE_NEW).call(task)}.
* {@link #runner(TransactionSemantics)} can also be used for alternate semantics and options.
*/
@Deprecated
static <T> T call(Callable<T> task) {
Expand All @@ -185,7 +185,7 @@ static <T> T call(Callable<T> task) {
*
* @param options Options that apply to the new transaction
* @param task The task to run in a transaction
* @deprecated Use {@link #runner(TransactionSemantic)} instead.
* @deprecated Use {@link #runner(TransactionSemantics)} instead.
*/
@Deprecated
static <T> T call(RunOptions options, Callable<T> task) {
Expand All @@ -194,7 +194,7 @@ static <T> T call(RunOptions options, Callable<T> task) {

/**
* @return a new RunOptions
* @deprecated Use {@link #runner(TransactionSemantic)} instead.
* @deprecated Use {@link #runner(TransactionSemantics)} instead.
*/
@Deprecated
static RunOptions runOptions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class QuarkusTransactionImpl {
private static UserTransaction cachedUserTransaction;

public static <T> T call(RunOptionsBase options, Callable<T> task) {
switch (options.semantic) {
switch (options.semantics) {
case REQUIRE_NEW:
return callRequireNew(options, task);
case DISALLOW_EXISTING:
Expand All @@ -34,7 +34,7 @@ public static <T> T call(RunOptionsBase options, Callable<T> task) {
case SUSPEND_EXISTING:
return callSuspendExisting(options, task);
}
throw new IllegalArgumentException("Unknown semantic");
throw new IllegalArgumentException("Unknown semantics");
}

private static <T> T callSuspendExisting(RunOptionsBase options, Callable<T> task) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Builder interface to allow a transaction to be customized, including things like timeout and semantics when an existing
* transaction is present.
*
* @deprecated Use {@link QuarkusTransaction#runner(TransactionSemantic)} instead.
* @deprecated Use {@link QuarkusTransaction#runner(TransactionSemantics)} instead.
*/
@Deprecated
public class RunOptions extends RunOptionsBase {
Expand All @@ -24,29 +24,29 @@ public RunOptions timeout(int seconds) {
}

/**
* Sets the transaction semantic that is used to determine the action to take if a transaction is already active.
* Sets the transaction semantics that is used to determine the action to take if a transaction is already active.
* <p>
*
* @param semantic The semantic
* @return This builder
*/
public RunOptions semantic(Semantic semantic) {
if (semantic == null) {
setSemantic(null);
setSemantics(null);
return this;
}
switch (semantic) {
case DISALLOW_EXISTING:
setSemantic(TransactionSemantic.DISALLOW_EXISTING);
setSemantics(TransactionSemantics.DISALLOW_EXISTING);
break;
case JOIN_EXISTING:
setSemantic(TransactionSemantic.JOIN_EXISTING);
setSemantics(TransactionSemantics.JOIN_EXISTING);
break;
case REQUIRE_NEW:
setSemantic(TransactionSemantic.REQUIRE_NEW);
setSemantics(TransactionSemantics.REQUIRE_NEW);
break;
case SUSPEND_EXISTING:
setSemantic(TransactionSemantic.SUSPEND_EXISTING);
setSemantics(TransactionSemantics.SUSPEND_EXISTING);
break;
default:
throw new IllegalArgumentException("Unsupported value: " + semantic);
Expand Down
Loading

0 comments on commit e10ebc8

Please sign in to comment.