You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/02/15 19:14:54 UTC
(commons-dbcp) branch master updated: Internal refactoring for constructing ZipException with cause
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git
The following commit(s) were added to refs/heads/master by this push:
new b625b5f3 Internal refactoring for constructing ZipException with cause
b625b5f3 is described below
commit b625b5f35550c50b719e7d2737719e8dca736496
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 15 14:14:49 2025 -0500
Internal refactoring for constructing ZipException with cause
Provide exception messages where missing for the above use cases
---
src/changes/changes.xml | 1 +
.../dbcp2/managed/LocalXAConnectionFactory.java | 18 ++++++++----------
2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 7e12fd27..72175768 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -74,6 +74,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix Javadoc warnings on Java 17.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix Javadoc warnings on Java 21.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Remove -nouses directive from maven-bundle-plugin. OSGi package imports now state 'uses' definitions for package imports, this doesn't affect JPMS (from org.apache.commons:commons-parent:80).</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">XAException thrown by LocalXAResource now all include a message.</action>
<!-- ADD -->
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-parent from 78 to 81.</action>
diff --git a/src/main/java/org/apache/commons/dbcp2/managed/LocalXAConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/managed/LocalXAConnectionFactory.java
index 189fa14b..5e56049d 100644
--- a/src/main/java/org/apache/commons/dbcp2/managed/LocalXAConnectionFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/managed/LocalXAConnectionFactory.java
@@ -102,7 +102,7 @@ public class LocalXAConnectionFactory implements XAConnectionFactory {
connection.commit();
}
} catch (final SQLException e) {
- throw (XAException) new XAException().initCause(e);
+ throw newXAException("Commit failed.", e);
} finally {
try {
connection.setAutoCommit(originalAutoCommit);
@@ -179,6 +179,10 @@ public class LocalXAConnectionFactory implements XAConnectionFactory {
return this == xaResource;
}
+ private XAException newXAException(final String message, final SQLException cause) {
+ return (XAException) new XAException(message).initCause(cause);
+ }
+
/**
* This method does nothing since the LocalXAConnection does not support two-phase-commit. This method will
* return XAResource.XA_RDONLY if the connection isReadOnly(). This assumes that the physical connection is
@@ -241,7 +245,7 @@ public class LocalXAConnectionFactory implements XAConnectionFactory {
try {
connection.rollback();
} catch (final SQLException e) {
- throw (XAException) new XAException().initCause(e);
+ throw newXAException("Rollback failed.", e);
} finally {
try {
connection.setAutoCommit(originalAutoCommit);
@@ -281,12 +285,10 @@ public class LocalXAConnectionFactory implements XAConnectionFactory {
public synchronized void start(final Xid xid, final int flag) throws XAException {
if (flag == TMNOFLAGS) {
// first time in this transaction
-
// make sure we aren't already in another tx
if (this.currentXid != null) {
throw new XAException("Already enlisted in another transaction with xid " + xid);
}
-
// save off the current auto commit flag, so it can be restored after the transaction completes
try {
originalAutoCommit = connection.getAutoCommit();
@@ -294,20 +296,16 @@ public class LocalXAConnectionFactory implements XAConnectionFactory {
// no big deal, just assume it was off
originalAutoCommit = true;
}
-
// update the auto commit flag
try {
connection.setAutoCommit(false);
} catch (final SQLException e) {
- throw (XAException) new XAException("Count not turn off auto commit for a XA transaction")
- .initCause(e);
+ throw newXAException("Count not turn off auto commit for a XA transaction", e);
}
-
this.currentXid = xid;
} else if (flag == TMRESUME) {
if (!xid.equals(this.currentXid)) {
- throw new XAException("Attempting to resume in different transaction: expected " + this.currentXid
- + ", but was " + xid);
+ throw new XAException("Attempting to resume in different transaction: expected " + this.currentXid + ", but was " + xid);
}
} else {
throw new XAException("Unknown start flag " + flag);