Slideshare.net (beta)

 
Post To TwitterPost to Twitter
Post: 
Myspace Hi5 Friendster Xanga LiveJournal Facebook Blogger Tagged Typepad Freewebs BlackPlanet gigya icons

All comments

Add a comment on Slide 1

If you have a SlideShare account, login to comment; else you can comment as a guest


Showing 1-50 of 2 (more)

Grails - What's the big deal?

From mcannonbrookes, 5 months ago

Presentation given at Sun Tech Days, Sydney 2008

856 views  |  0 comments  |  2 favorites
Download not available ?
 

Categories

Add Category
 
 
 
 

Groups / Events

 

 
Embed
options

More Info

This slideshow is Public
Total Views: 856
on Slideshare: 856
from embeds: 0

Slideshow transcript

Slide 1: Grails What’s the big deal? Mike Cannon-Brookes - mike@atlassian.com PRESENTATION EASTER EGGS >

Slide 2: Who am I? • Mike Cannon-Brookes - Co-Founder/CEO Atlassian - www.atlassian.com mike@atlassian.com - http://blogs.atlassian.com/rebelutionary • 10,000 enterprises use our products to power their development teams: JIRA - issue tracking, workflow & project management Confluence - world’s largest enterprise wiki Bamboo - continuous integration & build telemetry Crowd - Java SSO, identity management and OpenID Crucible - painless code review Fisheye - source code insight & communication Clover - world’s best code coverage ... all in pure Java. • Sun Java Champion (only one in Aus?) • OpenSymphony founder, OSS contributor • Author - Java Open Source Programming

Slide 3: What is Grails? • MVC Web Framework • Adapts the learnings from Ruby on Rails to Java world • Best of breed technology stack - pre- configured • A toolkit with flashy style and real depth • Get running fast - but run the distance!

Slide 4: Why Me? • I’ve used / written / contributed to lots of frameworks • Struts, WebWork, WW2, Spring... Grails! • I was asked to talk about ‘something exciting’ • Right now - that’s Grails • I’ve used Grails for ~24 hours - and it rocks!

Slide 5: Atlassian Fedex VII • Atlasbook - 42 screens, millions of rows of data, built in 24 hours Became “streams” in JIRA Studio http://www.jira.com • 361º - originally built in a ‘classic stack’ • Hibernate, Webwork, SiteMesh, Spring etc • 24 hours to get stack setup, basic actions, database etc • Rebuilt in 2 hours using Grails - from scratch

Slide 6: Philosophies 1. Convention over configuration • Always be able to get under the hood 2. Reuse, reuse, reuse 3. DRY - Don’t repeat yourself • No “reinventing the wheel”

Slide 7: Technology Stack • Groovy - agile, dynamic language for JVM • Java - world’s most used language • Hibernate - persistence, querying • Spring - IoC, DI, MVC, transactions • SiteMesh - page layout and composition

Slide 8: All this is in one instant start, pre-configured, pre-packaged box.

Slide 9: The best part?

Slide 10: You don’t care about what’s in the box...

Slide 11: ... until you do.

Slide 12: Demo

Slide 13: Grails Features

Slide 14: Groovy? • Think of Groovy as a ‘super set’ of Java • Compiles to bytecode, runs on the JVM • Extremely fast to develop in • Succinct, simple, modern syntax • Closures, default imports, native collections, native XML support, Groovy strings, simple regexes, safe navigation... • Easy for Java developers to learn

Slide 15: Groovy Examples // printing lines, string quotes // safe navigation println "he said 'cheese' once" variable?.doSomething() println 'he said "cheese!" again' def name // property = var + getter + setter // regex assert "cheesecheese" =~ "cheese" // list syntax def listA = [5, 6, 7, 8] def listB = 5..8 // closure assert listA.get(2) == 7 aaa = '"bread","apple","egg"' assert listB[2] == 7 items = aaa.split(',') assert items[1] == '"apple"' items.each{ println "item: $it" } // map syntax def map = [name:"Gromit", likes:"cheese", id:1234] assert map.name == "Gromit" assert map.id == 1234

Slide 16: Java! • Existing programmers and knowledge • eg need a servlet filter? Just add to web.xml like normal • Leverage existing code & libraries • Don’t underestimate this as an advantage! • Huge volume of tested, enterprise ready code in the Java world

Slide 17: Hibernate • De-facto standard O/R Mapping • In Grails, this becomes GORM • GORM maps domain classes automatically • Sensible defaults, always over-rideable • Automatic finder methods and querying • Convention over configuration • No more hibernate.cfg.xml

Slide 18: GORM Features • Simple POGOs for domain classes • Use your own .hbm.xml files for legacy • one:m and m:n support class Author { class Publisher { String firstName String name String lastName def hasMany= [books: Book] def hasMany= [books: Book] } } class Book { String title Author author Publisher publisher def belongsTo = [Publisher, Author] }

Slide 19: Constraints Validation class Author { String authorEmail static constraints = {authorEmail(email: • true)} Add an email to author } • class Book { Add an ISBN to book String isbn static constraints = { isbn(matches: "[0-9] • {9}[0-9X]") } Many types available } • blank, creditcard, email, inList, length, matches, max, min, nullable, range, size, unique, url, validator evenField(validator: { it % 2 == 0 } )

Slide 20: GORM Querying Dynamic finder methods Book.findByTitle("TheStand") Book.findByTitleLike("HarryPot%") Book.findByReleaseDateBetween(start, end) Book.findByTitleLikeOrReleaseDateLessThan("%Grails%", someDate) Find by relationship Book.findAllByAuthor( Author.get(1) ) Sorted results Book.findAllByAuthor( me, [sort: ‘title’, order: ‘asc’] )

Slide 21: GORM Querying Query By Example Book.find( new Book(title: ‘The Shining’) ) HQL Queries Book.find("from Book b where b.title like ‘Lord of%’") Book.find("from Book b where b.title like ?", [‘Lord of%’]) Criteria Builder def results = Book.createCriteria() { like("title", "Lord%") and{ between("price", 5, 20) eq("language", "English") } order("title", "desc") }.list()

Slide 22: No DAOs, just POGOs class Book { String title Author author Publisher publisher Date releaseDate long price String language String isbn def belongsTo = [Publisher, Author] static constraints = { isbn(matches: "[0-9]{9}[0-9X]") } } GORM handles all query types automagically.

Slide 23: Hibernate Integration • Specify your own hbm.xml files for your domain classes • You can even use your existing Java classes if you like • Working with legacy database schemas is getting really simple • Get benefits like dynamic finder methods

Slide 24: Spring Integration • Grails uses Spring MVC under the covers • All Grails objects autowired and wireable • You can put additional Spring configuration in the /spring directory and use it to configure your beans • Automatic DI is available even for these beans (not just Services) • Easily integrate existing (Java) functionality that was configured with Spring

Slide 25: Services • Promote separation of concerns • Get logic out of your controllers • As always, use grails create-service • Defined scopes, ie prototype, session, singleton • Injected into all other objects by convention: class BookController { def bookService // BookService instance will be injected ... }

Slide 26: AJAX • Grails supports AJAX with different toolkits, currently Prototype, Dojo and Yahoo • Special AJAX tags can be used for asynchronous calls and form submission <div id="message"><!-- Ajax result goes here --></div> <g:remoteLink action="delete" id="1" update="message"> Delete Book </g:remoteLink> • Lots of “niceties” to make life easy for developers <div id="message"><!-- Ajax result goes here --></div> <g:remoteLink action="delete" id="1" update="message" onLoading="showWaiting()" onComplete="hideWaiting()"> Delete Book </g:remoteLink>

Slide 27: AJAX • On the server side, Grails supports AJAX via the render() Method, which makes AJAX responses really easy: def time = { render(contentType:'text/xml') { time(new Date()) <time>(the current time)</time> } } def time = { render(contentType:'text/json') { time(new Date()) {time: "..." } } } • render() supports MarkupBuilders for XML, HTML, JSON, OpenRico

Slide 28: Plugins • Packaged, distributable extensions to Grails • Add new commands and features to framework in an extensible way • Simple to install and use, just like any other Grails feature - ie, to install and add a Quartz job: $> grails install-plugin quartz $> grails create-job MyJob

Slide 29: Job Scheduling • Grails makes using Quartz even easier • Jobs (like most plugins) are simple Groovy POGOs with conventions class MyJob { def cronExpression = "0,15,30,45 * * * * ?" //every 15 seconds def execute(){ println "Running job!" } }

Slide 30: Configuration • Everything is a Groovy ConfigSlurper file • Like properties, but with variable reuse and proper typing •/grails-app/config/Config.groovy • Examples are log4j configuration, datasources etc • 3 ‘environments’ like Rails: • development, test, production

Slide 31: DataSources • Pre-packaged to run out of the box with HSQL • Perfect for rapid development •/grails-app/config/ DataSource.groovy • Supports any J2EE datasource • Set up in Spring via ConfigSlurper for transactions etc.

Slide 32: Auto Reloading • In development mode, Grails synchronizes the current application with the server • Absolutely critical for rapid web development •No more 2 minute breaks in concentration for application server stop/start cycle • Controllers, GSPs, tag libraries, domain classes, database schema, services, Java code are all reloaded.

Slide 33: Eclipse Integration • Grails creates an Eclipse Project file automatically, just run File > Import > Existing Project • You'll have to tweak some file names if you use the development snapshot versions • Be sure to install the Groovy Plugin: http://groovy.codehaus.org/Eclipse+Plugin

Slide 34: Unit & Functional Testing • Both unit and functional testing supported • Functional Testing uses Canoo Webtest •“grails test-app” runs the unit tests •“grails run-webtest” • Generate a webtest with •“grails generate-webtest”

Slide 35: Enterprise? • Reuse, reuse, reuse • Existing Java libraries, employee skills & knowledge • Spring configured beans • Hibernate mappings for legacy schemas (free dynamic finders) • JSPs, taglibs, servlet filters etc • Deploy as WAR your existing J2EE infrastructure $> grails war

Slide 36: Thanks ... to all the characters behind Grails - you guys rock. Grails - try it today! http://grails.org

Slide 37: Q &A • Java guru? Tired of a boring corporate programming gig? Atlassian wants you. • See what we’re up to: blogs.atlassian.com/developer • What’s life like on Aus’ best Java team? www.atlassian.com/about/life.jsp • Atlassian - where VB is only in the fridge • Email: mike@atlassian.com