Friday, October 31, 2008

New GORM Features Coming in 1.1

Now that The Definitive Guide to Grails 2nd Edition (barring a few reviews) is a wrap, I've been refocusing in Grails development. First up, is GORM and we've implemented a number of great improvements including:

Better GORM events

Previously, GORM supported beforeInsert, beforeUpdate and beforeDelete events, now there is afterInsert, afterUpdate and afterDelete to complete the picture

Persistence of Collections of Basic Types

GORM now supports persisting basic types like String, Integer and so on using a join table:
class Person {
static hasMany = [nicknames:String]
}
Improvements to Data Binding

It is now simpler to bind data to a subset of properties. Previously you could use the syntax:
person.properties = params
Which would bind all the incoming request parameters to the person. If you didn't want that behavior you could use the bindData method. Now you can bind to a subset of properties using the subscript operator:
person.properties["firstName","lastName"] = params
And access a subset of the domain classes properties using the same syntax:
person.properties["firstName","lastName"].each { println it }
Read-Only Access to Objects

Persistent instances can now be loaded in a read-only state using the read method:
def book = Book.read(1)
Default Sort Order

Associations can now be sorted using a default sort order declared at the class level:
class Book {
String title
static mapping = {
sort "title"
}
}
Or at the association level:
class Author {
static hasMany = [books:Book]
static mapping = {
books sort:"title"
}
}
Batch Fetching

GORM now supports configuring batch fetching (an optimization of lazy loading) using the ORM DSL at the class level:
class Book {
String title
static mapping = {
batchSize 15
}
}
Or at the association level:
class Author {
static hasMany = [books:Book]
static mapping = {
books batchSize:15
}
}
Improvements to Dynamic Finders

There is a new InList suffix that can be used with dynamic finders:
def groovyBooks = Book.findByAuthorInList(['Dierk Koenig', 'Graeme Rocher'])
Dynamic finders can also now use the query cache:
def books = Book.findByTitle("Groovy in Action", [cache:true] )
And upgrade to a pessimistic lock:
def books = Book.findByTitle("Groovy in Action", [lock:true] )
Legacy Mapping for Many-to-Many and Unidirectional One-to-manys

Many-to-many and Unidirectional One-to-many associations can use the joinTable argument to alter the way they map to the underlying database:
class Book {
String title
static belongsTo = Author
static hasMany = [authors:Author]

static mapping = {
authors joinTable:[name:"mm_author_books", key:'mm_book_id' ]
}
}
class Author {
String name
static hasMany = [books:Book]
static mapping = {
books joinTable:[name:"mm_author_books", key:'mm_author_id']
}
}

Thursday, October 02, 2008

Sky.com relaunches written in Grails

The main portal for Sky television has relaunched written in Grails. Sky, also known as British Sky Broadcasting or BSkyB, employs 17000 people in the UK and operates the largest satellite network in the UK.

The site receives a million+ hits per day and joins all the other subsites also written in Grails:
Congrats to the Sky team!

Update 07/10: Couple of new things have arison since this was posted. Firstly, Sky actually employ 17000 people not 11000. Seems the Google sample data I obtained was out of date.

Also Glenn Saqui has a nice write-up on the architecture of Sky.com on Marc's Blog. Altogether the 4 subsites listed above receive over 110 million hits per month and run on a cluster of web layer machines and 2 db machines. Checkout the aforementioned link for more info.