66
What’s new in Grails 2.0?

What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Embed Size (px)

Citation preview

Page 1: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

What’s new in Grails 2.0?

Page 2: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

About me

• Jeff Brown• Grails Core Developer• SpringSource/VMware Engineer• [email protected]• @jeffscottbrown

2

Page 3: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

The Year in Grails

3

Page 4: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

The Year in Grails

• Grails 1.3–Plugins in Dependency DSL, Groovy 1.7, Named

Queries etc.

3

Page 5: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

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.

3

Page 6: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

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.

3

Page 7: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

High Profile Sites

4

Page 8: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Grails Continued Growth

5

0

150

300

450

600

2008 2009 2010 2011

Number of Plugins

Page 9: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Grails Continued Growth

5

0

150

300

450

600

2008 2009 2010 2011

Number of Plugins

Page 10: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

What’s new in Grails 2.0?

Page 11: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Development Environment Features

Page 12: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

New Console UI & Interactive Mode

8

Page 13: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Better Unit Test Template

9

Page 14: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Better Documentation Template

10

Page 15: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Enhanced Error Reporting

11

Page 16: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

H2 Console

• Available at http://localhost:8080/app/dbconsole in development only!

12

Page 17: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Upgraded Libraries

13

Page 18: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

New Automatic Reloading

14

Page 19: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

New Automatic Reloading

• Reloading in run-app works with–Typed service references–Domain classes–src/groovy, src/java

14

Page 20: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

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

15

$ grails package-plugin --binary

Page 21: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Web Features

Page 22: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Methods as Actions and Binding Arguments

• Actions are now declared as public methods

• Form parameters bound to method arguments

17

Page 23: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Methods as Actions and Binding Arguments

• Actions are now declared as public methods

• Form parameters bound to method arguments

17

def save(String name, int age) { // remaining}

Page 24: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Methods as Actions and Binding Arguments

• Actions are now declared as public methods

• Form parameters bound to method arguments

17

def save(String name, int age) { // remaining}

<g:form name="myForm" action="save"> <input name="name" /> <input name="age" /></g:form>

Page 25: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Methods as Actions and Binding Arguments

• Actions are now declared as public methods

• Form parameters bound to method arguments

17

def save(String name, int age) { // remaining}

Page 26: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

HTML5 Scaffolding

18

Page 27: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

New APIs

• Page Rendering

• Link Generation

19

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

LinkGenerator generatordef generateLink() { generator.link(controller:"book", action:"list")}

Page 28: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Other Web Novelties

• jQuery now the default • Easy Date Parsing

• Customizable URL formats• Filter exclusions

20

Page 29: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Other Web Novelties

• jQuery now the default • Easy Date Parsing

• Customizable URL formats• Filter exclusions

20

def val = params.date('myDate', 'dd-MM-yyyy')

Page 30: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Other Web Novelties

• jQuery now the default • Easy Date Parsing

• Customizable URL formats• Filter exclusions

20

Page 31: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Persistence Features

Page 32: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

GORM API

22

Page 33: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

GORM API

22

Page 34: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

GORM API

• Plugins should not assume Hibernate!

22

Page 35: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

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

23

Page 36: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Where Queries

• New, compile-time checked query DSL

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

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

24

Page 37: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Where Queries

• New, compile-time checked query DSL

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

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

24

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

Page 38: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Where Queries

• New, compile-time checked query DSL

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

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

24

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

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

Page 39: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Where Queries

• New, compile-time checked query DSL

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

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

24

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

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

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

Page 40: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Multiple Data Sources

• Support for defining multiple scoped data sources

• Each data source accessible via static property

25

Page 41: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Multiple Data Sources

• Support for defining multiple scoped data sources

• Each data source accessible via static property

25

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

Page 42: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Multiple Data Sources

• Support for defining multiple scoped data sources

• Each data source accessible via static property

25

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

def zipCode = ZipCode.auditing.get(42)

Page 43: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Other GORM Improvements

26

Page 44: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Other GORM Improvements

• Abstract base domain classes–These now result in a table

26

Page 45: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Other GORM Improvements

• Abstract base domain classes–These now result in a table

• findOrCreateWhere()

26

Page 46: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Other GORM Improvements

• Abstract base domain classes–These now result in a table

• findOrCreateWhere()• findOrSaveWhere()

26

Page 47: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Other GORM Improvements

• Abstract base domain classes–These now result in a table

• findOrCreateWhere()• findOrSaveWhere()

26

def user = User.findByLogin('admin')if (!user) { user = new User(login: 'admin') user.save(failOnError: true)}

def user = User.findOrSaveWhere(login: 'admin')

Page 48: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Better Unit Testing

Page 49: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Unit Testing 1.x

28

Page 50: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Unit Testing 1.x

• mockDomain() had only partial GORM support–always lagged changes in GORM

28

Page 51: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Unit Testing 1.x

• mockDomain() had only partial GORM support–always lagged changes in GORM

• Inheritance-based–hierarchy duplicated for Spock–difficult to extend

28

Page 52: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

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

28

Page 53: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

The Mixin Approach

29

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

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

Page 54: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Spockified

30

@TestFor(MyController)@Mock(Person)class MyControllerUnitTests 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 }}

Page 55: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

In-Memory GORM

• Full GORM implementation against ConcurrentHashMap• Based on GORM for NoSQL codebase• Support for

–Criteria queries–Where queries–Dynamic finders–Detached criteria

31

Page 56: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Contributions

32

Page 57: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Contributions

• 110+ pull requests on grails-core

32

Page 58: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Contributions

• 110+ pull requests on grails-core• 60+ pull requests on grails-docs

32

Page 59: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Contributions

• 110+ pull requests on grails-core• 60+ pull requests on grails-docs• More and more plugins

32

Page 60: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

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

32

Page 61: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Grails in the Cloud

33

Page 62: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Grails in the Cloud

33

Page 63: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Grails in the Cloud

33

Page 64: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Grails in the Cloud

33

Page 65: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

Roadmap

34

Page 66: What’s new in Grails 2.0? - chariotsolutions.comchariotsolutions.com/.../presentations/archive/613/grails2update.pdf · The Year in Grails • Grails 1.3 –Plugins in Dependency

35

Thank you!

Questions?