Existing Groovy DSLs
[ 228 ]
So what does Grails actually do? The answer is all of the tasks mentioned earlier,
depending on which version of Grails you look at. The 1.x.x versions of Grails
took the metaClass approach and added methods at runtime into all the domain
classes. By version 2.x.x, some new requirements were being considered for GORM
within the Groovy eco system, including the ability to use GORM as a standalone
persistence layer outside Grails.
This led to the rewriting of the GORM enhancement methods so that GORM
persistence could be added to a class via an @Entity annotation. To do this, the
injection of the GORM operations such as count(), save(), get(), and so on were
refactored into an AST transformation.
In Grails 2.x.x the GORM operations, methods were fully implemented in a
standalone API class. At compile time, the AST transformations would take over and
clone the fully formed properties and methods from the AST nodes of the API class
and inject them into the domain classes. This is a common pattern that is used in the
2.x.x Grails sources to enhance all the Grails artifact classes. It saves building out
the AST manually using ASTBuilder or the AST APIs directly. In Grails 3.x.x, this
is being improved even further by turning these API classes into traits that can be
applied to the artifact classes via AST transformations.
Modeling relationships
Storing and retrieving simple objects is all very well, but the real power of GORM is
that it allows us to model the relationships between objects, as we will now see. The
main types of relationships that we want to model are associations, where one object
has an associated relationship with another, for example, Customer and Account;
composition relationships, where we want to build an object from subcomponents;
and inheritance, where we want to model similar objects by describing their
common properties in a base class.
Associations
Every business system involves some sort of association between the main business
objects. Relationships between objects can be one-to-one, one-to-many, or many-to-
many. Relationships may also imply ownership, where one object only has relevance
in relation to another parent object.
http://www.ebook3000.com