commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject [commons-dbutils] branch master updated: Remove unnecessary array creation for varargs.
Date Wed, 18 Dec 2019 21:07:36 GMT
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-dbutils.git


The following commit(s) were added to refs/heads/master by this push:
     new 2dc083a  Remove unnecessary array creation for varargs.
2dc083a is described below

commit 2dc083a85bcc429d58dc785d1133dba7351b1449
Author: Gary Gregory <garydgregory@gmail.com>
AuthorDate: Wed Dec 18 16:07:32 2019 -0500

    Remove unnecessary array creation for varargs.
---
 .../apache/commons/dbutils/AbstractQueryRunner.java    |  2 +-
 .../java/org/apache/commons/dbutils/BeanProcessor.java |  2 +-
 src/main/java/org/apache/commons/dbutils/DbUtils.java  |  4 ++--
 .../java/org/apache/commons/dbutils/QueryRunner.java   |  8 ++++----
 .../org/apache/commons/dbutils/QueryRunnerTest.java    |  4 ++--
 .../dbutils/wrappers/SqlNullCheckedResultSetTest.java  | 18 ++++++------------
 6 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java b/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
index ec117db..b02bb38 100644
--- a/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
+++ b/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
@@ -361,7 +361,7 @@ public abstract class AbstractQueryRunner {
                         + bean.getClass() + " " + property.getName());
             }
             try {
-                value = method.invoke(bean, new Object[0]);
+                value = method.invoke(bean);
             } catch (final InvocationTargetException e) {
                 throw new RuntimeException("Couldn't invoke method: " + method,
                         e);
diff --git a/src/main/java/org/apache/commons/dbutils/BeanProcessor.java b/src/main/java/org/apache/commons/dbutils/BeanProcessor.java
index 802542f..79ae7bc 100644
--- a/src/main/java/org/apache/commons/dbutils/BeanProcessor.java
+++ b/src/main/java/org/apache/commons/dbutils/BeanProcessor.java
@@ -308,7 +308,7 @@ public class BeanProcessor {
 
             // Don't call setter if the value object isn't the right type
             if (this.isCompatibleType(value, firstParam)) {
-                setter.invoke(target, new Object[]{value});
+                setter.invoke(target, value);
             } else {
               throw new SQLException(
                   "Cannot set " + prop.getName() + ": incompatible types, cannot convert
"
diff --git a/src/main/java/org/apache/commons/dbutils/DbUtils.java b/src/main/java/org/apache/commons/dbutils/DbUtils.java
index 7b561a0..7ad90c6 100644
--- a/src/main/java/org/apache/commons/dbutils/DbUtils.java
+++ b/src/main/java/org/apache/commons/dbutils/DbUtils.java
@@ -410,8 +410,8 @@ public final class DbUtils {
         public Logger getParentLogger() throws SQLFeatureNotSupportedException {
             if (parentLoggerSupported) {
                 try {
-                    final Method method = adapted.getClass().getMethod("getParentLogger",
new Class[0]);
-                    return (Logger)method.invoke(adapted, new Object[0]);
+                    final Method method = adapted.getClass().getMethod("getParentLogger");
+                    return (Logger)method.invoke(adapted);
                 } catch (final NoSuchMethodException e) {
                     parentLoggerSupported = false;
                     throw new SQLFeatureNotSupportedException(e);
diff --git a/src/main/java/org/apache/commons/dbutils/QueryRunner.java b/src/main/java/org/apache/commons/dbutils/QueryRunner.java
index 997ff44..dfe59ab 100644
--- a/src/main/java/org/apache/commons/dbutils/QueryRunner.java
+++ b/src/main/java/org/apache/commons/dbutils/QueryRunner.java
@@ -217,7 +217,7 @@ public class QueryRunner extends AbstractQueryRunner {
      */
     @Deprecated
     public <T> T query(final Connection conn, final String sql, final Object param,
final ResultSetHandler<T> rsh) throws SQLException {
-        return this.<T>query(conn, false, sql, rsh, new Object[]{param});
+        return this.<T>query(conn, false, sql, rsh, param);
     }
 
     /**
@@ -284,7 +284,7 @@ public class QueryRunner extends AbstractQueryRunner {
     public <T> T query(final String sql, final Object param, final ResultSetHandler<T>
rsh) throws SQLException {
         final Connection conn = this.prepareConnection();
 
-        return this.<T>query(conn, true, sql, rsh, new Object[]{param});
+        return this.<T>query(conn, true, sql, rsh, param);
     }
 
     /**
@@ -425,7 +425,7 @@ public class QueryRunner extends AbstractQueryRunner {
      * @throws SQLException if a database access error occurs
      */
     public int update(final Connection conn, final String sql, final Object param) throws
SQLException {
-        return this.update(conn, false, sql, new Object[]{param});
+        return this.update(conn, false, sql, param);
     }
 
     /**
@@ -473,7 +473,7 @@ public class QueryRunner extends AbstractQueryRunner {
     public int update(final String sql, final Object param) throws SQLException {
         final Connection conn = this.prepareConnection();
 
-        return this.update(conn, true, sql, new Object[]{param});
+        return this.update(conn, true, sql, param);
     }
 
     /**
diff --git a/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java b/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
index ddf7e8f..727c2c9 100644
--- a/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
+++ b/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
@@ -1018,14 +1018,14 @@ public class QueryRunnerTest {
     public void testFillStatementWithBean() throws Exception {
         final MyBean bean = new MyBean();
         when(meta.getParameterCount()).thenReturn(3);
-        runner.fillStatementWithBean(stmt, bean, new String[] { "a", "b", "c" });
+        runner.fillStatementWithBean(stmt, bean, "a", "b", "c");
     }
 
     @Test(expected=NullPointerException.class)
     public void testFillStatementWithBeanNullNames() throws Exception {
         final MyBean bean = new MyBean();
         when(meta.getParameterCount()).thenReturn(3);
-        runner.fillStatementWithBean(stmt, bean, new String[] { "a", "b", null });
+        runner.fillStatementWithBean(stmt, bean, "a", "b", null);
     }
 
     @Test(expected=SQLException.class)
diff --git a/src/test/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java
b/src/test/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java
index 1e06f38..2b4df76 100644
--- a/src/test/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java
+++ b/src/test/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java
@@ -480,29 +480,23 @@ public class SqlNullCheckedResultSetTest extends BaseTestCase {
         Method getUrlInt = null;
         Method getUrlString = null;
         try {
-            getUrlInt = ResultSet.class.getMethod("getURL",
-                        new Class[] { Integer.TYPE } );
-            getUrlString = ResultSet.class.getMethod("getURL",
-                           new Class[] { String.class } );
+            getUrlInt = ResultSet.class.getMethod("getURL", Integer.TYPE);
+            getUrlString = ResultSet.class.getMethod("getURL", String.class);
         } catch(final NoSuchMethodException e) {
             // ignore
         } catch(final SecurityException e) {
             // ignore
         }
         if (getUrlInt != null && getUrlString != null) {
-            assertEquals(null, getUrlInt.invoke(rs,
-                         new Object[] { Integer.valueOf(1) } ) );
+            assertEquals(null, getUrlInt.invoke(rs, Integer.valueOf(1)) );
             assertTrue(rs.wasNull());
-            assertEquals(null, getUrlString.invoke(rs,
-                         new Object[] { "column" } ) );
+            assertEquals(null, getUrlString.invoke(rs, "column") );
             assertTrue(rs.wasNull());
             // Set what gets returned to something other than the default
             final URL u = new URL("http://www.apache.org");
             rs2.setNullURL(u);
-            assertEquals(u, getUrlInt.invoke(rs,
-                         new Object[] { Integer.valueOf(1) } ) );
-            assertEquals(u, getUrlString.invoke(rs,
-                         new Object[] { "column" } ) );
+            assertEquals(u, getUrlInt.invoke(rs, Integer.valueOf(1)) );
+            assertEquals(u, getUrlString.invoke(rs, "column") );
         }
     }
 


Mime
View raw message