You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2020/09/15 03:07:54 UTC

[groovy] branch master updated (0b86329 -> 67b111b)

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

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


    from 0b86329  reuse asExpression and hasUnresolvedGenerics plus other minor edits
     new 4847bb0  GROOVY-9743: Bump hsqldb to 2.5.1
     new 67b111b  doco: add minimal DataSet section

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 subprojects/groovy-sql/build.gradle                |  4 +-
 .../groovy-sql/src/spec/doc/sql-userguide.adoc     | 27 +++++++++++-
 .../groovy-sql/src/spec/test/Author.groovy         |  8 ++--
 .../src/spec/test/AuthorTestHelper.groovy          | 27 +++++-------
 .../groovy-sql/src/spec/test/SqlTest.groovy        | 49 ++++++++++++++++++++--
 5 files changed, 90 insertions(+), 25 deletions(-)
 copy src/test-resources/stubgenerator/circularLanguageReference/Shape.java => subprojects/groovy-sql/src/spec/test/Author.groovy (88%)
 copy src/test/gls/ch06/s05/testClasses/Tt1.java => subprojects/groovy-sql/src/spec/test/AuthorTestHelper.groovy (67%)


[groovy] 02/02: doco: add minimal DataSet section

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 67b111ba888bab477ff93413c15a4866ae80dad6
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Sep 15 13:07:04 2020 +1000

    doco: add minimal DataSet section
---
 subprojects/groovy-sql/build.gradle                |  2 +-
 .../groovy-sql/src/spec/doc/sql-userguide.adoc     | 27 +++++++++++++-
 .../{build.gradle => src/spec/test/Author.groovy}  | 24 +++---------
 .../spec/test/AuthorTestHelper.groovy}             | 30 ++++++---------
 .../groovy-sql/src/spec/test/SqlTest.groovy        | 43 ++++++++++++++++++++++
 5 files changed, 87 insertions(+), 39 deletions(-)

diff --git a/subprojects/groovy-sql/build.gradle b/subprojects/groovy-sql/build.gradle
index aa3474c..a17563e 100644
--- a/subprojects/groovy-sql/build.gradle
+++ b/subprojects/groovy-sql/build.gradle
@@ -29,7 +29,7 @@ dependencies {
 tasks.withType(Test) {
     excludes = ['**/*TestCase.class', '**/*$*.class']
 // required for DataSet tests
-    classpath = classpath + files('src/test/groovy')
+    classpath = classpath + files('src/test/groovy') + files('src/spec/test')
 }
 
 task moduleDescriptor(type: org.codehaus.groovy.gradle.WriteExtensionDescriptorTask) {
diff --git a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
index e7223f6..6f44f8e 100644
--- a/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
+++ b/subprojects/groovy-sql/src/spec/doc/sql-userguide.adoc
@@ -475,4 +475,29 @@ include::../test/SqlTest.groovy[tags=sql_use_stored_fun_inout_parameter,indent=0
 
 == Using DataSets
 
-(TBD)
+Groovy provides a gapi:groovy.sql.DataSet[] class which enhances the gapi:groovy.sql.Sql[] class
+with what can be thought of as mini https://en.wikipedia.org/wiki/Object-relational_mapping[ORM] functionality.
+Databases are accessed and queried using POGO fields and operators rather than JDBC-level API calls and RDBMS column names.
+
+So, instead of a query like:
+[source,groovy]
+----
+include::../test/SqlTest.groovy[tags=without_dataset,indent=0]
+----
+
+You can write code like this:
+
+[source,groovy]
+----
+include::../test/AuthorTestHelper.groovy[tags=with_dataset,indent=0]
+----
+
+Here we have a helper "domain" class:
+
+[source,groovy]
+----
+include::../test/Author.groovy[tags=dataset_class,indent=0]
+----
+
+Database access and manipulation involves creating or working with
+instances of the domain class.
\ No newline at end of file
diff --git a/subprojects/groovy-sql/build.gradle b/subprojects/groovy-sql/src/spec/test/Author.groovy
similarity index 51%
copy from subprojects/groovy-sql/build.gradle
copy to subprojects/groovy-sql/src/spec/test/Author.groovy
index aa3474c..84736ab 100644
--- a/subprojects/groovy-sql/build.gradle
+++ b/subprojects/groovy-sql/src/spec/test/Author.groovy
@@ -16,24 +16,10 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-dependencies {
-    api rootProject // Sql uses Closure...
-    testImplementation group: 'org.hsqldb', name: 'hsqldb', version: '2.5.1'
-// uncomment to test with other databases (requires changes elsewhere too)
-//    testImplementation 'com.h2database:h2:1.3.164'
-//    testImplementation 'hsqldb:hsqldb:1.8.0.10'
-    testImplementation project(':groovy-test')
-}
-
-// TODO move to parent build.gradle subprojects
-tasks.withType(Test) {
-    excludes = ['**/*TestCase.class', '**/*$*.class']
-// required for DataSet tests
-    classpath = classpath + files('src/test/groovy')
-}
 
-task moduleDescriptor(type: org.codehaus.groovy.gradle.WriteExtensionDescriptorTask) {
-    extensionClasses = 'org.apache.groovy.sql.extensions.SqlExtensions'
+// tag::dataset_class[]
+class Author {
+    String firstname
+    String lastname
 }
-
-compileJava.dependsOn moduleDescriptor
+// end::dataset_class[]
diff --git a/subprojects/groovy-sql/build.gradle b/subprojects/groovy-sql/src/spec/test/AuthorTestHelper.groovy
similarity index 51%
copy from subprojects/groovy-sql/build.gradle
copy to subprojects/groovy-sql/src/spec/test/AuthorTestHelper.groovy
index aa3474c..1c2d86c 100644
--- a/subprojects/groovy-sql/build.gradle
+++ b/subprojects/groovy-sql/src/spec/test/AuthorTestHelper.groovy
@@ -16,24 +16,18 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-dependencies {
-    api rootProject // Sql uses Closure...
-    testImplementation group: 'org.hsqldb', name: 'hsqldb', version: '2.5.1'
-// uncomment to test with other databases (requires changes elsewhere too)
-//    testImplementation 'com.h2database:h2:1.3.164'
-//    testImplementation 'hsqldb:hsqldb:1.8.0.10'
-    testImplementation project(':groovy-test')
-}
 
-// TODO move to parent build.gradle subprojects
-tasks.withType(Test) {
-    excludes = ['**/*TestCase.class', '**/*$*.class']
-// required for DataSet tests
-    classpath = classpath + files('src/test/groovy')
-}
+import groovy.sql.Sql
 
-task moduleDescriptor(type: org.codehaus.groovy.gradle.WriteExtensionDescriptorTask) {
-    extensionClasses = 'org.apache.groovy.sql.extensions.SqlExtensions'
+class AuthorTestHelper {
+    static void testAuthorDataSet(Sql sql) {
+        // tag::with_dataset[]
+        def authorDS = sql.dataSet('Author')
+        def result = authorDS.findAll{ it.firstname > 'Dierk' }
+                .findAll{ it.lastname < 'Pragt' }
+                .sort{ it.lastname }
+                .reverse()
+        assert result.rows()*.firstname == ['Eric', 'Guillaume', 'Paul']
+        // end::with_dataset[]
+    }
 }
-
-compileJava.dependsOn moduleDescriptor
diff --git a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
index fa12d25..7dc94de 100644
--- a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
+++ b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
@@ -504,6 +504,49 @@ class SqlTest extends GroovyTestCase {
         '''
     }
 
+    void testDataSets() {
+        assertScript '''
+            import groovy.sql.Sql
+            import groovy.sql.DataSet
+            def url = 'jdbc:hsqldb:mem:yourDB'
+            def user = 'sa'
+            def password = ''
+            def driver = 'org.hsqldb.jdbcDriver'
+            Sql.withInstance(url, user, password, driver) { sql ->
+              sql.execute """
+              DROP TABLE Author IF EXISTS
+              """
+              sql.execute """
+              CREATE TABLE Author (
+                id          INTEGER GENERATED BY DEFAULT AS IDENTITY,
+                firstname   VARCHAR(64),
+                lastname    VARCHAR(64)
+              )
+              """
+
+              sql.withBatch(3) { stmt ->
+                stmt.addBatch "INSERT INTO Author (firstname, lastname) VALUES ('Dierk', 'Koenig')"
+                stmt.addBatch "INSERT INTO Author (firstname, lastname) VALUES ('Paul', 'King')"
+                stmt.addBatch "INSERT INTO Author (firstname, lastname) VALUES ('Guillaume', 'Laforge')"
+                stmt.addBatch "INSERT INTO Author (firstname, lastname) VALUES ('Eric', 'Milles')"
+                stmt.addBatch "INSERT INTO Author (firstname, lastname) VALUES ('Cedric', 'Champeau')"
+                stmt.addBatch "INSERT INTO Author (firstname, lastname) VALUES ('Erik', 'Pragt')"
+                stmt.addBatch "INSERT INTO Author (firstname, lastname) VALUES ('Jon', 'Skeet')"
+              }
+              // tag::without_dataset[]
+              def qry = """SELECT * FROM Author
+                WHERE (firstname > ?)
+                AND (lastname < ?)
+                ORDER BY lastname DESC"""
+              def params = ['Dierk', 'Pragt']
+              def result = sql.rows(qry, params)
+              assert result*.firstname == ['Eric', 'Guillaume', 'Paul']
+              // end::without_dataset[]
+              AuthorTestHelper.testAuthorDataSet(sql)
+            }
+        '''
+    }
+
     void testPagination() {
         assertScript '''
             import groovy.sql.Sql


[groovy] 01/02: GROOVY-9743: Bump hsqldb to 2.5.1

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 4847bb0aadea5a0bb9d5ca0b434179452b4d166f
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Sep 15 09:53:13 2020 +1000

    GROOVY-9743: Bump hsqldb to 2.5.1
---
 subprojects/groovy-sql/build.gradle                 | 2 +-
 subprojects/groovy-sql/src/spec/test/SqlTest.groovy | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/subprojects/groovy-sql/build.gradle b/subprojects/groovy-sql/build.gradle
index 0e44dcf..aa3474c 100644
--- a/subprojects/groovy-sql/build.gradle
+++ b/subprojects/groovy-sql/build.gradle
@@ -18,7 +18,7 @@
  */
 dependencies {
     api rootProject // Sql uses Closure...
-    testImplementation group: 'org.hsqldb', name: 'hsqldb', version: '2.3.3'
+    testImplementation group: 'org.hsqldb', name: 'hsqldb', version: '2.5.1'
 // uncomment to test with other databases (requires changes elsewhere too)
 //    testImplementation 'com.h2database:h2:1.3.164'
 //    testImplementation 'hsqldb:hsqldb:1.8.0.10'
diff --git a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
index b16e36c..fa12d25 100644
--- a/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
+++ b/subprojects/groovy-sql/src/spec/test/SqlTest.groovy
@@ -72,7 +72,7 @@ class SqlTest extends GroovyTestCase {
         /*
         commented out as already on classpath
 // tag::sql_connecting_grab[]
-        @Grab('org.hsqldb:hsqldb:2.3.3')
+        @Grab('org.hsqldb:hsqldb:2.5.1')
         @GrabConfig(systemClassLoader=true)
         // create, use, and then close sql instance ...
 // end::sql_connecting_grab[]
@@ -335,8 +335,8 @@ class SqlTest extends GroovyTestCase {
               // tag::sql_basic_table_metadata[]
               def md = sql.connection.metaData
               assert md.driverName == 'HSQL Database Engine Driver'
-              assert md.databaseProductVersion == '2.3.3'
-              assert ['JDBCMajorVersion', 'JDBCMinorVersion'].collect{ md[it] } == [4, 0]
+              assert md.databaseProductVersion == '2.5.1'
+              assert ['JDBCMajorVersion', 'JDBCMinorVersion'].collect{ md[it] } == [4, 2]
               assert md.stringFunctions.tokenize(',').contains('CONCAT')
               def rs = md.getTables(null, null, 'AUTH%', null)
               assert rs.next()