groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [4/4] groovy git commit: GROOVY-8596: SqlGroovyMethods could be moved to avoid split packages - part (1) (closes #716)
Date Wed, 23 May 2018 14:53:37 GMT
GROOVY-8596: SqlGroovyMethods could be moved to avoid split packages - part (1) (closes #716)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/6b259362
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/6b259362
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/6b259362

Branch: refs/heads/GROOVY_2_5_X
Commit: 6b259362183842b873f65a16cdcf7cc829f15726
Parents: 3390f25
Author: Paul King <paulk@asert.com.au>
Authored: Wed May 23 09:06:05 2018 +1000
Committer: Paul King <paulk@asert.com.au>
Committed: Thu May 24 00:53:07 2018 +1000

----------------------------------------------------------------------
 gradle/docs.gradle                              |   2 +-
 .../groovy/runtime/DefaultGroovyMethods.java    |   2 +-
 subprojects/groovy-sql/build.gradle             |   2 +-
 .../groovy/sql/ResultSetMetaDataWrapper.java    |   3 +-
 .../src/main/java/groovy/sql/Sql.java           |   2 +-
 .../groovy/sql/extensions/SqlExtensions.java    | 123 +++++++++++++++++++
 .../groovy/runtime/SqlGroovyMethods.java        |  87 ++-----------
 7 files changed, 138 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/6b259362/gradle/docs.gradle
----------------------------------------------------------------------
diff --git a/gradle/docs.gradle b/gradle/docs.gradle
index 59b8111..f4770de 100644
--- a/gradle/docs.gradle
+++ b/gradle/docs.gradle
@@ -154,7 +154,7 @@ task docGDK {
                     arg(value: 'subprojects/groovy-dateutil/src/main/java/org/apache/groovy/dateutil/extensions/DateUtilExtensions.java')
                     arg(value: 'subprojects/groovy-datetime/src/main/java/org/apache/groovy/dateutil/extensions/DateTimeExtensions.java')
                     arg(value: 'subprojects/groovy-datetime/src/main/java/org/apache/groovy/dateutil/extensions/DateTimeStaticExtensions.java')
-                    arg(value: 'subprojects/groovy-sql/src/main/java/org/codehaus/groovy/runtime/SqlGroovyMethods.java')
+                    arg(value: 'subprojects/groovy-sql/src/main/java/org/apache/groovy/sql/extensions/SqlExtensions.java')
                     arg(value: 'subprojects/groovy-swing/src/main/java/org/codehaus/groovy/runtime/SwingGroovyMethods.java')
                     arg(value: 'subprojects/groovy-xml/src/main/java/org/codehaus/groovy/runtime/XmlGroovyMethods.java')
                     arg(value: 'subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java')

http://git-wip-us.apache.org/repos/asf/groovy/blob/6b259362/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 72a644f..c5d92a0 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -227,7 +227,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport
{
 //            DateUtilExtensions.class,
 //            DateTimeStaticExtensions.class,
 //            DateTimeExtensions.class,
-//            SqlGroovyMethods.class,
+//            SqlExtensions.class,
 //            SwingGroovyMethods.class,
 //            XmlGroovyMethods.class,
 //            NioGroovyMethods.class

http://git-wip-us.apache.org/repos/asf/groovy/blob/6b259362/subprojects/groovy-sql/build.gradle
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/build.gradle b/subprojects/groovy-sql/build.gradle
index b872f66..eb70ce4 100644
--- a/subprojects/groovy-sql/build.gradle
+++ b/subprojects/groovy-sql/build.gradle
@@ -33,7 +33,7 @@ tasks.withType(Test) {
 }
 
 task moduleDescriptor(type: org.codehaus.groovy.gradle.WriteExtensionDescriptorTask) {
-    extensionClasses = 'org.codehaus.groovy.runtime.SqlGroovyMethods'
+    extensionClasses = 'org.apache.groovy.sql.extensions.SqlExtensions'
 }
 
 compileJava.dependsOn moduleDescriptor

http://git-wip-us.apache.org/repos/asf/groovy/blob/6b259362/subprojects/groovy-sql/src/main/java/groovy/sql/ResultSetMetaDataWrapper.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/main/java/groovy/sql/ResultSetMetaDataWrapper.java
b/subprojects/groovy-sql/src/main/java/groovy/sql/ResultSetMetaDataWrapper.java
index 05ccdb3..025d171 100644
--- a/subprojects/groovy-sql/src/main/java/groovy/sql/ResultSetMetaDataWrapper.java
+++ b/subprojects/groovy-sql/src/main/java/groovy/sql/ResultSetMetaDataWrapper.java
@@ -38,8 +38,7 @@ import java.sql.ResultSetMetaData;
  * <p>
  * This wrapper is created by an iterator invoked for <code>ResultSetMetaData</code>.
  *
- * @author John Hurst
- * @see org.codehaus.groovy.runtime.SqlGroovyMethods
+ * @see org.apache.groovy.sql.extensions.SqlExtensions
  */
 public class ResultSetMetaDataWrapper extends GroovyObjectSupport {
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/6b259362/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
----------------------------------------------------------------------
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 da61e9f..a78c755 100644
--- a/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
+++ b/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
@@ -52,7 +52,7 @@ import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import static org.codehaus.groovy.runtime.SqlGroovyMethods.toRowResult;
+import static org.apache.groovy.sql.extensions.SqlExtensions.toRowResult;
 
 /**
  * A facade over Java's normal JDBC APIs providing greatly simplified

http://git-wip-us.apache.org/repos/asf/groovy/blob/6b259362/subprojects/groovy-sql/src/main/java/org/apache/groovy/sql/extensions/SqlExtensions.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/main/java/org/apache/groovy/sql/extensions/SqlExtensions.java
b/subprojects/groovy-sql/src/main/java/org/apache/groovy/sql/extensions/SqlExtensions.java
new file mode 100644
index 0000000..3540df9
--- /dev/null
+++ b/subprojects/groovy-sql/src/main/java/org/apache/groovy/sql/extensions/SqlExtensions.java
@@ -0,0 +1,123 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.groovy.sql.extensions;
+
+import groovy.lang.GroovyRuntimeException;
+import groovy.sql.GroovyResultSet;
+import groovy.sql.GroovyRowResult;
+import groovy.sql.ResultSetMetaDataWrapper;
+
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * This class defines all the new SQL-related groovy methods which enhance
+ * the normal JDK SQL classes when inside the Groovy environment.
+ * Static methods are used with the first parameter the destination class.
+ */
+public class SqlExtensions {
+
+    /**
+     * Returns a GroovyRowResult given a ResultSet.
+     *
+     * @param rs a ResultSet
+     * @return the resulting GroovyRowResult
+     * @throws java.sql.SQLException if a database error occurs
+     * @since 1.6.0
+     */
+    public static GroovyRowResult toRowResult(ResultSet rs) throws SQLException {
+        ResultSetMetaData metadata = rs.getMetaData();
+        Map<String, Object> lhm = new LinkedHashMap<String, Object>(metadata.getColumnCount(),
1);
+        for (int i = 1; i <= metadata.getColumnCount(); i++) {
+            lhm.put(metadata.getColumnLabel(i), rs.getObject(i));
+        }
+        return new GroovyRowResult(lhm);
+    }
+
+    /**
+     * Return a java.sql.Timestamp given a java.util.Date.
+     *
+     * @param d a date
+     * @return the date wrapped as a Timestamp
+     * @since 1.6.6
+     */
+    public static Timestamp toTimestamp(Date d) {
+        return new Timestamp(d.getTime());
+    }
+
+    /**
+     * Coerce a GroovyResultSet to a boolean value.
+     * A GroovyResultSet is coerced to false if there are no more rows to iterate over,
+     * and to true otherwise.
+     *
+     * @param grs the GroovyResultSet
+     * @return the boolean value
+     * @since 1.7.0
+     */
+    public static boolean asBoolean(GroovyResultSet grs) {
+        //TODO: check why this asBoolean() method is needed for SqlTest to pass with custom
boolean coercion in place
+        return true;
+    }
+
+    /**
+     * Return an Iterator given a ResultSetMetaData.
+     *
+     * Enables Groovy collection method syntactic sugar on ResultSetMetaData.
+     *
+     * @param resultSetMetaData the ResultSetMetaData to iterate over
+     * @return an iterator for the ResultSetMetaData
+     * @since 1.7
+     */
+    public static Iterator<ResultSetMetaDataWrapper> iterator(ResultSetMetaData resultSetMetaData)
{
+        return new ResultSetMetaDataIterator(resultSetMetaData);
+    }
+
+    private static class ResultSetMetaDataIterator implements Iterator<ResultSetMetaDataWrapper>
{
+        private final ResultSetMetaData target;
+        private int index = 1;
+
+        public ResultSetMetaDataIterator(ResultSetMetaData target) {
+            this.target = target;
+        }
+
+        public boolean hasNext() {
+            try {
+                return index <= target.getColumnCount();
+            }
+            catch (SQLException ex) {
+                throw new GroovyRuntimeException("Unable to obtain column count from ResultSetMetaData",
ex);
+            }
+        }
+
+        public ResultSetMetaDataWrapper next() {
+            return new ResultSetMetaDataWrapper(target, index++);
+        }
+
+        public void remove() {
+            throw new UnsupportedOperationException("Cannot remove from ResultSetMetaData");
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/6b259362/subprojects/groovy-sql/src/main/java/org/codehaus/groovy/runtime/SqlGroovyMethods.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-sql/src/main/java/org/codehaus/groovy/runtime/SqlGroovyMethods.java
b/subprojects/groovy-sql/src/main/java/org/codehaus/groovy/runtime/SqlGroovyMethods.java
index af426c7..b69c993 100644
--- a/subprojects/groovy-sql/src/main/java/org/codehaus/groovy/runtime/SqlGroovyMethods.java
+++ b/subprojects/groovy-sql/src/main/java/org/codehaus/groovy/runtime/SqlGroovyMethods.java
@@ -18,10 +18,10 @@
  */
 package org.codehaus.groovy.runtime;
 
-import groovy.lang.GroovyRuntimeException;
 import groovy.sql.GroovyResultSet;
 import groovy.sql.GroovyRowResult;
 import groovy.sql.ResultSetMetaDataWrapper;
+import org.apache.groovy.sql.extensions.SqlExtensions;
 
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
@@ -29,98 +29,31 @@ import java.sql.SQLException;
 import java.sql.Timestamp;
 import java.util.Date;
 import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
 
 /**
- * This class defines all the new SQL-related groovy methods which enhance
- * the normal JDK SQL classes when inside the Groovy environment.
- * Static methods are used with the first parameter the destination class.
- *
- * @author Paul King
- * @author John Hurst
+ * @deprecated use org.apache.groovy.sql.extensions.SqlExtensions
  */
+@Deprecated
 public class SqlGroovyMethods {
 
-    /**
-     * Returns a GroovyRowResult given a ResultSet.
-     *
-     * @param rs a ResultSet
-     * @return the resulting GroovyRowResult
-     * @throws java.sql.SQLException if a database error occurs
-     * @since 1.6.0
-     */
+    @Deprecated
     public static GroovyRowResult toRowResult(ResultSet rs) throws SQLException {
-        ResultSetMetaData metadata = rs.getMetaData();
-        Map<String, Object> lhm = new LinkedHashMap<String, Object>(metadata.getColumnCount(),
1);
-        for (int i = 1; i <= metadata.getColumnCount(); i++) {
-            lhm.put(metadata.getColumnLabel(i), rs.getObject(i));
-        }
-        return new GroovyRowResult(lhm);
+        return SqlExtensions.toRowResult(rs);
     }
 
-    /**
-     * Return a java.sql.Timestamp given a java.util.Date.
-     *
-     * @param d a date
-     * @return the date wrapped as a Timestamp
-     * @since 1.6.6
-     */
+    @Deprecated
     public static Timestamp toTimestamp(Date d) {
-        return new Timestamp(d.getTime());
+        return SqlExtensions.toTimestamp(d);
     }
 
-    /**
-     * Coerce a GroovyResultSet to a boolean value.
-     * A GroovyResultSet is coerced to false if there are no more rows to iterate over,
-     * and to true otherwise.
-     *
-     * @param grs the GroovyResultSet
-     * @return the boolean value
-     * @since 1.7.0
-     */
+    @Deprecated
     public static boolean asBoolean(GroovyResultSet grs) {
-        //TODO: check why this asBoolean() method is needed for SqlTest to pass with custom
boolean coercion in place
         return true;
     }
 
-    /**
-     * Return an Iterator given a ResultSetMetaData.
-     *
-     * Enables Groovy collection method syntactic sugar on ResultSetMetaData.
-     *
-     * @param resultSetMetaData the ResultSetMetaData to iterate over
-     * @return an iterator for the ResultSetMetaData
-     * @since 1.7
-     */
+    @Deprecated
     public static Iterator<ResultSetMetaDataWrapper> iterator(ResultSetMetaData resultSetMetaData)
{
-        return new ResultSetMetaDataIterator(resultSetMetaData);
-    }
-
-    private static class ResultSetMetaDataIterator implements Iterator<ResultSetMetaDataWrapper>
{
-        private final ResultSetMetaData target;
-        private int index = 1;
-
-        public ResultSetMetaDataIterator(ResultSetMetaData target) {
-            this.target = target;
-        }
-
-        public boolean hasNext() {
-            try {
-                return index <= target.getColumnCount();
-            }
-            catch (SQLException ex) {
-                throw new GroovyRuntimeException("Unable to obtain column count from ResultSetMetaData",
ex);
-            }
-        }
-
-        public ResultSetMetaDataWrapper next() {
-            return new ResultSetMetaDataWrapper(target, index++);
-        }
-
-        public void remove() {
-            throw new UnsupportedOperationException("Cannot remove from ResultSetMetaData");
-        }
+        return SqlExtensions.iterator(resultSetMetaData);
     }
 
 }


Mime
View raw message