Grails Persistence with GORM and GSQL
Grails Persistence with GORM and GSQL by Robert Fischer
- Binding:
- Paperback
- Number of Pages:
- 125
- ISBN:
- 1430219262
- Product Group:
- book
- Publisher:
- firstPress
- Publication Date:
- May 1, 2009
- BooksForGeeks.com ID:
- 27
Reviews for Grails Persistence with GORM and GSQL
-
A mixed bag
Rated out of 5 stars, January 12th, 2010
This book has some some five star content in places.
I've picked up a few new Groovy tricks to add to my coding repertoire and I'd recommend this book for that alone.
The book demonstrated things with extensive use of Assert statements which was good.
But there are a few things that irked me and hence the loss of a couple of stars (points 5-7 lose a star and points 8 & 9 causes loss of a second).
1) Comments showing artifact names weren't in some other font or bold or in italics to show a clear deliniation between artifacts in an individual listing.
2) P25 Luke Daley's Injecto library. The link seems to have stopped working at the time I write this.
I looked on the Wayback machine and found it was also used in GLDAPO. Then I exchanged Tweets with Luke & he tells me the @mixin annotation have replaced this.
Guiilliame LaForge covers @mixin this in the Groovymag April 2009 issue (What's new in Groovy 1.6) and Craig Wickesser gave an example in Dec 2009 issue (Groovy MetaObject Programming).
3) P27 1-30 should be 1-32
4) P130.
- Firstly, it seems there are a couple of lines missing here to declare the Testing class and a comment to signify where the artifact is along with its name.
- Secondly the author quotes parameter mapping for Dates as not working in Grails Controllers. So statements like:
def foo = new Foo(params)
Or
def foo = new Foo()
foo.properties = params
wouldn't work for Dates.
I investigated this a bit more and I think this was as a result of the test the author was performing not a Grails problem per se!
ie Date.toString() doesn't give a date in a format that the underlying Spring binding understands!
- I found a quote from Graeme Rocher on Nabble stating:
-- Default date format is "yyyy-MM-dd HH:mm:ss.S" but you can change this by defining a custom PropertyEditorRegistrar in resources.groovy that registers a new CustomDateEditor using whatever pattern you want.
- If you look at the API docs for java.util.Date.toString() you will find the format returned is
dow mon dd hh:mm:ss zzz yyyy (eg Sun Jan 10 11:06:01 GMT 2010)
So the binding obviously wouldn't work from the test given!
Date and Calendar are in fact a pet hate of mine in Java anyway. I wish the Groovy guys could tidy up the Java library. Thanks for commons.lang DateUtils parseDate tip Robert. I've been meaning to look into Yoda time too...
5) There must be a discrepancy with what is in print in places compared to something that would run.
For example:
6) Listing 1-14 on P12. The assertEquals above the shouldFail and the foo.ReadOnly should be swapped around.
7)P16 GORM does not update the lastUpdated property of a Domain class on Create
Try Googling on "Grails GORM Events".
Also lastUpdate needs a nullable constraint in ClassFoo as a result at top of page, and the FooTests should be assertNull foo.lastUpdated instead.
8) Parts of book were hard to fathom:
P24 Listing 1-28. The line that looks like a map calling a closure starting doAddedMethod:{-> This is some sort of MOP stuff I'm unaware of. Could have done with a better overview.
P29 - last four lines above listing 1-33
P41 At this point there is no support for using external or custom comparators on domain classes in GORM. (Wasn't sure what author was getting at here)
P61-65 The whole section on Custom Constraints and Listing 2-2 in particular.
After staring at this for a few minutes I suddenly realised Listing 2-2 was in fact three artifacts! This was not helped by the fact there were no blank lines either side of the messages.properties.
But it still didn't make it eay to understand the example and I particularly found the testListValueMessage perplexing.
I think once again this primariy came down to a map/closure like combo (P62-63) like the P24 example.
I just didn't get what listings 2-2 & 2-3 were supposed to be showing me!!
Bashar's Abdul-Jawad's Groovy & Grails Recipes - has a better example of this. I prefer examples based on a realistic validation, not some convoluted and contrived example. That, combined with the fact that book didn't set the scene well to describe the context in which you'd use this is what makes this difficult to follow.
P110 Sentence ending in 'appropriate' didn't seem to make sense. A wording issue. Perhaps appropriation? Who knows.
As a passing comment, the overloading of the term 'projection' seemed a bit odd too, to me.
It means different things in the context of Criteria Builder (P112) and HQL (P122).
The latter was the context I was familiar with as it relates to the way you would describe projections with SQL - ie column selection.
9) The book also left me with the impression that it was finished to a deadline, as some of the latter chapters were a little light in content.
They gave you pointers to go research, rather than give an example. Materialized views on P141 for example.
As a final footnote it would have been helpful if the book notified the reader against which version of Grails the tests were performed. As I'm wondering if embedded classes (value objects) and associations are now properly initialized too from the request parameters in Controllers. If the author had raised some JIRA issues and left references to those, it would have made it easy to check up on this.

