Skip to content

Commit 277e7fe

Browse files
committed
Squashable commit; refactoring, general edits
Signed-off-by: Laird Nelson <laird.nelson@oracle.com>
1 parent 9b85249 commit 277e7fe

3 files changed

Lines changed: 40 additions & 21 deletions

File tree

integrations/cdi/jpa-cdi/pom.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@
3030
<name>Helidon CDI Integrations JPA</name>
3131

3232
<properties>
33-
<doclint>-syntax</doclint>
34-
<eclipselink.skip>false</eclipselink.skip>
35-
<hibernate.skip>false</hibernate.skip>
36-
<spotbugs.exclude>etc/spotbugs/exclude.xml</spotbugs.exclude>
33+
<doclint>-syntax</doclint>
34+
<eclipselink.skip>false</eclipselink.skip>
35+
<helidon.jta.immediateEnlistment>false</helidon.jta.immediateEnlistment>
36+
<helidon.jta.interposedSynchronizations>true</helidon.jta.interposedSynchronizations>
37+
<helidon.jta.preemptiveEnlistmentChecks>true</helidon.jta.preemptiveEnlistmentChecks>
38+
<hibernate.skip>false</hibernate.skip>
39+
<spotbugs.exclude>etc/spotbugs/exclude.xml</spotbugs.exclude>
3740
</properties>
3841

3942
<dependencies>
@@ -291,6 +294,9 @@
291294
<reportNameSuffix>eclipselink</reportNameSuffix>
292295
<skip>${eclipselink.skip}</skip>
293296
<systemPropertyVariables>
297+
<helidon.jta.immediateEnlistment>${helidon.jta.immediateEnlistment}</helidon.jta.immediateEnlistment>
298+
<helidon.jta.interposedSynchronizations>${helidon.jta.interposedSynchronizations}</helidon.jta.interposedSynchronizations>
299+
<helidon.jta.preemptiveEnlistmentChecks>${helidon.jta.preemptiveEnlistmentChecks}</helidon.jta.preemptiveEnlistmentChecks>
294300
<java.util.logging.config.file>${project.basedir}/src/test/logging.properties</java.util.logging.config.file>
295301
</systemPropertyVariables>
296302
<testClassesDirectory>${project.build.directory}/eclipselink/test-classes</testClassesDirectory>

integrations/jta/jdbc/src/main/java/io/helidon/integrations/jta/jdbc/JtaConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ private boolean continueEnlisting() throws SQLException {
12751275

12761276
this.validateTransactionStatusForEnlistment(currentThreadTransactionStatus);
12771277

1278-
if (!super.getAutoCommit()) {
1278+
if (this.preemptiveEnlistmentChecks && !super.getAutoCommit()) {
12791279
// There is, as far as we can tell, a global transaction on the current thread, and super.getAutoCommit()
12801280
// (super. on purpose, not this., to prevent a circular call to enlist()) returned false, and we aren't
12811281
// (yet) enlisted with the global transaction, so autoCommit must have been disabled on purpose by the

integrations/jta/jdbc/src/main/java/io/helidon/integrations/jta/jdbc/LocalXAResource.java

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static javax.transaction.xa.XAException.XAER_DUPID;
3939
import static javax.transaction.xa.XAException.XAER_INVAL;
4040
import static javax.transaction.xa.XAException.XAER_NOTA;
41+
import static javax.transaction.xa.XAException.XAER_OUTSIDE;
4142
import static javax.transaction.xa.XAException.XAER_PROTO;
4243
import static javax.transaction.xa.XAException.XAER_RMERR;
4344
import static javax.transaction.xa.XAException.XAER_RMFAIL;
@@ -171,7 +172,20 @@ private Association start(Xid x, Association a) {
171172
throw new UncheckedXAException((XAException) new XAException(XAER_RMERR)
172173
.initCause(new NullPointerException("connectionFunction.apply(" + x + ")")));
173174
}
174-
a = new Association(Association.BranchState.ACTIVE, x, c);
175+
if (!autoCommit(c)) {
176+
// The Connection is doing work outside of a global transaction, i.e. someone else set its autoCommit status
177+
// to false before this branch started, so there is work going on outside of the about-to-start branch, so
178+
// if we were to call commit() on the connection we would have no idea what would be committed. The XA
179+
// specification calls this "work outside of a global transaction", and says to report XAER_OUTSIDE here in
180+
// such a case.
181+
throw new UncheckedXAException((XAException) new XAException(XAER_OUTSIDE)
182+
.initCause(new IllegalStateException("!c.getAutoCommit(): " + c)));
183+
}
184+
a = new Association(Association.BranchState.ACTIVE,
185+
x,
186+
false, // not suspended
187+
c,
188+
true); // already checked for a false autoCommit status
175189
if (LOGGER.isLoggable(Level.FINE)) {
176190
LOGGER.logp(Level.FINE, this.getClass().getName(), "start",
177191
"Created new Association ({0}) for connection ({1}) in state ACTIVE", new Object[] {a, c});
@@ -407,15 +421,18 @@ private XAException convert(XARoutine xaRoutine, Throwable e) {
407421
returnValue = (XAException) new XAException(XAER_PROTO).initCause(e);
408422
} else if (e instanceof SQLException sqlException) {
409423
returnValue = this.exceptionConverter.convert(xaRoutine, sqlException);
424+
if (returnValue == null) {
425+
returnValue = (XAException) new XAException(XAER_RMERR).initCause(e);
426+
}
410427
} else if (cause instanceof SQLException sqlException) {
411428
returnValue = this.exceptionConverter.convert(xaRoutine, sqlException);
429+
if (returnValue == null) {
430+
returnValue = (XAException) new XAException(XAER_RMERR).initCause(e);
431+
}
412432
} else {
413433
returnValue = (XAException) new XAException(XAER_RMERR).initCause(e);
414434
}
415435
}
416-
if (returnValue == null) {
417-
returnValue = (XAException) new XAException(XAER_RMERR).initCause(e);
418-
}
419436
return returnValue;
420437
}
421438

@@ -691,6 +708,14 @@ private static String flagsToString(int flags) {
691708
}
692709
}
693710

711+
private static boolean autoCommit(Connection c) {
712+
try {
713+
return c.getAutoCommit();
714+
} catch (SQLException e) {
715+
throw new UncheckedSQLException(e);
716+
}
717+
}
718+
694719

695720
/*
696721
* Inner and nested classes.
@@ -781,10 +806,6 @@ record Association(BranchState branchState,
781806
}
782807
*/
783808

784-
Association(BranchState branchState, Xid xid, Connection connection) {
785-
this(branchState, xid, false, connection, autoCommit(connection));
786-
}
787-
788809
Association {
789810
Objects.requireNonNull(xid, "xid");
790811
boolean autoCommit = false;
@@ -1059,14 +1080,6 @@ private Association reset() throws SQLException {
10591080
this.priorAutoCommit());
10601081
}
10611082

1062-
private static boolean autoCommit(Connection c) {
1063-
try {
1064-
return c.getAutoCommit();
1065-
} catch (SQLException e) {
1066-
throw new UncheckedSQLException(e);
1067-
}
1068-
}
1069-
10701083
// Transaction Branch States (XA specification, table 6-4):
10711084
// S0: Non-existent Transaction
10721085
// S1: Active

0 commit comments

Comments
 (0)