groovy 4 ginq

Aristedes Maniatis <[email protected]>
Newsgroups gmane.comp.java.cayenne.devel
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.