Add org.apache.commons.dbcp2.Utils.closeQuietly(AutoCloseable) and
deprecate:
- org.apache.commons.dbcp2.Utils.closeQuietly(Connection)
- org.apache.commons.dbcp2.Utils.closeQuietly(ResultSet)
- org.apache.commons.dbcp2.Utils.closeQuietly(Statement)
diff --git a/src/main/java/org/apache/commons/dbcp2/Utils.java b/src/main/java/org/apache/commons/dbcp2/Utils.java
index 4cd37b3..4659841 100644
--- a/src/main/java/org/apache/commons/dbcp2/Utils.java
+++ b/src/main/java/org/apache/commons/dbcp2/Utils.java
@@ -67,10 +67,6 @@
DISCONNECTION_SQL_CODES.add("JZ0C1"); // Sybase disconnect error
}
- private Utils() {
- // not instantiable
- }
-
/**
* Clones the given char[] if not null.
*
@@ -83,15 +79,15 @@
}
/**
- * Closes the ResultSet (which may be null).
+ * Closes the AutoCloseable (which may be null).
*
- * @param resultSet
- * a ResultSet, may be {@code null}
+ * @param autoCloseable
+ * an AutoCloseable, may be {@code null}
*/
- public static void closeQuietly(final ResultSet resultSet) {
- if (resultSet != null) {
+ public static void closeQuietly(final AutoCloseable autoCloseable) {
+ if (autoCloseable != null) {
try {
- resultSet.close();
+ autoCloseable.close();
} catch (final Exception e) {
// ignored
}
@@ -103,7 +99,9 @@
*
* @param connection
* a Connection, may be {@code null}
+ * @deprecated Use {@link #closeQuietly(AutoCloseable)}.
*/
+ @Deprecated
public static void closeQuietly(final Connection connection) {
if (connection != null) {
try {
@@ -115,11 +113,31 @@
}
/**
+ * Closes the ResultSet (which may be null).
+ *
+ * @param resultSet
+ * a ResultSet, may be {@code null}
+ * @deprecated Use {@link #closeQuietly(AutoCloseable)}.
+ */
+ @Deprecated
+ public static void closeQuietly(final ResultSet resultSet) {
+ if (resultSet != null) {
+ try {
+ resultSet.close();
+ } catch (final Exception e) {
+ // ignored
+ }
+ }
+ }
+
+ /**
* Closes the Statement (which may be null).
*
* @param statement
* a Statement, may be {@code null}.
+ * @deprecated Use {@link #closeQuietly(AutoCloseable)}.
*/
+ @Deprecated
public static void closeQuietly(final Statement statement) {
if (statement != null) {
try {
@@ -181,4 +199,8 @@
return value == null ? null : String.valueOf(value);
}
+ private Utils() {
+ // not instantiable
+ }
+
}