I came across this really interesting new feature in groovy 4 today...

            class Person {
                String name
                int age

                Person(String name, int age) {
                    this.name = name
                    this.age = age
                }
            }

            def persons1 = [new Person('Daniel', 35), new Person('Linda', 21), 
new Person('Peter', 30)]
            def persons2 = [new Person('Jack', 35), new Person('Rose', 21), new 
Person('Smith', 30)]


           def output = GQ {
                from p1 in persons1
                innerjoin p2 in persons2 on p1.age == p2.age
                select p1.name.toUpperCase(), p2.name.toUpperCase()
           }

            assert [['DANIEL', 'JACK'], ['LINDA', 'ROSE'], ['PETER', 'SMITH']] 
== output.toList()


So GQ invokes this sql-like query language for Java/groovy objects.


Not suggesting it is useful for Cayenne, but interesting nevertheless.


Ari




docs:https://github.com/apache/groovy/blob/master/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc

examples: https://github.com/apache/groovy/blob/master/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy

src: https://github.com/apache/groovy/tree/master/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq

Reply via email to