74
© 2010 SpringSource, A division of VMware. All rights reserved CONFIDENTIAL CONFIDENTIAL What's New in Grails 2.0 Burt Beckwith SpringSource

What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

  • Upload
    dokhue

  • View
    216

  • Download
    0

Embed Size (px)

Citation preview

Page 1: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

© 2010 SpringSource, A division of VMware. All rights reserved

CONFIDENTIALCONFIDENTIAL

What's New in Grails 2.0Burt Beckwith

SpringSource

Page 2: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

2CONFIDENTIAL 2CONFIDENTIAL

Who Am I

Java developer for over 12 years

Background in Spring, Hibernate, Spring Security

Grails developer for 4 years

SpringSource employee on the Grails team

Created or reworked over 35 Grails plugins

http://burtbeckwith.com/blog/

https://twitter.com/#!/burtbeckwith

Page 3: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

3CONFIDENTIAL 3CONFIDENTIAL

Development Environment Features

Page 4: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

4CONFIDENTIAL 4CONFIDENTIAL

New Console UI & Interactive Mode

Page 5: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

5CONFIDENTIAL 5CONFIDENTIAL

Better Unit Test Template

Page 6: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

6CONFIDENTIAL 6CONFIDENTIAL

Better Documentation Template

Page 7: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

7CONFIDENTIAL 7CONFIDENTIAL

Enhanced Error Reporting

Page 8: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

8CONFIDENTIAL 8CONFIDENTIAL

Database Console

Available at http://localhost:8080/appname/dbconsole in dev environment; can be enabled in other environments

Page 9: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

9CONFIDENTIAL 9CONFIDENTIAL

Plugin Portal Usage Tracking

Opt-in usage tracking of plugins

Page 10: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

10CONFIDENTIAL 10CONFIDENTIAL

Upgraded Libraries

Page 11: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

11CONFIDENTIAL 11CONFIDENTIAL

What's new in Groovy 1.8?

Page 12: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

12CONFIDENTIAL 12CONFIDENTIAL

What's new in Groovy 1.8?

Nicer DSLs with command chains expressions

Runtime performance improvements

GPars bundled

Closure enhancements

Builtin JSON support

New AST transformations

Page 13: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

13CONFIDENTIAL 13CONFIDENTIAL

Command Chains Expressions

Simple example:

• turn left then right• Was turn(left).then(right)

These are equivalent:

• take 2.pills, of: chloroquinine, after: 6.hours• take(2).pills(of).chloroquinine(after).6(hours)• take 2 pills of chloroquinine after 6 hours

Page 14: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

14CONFIDENTIAL 14CONFIDENTIAL

Runtime performance improvements

Significant runtime improvements for primitive type operations

• Classical Fibonacci example 13x faster!

• almost as fast as Java

Some direct method calls

Current work being done for static type checking

• http://blackdragsview.blogspot.com/2011/10/feeling-grumpy.html

Page 15: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

15CONFIDENTIAL 15CONFIDENTIAL

GPars bundled

GPars is bundled in the Groovy distribution

Covers a wide range of parallel and concurrent paradigms:

• Actors

• Fork/join

• Map/filter/reduce

• Dataflow

• Agents

• STM

• Parallel arrays

• Executors

• and more ...

Page 16: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

16CONFIDENTIAL 16CONFIDENTIAL

Closure enhancements

Closure annotation parameters

Some more functional flavor

• composition

• trampoline

• memoization

Currying improvements

Page 17: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

17CONFIDENTIAL 17CONFIDENTIAL

Closure annotation parameters

@Retention(RetentionPolicy.RUNTIME)@interface Invariant {   Class value() // a closure class}

@Invariant({number >= 0 })class Distance {   float number

String unit}

def d = new Distance(number: 10, unit: "meters")def anno = Distance.getAnnotation(Invariant)def check = anno.value().newInstance(d, d)assert check(d)

Page 18: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

18CONFIDENTIAL 18CONFIDENTIAL

Built in JSON support

Consuming

Producing

Pretty-printing

import groovy.json.*

def json = new JsonBuilder()json.person {   name 'Guillaume'   age 33   pets 'Hector', 'Felix'}println json.toString()println json.toPrettyString()

{"person":{"name":"Guillaume","age":33,"pets":"Hector","Felix"]}}{    "person": {        "name": "Guillaume",        "age": 33,        "pets": [            "Hector",            "Felix"        ]    }}

Page 19: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

19CONFIDENTIAL 19CONFIDENTIAL

New AST transformations

@Log

@Field

@AutoClone

@AutoExternalizable

@ThreadInterrupt,

@TimedInterrupt,

@ConditionalInterrupt

@InheritConstructor

@Canonical

• @ToString

• @EqualsAndHashCode

• @TupleConstructor

@WithReadLock

@WithWriteLock

Page 20: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

20CONFIDENTIAL 20CONFIDENTIAL

New Automatic Reloading

Page 21: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

21CONFIDENTIAL 21CONFIDENTIAL

New Automatic Reloading

Reloading in run-app works with

• Typed service references

• Domain classes

• src/groovy, src/java

Page 22: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

22CONFIDENTIAL 22CONFIDENTIAL

New Automatic Reloading

Reloading in run-app works with

• Typed service references

• Domain classes

• src/groovy, src/java

Any command with -reloading

Page 23: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

23CONFIDENTIAL 23CONFIDENTIAL

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

Page 24: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

24CONFIDENTIAL 24CONFIDENTIAL

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

Page 25: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

25CONFIDENTIAL 25CONFIDENTIAL

Web Features

Page 26: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

26CONFIDENTIAL 26CONFIDENTIAL

HTML5 Scaffolding

Page 27: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

27CONFIDENTIAL 27CONFIDENTIAL

New APIs

Page Rendering

Link Generation

PageRenderer groovyPageRenderervoid welcomeUser(User user) {   def contents = groovyPageRenderer.render(          view: "/emails/welcome",          model: [user: user])   ...}

LinkGenerator grailsLinkGeneratorString generateLink() {   grailsLinkGenerator.link(          controller: "book", action: "list")}

Page 28: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

28CONFIDENTIAL 28CONFIDENTIAL

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

Page 29: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

29CONFIDENTIAL 29CONFIDENTIAL

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'   }}

Page 30: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

30CONFIDENTIAL 30CONFIDENTIAL

Zipping and Caching

$ grails install­plugin cached­resources$ grails install­plugin zipped­resources

plugins {   runtime ":hibernate:$grailsVersion"   runtime ":jquery:1.7.1"   runtime ":resources:1.1.5"   build ":tomcat:$grailsVersion"

   runtime ":cached­resources:1.0"   runtime ":zipped­resources:1.0"}

Or add dependency in BuildConfig.groovy:

Page 31: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

31CONFIDENTIAL 31CONFIDENTIAL

Persistence Features

Page 32: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

32CONFIDENTIAL 32CONFIDENTIAL

GORM API

Page 33: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

33CONFIDENTIAL 33CONFIDENTIAL

GORM API

Page 34: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

34CONFIDENTIAL 34CONFIDENTIAL

GORM API

Plugins should not assume Hibernate is available

Page 35: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

35CONFIDENTIAL 35CONFIDENTIAL

GORM Plugins

Redis - http://grails.org/plugin/redis-gorm

MongoDB - http://grails.org/plugin/mongodb

Amazon SimpleDB - http://grails.org/plugin/simpledb

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

Page 36: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

36CONFIDENTIAL 36CONFIDENTIAL

Where Queries

Page 37: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

37CONFIDENTIAL 37CONFIDENTIAL

Where Queries

New, compile-time checked query DSL

def query = Person.where {   firstName == "Bart"}Person bart = query.find()

Page 38: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

38CONFIDENTIAL 38CONFIDENTIAL

Where Queries

New, compile-time checked query DSL

Uses native Groovy operators ==, !=, >, <, <=, >= etc.

def query = Person.where {   firstName == "Fred" && !(lastName == 'Simpson')}

def query = Person.where {   firstName == "Bart"}Person bart = query.find()

Page 39: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

39CONFIDENTIAL 39CONFIDENTIAL

Where Queries

New, compile-time checked query DSL

Uses native Groovy operators ==, !=, >, <, <=, >= etc.

Aggregate functions supported avg, sum, max, min etc.

def query = Person.where {   age > avg(age)}

def query = Person.where {   firstName == "Fred" && !(lastName == 'Simpson')}

def query = Person.where {   firstName == "Bart"}Person bart = query.find()

Page 40: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

40CONFIDENTIAL 40CONFIDENTIAL

Multiple Data Sources

Support for defining multiple scoped data sources

class ZipCode {   String code   static mapping = {      datasource 'auditing'   }}

Page 41: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

41CONFIDENTIAL 41CONFIDENTIAL

Multiple Data Sources

Support for defining multiple scoped data sources

Each data source accessible via static property

def zipCode = ZipCode.auditing.get(42)

class ZipCode {   String code   static mapping = {      datasource 'auditing'   }}

Page 42: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

42CONFIDENTIAL 42CONFIDENTIAL

SQL Database Migration

Hibernate 'update'+

Production data=

?

Page 43: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

43CONFIDENTIAL 43CONFIDENTIAL

SQL Database Migration

Hibernate 'update'+

Production data=

Page 44: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

44CONFIDENTIAL 44CONFIDENTIAL

GORM Plugins

Install the Database Migration plugin:

Official Docs at:

• http://grails-plugins.github.com/grails-database-migration/

$ grails install­plugin database­migration

Page 45: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

45CONFIDENTIAL 45CONFIDENTIAL

SQL Database Migration

Pre-production, Hibernate 'update' or 'create-drop'

Page 46: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

46CONFIDENTIAL 46CONFIDENTIAL

SQL Database Migration

Pre-production, Hibernate 'update' or 'create-drop'

dbm-generate-changelogdbm-changelog-sync

Page 47: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

47CONFIDENTIAL 47CONFIDENTIAL

SQL Database Migration

Pre-production, Hibernate 'update' or 'create-drop'

dbm-generate-changelogdbm-changelog-sync

Change domain model

dbm-gorm-diffdbm-update

Page 48: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

48CONFIDENTIAL 48CONFIDENTIAL

SQL Reverse Engineering

Page 49: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

49CONFIDENTIAL 49CONFIDENTIAL

SQL Reverse Engineering

$ grails install-plugin db-reverse-engineer$ grails db-reverse-engineer

Page 50: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

50CONFIDENTIAL 50CONFIDENTIAL

SQL Reverse Engineering

class Person {   String name   Integer age   Date dateCreated   ...}

$ grails install-plugin db-reverse-engineer$ grails db-reverse-engineer

Page 51: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

51CONFIDENTIAL 51CONFIDENTIAL

Other GORM Improvements

Abstract base domain classes

• These now result in a table

Page 52: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

52CONFIDENTIAL 52CONFIDENTIAL

Other GORM Improvements

Abstract base domain classes

• These now result in a table

findOrCreateWhere()

findOrSaveWhere()

Page 53: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

53CONFIDENTIAL 53CONFIDENTIAL

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)}

Page 54: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

54CONFIDENTIAL 54CONFIDENTIAL

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')

Page 55: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

55CONFIDENTIAL 55CONFIDENTIAL

Better Unit Testing

Page 56: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

56CONFIDENTIAL 56CONFIDENTIAL

Unit Testing Pre-2.0

Page 57: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

57CONFIDENTIAL 57CONFIDENTIAL

Unit Testing Pre-2.0

• mockDomain() had only partial GORM support

• always lagged changes in GORM

Page 58: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

58CONFIDENTIAL 58CONFIDENTIAL

Unit Testing Pre-2.0

• mockDomain() had only partial GORM support

• always lagged changes in GORM

Inheritance-based

• hierarchy duplicated for Spock

• difficult to extend

Page 59: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

59CONFIDENTIAL 59CONFIDENTIAL

Unit Testing Pre-2.0

• 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

Page 60: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

60CONFIDENTIAL 60CONFIDENTIAL

The Mixin Approach

@TestFor(MyController)@Mock(Person)class MyControllerUnitTests {   protected void setUp() {      new Person(...).save()      new Person(...).save()   }

   void testIndex() {      def model = controller.index()      ...   }}

Page 61: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

61CONFIDENTIAL 61CONFIDENTIAL

Support for testing...

Page 62: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

62CONFIDENTIAL 62CONFIDENTIAL

Support for testing...

Tag libraries

Page 63: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

63CONFIDENTIAL 63CONFIDENTIAL

Support for testing...

Tag libraries

Command objects

Page 64: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

64CONFIDENTIAL 64CONFIDENTIAL

Support for testing...

Tag libraries

Command objects

XML & JSON responses

Page 65: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

65CONFIDENTIAL 65CONFIDENTIAL

Support for testing...

Tag libraries

Command objects

XML & JSON responses

File upload

Page 66: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

66CONFIDENTIAL 66CONFIDENTIAL

Support for testing...

Tag libraries

Command objects

XML & JSON responses

File upload

View and template rendering

Page 67: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

67CONFIDENTIAL 67CONFIDENTIAL

Support for testing...

Tag libraries

Command objects

XML & JSON responses

File upload

View and template rendering

Filters

Page 68: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

68CONFIDENTIAL 68CONFIDENTIAL

Support for testing...

Tag libraries

Command objects

XML & JSON responses

File upload

View and template rendering

Filters

URL mappings

Page 69: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

69CONFIDENTIAL 69CONFIDENTIAL

Support for testing...

Tag libraries

Command objects

XML & JSON responses

File upload

View and template rendering

Filters

URL mappings

Criteria queries

Page 70: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

70CONFIDENTIAL 70CONFIDENTIAL

Support for testing...

Tag libraries

Command objects

XML & JSON responses

File upload

View and template rendering

Filters

URL mappings

Criteria queries

and more!

Page 71: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

71CONFIDENTIAL 71CONFIDENTIAL

Grails in the Cloud

Page 72: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

72CONFIDENTIAL 72CONFIDENTIAL

For the Future

A continued focus on

•Reliability

•User experience

•Modularity

•More cloud

Page 73: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

73CONFIDENTIAL 73CONFIDENTIAL

Demo

Page 74: What's New in Grails 2 - Burt Beckwithburtbeckwith.com/blog/files/1150/NEJUG_Grails_2012.pdf · What's New in Grails 2.0 Burt Beckwith SpringSource. CONFIDENTIAL 2 Who Am I ... What's

74CONFIDENTIAL 74CONFIDENTIAL

Thank You

Questions?