This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
     new 1c54464  GROOVY-8903: Retrofit NamedParams to groovy.sql.Sql
1c54464 is described below

commit 1c54464e04d4c0f42f18ed3e9020ae78fa829a7b
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Nov 27 19:20:37 2018 +1000

    GROOVY-8903: Retrofit NamedParams to groovy.sql.Sql
---
 .../groovy-sql/src/main/java/groovy/sql/Sql.java   | 39 ++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java 
b/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
index 8378288..8081138 100644
--- a/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
+++ b/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
@@ -22,6 +22,7 @@ import groovy.lang.Closure;
 import groovy.lang.GString;
 import groovy.lang.MissingPropertyException;
 import groovy.lang.Tuple;
+import groovy.transform.NamedParam;
 import groovy.transform.stc.ClosureParams;
 import groovy.transform.stc.SimpleType;
 import org.codehaus.groovy.runtime.InvokerHelper;
@@ -528,7 +529,23 @@ public class Sql implements AutoCloseable {
      * @throws SQLException           if a database access error occurs
      * @throws ClassNotFoundException if the driver class cannot be found or 
loaded
      */
-    public static Sql newInstance(Map<String, Object> args) throws 
SQLException, ClassNotFoundException {
+    public static Sql newInstance(
+            @NamedParam(value = "url", type = String.class, required = true)
+            @NamedParam(value = "properties", type = Properties.class)
+            @NamedParam(value = "driverClassName", type = String.class)
+            @NamedParam(value = "driver", type = String.class)
+            @NamedParam(value = "user", type = String.class)
+            @NamedParam(value = "password", type = String.class)
+            @NamedParam(value = "cacheNamedQueries", type = Boolean.class)
+            @NamedParam(value = "cacheStatements", type = Boolean.class)
+            @NamedParam(value = "enableNamedQueries", type = Boolean.class)
+            @NamedParam(value = "resultSetConcurrency", type = Integer.class)
+            @NamedParam(value = "resultSetHoldability", type = Integer.class)
+            @NamedParam(value = "resultSetType", type = Integer.class)
+            // TODO below will be deleted once we fix type checker to 
understand
+            // readonly Map otherwise seen as Map<String, Serializable>
+            @NamedParam(value = "unused", type = Object.class)
+            Map<String, Object> args) throws SQLException, 
ClassNotFoundException {
         if (!args.containsKey("url"))
             throw new IllegalArgumentException("Argument 'url' is required");
 
@@ -541,6 +558,7 @@ public class Sql implements AutoCloseable {
         // Make a copy so destructive operations will not affect the caller
         Map<String, Object> sqlArgs = new HashMap<String, Object>(args);
 
+        sqlArgs.remove("unused"); // TODO remove
         Object driverClassName = sqlArgs.remove("driverClassName");
         if (driverClassName == null) driverClassName = 
sqlArgs.remove("driver");
         if (driverClassName != null) loadDriver(driverClassName.toString());
@@ -597,7 +615,24 @@ public class Sql implements AutoCloseable {
      * @throws SQLException if a database access error occurs
      * @throws ClassNotFoundException if the driver class cannot be found or 
loaded
      */
-    public static void withInstance(Map<String, Object> args, Closure c) 
throws SQLException, ClassNotFoundException {
+    public static void withInstance(
+            @NamedParam(value = "url", type = String.class, required = true)
+            @NamedParam(value = "properties", type = Properties.class)
+            @NamedParam(value = "driverClassName", type = String.class)
+            @NamedParam(value = "driver", type = String.class)
+            @NamedParam(value = "user", type = String.class)
+            @NamedParam(value = "password", type = String.class)
+            @NamedParam(value = "cacheNamedQueries", type = Boolean.class)
+            @NamedParam(value = "cacheStatements", type = Boolean.class)
+            @NamedParam(value = "enableNamedQueries", type = Boolean.class)
+            @NamedParam(value = "resultSetConcurrency", type = Integer.class)
+            @NamedParam(value = "resultSetHoldability", type = Integer.class)
+            @NamedParam(value = "resultSetType", type = Integer.class)
+            // TODO below will be deleted once we fix type checker to 
understand
+            // readonly Map otherwise seen as Map<String, Serializable>
+            @NamedParam(value = "unused", type = Object.class)
+            Map<String, Object> args,
+            Closure c) throws SQLException, ClassNotFoundException {
         try (Sql sql = newInstance(args)) {
             c.call(sql);
         }

Reply via email to