Grails 2.0 Update

  • 2,508 views
Uploaded on

See what's new in Grails 2.0

See what's new in Grails 2.0

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,508
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
58
Comments
0
Likes
5

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. What’s new in 2.0 Peter Ledbrook SpringSource t: @pledbrook g: +PeterLedbrook e: pledbrook@vmware.comWednesday, 2 May 12
  • 2. The Year in Grails • Grails 1.3 –Plugins in Dependency DSL, Groovy 1.7, Named Queries etc. • More and more plugins –Spring Security Core et al. –RabbitMQ –Gemfire –Resources, etc. • NoSQL –Redis, MongoDB, Riak, etc. 2Wednesday, 2 May 12
  • 3. High Profile Sites 3Wednesday, 2 May 12
  • 4. Grails Continued Growth Number of Plugins800600400200 0 2008 2009 2010 2011 4Wednesday, 2 May 12
  • 5. Development Environment FeaturesWednesday, 2 May 12
  • 6. New Console UI & Interactive Mode 6Wednesday, 2 May 12
  • 7. Better Unit Test Template 7Wednesday, 2 May 12
  • 8. Better Documentation Template 8Wednesday, 2 May 12
  • 9. Enhanced Error Reporting 9Wednesday, 2 May 12
  • 10. H2 Console • Available at http://localhost:8080/app/dbconsole in development only! 10Wednesday, 2 May 12
  • 11. Plugin Portal Usage Tracking • Opt-in usage tracking of plugins 11Wednesday, 2 May 12
  • 12. Upgraded Libraries 12Wednesday, 2 May 12
  • 13. New Automatic Reloading • Reloading in run-app works with – Typed service references – Domain classes – src/groovy, src/java • Any command with -reloading • Interactive mode and integration tests 13Wednesday, 2 May 12
  • 14. Binary Plugins • Package pre-compiled plugins into JAR files • Deployable as standard JARs to Maven repositories • Declared as JAR dependencies • Commercial plugins more viable • No special IDE integration needed $ grails package-plugin --binary 14Wednesday, 2 May 12
  • 15. Web FeaturesWednesday, 2 May 12
  • 16. Methods as Actions and Binding Arguments • Actions are now declared as public methods def save(String name, int age) { // remaining } • Form parameters bound to method arguments <g:form name="myForm" action="save"> <input name="name" /> <input name="age" /> </g:form> 16Wednesday, 2 May 12
  • 17. HTML5 Scaffolding 17Wednesday, 2 May 12
  • 18. New APIs • Page Rendering PageRenderer renderer void welcomeUser(User user) { def contents = renderer.render(view:"/emails/welcome", model:[user: user]) ... } • Link Generation LinkGenerator generator def generateLink() { generator.link(controller:"book", action:"list") } 18Wednesday, 2 May 12
  • 19. Servlet 3.0 Async • Servlet 3.0 async API supported for async response rendering def index() { def ctx = startAsync() ctx.start { new Book(title:"The Stand").save() render template:"books", model:[books: Book.list() ] ctx.complete() } } 19Wednesday, 2 May 12
  • 20. Advanced Static Resource Handling • Integrated resource plugin into core – http://grails.org/plugin/resources • Tuning static resources no longer a headache – gzip (http://grails.org/plugin/zipped-resources) – cache (http://grails.org/plugin/cached-resources) – de-duplication – bundling • New tags to ease integration – img – external – javascript 20Wednesday, 2 May 12
  • 21. Bundling Static Resources modules = { core { dependsOn utils resource url:/js/core.js, disposition: head resource url:/js/ui.js resource url:/css/main.css, resource url:/css/branding.css resource url:/css/print.css, attrs:[media:print] } utils { dependsOn jquery resource url:/js/utils.js } } 21Wednesday, 2 May 12
  • 22. Zipping and Caching $ grails install-plugin cached-resources $ grails install-plugin zipped-resources 22Wednesday, 2 May 12
  • 23. Other Web Novelties • jQuery now the default • Easy Date Parsing def val = params.date(myDate, dd-MM-yyyy) • Customizable URL formats • Filter exclusions 23Wednesday, 2 May 12
  • 24. Persistence FeaturesWednesday, 2 May 12
  • 25. GORM API • Plugins should not assume Hibernate! 25Wednesday, 2 May 12
  • 26. GORM Plugins • Redis - http://grails.org/plugin/redis-gorm • MongoDB - http://grails.org/plugin/mongodb • Amazon SimpleDB - http://grails.org/plugin/simpledb • Amazon DynamoDB - http://grails.org/plugin/dynamodb • Neo4j - http://grails.org/plugin/neo4j • Riak - http://grails.org/plugin/riak • GORM JPA - http://grails.org/plugin/gorm-jpa • Hibernate - http://grails.org/plugin/hibernate 26Wednesday, 2 May 12
  • 27. Where Queries • New, compile-time checked query DSL def query = Person.where { firstName == "Bart" } Person bart = query.find() • Uses native Groovy operators ==, !=, >, <, <=, >= etc def query = Person.where { firstName == "Fred" && !(lastName == Simpson) } • Aggregate functions supported avg, sum, max, min etc. def query = Person.where { age > avg(age) } 27Wednesday, 2 May 12
  • 28. Multiple Data Sources • Support for defining multiple scoped data sources class ZipCode { String code static mapping = { datasource auditing } } • Each data source accessible via static property def zipCode = ZipCode.auditing.get(42) 28Wednesday, 2 May 12
  • 29. SQL Database Migration Hibernate ‘update’ + Production data = ? 29Wednesday, 2 May 12
  • 30. SQL Database Migration • Install the Database Migration plugin: $ grails install-plugin database-migration • Official Docs at: – http://grails-plugins.github.com/grails-database-migration/ 30Wednesday, 2 May 12
  • 31. SQL Database Migration Pre-production, Hibernate ‘update’ or ‘create-drop’ dbm-generate-changelog dbm-changelog-sync Change domain model dbm-gorm-diff dbm-update 31Wednesday, 2 May 12
  • 32. SQL Reverse Engineering $ grails install-plugin db-reverse-engineer $ grails db-reverse-engineer class Person { String name Integer age ... } 32Wednesday, 2 May 12
  • 33. Other GORM Improvements • Abstract base domain classes – These now result in a table • findOrCreateWhere() • findOrSaveWhere() def user = User.findByLogin(admin) if (!user) { user = new User(login: admin) user.save(failOnError: true) } def user = User.findOrSaveWhere(login: admin) 33Wednesday, 2 May 12
  • 34. Better Unit TestingWednesday, 2 May 12
  • 35. Unit Testing 1.x • mockDomain() had only partial GORM support – always lagged changes in GORM • Inheritance-based – hierarchy duplicated for Spock – difficult to extend • Weak support for web-related testing – controllers – tag libraries 35Wednesday, 2 May 12
  • 36. The Mixin Approach @TestFor(MyController) @Mock(Person) class MyControllerUnitTests { void setUp() { new Person(...).save() new Person(...).save() } void testIndex() { def model = this.controller.index() ... } } 36Wednesday, 2 May 12
  • 37. Spockified @TestFor(MyController) @Mock(Person) class MyControllerUnitSpec extends Specification { void loadPeople() { new Person(...).save() new Person(...).save() } def Test index action() { given: Some people loadPeople() when: The index action is called def model = this.controller.index() then: The people variable is in the model model.people != null } } 37Wednesday, 2 May 12
  • 38. In-Memory GORM • Full GORM implementation against ConcurrentHashMap • Based on GORM for NoSQL codebase • Support for – Criteria queries – Where queries – Dynamic finders – Detached criteria 38Wednesday, 2 May 12
  • 39. Support for testing... • Tag libraries • Command objects • XML & JSON responses • File upload • View and template rendering • Filters • URL mappings • Criteria queries • and more! 39Wednesday, 2 May 12
  • 40. Contributions • 110+ pull requests on grails-core • 60+ pull requests on grails-docs • More and more plugins • GitHub for the win! – grails-core – grails-docs – grails-website – grails-maven – and many, many plugins 40Wednesday, 2 May 12
  • 41. Grails in the Cloud 41Wednesday, 2 May 12
  • 42. Roadmap 42Wednesday, 2 May 12
  • 43. Thank you! Questions? 43Wednesday, 2 May 12