Thursday, January 05, 2012

Thursday, December 15, 2011

Grails 2.0 Released!

Long time no post, but after lots of hard work from the Grails core team we are pleased to announce the Grails 2.0 release.

I have posted a comprehensive announcement on the SpringSource blog.

Enjoy!

Wednesday, April 13, 2011

Grails on Cloud Foundry

For those of you who missed it, yesterday we launched the new Cloud
Foundry
which we hope will become the premier deployment model for
Grails (and Spring, Ruby, Node.js etc.) applications in the the
future. If you missed the presentation checkout the YouTube recording.

It represents the culmination of a huge amount of work within VMware and we're super excited about the potential it has to completely revolutionize deployment models for Grails applications in the future.

Here are some further resources specific to Grails users:

Website: http://www.cloudfoundry.com/
Wiki & Sample applications: https://github.com/SpringSource/cloudfoundry-samples/wiki/Grails
Tutorial: http://blog.springsource.com/2011/04/12/one-step-deployment-with-grails-and-cloud-foundry/
Plugin Documentation: http://grails-plugins.github.com/grails-cloud-foundry/docs/manual/index.html

Signups are currently on a first come first serve basis under a limited beta programme.

Friday, April 16, 2010

Reading i18n messages from the database with Grails

In a recent consulting engagement, a client wanted to know how to go about reading i18n messages from the database rather than static properties files (the default in Grails). Considering how easy this is to do I was surprised when I Googled it that there was no information on how this is achieved.

Anyway it's dead simple. Just create a domain class that models a message:

class Message {

String code

Locale locale

String text

}


Then implement a class that extends the org.springframework.context.support.AbstractMessageSource class. In the example below I am using simple GORM finders to lookup a message using the code and locale

class DatabaseMessageSource extends AbstractMessageSource {


protected MessageFormat resolveCode(String code, Locale locale) {

Message msg = Message.findByCodeAndLocale(code, locale)

def format

if(msg) {

format = new MessageFormat(msg.text, msg.locale)

}

else {

format = new MessageFormat(code, locale )

}

return format;

}

}


Then wire it in using Spring by configuring a "messageSource" bean in the grails-app/conf/spring/resources.groovy file:

beans = {

messageSource(DatabaseMessageSource)

}


And that's it. Now you're serving messages from the database. Of course this is a terrible inefficient implementation since we're hitting the database for ever message code used in the application. However, it's pretty easy to introduce caching. Just create a cache key:

@Immutable

class MessageKey implements Serializable {

String code

Locale locale

}


Then configure an appropriate cache bean (I'm using Ehcache) in Spring and wire it into your MessageSource:

beans = {

messageCache(EhCacheFactoryBean) {

timeToLive = 500

// other cache properties

}

messageSource(DatabaseMessageSource) {

messageCache = messageCache

}

}


Finally, update your implementation to use caching:

class DatabaseMessageSource extends AbstractMessageSource {


Ehcache messageCache

@Override

protected MessageFormat resolveCode(String code, Locale locale) {

def key = new MessageKey(code,locale)

def format = messageCache.get(key)?.value

if(!format) {

Message msg = Message.findByCodeAndLocale(code, locale)

if(msg) {

format = new MessageFormat(msg.text, msg.locale)

}

else {

format = new MessageFormat(code, locale)

}

messageCache.put new Element(key, format)

return format

}

return format;

}

}




Thursday, September 17, 2009

Grails - dependency resolution done right

Over the past couple of weeks I have been working on improving Grails dependency resolution capabilities for both applications and plugins. In previous versions of Grails (1.1 and below) you had limited options when it came to dependency resolution.

You could use the Grails Maven plugin, but that forced you to use, heavin forbid, Maven. We also shipped with basic Ant + Ivy support, but it was only really designed to be used for automation with continuous integration servers that support Ant and not at development time.

With Grails 1.2 this all changes with the introduction of Grails' dependency resolution DSL, which you can use to define your dependencies. Built on Ivy we have now eliminated one of the last remnants of XML usage in the Grails framework:
    dependencies {
runtime 'com.mysql:mysql-connector-java:5.1.5'
test 'junit:junit:3.8.2'
}
Grails takes application defined dependencies (defined in grails-app/conf/BuildConfig.groovy) and merges them with dependencies defined in the framework or any installed plugins. If there are conflicts you can exclude dependencies inherited from the framework or you can override plugin dependencies.

By default Grails will only resolve dependencies against your Grails installation but you can enable remote repository resolution easily:
repositories {
mavenCentral()
mavenRepo "http://repository.codehaus.org"
}
If you're addicted to your pom.xml file then we have even added the ability to read dependencies from the pom.xml instead of using the DSL. All in all, Grails 1.2 will give you significantly better control over dependencies and how they are resolved.

We're still on track to release Grails 1.2 by the end of the month, but if you want to hear more about it I'll be talking about Grails 1.2 at upcoming events such as JAOO (Denmark), SpringOne2GX (New Orleans, USA) and the Grails eXchange (London). See you there!

Thursday, May 21, 2009

Grails 1.1.1, Gr8conf, AppEngine and other happenings

Just got back from Gr8conf and really had a blast. It was a nice small group of 90-100 which meant you could really have a lot of one on one time with many of the attendees who had questions. The sessions were also not too short. Having that extra bit of time to elaborate on things makes a real different compared to the 45 minute rush you have at JavaOne et al.

All in all it felt more like a No Fluff event, which can only be described as a good thing. Right before the conference we released Grails 1.1.1 which is mainly a bug fix release, but the exciting part is the new Google AppEngine plugin which works with Grails 1.1.1

The plugin takes the heavy lifting out of configuring a Grails application for usage on AppEngine by automatically configuring the AppEngine development environment and a JDO persistence layer (JPA is coming too soon). You get reloading out of the box too, so Grails + AppEngine is really the most productive environment for developing JVM applications for AppEngine.

One missing feature from the AppEngine support right now is GORM (you have to use the raw JDO APIs). However, we are hard at work developing GORM-JPA (and potentially GORM-JDO) which will bring most of the features of GORM on top of standard JPA.

GORM-JPA is not the only exciting thing happening right now in the Grails plugin front. We are working with Adobe on integrating Flex and BlazeDS closely with Spring. The results of that can be seen in the recent Spring/BlazeDS integration 1.0 Rc2 release. The next phase is to build on top of that for the Grails plugin which is on my todo list to complete soon. Exciting times.

The plugin community itself continues to flourish, checkout these:
  • It is now finally possible to write Grails applications for different Portals such as Liferay and Pluto thanks to the Portlets plugins.
  • There is an excellent new plugin that embeds an LDAP server into Grails for easily testing LDAP
  • The Flex Scaffold plugin let's you generated complete CRUD applications using Grails and Adobe Flex
  • The Build Test Data plugin let's you quickly create dummy test data
  • Using the Spring WS plugin writing SOAP web services, feels more like writing REST service. Easy and painless.
These are just a few isolated mentions, there is activity going on all the time on the plugin space.

Tuesday, March 10, 2009

Grails 1.1 Released

Yes! Grails 1.1 is out and available for download. Checkout my blog post on the SpringSource team blog for a more detailed overview of the highlights. It is a strange feeling after a release goes out, like a mixture of relief, happiness and that "ok what now" feeling. Maybe I take software too seriously :-|

Nice to see how Twitter is abuzz with the news (note live results, link will change overtime) right now. Other than that we are now planning the launch of the Grails.org plugin portal. To support that I have been writing a few plugins for Grails. It is niceto actually write Grails apps/plugins rather than work on the internals all the time.

Anyway the result is 2 new plugins called Commentable and Taggable that allow you to generically tag and comment on domain instances. I also have a new blog plugin in the works which will power the new Grails.org blog when that is ready. Actually its already available, but I need to document it better, and I'll save that for another post.

As for beyond Grails 1.1, we are now at the planning phase, but there are loads of things we are considering from OSGi to JCR to Cloud computing. Exciting times.