Your SlideShare is downloading. ×
A Case for Grails
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

A Case for Grails


Published on

Published in: Technology

1 Like
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. (A case for) GRAILS
    Mark Daugherty
    CITYTECH, Inc.
    July 7th, 2010
  • 2. Outline
    Grails overview
    Comparison of Java/Spring/JPA application to Groovy/Grails
  • 3. Context
    February 2010 : wrote a small Groovy/Grails app to learn the technologies
    March 1st, 2010 : started on CDGA project (Struts, Spring, JPA)
    March 1st, 2010 (later that day) : realized that CDGA had an enormous amount of boilerplate code that Grails could eliminate
  • 4. (Additional) Context
    May 7th, 2010 : wrote CITYTECH blog post about code savings from replacing Spring DAO code with Grails
    May 8th, 2010 – present : blog is read by a total of 4 CITYTECH employees
    July 7th, 2010 : Grails begins to learn at a geometric rate. It becomes self-aware at 2:14 AM, Eastern time.
  • 5. Grails Primer
    Web application framework built with Groovy (Java-based dynamic language) on top of proven Java technologies
    Spring MVC, Hibernate
    Full stack for rapid development
    Embedded Tomcat container, HSQLDB, (G)Ant, scaffolding features
    Get a basic app running within minutes
  • 6. You may notice…
    Convention over configuration
    Little-to-no initial configuration
    Project structure is predefined according to best practices
    Command line scripts for common tasks
    Create new application, compile, test, run
    Generate domain classes, controllers, services, test cases
    Install plugins
    Contrast with your last Maven-built project
  • 7. In practice…
  • 8. Simple Domain
    Delegate 1  ∞ User
    Delegate 1  ∞ Application
    A “delegate agency” has one-to-many users and one-to-many applications. An application contains various forms, input by users, to collect data about the delegate agency.
  • 9. JPA (Java Persistence API)
    @Table(name = "USER")
    public class User implements Serializable {
    private Integer id;
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "DELEGATE", referencedColumnName = "ID")
    private Delegate delegate;
    // getters and setters, equals(), hashCode(), toString()…
  • 10. (More) JPA
    @Table(name = "DELEGATE")
    public class Delegate implements Serializable {
    private Integer id;
    @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
    private Set<User> users;
    @OneToMany(cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
    private Set<Application> applications;
    // getters and setters, equals(), hashCode(), toString()...
  • 11. (Still more) JPA
    @Table(name = "APPLICATION")
    public class Application implements Serializable {
    private Integer id;
    @ManyToOne(cascade = { CascadeType.REFRESH }, optional = false)
    @JoinColumn(name = "DELEGATE”)
    private Delegate delegate;
    // getters and setters, equals(), hashCode(), toString()...
  • 12. Grails
    class User {
    static belongsTo = [delegate:Delegate]
    class Delegate {
    static hasMany = [users:User, applications:Application]
    static mapping = {
    users lazy:false
    applications cascade:'delete'
    class Application {
    static belongsTo = [delegate:Delegate]
    static mapping = {
    delegate cascade:'refresh'
  • 13. DAO
    JPA/Hibernate = verbose, repetitive
    Even a small domain model can have 1000’s of lines of code for basic CRUD operations
    Tedious to maintain
  • 14. GORM!
    Hibernate under the hood
    Groovy + runtime code synthesis to eliminate boilerplate code
  • 15. Basic CRUD
  • 16. Dynamic Finders
  • 17. Additional GORM Features
    ORM DSL for mapping to legacy DB schemas
    Custom mappings for non-standard table and column names
    Event handlers (beforeInsert, afterUpdate)
    Customizable caching and fetching strategies, transactions
  • 18. Web
    Render XML or JSON responses using markup builders
    Automatic marshalling of domain classes to XML/JSON
  • 19. (More) Web
    Similar to JSP, but with better tag libraries
    findAll, grep (filter) for collections
    Method calls
    Sitemesh (decorator) layouts
    Customizable URL mappings
  • 20. Validation
    Often painful, less so with Grails
  • 21. More Features
    Spring Web Flow
    Supports subflows, conversation scope (similar to Seam)
    Interceptors / Filters
    DOJO, GWT plugins
  • 22. Even more to like
    Groovy tests
    Ideal for TDD
    Unit tests created automatically from command line script
    Dynamic language features for easy mocking
    Easy RESTful web services
    URL mappings
    Controllers can render XML or JSON
    Consider attending a CGUG meeting
    Extremely active community
    400+ plugins (Spring Security, JQuery, GWT, Google App Engine, Flex)
    Wide range of tutorials
    Frequent releases
  • 23. Summary
    Grails compared to Spring, EJB, JPA
    Substantially less code without compromises
    Easier to maintain and test
    Shorter iterations and release cycles
    Same proven underlying technologies
    Gain competitive edge
    Why not?