groovy & grails in depth - goto...
TRANSCRIPT
![Page 1: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/1.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Groovy & Grails in Depth
Simplifying Java EE with Grails
![Page 2: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/2.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Speaker’s qualifications
• Graeme Rocher is Head of Grails Development at SpringSource
• Graeme Rocher is author of “The Definitive Guide to Grails” 1st and 2nd Edition (Apress)
• Graeme Rocher leads the development of the Grails framework and is a core committer on the Groovy language
• Graeme Rocher speaks frequently at industry conferences on the subjects of Groovy and Grails
2
![Page 3: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/3.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 3
What is Groovy?
Groovy is a dynamic language for the Java Virtual Machine (JVM)Takes inspiration from Small Talk, Python and Ruby Integrates with the Java languageand platform at every level
![Page 4: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/4.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 4
What is Grails?
A Web platform that implements the full stack from build system down to ORM layerLeverages existing technologies like Spring, Hibernate, Quartz etc. avoiding re-inventing the wheelFeatures and extensible plug-in system and an environment for runtime configuration built on Spring
![Page 5: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/5.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 5
Solid Foundations
SpringHibernateGroovyQuartzSiteMeshJettyApache AntJava
![Page 6: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/6.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 6
Why Groovy & Grails?
All the power of frameworks from other platforms like Ruby on Rails, Django etc.Built from the ground up on Java technologies. • Design for Java by Java Developers
Leverage existing tools and technologies• Distributed caches, replicating technologies etc.• Profiling, monitoring and debugging tools
![Page 7: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/7.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 7
Grails Headline Features
GORM - ORM Layer built on HibernateRich conversation support with Web FlowDomain Specific Languages• Validation Rules• ORM Mapping• URL Mapping
Vibrant Plug-in community• http://grails.org/Plugins• Over 100 user contributed plug-ins• Everything from web services to RIA with Flex
![Page 8: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/8.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 8
Grails – The Platform
J2EE was too complex. Spring and Hibernate reduced that complexity and became very successfulGrails represents the next level of abstraction for the Java EE platform.Built on Spring and Hibernate, but simplifying their usage with Groovy
![Page 9: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/9.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 9
Getting Started
Download from http://grails.org/DownloadExtract zip to diskSet GRAILS_HOME variable to location on diskAdd $GRAILS_HOME/bin to your environment variables
Download from http://groovy.codehaus.orgExtract zip to diskSet GROOVY_HOME variable to location on diskAdd $GROOVY_HOME/bin to your environment variables
![Page 10: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/10.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 10
Grails – The Basics
Creating and Running
Grails will load by default with an in-memory HSQLDBThe default container is an embedded Jetty ContainerGrails is configured for automatic hot-reloading at runtime
WAR’ing and Deploying
Grails deploys as a standard WAR file deployable onto modern Java EE containers In production mode Grails is fully compiled byte code
> grails create-app gtunes> cd gtunes> grails run-app
> grails run-war // or> grails war
![Page 11: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/11.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Grails Demo
Getting to know Grails
![Page 12: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/12.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 12
Easy ORM with GORM
class Album { String title String artist Date releaseDate static hasMany = [songs:Song]}class Song { String title Double duration}
id title artist release_date
table - album
id title duration album_id
table - song
GORM classes, also known as domain classes, go in the domain directory
![Page 13: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/13.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 13
Dynamic Finders & Criteria
def albums = Album.list()
def recentAlbums = Album.findAllByReleaseDateGreaterThan(new Date()-7)
def albumsStartingWithA = Album.findAllByTitleLike("A%")
def albumsWithSongsAboutSummer = Album.withCriteria { songs { like("title", "%Summmer%") } }
List all records
Form method expressions
Use “like” queries
Construct criteria on the fly to query associations
![Page 14: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/14.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 14
GORM Features
Dynamic finder and persistence methodsCriteria with a Groovy builderObject-relational Mapping DSL• Caching• Legacy mapping• Locking strategy (optimistic/pessimistic)
Built on Hibernate
+
![Page 15: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/15.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 15
Easy MVC with Grails
Comprehensive MVC framework built on Spring• Command objects• Data binding• Zero configuration• URL Mappings• Groovy Server Pages (GSP) • Tag libraries• CRUD (Scaffolding)• Internationalization (i18n)
![Page 16: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/16.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 16
Grails Controllers
class AlbumController {
def search = { def albums= Album.findByTitleLike("%${params.q}%")
[albumResults:albums] }}
Controllers go in the “controllers” directory
Actions are properties assigned a block or closure
Return a model as a map
![Page 17: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/17.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Plugins - Extend & Conquer
17
Plugin Plugin Plugin Plugin
Grails Runtime Environment
GrailsApplication ApplicationContext
Read ConventionsRegister Bean Definitions
![Page 18: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/18.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
What plugins enable...
18
![Page 19: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/19.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
What plugins enable...
• Test Grails: selenium, fitnesse, code coverage etc.
18
![Page 20: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/20.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
What plugins enable...
• Test Grails: selenium, fitnesse, code coverage etc.
• Rich Grails: Flex, GWT, GrailsUI (YahooUI) etc.
18
![Page 21: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/21.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
What plugins enable...
• Test Grails: selenium, fitnesse, code coverage etc.
• Rich Grails: Flex, GWT, GrailsUI (YahooUI) etc.
• Secure Grails: Spring Security, JSecurity, OpenID etc.
18
![Page 22: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/22.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
What plugins enable...
• Test Grails: selenium, fitnesse, code coverage etc.
• Rich Grails: Flex, GWT, GrailsUI (YahooUI) etc.
• Secure Grails: Spring Security, JSecurity, OpenID etc.
• Integrate Grails: Search, Jasper Reports, JMS etc,
18
![Page 23: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/23.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Books
19
![Page 24: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/24.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 20
For More Information
Grails• Web Site: http://grails.org• User Guide: http://grails.org/doc/1.1.x/
Groovy• http://groovy.codehaus.org
SpringSource• http://www.springsource.com
![Page 25: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/25.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 21
Summary
Grails is not just a web framework, but a web platformGrails is the next generation abstraction of the Java EE platform built on Spring and HibernateGroovy and Grails integrate tightly with Java, the Java Virtual Machine at every level providing an easy migration pathGrails == Simplifying Java EE on the web
![Page 26: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/26.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Q & A
![Page 27: Groovy & Grails in Depth - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2009/slides/GraemeRocher_GrailsInDepth.pdf · Title: PRESENTATION TITLE UP TO A MAXIMUM OF THREE LINES FONT IS](https://reader034.vdocuments.us/reader034/viewer/2022042305/5ed0627595aabc20a95fc705/html5/thumbnails/27.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Thank You!