grails 2.0 update
Post on 01-Sep-2014
2.896 Views
Preview:
DESCRIPTION
TRANSCRIPT
What’s new in 2.0
t: @pledbrookg: +PeterLedbrooke: pledbrook@vmware.com
Peter LedbrookSpringSource
Wednesday, 2 May 12
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.
2
Wednesday, 2 May 12
High Profile Sites
3
Wednesday, 2 May 12
Grails Continued Growth
4
0
200
400
600
800
2008 2009 2010 2011
Number of Plugins
Wednesday, 2 May 12
Development Environment Features
Wednesday, 2 May 12
New Console UI & Interactive Mode
6
Wednesday, 2 May 12
Better Unit Test Template
7
Wednesday, 2 May 12
Better Documentation Template
8
Wednesday, 2 May 12
Enhanced Error Reporting
9
Wednesday, 2 May 12
H2 Console
• Available at http://localhost:8080/app/dbconsole in development only!
10
Wednesday, 2 May 12
Plugin Portal Usage Tracking
• Opt-in usage tracking of plugins
11
Wednesday, 2 May 12
Upgraded Libraries
12
Wednesday, 2 May 12
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
13
Wednesday, 2 May 12
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
14
$ grails package-plugin --binary
Wednesday, 2 May 12
Web Features
Wednesday, 2 May 12
Methods as Actions and Binding Arguments
• Actions are now declared as public methods
• Form parameters bound to method arguments
16
def save(String name, int age) { // remaining}
<g:form name="myForm" action="save"> <input name="name" /> <input name="age" /></g:form>
Wednesday, 2 May 12
HTML5 Scaffolding
17
Wednesday, 2 May 12
New APIs
• Page Rendering
• Link Generation
18
PageRenderer renderervoid welcomeUser(User user) { def contents = renderer.render(view:"/emails/welcome", model:[user: user]) ...}
LinkGenerator generatordef generateLink() { generator.link(controller:"book", action:"list")}
Wednesday, 2 May 12
Servlet 3.0 Async
• Servlet 3.0 async API supported for async response rendering
19
def index() { def ctx = startAsync() ctx.start { new Book(title:"The Stand").save() render template:"books", model:[books: Book.list() ] ctx.complete() }}
Wednesday, 2 May 12
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
20
Wednesday, 2 May 12
Bundling Static Resources
21
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' }}
Wednesday, 2 May 12
Zipping and Caching
22
$ grails install-plugin cached-resources
$ grails install-plugin zipped-resources
Wednesday, 2 May 12
Other Web Novelties
• jQuery now the default • Easy Date Parsing
• Customizable URL formats• Filter exclusions
23
def val = params.date('myDate', 'dd-MM-yyyy')
Wednesday, 2 May 12
Persistence Features
Wednesday, 2 May 12
GORM API
• Plugins should not assume Hibernate!
25
Wednesday, 2 May 12
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
26
Wednesday, 2 May 12
Where Queries
• New, compile-time checked query DSL
• Uses native Groovy operators ==, !=, >, <, <=, >= etc
• Aggregate functions supported avg, sum, max, min etc.
27
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)}
Wednesday, 2 May 12
Multiple Data Sources
• Support for defining multiple scoped data sources
• Each data source accessible via static property
28
class ZipCode { String code static mapping = { datasource 'auditing' }}
def zipCode = ZipCode.auditing.get(42)
Wednesday, 2 May 12
?
SQL Database Migration
29
Hibernate ‘update’+
Production data=
Wednesday, 2 May 12
SQL Database Migration
• Install the Database Migration plugin:
• Official Docs at:–http://grails-plugins.github.com/grails-database-migration/
30
$ grails install-plugin database-migration
Wednesday, 2 May 12
SQL Database Migration
31
Pre-production, Hibernate ‘update’ or ‘create-drop’
dbm-generate-changelogdbm-changelog-sync
Change domain model
dbm-gorm-diffdbm-update
Wednesday, 2 May 12
SQL Reverse Engineering
32
class Person { String name Integer age ...}
$ grails install-plugin db-reverse-engineer$ grails db-reverse-engineer
Wednesday, 2 May 12
Other GORM Improvements
• Abstract base domain classes–These now result in a table
• findOrCreateWhere()• findOrSaveWhere()
33
def user = User.findByLogin('admin')if (!user) { user = new User(login: 'admin') user.save(failOnError: true)}
def user = User.findOrSaveWhere(login: 'admin')
Wednesday, 2 May 12
Better Unit Testing
Wednesday, 2 May 12
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
35
Wednesday, 2 May 12
The Mixin Approach
36
@TestFor(MyController)@Mock(Person)class MyControllerUnitTests { void setUp() { new Person(...).save() new Person(...).save() }
void testIndex() { def model = this.controller.index() ... }}
Wednesday, 2 May 12
Spockified
37
@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 }}
Wednesday, 2 May 12
In-Memory GORM
• Full GORM implementation against ConcurrentHashMap• Based on GORM for NoSQL codebase• Support for
–Criteria queries–Where queries–Dynamic finders–Detached criteria
38
Wednesday, 2 May 12
Support for testing...
• Tag libraries• Command objects• XML & JSON responses• File upload• View and template rendering• Filters• URL mappings• Criteria queries• and more!
39
Wednesday, 2 May 12
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
40
Wednesday, 2 May 12
Grails in the Cloud
41
Wednesday, 2 May 12
Roadmap
42
Wednesday, 2 May 12
43
Thank you!
Questions?
Wednesday, 2 May 12
top related