This is an automated email from the ASF dual-hosted git repository.
mridulpathak pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-plugins.git
The following commit(s) were added to refs/heads/trunk by this push:
new d780c1807 Improved: Run the passport user sync with
TransactionUtil.doNewTransaction (OFBIZ-13723)
d780c1807 is described below
commit d780c1807a5be239567d2d398d9af6119e5cddb5
Author: Mridul Pathak <[email protected]>
AuthorDate: Fri Oct 23 16:55:07 2026 +0530
Improved: Run the passport user sync with TransactionUtil.doNewTransaction
(OFBIZ-13723)
GitHubAuthenticator and LinkedInAuthenticator suspended the current
transaction by hand and kept it in a javax.transaction.Transaction variable,
which ties the plugin to the javax.transaction API that the framework is moving
away from. They now use TransactionUtil.doNewTransaction, which compiles
against both javax.transaction and jakarta.transaction. A failure while
creating or updating the user now rolls back that transaction instead of
committing the partial work, and a failure to [...]
---
.../ofbiz/passport/user/GitHubAuthenticator.java | 44 +++-------------------
.../ofbiz/passport/user/LinkedInAuthenticator.java | 43 +++------------------
2 files changed, 12 insertions(+), 75 deletions(-)
diff --git
a/passport/src/main/java/org/apache/ofbiz/passport/user/GitHubAuthenticator.java
b/passport/src/main/java/org/apache/ofbiz/passport/user/GitHubAuthenticator.java
index 4b553fc96..92c20682d 100644
---
a/passport/src/main/java/org/apache/ofbiz/passport/user/GitHubAuthenticator.java
+++
b/passport/src/main/java/org/apache/ofbiz/passport/user/GitHubAuthenticator.java
@@ -25,8 +25,6 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
-import javax.transaction.Transaction;
-
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -47,7 +45,6 @@ import
org.apache.ofbiz.common.authentication.api.AuthenticatorException;
import org.apache.ofbiz.entity.Delegator;
import org.apache.ofbiz.entity.GenericEntityException;
import org.apache.ofbiz.entity.GenericValue;
-import org.apache.ofbiz.entity.transaction.GenericTransactionException;
import org.apache.ofbiz.entity.transaction.TransactionUtil;
import org.apache.ofbiz.entity.util.EntityQuery;
import org.apache.ofbiz.passport.event.GitHubEvents;
@@ -155,20 +152,9 @@ public class GitHubAuthenticator implements Authenticator {
throw new AuthenticatorException(e.getMessage(), e);
}
- // suspend the current transaction and load the user
- Transaction parentTx = null;
- boolean beganTransaction = false;
-
+ // load the user in its own transaction, the current one being
suspended
try {
- try {
- parentTx = TransactionUtil.suspend();
- } catch (GenericTransactionException e) {
- Debug.logError(e, "Could not suspend transaction: " +
e.getMessage(), MODULE);
- }
-
- try {
- beganTransaction = TransactionUtil.begin();
-
+ TransactionUtil.doNewTransaction(() -> {
if (userLogin == null) {
// create the user
createUser(userMap, system);
@@ -176,28 +162,10 @@ public class GitHubAuthenticator implements Authenticator
{
// update the user information
updateUser(userMap, system, userLogin);
}
-
- } catch (GenericTransactionException e) {
- Debug.logError(e, "Could not suspend transaction: " +
e.getMessage(), MODULE);
- } finally {
- try {
- TransactionUtil.commit(beganTransaction);
- } catch (GenericTransactionException e) {
- Debug.logError(e, "Could not commit nested transaction: "
+ e.getMessage(), MODULE);
- }
- }
- } finally {
- // resume/restore parent transaction
- if (parentTx != null) {
- try {
- TransactionUtil.resume(parentTx);
- if (Debug.verboseOn()) {
- Debug.logVerbose("Resumed the parent transaction.",
MODULE);
- }
- } catch (GenericTransactionException e) {
- Debug.logError(e, "Could not resume parent nested
transaction: " + e.getMessage(), MODULE);
- }
- }
+ return null;
+ }, "Could not sync the GitHub user " + userLoginId, 0, true);
+ } catch (GenericEntityException e) {
+ throw new AuthenticatorException(e.getMessage(), e);
}
}
diff --git
a/passport/src/main/java/org/apache/ofbiz/passport/user/LinkedInAuthenticator.java
b/passport/src/main/java/org/apache/ofbiz/passport/user/LinkedInAuthenticator.java
index 6645cf013..e12d63bfb 100644
---
a/passport/src/main/java/org/apache/ofbiz/passport/user/LinkedInAuthenticator.java
+++
b/passport/src/main/java/org/apache/ofbiz/passport/user/LinkedInAuthenticator.java
@@ -25,7 +25,6 @@ import java.io.IOException;
import java.io.Serializable;
import java.sql.Timestamp;
-import javax.transaction.Transaction;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.http.HttpStatus;
@@ -45,7 +44,6 @@ import org.apache.ofbiz.entity.Delegator;
import org.apache.ofbiz.entity.GenericValue;
import org.apache.ofbiz.entity.GenericEntityException;
import org.apache.ofbiz.entity.transaction.TransactionUtil;
-import org.apache.ofbiz.entity.transaction.GenericTransactionException;
import org.apache.ofbiz.entity.util.EntityQuery;
import org.apache.ofbiz.base.util.UtilProperties;
import org.apache.ofbiz.base.util.Debug;
@@ -160,20 +158,9 @@ public class LinkedInAuthenticator implements
Authenticator {
throw new AuthenticatorException(e.getMessage(), e);
}
- // suspend the current transaction and load the user
- Transaction parentTx = null;
- boolean beganTransaction = false;
-
+ // load the user in its own transaction, the current one being
suspended
try {
- try {
- parentTx = TransactionUtil.suspend();
- } catch (GenericTransactionException e) {
- Debug.logError(e, "Could not suspend transaction: " +
e.getMessage(), MODULE);
- }
-
- try {
- beganTransaction = TransactionUtil.begin();
-
+ TransactionUtil.doNewTransaction(() -> {
if (userLogin == null) {
// create the user
createUser(user, system);
@@ -181,28 +168,10 @@ public class LinkedInAuthenticator implements
Authenticator {
// update the user information
updateUser(user, system, userLogin);
}
-
- } catch (GenericTransactionException e) {
- Debug.logError(e, "Could not suspend transaction: " +
e.getMessage(), MODULE);
- } finally {
- try {
- TransactionUtil.commit(beganTransaction);
- } catch (GenericTransactionException e) {
- Debug.logError(e, "Could not commit nested transaction: "
+ e.getMessage(), MODULE);
- }
- }
- } finally {
- // resume/restore parent transaction
- if (parentTx != null) {
- try {
- TransactionUtil.resume(parentTx);
- if (Debug.verboseOn()) {
- Debug.logVerbose("Resumed the parent transaction.",
MODULE);
- }
- } catch (GenericTransactionException e) {
- Debug.logError(e, "Could not resume parent nested
transaction: " + e.getMessage(), MODULE);
- }
- }
+ return null;
+ }, "Could not sync the LinkedIn user " + userLoginId, 0, true);
+ } catch (GenericEntityException e) {
+ throw new AuthenticatorException(e.getMessage(), e);
}
}