Groovy for Domain-specific Languages - Second Edition

(nextflipdebug2) #1
[ 223 ]

Existing Groovy DSLs


By now, we have covered a lot of ground in describing the DSL-enabling features
of Groovy. In this chapter, we will look at two of the existing Groovy DSLs that are
freely available for download. The purpose of this chapter is not to try to give a
comprehensive tutorial on either of them. We will explore each in turn in order to
understand how they work, but more importantly, we will go through them in order
to understand how they are implemented using the Groovy features and techniques
that we have covered in the book so far. In this chapter, we will discuss:



  • Grails object relational mapping (GORM), which is a core component of the
    Grails web application framework and uses DSL-style techniques to apply
    persistence to regular Groovy classes. We will be looking at how GORM
    decorates regular POGO classes to add persistence semantics to them.

  • Spock, which is a behavior-driven development (BDD) tool. We have
    already encountered Spock throughout the book. In this chapter, we will
    look at how the Spock framework implements its DSL-style features.


Grails object relational mapping – GORM


The Grails framework is an open source web application framework built for the
Groovy language. Grails not only leverages Hibernate under the covers as its
persistence layer, but also implements its own object relational mapping layer for
Groovy, known as GORM. With GORM, we can take a POGO class and decorate
it with DSL-like settings in order to control how it is persisted. GORM can be
considered a DSL as it uses many of the cool DSL features that we have discussed
in previous chapters, in order to add its own mini dialect to Groovy in order to
implement persistence.

Free download pdf