(A case for) GRAILS<br />Mark Daugherty<br />CITYTECH, Inc.<br />July 7th, 2010<br />
Outline<br />Inspiration<br />Grails overview<br />Comparison of Java/Spring/JPA application to Groovy/Grails<br />
Context<br />February 2010 : wrote a small Groovy/Grails app to learn the technologies<br />March 1st, 2010 : started on C...
(Additional) Context<br />May 7th, 2010 : wrote CITYTECH blog post about code savings from replacing Spring DAO code with ...
Grails Primer<br />Web application framework built with Groovy (Java-based dynamic language) on top of proven Java technol...
You may notice…<br />Convention over configuration<br />Little-to-no initial configuration<br />Project structure is prede...
In practice…<br />
Simple Domain<br />Delegate 1  ∞ User<br />Delegate 1  ∞ Application<br />A “delegate agency” has one-to-many users and ...
JPA (Java Persistence API)<br />@Entity<br />@Table(name = "USER")<br />public class User implements Serializable {<br /> ...
(More) JPA<br />@Entity<br />@Table(name = "DELEGATE")<br />public class Delegate implements Serializable {<br />    @Id<b...
(Still more) JPA<br />@Entity<br />@Table(name = "APPLICATION")<br />public class Application implements Serializable {<br...
Grails<br />class User {<br />	static belongsTo = [delegate:Delegate]<br />}<br />class Delegate {<br />	static hasMany = ...
DAO<br />JPA/Hibernate = verbose, repetitive<br />Even a small domain model can have 1000’s of lines of code for basic CRU...
GORM!<br />Hibernate under the hood<br />Groovy + runtime code synthesis to eliminate boilerplate code<br />
Basic CRUD<br />
Dynamic Finders<br />
Additional GORM Features<br />ORM DSL for mapping to legacy DB schemas<br />Custom mappings for non-standard table and col...
Web<br />Render XML or JSON responses using markup builders<br />Automatic marshalling of domain classes to XML/JSON<br />
(More) Web<br />GSP<br />Similar to JSP, but with better tag libraries<br />findAll, grep (filter) for collections<br />Me...
Validation<br />Often painful, less so with Grails<br />
More Features<br />Spring Web Flow<br />Supports subflows, conversation scope (similar to Seam)<br />Interceptors / Filter...
Even more to like<br />Groovy tests<br />Ideal for TDD<br />Unit tests created automatically from command line script<br /...
Summary<br />Grails compared to Spring, EJB, JPA<br />Substantially less code without compromises<br />Easier to maintain ...
Upcoming SlideShare
Loading in...5
×

A Case for Grails

2,743

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,743
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
14
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

A Case for Grails

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

    Clipping is a handy way to collect important slides you want to go back to later.

×