SlideShare a Scribd company logo
1 of 97
www.devoxx.com
Groovy & Grails in Action!

     Guillaume Laforge
     Groovy Project Manager


     Head of Groovy Development



                 www.devoxx.com
Overall Presentation Goal

Discover the Groovy dynamic language for the JVM
 Understand how you can create DSLs in Groovy
 Getting productive with the Grails agile web stack




                       www.devoxx.com
Guillaume Laforge
 Groovy Project Manager
 JSR-241 Spec Lead
 Head of Groovy Development
 at SpringSource
 Initiator of the Grails framework
 Co-author of Groovy in Action
 Speaker at numerous conferences
  JavaOne, QCon, JavaZone, Sun TechDays, JavaPolis,
  The Spring Experience, JAX, Dynamic Language World...

  4                         www.devoxx.com
G2One / SpringSource
 Back in 2007, Graeme Rocher and Guillaume Laforge
 created G2One, the Groovy/Grails company
 Professional services
      consulting, expertise, training, support
 Last november, SpringSource acquired G2One




  5                            www.devoxx.com
Groovy in Action

     A bit of history and background
           Groovy syntax basics
         Interesting Groovy APIs
      Domain-Specific Languages
       What’s new in Groovy 1.6?
         The Groovy Ecosystem


                  www.devoxx.com
James Strachan to Bob McWhirter in 2003:
        Wouldn’t it be “groovy” if we could have
       native syntax for lists, maps and regexs
        in Java like in most scripting languages?
             Wouldn’t it be “groovy” if we
           could have duck typing in Java?
           Wouldn’t it be “groovy” if we had
           closures and properties in Java?




                        www.devoxx.com
Groovy agenda
 A bit of history and
 background
 Syntax basics
 Interesting Groovy APIs
 Domain-Specific Languages
 What’s new in Groovy 1.6?
 The Groovy ecosystem



                        www.devoxx.com
Groovy is...
 Groovy is a dynamic language for the JVM
 Groovy directly compiles down to bytecode
 Inspired by other languages: Python, Ruby, Smalltalk
 Whose goal is to simplify the life of developers
 Apache 2 licensed Open Source project
 hosted at Codehaus
 Grammar directly deriving from the Java 5 language
 support for annotations, generics, enums, static imports

  9                       www.devoxx.com
Groovy is everywhere
 Integrated in Open Source projects
 Spring, JBoss SEAM, ServiceMix, Mule, Oracle OC4J
 Integrated in mission-critical applications
 Mutual of Omaha, US Fortune 500 insurance company
 US National Cancer Institute
 Integrated in commercial products
 IBM WebSphere Smash, SAP Composition on Grails
 Oracle Data Integrator, Oracle Fusion (ADF)

  10                      www.devoxx.com
Lots of books to read




 11           www.devoxx.com
Features at a glance
 Totally object-oriented
 Optional typing
 No need to wait for Java 7 / 8 / 9:
  Closures: reusable / assignable code blocks
  Properties: auto-generated getters / setters
 Multimethods: call the right method for the right type
 BigDecimal arithmetics
 Useful wrapper APIs: SQL, XML, Swing, templates, JMX...

  12                        www.devoxx.com
Java integration
 Groovy generates Java bytecode for the JVM
 Same strings, same regex
 Same APIs — JDK, collections, 3rd party, etc.
 Same security model, same threading model
 Same OO concepts                         JInterface    GInterface

 Joint-compilation                   <<implements>>    <<implements>>


                                           GClass         JClass




                                           JClass         GClass

  13                     www.devoxx.com
Let’s get started
 Go to http://groovy.codehaus.org/Download
 Download the latest version
 Groovy 1.5.7 — maintenance branch
 Groovy 1.6-beta-2 — soon to be released
 Unzip the archive, set GROOVY_HOME
 Add $GROOVY_HOME/bin to your path


 You’re ready!

  14                      www.devoxx.com
Tools at your disposal
 Shell and console: groovysh and groovyConsole
 An Ant task, a Maven plugin (GMaven)
 A joint compiler
 Lets you compile both Groovy and Java together!
 IDE support




  15                     www.devoxx.com
DEMO
Groovy shell
Groovy console




                 www.devoxx.com
Groovy agenda
 A bit of history and
 background
 Syntax basics
 Interesting Groovy APIs
 Domain-Specific Languages
 What’s new in Groovy 1.6?
 The Groovy ecosystem



                        www.devoxx.com
A Java program
public class HelloWorld {
     private String name;

          public void setName(String name) {
              this.name = name;
          }

          public String getName() {
              return name;
          }

          public String greet() {
              return quot;Hello quot;+ name;
          }

          public static void main(String[] args) {
              HelloWorld helloWorld = new HelloWorld();
              helloWorld.setName(quot;Groovyquot;);
              System.out.println( helloWorld.greet() );
          }
 }


     18                                www.devoxx.com
A Groovy program
public class HelloWorld {
     private String name;

          public void setName(String name) {
              this.name = name;
          }

          public String getName() {
              return name;
          }

          public String greet() {
              return quot;Hello quot;+ name;
          }

          public static void main(String[] args) {
              HelloWorld helloWorld = new HelloWorld();
              helloWorld.setName(quot;Groovyquot;);
              System.out.println( helloWorld.greet() );
          }
 }


     19                                www.devoxx.com
DEMO
From Java to Groovy




                      www.devoxx.com
A groovier version

 class HelloWorld {
     String name
     String greet() { quot;Hello $namequot; }
 }

 def helloWorld = new HelloWorld(name: quot;Groovyquot;)
 println helloWorld.greet()




 21                   www.devoxx.com
Native syntax constructs
 Lists
  def numbers = [1, 2, 3, 4, 5]
 Maps
  def map = [FR: “France”, BE: “Belgium”]
 Ranges
  def allowedAges = 18..65

 Regular expressions
  def whitespace = ~/s+?/

  22                   www.devoxx.com
Groovy Strings	
 GStrings: interpolated strings
  def person = “John”
  def letter = “““${new Date()}
      Dear ${person},
      this is a Groovy letter!”””
  println letter
 Multiline strings: triple single or double quotes
 Slashy syntax
  def whitespace = ~/s+?/


  23                        www.devoxx.com
Closures
 A reusable / assignable block of code
 delimited by curly braces
 can take parameters
 can be passed as parameters to methods, or inline
 def printer = { println it }
 def double = { int i -> 2 * i }
 new File(“f.txt”).eachLine { line ->
     println line
 }
 new File(“f.txt”).eachLine( printer )

  24                         www.devoxx.com
Time savers
 The Groovy Truth
  def blank = “”; assert !blank
  def empty = []; assert !empty
 Safe graph navigation
  def order = null
  assert order?.customer?.address == null
 Elvis operator
  def name = customer.name ?: “Unknown”



  25                     www.devoxx.com
Java 5 features
 Since Groovy 1.5
 Annotations, generics, static imports, enums, varargs


 You can leverage frameworks supporting annotations
 Spring, Hibernate, Guice, JPA, EJB3, TestNG, and more


 Sole dynamic language supporting annotations



  26                      www.devoxx.com
Annotation example
 @Entity
 @Name(“hotel”)
 class Hotel implements Serializable {
     @Id @GeneratedValue
     Long id

      @Length(max = 40) @NotNull
      String name

      @Override String toString() {
          “Hotel ${name}”
      }
 }

 27                  www.devoxx.com
Groovy agenda
 A bit of history and
 background
 Syntax basics
 Interesting Groovy APIs
 Domain-Specific Languages
 What’s new in Groovy 1.6?
 The Groovy ecosystem



                        www.devoxx.com
The GDK — Groovy Dev Kit
 Groovy “decorates” existing JDK APIs
 We can’t extend java.lang.String or java.io.File, can we?
 new File(“f.txt”).eachLine { println it }
 (1..100).findAll { it % 2 == 1 }
 speakers.groupBy { it.lastname }
 “123”.padLeft(5, ‘0’)
 “ls -la”.execute()
 “R3Jvb3Z5IHJvY2tzIQ==”.decodeBase64()
 Thread.start { /* code to be executed */ }


  29                      www.devoxx.com
JDBC made easy
With transparent resource handling, thanks to closures
 def sql = Sql.newInstance(url, usr, pwd, driver)
 sql.execute(quot;insert into table values ($foo, $bar)quot;)
 sql.execute(quot;insert into table values(?,?)quot;, [a, b])
 sql.eachRow(quot;select * from USERquot;) { print it.name }
 def list = sql.rows(quot;select * from USERquot;)




A poor-man’s dataset notion
 def set = sql.dataSet(quot;USERquot;)
 set.add(name: quot;Johnnyquot;, age: 33)
 set.each { user -> println user.name }
 set.findAll { it.age > 22 && it.age < 42 }




 30                        www.devoxx.com
Parsing XML
 With this multiline string XML fragment
       def xml = quot;quot;quot;
       <languages>
         <language name=quot;Groovyquot;>
           <feature coolness=quot;lowquot;>SQL</feature>
           <feature coolness=quot;highquot;>Template</feature>
         </language>
         <language name=quot;Perlquot;/>
       </languages>quot;quot;quot;

 Navigate your XML graph as an object graph!
       def root = new XmlParser().parseText(xml)
       println root.language.feature[1].text()

       root.language.feature
           .findAll{ it['@coolness'] == quot;lowquot; }
            .each{ println it.text() }

  31                            www.devoxx.com
Producing XML too!
 The same XML document as before
 new MarkupBuilder().languages {
     language(name: quot;Groovyquot;) {
         feature(coolness: quot;lowquot;, quot;SQLquot;)
         feature(coolness: quot;highquot;, quot;Templatequot;)
     }
     language(name: quot;Perlquot;)
 }




  32                       www.devoxx.com
Swing builder
 Following the same “builder pattern”, but for Swing
 import javax.swing.WindowConstants as WC
 import groovy.swing.SwingBuilder
 def theMap = [color: quot;greenquot;, object: quot;pencilquot;]
 def swing = new SwingBuilder()
 def frame = swing.frame(
     title: 'A Groovy Swing', location: [240,240],
     defaultCloseOperation:WC.EXIT_ON_CLOSE) {
     panel {
         for (entry in theMap) {
              label(text: entry.key)
              textField(text: entry.value)
         }
         button(text: 'About', actionPerformed: {
              def pane = swing.optionPane(message: 'SwingBuilder')
              def dialog = pane.createDialog(null, 'About')
              dialog.show()
         })
         button(text:'Quit', actionPerformed:{ System.exit(0) })
     }
 }
 frame.pack()
 frame.show()
  33                               www.devoxx.com
Swing builder
 Following the same “builder pattern”, but for Swing
 import javax.swing.WindowConstants as WC
 import groovy.swing.SwingBuilder
 def theMap = [color: quot;greenquot;, object: quot;pencilquot;]
 def swing = new SwingBuilder()
 def frame = swing.frame(
     title: 'A Groovy Swing', location: [240,240],
     defaultCloseOperation:WC.EXIT_ON_CLOSE) {
     panel {
         for (entry in theMap) {
              label(text: entry.key)
              textField(text: entry.value)
         }
         button(text: 'About', actionPerformed: {
              def pane = swing.optionPane(message: 'SwingBuilder')
              def dialog = pane.createDialog(null, 'About')
              dialog.show()
         })
         button(text:'Quit', actionPerformed:{ System.exit(0) })
     }
 }
 frame.pack()
 frame.show()
  33                               www.devoxx.com
Another builder with Ant
 Reuse the wealth of Ant tasks for your build or system
 scripting needs
 // create sequantial Ant execution
 new AntBuilder().sequential {
     def buildClasses = “build/classes”

       // create classes directory
       mkdir(dir: buildClasses)

       // compile sources
       javac(srcdir: “src”,
            destdir: buildClasses)

       // jar everything
       jar(destfile: “my.jar”,
            basedir: buildClasses)
 }


  34                         www.devoxx.com
Groovy agenda
 A bit of history and
 background
 Syntax basics
 Interesting Groovy APIs
 Domain-Specific Languages
 What’s new in Groovy 1.6?
 The Groovy ecosystem



                        www.devoxx.com
What’s a DSL?
 A Domain-Specific Language is a small language
 designed to be useful for a specific set of tasks, for a
 given domain
 Not necessarily Turing-complete
 Produces some result
  configuration, data structures, simulation declarations...
 Can be internal or external
 Has a form: textual or visual


  36                       www.devoxx.com
Some examples
Technical
 SELECT * FROM USERS WHERE NAME LIKE ‘Guil%’
 ^[w-.]+@([w-]+.)+[w-]{2,4}$
Notation
 1. e4 e5 2. Nf3 Nc6 3. Bb5 a6
 U R’ U2 R U R’ U R
Business oriented
 Risk calculation for insurance policies
 Human Resources employee skills representation
 Anti-malaria drug resistance simulation
 37                         www.devoxx.com
Towards more readability (1/2)




 38           www.devoxx.com
Towards more readability (1/2)




 38           www.devoxx.com
Towards more readability (1/2)




                               20%




 38           www.devoxx.com
Towards more readability (2/2)




 39           www.devoxx.com
Towards more readability (2/2)




 39           www.devoxx.com
Towards more readability (2/2)




                               80%




 39           www.devoxx.com
Groovy’s MOP to the rescue
 DSLs are possible in Groovy because of
 Groovy’s malleable syntax and APIs
       Omitting parentheses, semi-columns
       Named arguments, Closures
       Everything is an object
 Groovy’s dynamic nature
       MOP: Meta-Object Protocol
        Nothing hard-wired,
        behavior modifiable at runtime!
  40                             www.devoxx.com
Parentheses & named args
 Optional parentheses
 move left
 Named arguments
 compare fund: ‘XYZ’, withIndicator: ‘NIKEI’
 account.debit amount: 30.euros, in: 3.days
 Plus native syntax elements
 Lists: [NIKEI, CAC40, NASDAK]
 Maps: [CA: ‘California’, CO: ‘Colorado’]
 Ranges: Monday..Friday
  41                      www.devoxx.com
DEMO
Adding properties to
numbers
Categories
ExpandoMetaClass




                       www.devoxx.com
Operator overloading
Operators are a shorcut
for method calls
a + b == a.plus(b)

a - b == a.minus(b)

a * b == a.multiply(b)

a / b == a.divide(b)

a % b == a.modulo(b)

a | b == a.or(b)

a & b == a.and(b)

a[b] == a.getAt(b)

a << b == a.leftShift(b)
  43                       www.devoxx.com
Operator overloading
Operators are a shorcut     Currency arithmetics
for method calls
                                    30.euros + 15.dollars
a + b == a.plus(b)
                            Distances
a - b == a.minus(b)

a * b == a.multiply(b)              12.kilometers + 3.meters
a / b == a.divide(b)           Parallelism or workflow
a % b == a.modulo(b)
                                  taskA & taskB | taskC
a | b == a.or(b)
                               Banking
a & b == a.and(b)

a[b] == a.getAt(b)                account += 10.euros
a << b == a.leftShift(b)
  43                       www.devoxx.com
Closures and builders
 Remember the builder pattern? Ant, Swing, Markup...
 You can easily create your own
 Extend BuilderSupport or FactoryBuilderSupport
 Nested method calls with closures as last argument
 plan {
     artifact {
         name = ‘spring.core’
         type = ‘bundle’
         version = ‘2.5.6’
     }
 }
  44                      www.devoxx.com
Why creating your own DSL?
 Use a more expressive language than a general purpose
 Share a common metaphore between developers and
 subject matter experts
 Have domain experts help with the design of the
 business logic of an application
 Avoid cluttering business code with too much boilerplate
 technical code
 Cleanly separate business logic from application code
 Let business rules have their own lifecycle

  45                       www.devoxx.com
Groovy agenda
 A bit of history and
 background
 Syntax basics
 Interesting Groovy APIs
 Domain-Specific Languages
 What’s new in Groovy 1.6?
 The Groovy ecosystem



                        www.devoxx.com
Groovy 1.6
 Main focus on performance
 to make Groovy the fastest dynamic language
 Multiple assignment
 def (a, b) = [1, 2]
 def (int i, String s) = [1, ‘Groovy’]
 (a, b) = functionReturningAList()
 AST Transformations
 @Lazy, @Immutable, @Singleton, @Delegate
 Annotation definition

  47                    www.devoxx.com
Groovy agenda
 A bit of history and
 background
 Syntax basics
 Interesting Groovy APIs
 Domain-Specific Languages
 What’s new in Groovy 1.6?
 The Groovy ecosystem



                        www.devoxx.com
More than just Groovy...
 First major Groovy child: Grails, but there’s more...
  Griffon: a Grails-like MVC framework for building rich
  Swing applications
  Gradle: a new build system learning from the good ideas
  and mistakes of Ant, Maven and Ivy
  Easyb: a Behavior Driven Development toolkit which lets
  you write user stories with a Groovy DSL


 All three will be presented at Devoxx, check your agenda!

  49                        www.devoxx.com
Groovy Summary
The Groovy dynamic language for the JVM simplifies the
life of developers
Groovy opens up some interesting perspectives towards
extending and enhancing your applications
Groovy provides the most seamless Java integration
experience
Groovy lets you create Domain-Specific Languages
Groovy protects your investment in skills, tools, libraries
and application servers


 50                       www.devoxx.com
Grails in Action

          A bit of history and background
                   The Grails stack
           Getting started with scaffolding
The layers: persistence, controllers & services, views
                The plugin ecosystem
              What’s new in Grails 1.1?


                        www.devoxx.com
Grails agenda
 A bit of history and
 background
 The Grails stack
 Getting started with
 scaffolding
 The various layers
 The plugin ecosystem
 What’s new in Grails 1.1?


                        www.devoxx.com
Guillaume Laforge on the Groovy lists in 2005:
    Ruby on Rails is all the rage these days, but you
 compromise on your past investment, if you’re a Java
 shop: developer and IT team skills, training, app servers,
      the great JVM platform, third-party libraries...
Can’t we leverage Groovy and proven technologies like
 Spring and Hibernate to bring the “Convention over
 Configuration” paradigm on the Java platform, without
           compromising on your investment?




                          www.devoxx.com
The Holy Grail(s)
 Observation: lack of productivity in webapp development
 We have all the tools at our disposal to change that
 Back in 2005, Graeme Rocher, Steven Devijsver and
 myself launched Grails
  Apache licensed OSS project, hosted at Codehaus
 Goal similar to Groovy: simplify the life of developers
 So what’s under the hood?




  54                       www.devoxx.com
Grails agenda
 A bit of history and
 background
 The Grails stack
 Getting started with
 scaffolding
 The various layers
 The plugin ecosystem
 What’s new in Grails 1.1?


                        www.devoxx.com
From 10,000 feet
 Grails is an MVC action-based framework


 Grails follows good principles popularized by Rails
 CoC: Convention over Configuration
 DRY: Don’t Repeat Yourself


 The essence of Rails but with tight integration with the
 Java platform to protect your investment!


  56                       www.devoxx.com
From 1,000 feet



             =
       +                      +

 57          www.devoxx.com
Near the ground...
 Grails is built on rock-solid and proven technologies
 the JVM, the Java EE specs, existing app servers, and...
       Spring: IoC, DI, Spring MVC, Spring WebFlow
       Hibernate: Object-Relational Mapping
       SiteMesh: page layout and composition
       Quartz: for job scheduling
       Jetty and HSQLDB: for fast development cycles
 Productive out of the box with a full development stack

  58                           www.devoxx.com
Grails agenda
 A bit of history and
 background
 The Grails stack
 Getting started with
 scaffolding
 The various layers
 The plugin ecosystem
 What’s new in Grails 1.1?


                        www.devoxx.com
First step, download & install
 Go to http://grails.org/Download
 Download the latest archive
 Unzip it somewhere
 Create GRAILS_HOME
 Add $GRAILS_HOME/bin to your PATH


 You’re ready to go!
 Next step: grails create-app

  60                      www.devoxx.com
DEMO
Getting started
with scaffolding


Remember scaffolding is nice for CRUD,
admin interfaces, prototyping, getting up
and running quickly, but Grails is more
than just a CRUD framework!




                                  www.devoxx.com
Layout and naming convention




 62          www.devoxx.com
Did you notice?
Where are my configuration files?
Why haven’t I written any XML file?
Where are my DAOs?
Where are my mapping files?
No database to configure?
Nor a servlet container or
app server to install?
Or tons of jars to download
from Maven repositories?
There must be some magic under the hood :-)
                              www.devoxx.com
Grails agenda
 A bit of history and
 background
 The Grails stack
 Getting started with
 scaffolding
 The various layers
 The plugin ecosystem
 What’s new in Grails 1.1?


                        www.devoxx.com
The usual problems
 When you start a project, you have to setup everything
  The build, wire all components together


 You suffer from impedance mismatch
  You have to handle the ORM mapping manually


 It’s hard to write clean views
  Taglibs are a pain to develop

  65                        www.devoxx.com
Persistence
 Enters GORM: Grails Object Relational Mapping
 Hibernate under the hood
 Your domain model is a set of POGOs
 Your domain classes are transparentely mapped
 Although you can use legacy schemas with GORM DSL
 No conf: hibernate.cfg.xml, no *.hbm.xml files!
 But you can bring your own existing ones if needed
 Always a path to configuration when in need

  66                      www.devoxx.com
Persistence
 Enters GORM: Grails Object Relational Mapping
 Hibernate under the hood                  Not limited by
 Your domain model is a set of POGOs       conventions?

 Your domain classes are transparentely mapped
 Although you can use legacy schemas with GORM DSL
 No conf: hibernate.cfg.xml, no *.hbm.xml files!
 But you can bring your own existing ones if needed
 Always a path to configuration when in need

  66                      www.devoxx.com
Dynamic finders
 All domain classes have got injected methods like
 Book.count(), Book.list(), Book.get(id)
 book.save(), book.delete(), etc...
 Dynamic finders
 Book.findByTitle(“Harry Potter”)
 Book.findAllByAuthorLike(“%Rowlins”)
 Book.findAllByTitleLikeAndReleaseDateLessThan(
     ‘%Grails%’, 2007
 ) // don’t do that :-)




  67                       www.devoxx.com
Dynamic finders
 All domain classes have got injected methods like
 Book.count(), Book.list(), Book.get(id)
 book.save(), book.delete(), etc...
 Dynamic finders
 Book.findByTitle(“Harry Potter”)
 Book.findAllByAuthorLike(“%Rowlins”)
 Book.findAllByTitleLikeAndReleaseDateLessThan(
     ‘%Grails%’, 2007
 ) // don’t do that :-)


                                            Where’s
                                            my DAO?

  67                       www.devoxx.com
Queries
 You can use raw HQL queries
 Book.find(“from Book b where b.title = ?”, [‘Shining’])


 Grails wraps the Hibernate Criteria API
 def results = Account.list {
     like “holderFirstName”, “Fred%”
     and {
         between “balance”, 500, 1000
         eq “branch”, “London”
     }
     order “holderLastName”, “desc”
 }



  68                       www.devoxx.com
Constraints
 Constraints can be added to domain classes
 through a static constraints field
 static constraints = {
     isbn matches: /[0-9]{9}[0-9X]/
 }
 Many constraints available
 blank, creditcard, email, nullable, matches, range, unique
 Create your own validator
 myIntField = { it % 2 == 0 }
 You can also register your own constraints
  69                         www.devoxx.com
Controllers
 In the controller directory, name ending with Controller
  http://myserver:8080/app/controller/action
 Handy things at your disposal
  redirect, chain, render, flash scope
 Controllers return Maps as models for the view to render
  Possible access to the raw output stream
 Easy databinding from form fields
  book.properties = params

  70                        www.devoxx.com
Controllers
 In the controller directory, name ending with Controller
  http://myserver:8080/app/controller/action
                                                        a d
 Handy things at your disposal
                                                  e lo
  redirect, chain, render, flash scope          R
 Controllers return Maps as models for the view to render
  Possible access to the raw output stream
 Easy databinding from form fields
  book.properties = params

  70                        www.devoxx.com
Services
 Another naming convention and placement


 Transactional by default


 Just declare your service, it’ll be transparently injected!
  no need to configure it in some XML fle




  71                         www.devoxx.com
The view tier
 The view tier is essentially composed of two things
 The Groovy Server Pages
       Similar to JSPs
       But with GString interpolation
 The Grails Tag Libraries
       Useful existing tag libraries
       So easy to write your own!
 Templates, URL mapping, conversations and more

  72                             www.devoxx.com
GSPs
  Auto-reloading
<html>
    <head>
        <meta name=quot;layoutquot; content=quot;mainquot; />
        <title>Book List</title>
    </head>
    <body>
        <a href=quot;${createLinkTo(dir:'')}quot;>Home</a>
        <g:link action=quot;createquot;>New Book</g:link>
        <g:if test=quot;${flash.message}quot;>
            ${flash.message}
        </g:if>
        <g:each in=quot;${bookList}quot;>${it.title}</g:each>
    </body>
</html>




    73                        www.devoxx.com
GSPs
  Auto-reloading
<html>
                                                            a d
    <head>
                                                        e lo
                                                   R
        <meta name=quot;layoutquot; content=quot;mainquot; />
        <title>Book List</title>
    </head>
    <body>
        <a href=quot;${createLinkTo(dir:'')}quot;>Home</a>
        <g:link action=quot;createquot;>New Book</g:link>
        <g:if test=quot;${flash.message}quot;>
            ${flash.message}
        </g:if>
        <g:each in=quot;${bookList}quot;>${it.title}</g:each>
    </body>
</html>




    73                        www.devoxx.com
Taglibs
 Lots of existing taglibs
  Logical: if, else, elseif
  Iterative: each, collect, findAll
  Linking: createLink, createLinkTo
  Ajax: remoteLink, remoteForm, remoteFunction
  Form: select, datePicker, currencySelect
  Validation: hasError, eachError
  UI: rich text editor

  74                          www.devoxx.com
Create your own taglib
 Yet another Grails convention
 class MyTaglib {
     def isAdmin = { attrs, body ->
         def user = attrs[‘user’]
         if (user && checkUserPrivs(user)) {
             body()
         }
     }
 }

 Use it in your GSP
 <g:isAdmin user=”${user}”>
     Some restricted content
  75                      www.devoxx.com
Create your own taglib
 Yet another Grails convention
 class MyTaglib {
     def isAdmin = { attrs, body ->
         def user = attrs[‘user’]
         if (user && checkUserPrivs(user)) {
             body()
         }
     }
                                                a d
 }
                                            e lo
 Use it in your GSP                        R
 <g:isAdmin user=”${user}”>
     Some restricted content
  75                      www.devoxx.com
Custom URL mappings
Not satisfied with the default URL mapping?
 Define your URLs yourself!


class UrlMapping {
    static mappings = {
        “$blog/$yeah?/$month?/$day?” (controller: ‘blog’,
                                          action: ‘show’) {
            constraints {
                year matches: /d{4}/
            }
        }
    }
}



 76                        www.devoxx.com
What have I not shown?
 Conversation concept using Spring WebFlow
 Templates for reusing view logic and presentation
 Internationalization
 You can reuse JSP tag libraries (in Grails 1.1)
 SiteMesh layouts and page componentization
 Handling of REST style architecture
 Unit and integration tests
 Reuse legacy schemas
 or Spring configurations
  77                          www.devoxx.com
What have I not shown?
 Conversation concept using Spring WebFlow
 Templates for reusing view logic and presentation
 Internationalization
 You can reuse JSP tag libraries (in Grails 1.1)
 SiteMesh layouts and page componentization
 Handling of REST style architecture
 Unit and integration tests                    Not limited by
                                               conventions?
 Reuse legacy schemas
 or Spring configurations
  77                          www.devoxx.com
Grails agenda
 A bit of history and
 background
 The Grails stack
 Getting started with
 scaffolding
 The various layers
 The plugin ecosystem
 What’s new in Grails 1.1?


                        www.devoxx.com
A wealth of plugins
 Grails is built on top of a core plugin system
 100+ plugins already available
 Testing: Webtest, Easyb, Selenium, jsUnit, Fitnesse
 Rich client / AJAX: Yahoo, Ext-JS, GWT, jQuery, iUI
 Web Services: XFire, remoting, Axis2, Metro
 Security: Spring Security, JSecurity
 Search: Compass integration
 Other integration: Drools, Struts, GridGain, Terracotta

  79                        www.devoxx.com
Grails agenda
 A bit of history and
 background
 The Grails stack
 Getting started with
 scaffolding
 The various layers
 The plugin ecosystem
 What’s new in Grails 1.1?


                        www.devoxx.com
Grails 1.1
 JSP tag library support and reuse
 New GORM events
 Improvements to data binding
 Read-only access to domain objects
 More options for the GORM DSL
 Improvements to dynamic finders
 More support for legacy mappings
 New testing plugin included for easier testing

  81                       www.devoxx.com
Grails Summary
 Grails is not just a web framework,
 but a full-blown development stack
 Grails is not a clone of Ruby on Rails
 Grails is built on proven rock-solid technologies
 Grails brings back the productivity to Java developers
 Grails is a new weapon for the war on Java complexity




  82                        www.devoxx.com
Q&A




      www.devoxx.com
Thanks for your attention!

        http://groovy.codehaus.org
               http://grails.org
   http://www.springsource.com/g2one
     http://glaforge.free.fr/blog/groovy

           glaforge@gmail.com


                   www.devoxx.com
Pictures from the web used in this presentation:

      Question marks: http://weblogs.newsday.com
              Agenda: http://www.jouy.inra.fr
               Mop: http://www.spitjack.com
Harry Potter: http://madhavgopalkrish.files.wordpress.com




                         www.devoxx.com

More Related Content

What's hot

AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokusHamletDRC
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
 
Challenges of container configuration
Challenges of container configurationChallenges of container configuration
Challenges of container configurationlutter
 
Jersey framework
Jersey frameworkJersey framework
Jersey frameworkknight1128
 
Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Hermann Hueck
 
Embedding Groovy in a Java Application
Embedding Groovy in a Java ApplicationEmbedding Groovy in a Java Application
Embedding Groovy in a Java ApplicationPaolo Predonzani
 
10 Cool Facts about Gradle
10 Cool Facts about Gradle10 Cool Facts about Gradle
10 Cool Facts about GradleEvgeny Goldin
 
Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Anton Arhipov
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoinknight1128
 
Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Sylvain Wallez
 
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -Kenji Tanaka
 
Designing with Groovy Traits - Gr8Conf India
Designing with Groovy Traits - Gr8Conf IndiaDesigning with Groovy Traits - Gr8Conf India
Designing with Groovy Traits - Gr8Conf IndiaNaresha K
 
XML-Free Programming
XML-Free ProgrammingXML-Free Programming
XML-Free ProgrammingStephen Chin
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...go_oh
 
ClojureScript: The Good Parts
ClojureScript: The Good PartsClojureScript: The Good Parts
ClojureScript: The Good PartsKent Ohashi
 
Bytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMBytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMashleypuls
 

What's hot (20)

AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Challenges of container configuration
Challenges of container configurationChallenges of container configuration
Challenges of container configuration
 
Jersey framework
Jersey frameworkJersey framework
Jersey framework
 
Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8
 
Embedding Groovy in a Java Application
Embedding Groovy in a Java ApplicationEmbedding Groovy in a Java Application
Embedding Groovy in a Java Application
 
groovy & grails - lecture 12
groovy & grails - lecture 12groovy & grails - lecture 12
groovy & grails - lecture 12
 
10 Cool Facts about Gradle
10 Cool Facts about Gradle10 Cool Facts about Gradle
10 Cool Facts about Gradle
 
Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!
 
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
 
groovy & grails - lecture 5
groovy & grails - lecture 5groovy & grails - lecture 5
groovy & grails - lecture 5
 
Designing with Groovy Traits - Gr8Conf India
Designing with Groovy Traits - Gr8Conf IndiaDesigning with Groovy Traits - Gr8Conf India
Designing with Groovy Traits - Gr8Conf India
 
NIO and NIO2
NIO and NIO2NIO and NIO2
NIO and NIO2
 
XML-Free Programming
XML-Free ProgrammingXML-Free Programming
XML-Free Programming
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
 
ClojureScript: The Good Parts
ClojureScript: The Good PartsClojureScript: The Good Parts
ClojureScript: The Good Parts
 
Bytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMBytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASM
 

Viewers also liked

レガシーコード改善はじめました 横浜道場
レガシーコード改善はじめました 横浜道場レガシーコード改善はじめました 横浜道場
レガシーコード改善はじめました 横浜道場Hiroyuki Ohnaka
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Tomek Kaczanowski
 
The outlineoftestprocess
The outlineoftestprocessThe outlineoftestprocess
The outlineoftestprocesskyon mm
 
うさぎ組 in G* WorkShop -うさみみの日常-
うさぎ組 in G* WorkShop -うさみみの日常-うさぎ組 in G* WorkShop -うさみみの日常-
うさぎ組 in G* WorkShop -うさみみの日常-kyon mm
 
AgileJapan2010 基調講演:野中郁次郎先生による「実践知のリーダシップ~スクラムと知の場作り」
AgileJapan2010 基調講演:野中郁次郎先生による「実践知のリーダシップ~スクラムと知の場作り」AgileJapan2010 基調講演:野中郁次郎先生による「実践知のリーダシップ~スクラムと知の場作り」
AgileJapan2010 基調講演:野中郁次郎先生による「実践知のリーダシップ~スクラムと知の場作り」Kenji Hiranabe
 
Groovy 1.8の新機能について
Groovy 1.8の新機能についてGroovy 1.8の新機能について
Groovy 1.8の新機能についてUehara Junji
 
Groovier testing with Spock
Groovier testing with SpockGroovier testing with Spock
Groovier testing with SpockRobert Fletcher
 
Spock Framework 2
Spock Framework 2Spock Framework 2
Spock Framework 2Ismael
 
Groovy Testing Aug2009
Groovy Testing Aug2009Groovy Testing Aug2009
Groovy Testing Aug2009guest4a266c
 
Groovy, Transforming Language
Groovy, Transforming LanguageGroovy, Transforming Language
Groovy, Transforming LanguageUehara Junji
 
Androidリリース作業の効率化(2)
Androidリリース作業の効率化(2)Androidリリース作業の効率化(2)
Androidリリース作業の効率化(2)Kenichi Kambara
 
Spock Framework
Spock FrameworkSpock Framework
Spock FrameworkIsmael
 
Spock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestSpock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestHoward Lewis Ship
 
GradleによるG*なビルドシステムの構築
GradleによるG*なビルドシステムの構築GradleによるG*なビルドシステムの構築
GradleによるG*なビルドシステムの構築Masatoshi Hayashi
 
Jenkinsを用いたAndroidアプリビルド作業効率化
Jenkinsを用いたAndroidアプリビルド作業効率化Jenkinsを用いたAndroidアプリビルド作業効率化
Jenkinsを用いたAndroidアプリビルド作業効率化Kenichi Kambara
 
Jenkinsプラグイン開発
Jenkinsプラグイン開発Jenkinsプラグイン開発
Jenkinsプラグイン開発Takahisa Wada
 
function list
function listfunction list
function listkyon mm
 

Viewers also liked (20)

レガシーコード改善はじめました 横浜道場
レガシーコード改善はじめました 横浜道場レガシーコード改善はじめました 横浜道場
レガシーコード改善はじめました 横浜道場
 
Spockを使おう!
Spockを使おう!Spockを使おう!
Spockを使おう!
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010
 
The outlineoftestprocess
The outlineoftestprocessThe outlineoftestprocess
The outlineoftestprocess
 
うさぎ組 in G* WorkShop -うさみみの日常-
うさぎ組 in G* WorkShop -うさみみの日常-うさぎ組 in G* WorkShop -うさみみの日常-
うさぎ組 in G* WorkShop -うさみみの日常-
 
AgileJapan2010 基調講演:野中郁次郎先生による「実践知のリーダシップ~スクラムと知の場作り」
AgileJapan2010 基調講演:野中郁次郎先生による「実践知のリーダシップ~スクラムと知の場作り」AgileJapan2010 基調講演:野中郁次郎先生による「実践知のリーダシップ~スクラムと知の場作り」
AgileJapan2010 基調講演:野中郁次郎先生による「実践知のリーダシップ~スクラムと知の場作り」
 
Groovy 1.8の新機能について
Groovy 1.8の新機能についてGroovy 1.8の新機能について
Groovy 1.8の新機能について
 
Groovier testing with Spock
Groovier testing with SpockGroovier testing with Spock
Groovier testing with Spock
 
Spock Framework 2
Spock Framework 2Spock Framework 2
Spock Framework 2
 
Groovy Testing Aug2009
Groovy Testing Aug2009Groovy Testing Aug2009
Groovy Testing Aug2009
 
Jenkins導入ライブ
Jenkins導入ライブJenkins導入ライブ
Jenkins導入ライブ
 
Groovy, Transforming Language
Groovy, Transforming LanguageGroovy, Transforming Language
Groovy, Transforming Language
 
Androidリリース作業の効率化(2)
Androidリリース作業の効率化(2)Androidリリース作業の効率化(2)
Androidリリース作業の効率化(2)
 
Spock Framework
Spock FrameworkSpock Framework
Spock Framework
 
Spock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestSpock: A Highly Logical Way To Test
Spock: A Highly Logical Way To Test
 
GradleによるG*なビルドシステムの構築
GradleによるG*なビルドシステムの構築GradleによるG*なビルドシステムの構築
GradleによるG*なビルドシステムの構築
 
Jenkinsを用いたAndroidアプリビルド作業効率化
Jenkinsを用いたAndroidアプリビルド作業効率化Jenkinsを用いたAndroidアプリビルド作業効率化
Jenkinsを用いたAndroidアプリビルド作業効率化
 
Jenkinsプラグイン開発
Jenkinsプラグイン開発Jenkinsプラグイン開発
Jenkinsプラグイン開発
 
How about Gradle?
How about Gradle?How about Gradle?
How about Gradle?
 
function list
function listfunction list
function list
 

Similar to Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge

2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Wsloffenauer
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Guillaume Laforge
 
Groovy a Scripting Language for Java
Groovy a Scripting Language for JavaGroovy a Scripting Language for Java
Groovy a Scripting Language for JavaCharles Anderson
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGuillaume Laforge
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneAndres Almiray
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applicationsrohitnayak
 
Eclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To GroovyEclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To GroovyAndres Almiray
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyJames Williams
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingAndres Almiray
 
Groovy And Grails Introduction
Groovy And Grails IntroductionGroovy And Grails Introduction
Groovy And Grails IntroductionEric Weimer
 
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyAndres Almiray
 
Groovy and Grails
Groovy and GrailsGroovy and Grails
Groovy and GrailsGiltTech
 
Introduction To Groovy
Introduction To GroovyIntroduction To Groovy
Introduction To Groovymanishkp84
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...Guillaume Laforge
 
Groovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applicationsGroovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applicationsIndicThreads
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsTobias Oetiker
 
Groovy Finesse
Groovy FinesseGroovy Finesse
Groovy Finessemzgubin
 

Similar to Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge (20)

2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
What's New in Groovy 1.6?
What's New in Groovy 1.6?What's New in Groovy 1.6?
What's New in Groovy 1.6?
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
 
Groovy a Scripting Language for Java
Groovy a Scripting Language for JavaGroovy a Scripting Language for Java
Groovy a Scripting Language for Java
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applications
 
Eclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To GroovyEclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To Groovy
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
 
Groovy And Grails Introduction
Groovy And Grails IntroductionGroovy And Grails Introduction
Groovy And Grails Introduction
 
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with Groovy
 
Groovy and Grails
Groovy and GrailsGroovy and Grails
Groovy and Grails
 
OpenLogic
OpenLogicOpenLogic
OpenLogic
 
Introduction To Groovy
Introduction To GroovyIntroduction To Groovy
Introduction To Groovy
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
 
Groovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applicationsGroovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applications
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial Handouts
 
Groovy Finesse
Groovy FinesseGroovy Finesse
Groovy Finesse
 

More from Guillaume Laforge

Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Guillaume Laforge
 
Groovy workshop à Mix-IT 2013
Groovy workshop à Mix-IT 2013Groovy workshop à Mix-IT 2013
Groovy workshop à Mix-IT 2013Guillaume Laforge
 
Les nouveautés de Groovy 2 -- Mix-IT 2013
Les nouveautés de Groovy 2 -- Mix-IT 2013Les nouveautés de Groovy 2 -- Mix-IT 2013
Les nouveautés de Groovy 2 -- Mix-IT 2013Guillaume Laforge
 
Groovy 2.0 update at Devoxx 2012
Groovy 2.0 update at Devoxx 2012Groovy 2.0 update at Devoxx 2012
Groovy 2.0 update at Devoxx 2012Guillaume Laforge
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Guillaume Laforge
 
Groovy update at SpringOne2GX 2012
Groovy update at SpringOne2GX 2012Groovy update at SpringOne2GX 2012
Groovy update at SpringOne2GX 2012Guillaume Laforge
 
Groovy 1.8 et 2.0 au BreizhC@mp 2012
Groovy 1.8 et 2.0 au BreizhC@mp 2012Groovy 1.8 et 2.0 au BreizhC@mp 2012
Groovy 1.8 et 2.0 au BreizhC@mp 2012Guillaume Laforge
 
Groovy 1.8 and 2.0 at GR8Conf Europe 2012
Groovy 1.8 and 2.0 at GR8Conf Europe 2012Groovy 1.8 and 2.0 at GR8Conf Europe 2012
Groovy 1.8 and 2.0 at GR8Conf Europe 2012Guillaume Laforge
 
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume Laforge
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume LaforgeGroovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume Laforge
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume LaforgeGuillaume Laforge
 
Going to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGoing to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGuillaume Laforge
 
Groovy 2.0 - Devoxx France 2012
Groovy 2.0 - Devoxx France 2012Groovy 2.0 - Devoxx France 2012
Groovy 2.0 - Devoxx France 2012Guillaume Laforge
 
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011Guillaume Laforge
 
GPars et PrettyTime - Paris JUG 2011 - Guillaume Laforge
GPars et PrettyTime - Paris JUG 2011 - Guillaume LaforgeGPars et PrettyTime - Paris JUG 2011 - Guillaume Laforge
GPars et PrettyTime - Paris JUG 2011 - Guillaume LaforgeGuillaume Laforge
 
Groovy Update - Guillaume Laforge - Greach 2011
Groovy Update - Guillaume Laforge - Greach 2011Groovy Update - Guillaume Laforge - Greach 2011
Groovy Update - Guillaume Laforge - Greach 2011Guillaume Laforge
 
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011Gaelyk update - Guillaume Laforge - SpringOne2GX 2011
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011Guillaume Laforge
 
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...Guillaume Laforge
 

More from Guillaume Laforge (20)

Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013
 
Groovy workshop à Mix-IT 2013
Groovy workshop à Mix-IT 2013Groovy workshop à Mix-IT 2013
Groovy workshop à Mix-IT 2013
 
Les nouveautés de Groovy 2 -- Mix-IT 2013
Les nouveautés de Groovy 2 -- Mix-IT 2013Les nouveautés de Groovy 2 -- Mix-IT 2013
Les nouveautés de Groovy 2 -- Mix-IT 2013
 
Groovy 2 and beyond
Groovy 2 and beyondGroovy 2 and beyond
Groovy 2 and beyond
 
Groovy 2.0 update at Devoxx 2012
Groovy 2.0 update at Devoxx 2012Groovy 2.0 update at Devoxx 2012
Groovy 2.0 update at Devoxx 2012
 
Groovy 2.0 webinar
Groovy 2.0 webinarGroovy 2.0 webinar
Groovy 2.0 webinar
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012
 
Groovy update at SpringOne2GX 2012
Groovy update at SpringOne2GX 2012Groovy update at SpringOne2GX 2012
Groovy update at SpringOne2GX 2012
 
JavaOne 2012 Groovy update
JavaOne 2012 Groovy updateJavaOne 2012 Groovy update
JavaOne 2012 Groovy update
 
Groovy 1.8 et 2.0 au BreizhC@mp 2012
Groovy 1.8 et 2.0 au BreizhC@mp 2012Groovy 1.8 et 2.0 au BreizhC@mp 2012
Groovy 1.8 et 2.0 au BreizhC@mp 2012
 
Groovy 1.8 and 2.0 at GR8Conf Europe 2012
Groovy 1.8 and 2.0 at GR8Conf Europe 2012Groovy 1.8 and 2.0 at GR8Conf Europe 2012
Groovy 1.8 and 2.0 at GR8Conf Europe 2012
 
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume Laforge
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume LaforgeGroovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume Laforge
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume Laforge
 
Going to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGoing to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific Languages
 
Groovy 2.0 - Devoxx France 2012
Groovy 2.0 - Devoxx France 2012Groovy 2.0 - Devoxx France 2012
Groovy 2.0 - Devoxx France 2012
 
Whats new in Groovy 2.0?
Whats new in Groovy 2.0?Whats new in Groovy 2.0?
Whats new in Groovy 2.0?
 
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011
 
GPars et PrettyTime - Paris JUG 2011 - Guillaume Laforge
GPars et PrettyTime - Paris JUG 2011 - Guillaume LaforgeGPars et PrettyTime - Paris JUG 2011 - Guillaume Laforge
GPars et PrettyTime - Paris JUG 2011 - Guillaume Laforge
 
Groovy Update - Guillaume Laforge - Greach 2011
Groovy Update - Guillaume Laforge - Greach 2011Groovy Update - Guillaume Laforge - Greach 2011
Groovy Update - Guillaume Laforge - Greach 2011
 
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011Gaelyk update - Guillaume Laforge - SpringOne2GX 2011
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011
 
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...
 

Recently uploaded

AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxFIDO Alliance
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!Memoori
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityVictorSzoltysek
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch TuesdayIvanti
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightSafe Software
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...ScyllaDB
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxFIDO Alliance
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTopCSSGallery
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfalexjohnson7307
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024Lorenzo Miniero
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data SciencePaolo Missier
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxFIDO Alliance
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfdanishmna97
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...ScyllaDB
 
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...SOFTTECHHUB
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfSrushith Repakula
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...FIDO Alliance
 

Recently uploaded (20)

AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 

Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge

  • 2. Groovy & Grails in Action! Guillaume Laforge Groovy Project Manager Head of Groovy Development www.devoxx.com
  • 3. Overall Presentation Goal Discover the Groovy dynamic language for the JVM Understand how you can create DSLs in Groovy Getting productive with the Grails agile web stack www.devoxx.com
  • 4. Guillaume Laforge Groovy Project Manager JSR-241 Spec Lead Head of Groovy Development at SpringSource Initiator of the Grails framework Co-author of Groovy in Action Speaker at numerous conferences JavaOne, QCon, JavaZone, Sun TechDays, JavaPolis, The Spring Experience, JAX, Dynamic Language World... 4 www.devoxx.com
  • 5. G2One / SpringSource Back in 2007, Graeme Rocher and Guillaume Laforge created G2One, the Groovy/Grails company Professional services consulting, expertise, training, support Last november, SpringSource acquired G2One 5 www.devoxx.com
  • 6. Groovy in Action A bit of history and background Groovy syntax basics Interesting Groovy APIs Domain-Specific Languages What’s new in Groovy 1.6? The Groovy Ecosystem www.devoxx.com
  • 7. James Strachan to Bob McWhirter in 2003: Wouldn’t it be “groovy” if we could have native syntax for lists, maps and regexs in Java like in most scripting languages? Wouldn’t it be “groovy” if we could have duck typing in Java? Wouldn’t it be “groovy” if we had closures and properties in Java? www.devoxx.com
  • 8. Groovy agenda A bit of history and background Syntax basics Interesting Groovy APIs Domain-Specific Languages What’s new in Groovy 1.6? The Groovy ecosystem www.devoxx.com
  • 9. Groovy is... Groovy is a dynamic language for the JVM Groovy directly compiles down to bytecode Inspired by other languages: Python, Ruby, Smalltalk Whose goal is to simplify the life of developers Apache 2 licensed Open Source project hosted at Codehaus Grammar directly deriving from the Java 5 language support for annotations, generics, enums, static imports 9 www.devoxx.com
  • 10. Groovy is everywhere Integrated in Open Source projects Spring, JBoss SEAM, ServiceMix, Mule, Oracle OC4J Integrated in mission-critical applications Mutual of Omaha, US Fortune 500 insurance company US National Cancer Institute Integrated in commercial products IBM WebSphere Smash, SAP Composition on Grails Oracle Data Integrator, Oracle Fusion (ADF) 10 www.devoxx.com
  • 11. Lots of books to read 11 www.devoxx.com
  • 12. Features at a glance Totally object-oriented Optional typing No need to wait for Java 7 / 8 / 9: Closures: reusable / assignable code blocks Properties: auto-generated getters / setters Multimethods: call the right method for the right type BigDecimal arithmetics Useful wrapper APIs: SQL, XML, Swing, templates, JMX... 12 www.devoxx.com
  • 13. Java integration Groovy generates Java bytecode for the JVM Same strings, same regex Same APIs — JDK, collections, 3rd party, etc. Same security model, same threading model Same OO concepts JInterface GInterface Joint-compilation <<implements>> <<implements>> GClass JClass JClass GClass 13 www.devoxx.com
  • 14. Let’s get started Go to http://groovy.codehaus.org/Download Download the latest version Groovy 1.5.7 — maintenance branch Groovy 1.6-beta-2 — soon to be released Unzip the archive, set GROOVY_HOME Add $GROOVY_HOME/bin to your path You’re ready! 14 www.devoxx.com
  • 15. Tools at your disposal Shell and console: groovysh and groovyConsole An Ant task, a Maven plugin (GMaven) A joint compiler Lets you compile both Groovy and Java together! IDE support 15 www.devoxx.com
  • 17. Groovy agenda A bit of history and background Syntax basics Interesting Groovy APIs Domain-Specific Languages What’s new in Groovy 1.6? The Groovy ecosystem www.devoxx.com
  • 18. A Java program public class HelloWorld { private String name; public void setName(String name) { this.name = name; } public String getName() { return name; } public String greet() { return quot;Hello quot;+ name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName(quot;Groovyquot;); System.out.println( helloWorld.greet() ); } } 18 www.devoxx.com
  • 19. A Groovy program public class HelloWorld { private String name; public void setName(String name) { this.name = name; } public String getName() { return name; } public String greet() { return quot;Hello quot;+ name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName(quot;Groovyquot;); System.out.println( helloWorld.greet() ); } } 19 www.devoxx.com
  • 20. DEMO From Java to Groovy www.devoxx.com
  • 21. A groovier version class HelloWorld { String name String greet() { quot;Hello $namequot; } } def helloWorld = new HelloWorld(name: quot;Groovyquot;) println helloWorld.greet() 21 www.devoxx.com
  • 22. Native syntax constructs Lists def numbers = [1, 2, 3, 4, 5] Maps def map = [FR: “France”, BE: “Belgium”] Ranges def allowedAges = 18..65 Regular expressions def whitespace = ~/s+?/ 22 www.devoxx.com
  • 23. Groovy Strings GStrings: interpolated strings def person = “John” def letter = “““${new Date()} Dear ${person}, this is a Groovy letter!””” println letter Multiline strings: triple single or double quotes Slashy syntax def whitespace = ~/s+?/ 23 www.devoxx.com
  • 24. Closures A reusable / assignable block of code delimited by curly braces can take parameters can be passed as parameters to methods, or inline def printer = { println it } def double = { int i -> 2 * i } new File(“f.txt”).eachLine { line -> println line } new File(“f.txt”).eachLine( printer ) 24 www.devoxx.com
  • 25. Time savers The Groovy Truth def blank = “”; assert !blank def empty = []; assert !empty Safe graph navigation def order = null assert order?.customer?.address == null Elvis operator def name = customer.name ?: “Unknown” 25 www.devoxx.com
  • 26. Java 5 features Since Groovy 1.5 Annotations, generics, static imports, enums, varargs You can leverage frameworks supporting annotations Spring, Hibernate, Guice, JPA, EJB3, TestNG, and more Sole dynamic language supporting annotations 26 www.devoxx.com
  • 27. Annotation example @Entity @Name(“hotel”) class Hotel implements Serializable { @Id @GeneratedValue Long id @Length(max = 40) @NotNull String name @Override String toString() { “Hotel ${name}” } } 27 www.devoxx.com
  • 28. Groovy agenda A bit of history and background Syntax basics Interesting Groovy APIs Domain-Specific Languages What’s new in Groovy 1.6? The Groovy ecosystem www.devoxx.com
  • 29. The GDK — Groovy Dev Kit Groovy “decorates” existing JDK APIs We can’t extend java.lang.String or java.io.File, can we? new File(“f.txt”).eachLine { println it } (1..100).findAll { it % 2 == 1 } speakers.groupBy { it.lastname } “123”.padLeft(5, ‘0’) “ls -la”.execute() “R3Jvb3Z5IHJvY2tzIQ==”.decodeBase64() Thread.start { /* code to be executed */ } 29 www.devoxx.com
  • 30. JDBC made easy With transparent resource handling, thanks to closures def sql = Sql.newInstance(url, usr, pwd, driver) sql.execute(quot;insert into table values ($foo, $bar)quot;) sql.execute(quot;insert into table values(?,?)quot;, [a, b]) sql.eachRow(quot;select * from USERquot;) { print it.name } def list = sql.rows(quot;select * from USERquot;) A poor-man’s dataset notion def set = sql.dataSet(quot;USERquot;) set.add(name: quot;Johnnyquot;, age: 33) set.each { user -> println user.name } set.findAll { it.age > 22 && it.age < 42 } 30 www.devoxx.com
  • 31. Parsing XML With this multiline string XML fragment def xml = quot;quot;quot; <languages> <language name=quot;Groovyquot;> <feature coolness=quot;lowquot;>SQL</feature> <feature coolness=quot;highquot;>Template</feature> </language> <language name=quot;Perlquot;/> </languages>quot;quot;quot; Navigate your XML graph as an object graph! def root = new XmlParser().parseText(xml) println root.language.feature[1].text() root.language.feature .findAll{ it['@coolness'] == quot;lowquot; } .each{ println it.text() } 31 www.devoxx.com
  • 32. Producing XML too! The same XML document as before new MarkupBuilder().languages { language(name: quot;Groovyquot;) { feature(coolness: quot;lowquot;, quot;SQLquot;) feature(coolness: quot;highquot;, quot;Templatequot;) } language(name: quot;Perlquot;) } 32 www.devoxx.com
  • 33. Swing builder Following the same “builder pattern”, but for Swing import javax.swing.WindowConstants as WC import groovy.swing.SwingBuilder def theMap = [color: quot;greenquot;, object: quot;pencilquot;] def swing = new SwingBuilder() def frame = swing.frame( title: 'A Groovy Swing', location: [240,240], defaultCloseOperation:WC.EXIT_ON_CLOSE) { panel { for (entry in theMap) { label(text: entry.key) textField(text: entry.value) } button(text: 'About', actionPerformed: { def pane = swing.optionPane(message: 'SwingBuilder') def dialog = pane.createDialog(null, 'About') dialog.show() }) button(text:'Quit', actionPerformed:{ System.exit(0) }) } } frame.pack() frame.show() 33 www.devoxx.com
  • 34. Swing builder Following the same “builder pattern”, but for Swing import javax.swing.WindowConstants as WC import groovy.swing.SwingBuilder def theMap = [color: quot;greenquot;, object: quot;pencilquot;] def swing = new SwingBuilder() def frame = swing.frame( title: 'A Groovy Swing', location: [240,240], defaultCloseOperation:WC.EXIT_ON_CLOSE) { panel { for (entry in theMap) { label(text: entry.key) textField(text: entry.value) } button(text: 'About', actionPerformed: { def pane = swing.optionPane(message: 'SwingBuilder') def dialog = pane.createDialog(null, 'About') dialog.show() }) button(text:'Quit', actionPerformed:{ System.exit(0) }) } } frame.pack() frame.show() 33 www.devoxx.com
  • 35. Another builder with Ant Reuse the wealth of Ant tasks for your build or system scripting needs // create sequantial Ant execution new AntBuilder().sequential { def buildClasses = “build/classes” // create classes directory mkdir(dir: buildClasses) // compile sources javac(srcdir: “src”, destdir: buildClasses) // jar everything jar(destfile: “my.jar”, basedir: buildClasses) } 34 www.devoxx.com
  • 36. Groovy agenda A bit of history and background Syntax basics Interesting Groovy APIs Domain-Specific Languages What’s new in Groovy 1.6? The Groovy ecosystem www.devoxx.com
  • 37. What’s a DSL? A Domain-Specific Language is a small language designed to be useful for a specific set of tasks, for a given domain Not necessarily Turing-complete Produces some result configuration, data structures, simulation declarations... Can be internal or external Has a form: textual or visual 36 www.devoxx.com
  • 38. Some examples Technical SELECT * FROM USERS WHERE NAME LIKE ‘Guil%’ ^[w-.]+@([w-]+.)+[w-]{2,4}$ Notation 1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 U R’ U2 R U R’ U R Business oriented Risk calculation for insurance policies Human Resources employee skills representation Anti-malaria drug resistance simulation 37 www.devoxx.com
  • 39. Towards more readability (1/2) 38 www.devoxx.com
  • 40. Towards more readability (1/2) 38 www.devoxx.com
  • 41. Towards more readability (1/2) 20% 38 www.devoxx.com
  • 42. Towards more readability (2/2) 39 www.devoxx.com
  • 43. Towards more readability (2/2) 39 www.devoxx.com
  • 44. Towards more readability (2/2) 80% 39 www.devoxx.com
  • 45. Groovy’s MOP to the rescue DSLs are possible in Groovy because of Groovy’s malleable syntax and APIs Omitting parentheses, semi-columns Named arguments, Closures Everything is an object Groovy’s dynamic nature MOP: Meta-Object Protocol Nothing hard-wired, behavior modifiable at runtime! 40 www.devoxx.com
  • 46. Parentheses & named args Optional parentheses move left Named arguments compare fund: ‘XYZ’, withIndicator: ‘NIKEI’ account.debit amount: 30.euros, in: 3.days Plus native syntax elements Lists: [NIKEI, CAC40, NASDAK] Maps: [CA: ‘California’, CO: ‘Colorado’] Ranges: Monday..Friday 41 www.devoxx.com
  • 48. Operator overloading Operators are a shorcut for method calls a + b == a.plus(b) a - b == a.minus(b) a * b == a.multiply(b) a / b == a.divide(b) a % b == a.modulo(b) a | b == a.or(b) a & b == a.and(b) a[b] == a.getAt(b) a << b == a.leftShift(b) 43 www.devoxx.com
  • 49. Operator overloading Operators are a shorcut Currency arithmetics for method calls 30.euros + 15.dollars a + b == a.plus(b) Distances a - b == a.minus(b) a * b == a.multiply(b) 12.kilometers + 3.meters a / b == a.divide(b) Parallelism or workflow a % b == a.modulo(b) taskA & taskB | taskC a | b == a.or(b) Banking a & b == a.and(b) a[b] == a.getAt(b) account += 10.euros a << b == a.leftShift(b) 43 www.devoxx.com
  • 50. Closures and builders Remember the builder pattern? Ant, Swing, Markup... You can easily create your own Extend BuilderSupport or FactoryBuilderSupport Nested method calls with closures as last argument plan { artifact { name = ‘spring.core’ type = ‘bundle’ version = ‘2.5.6’ } } 44 www.devoxx.com
  • 51. Why creating your own DSL? Use a more expressive language than a general purpose Share a common metaphore between developers and subject matter experts Have domain experts help with the design of the business logic of an application Avoid cluttering business code with too much boilerplate technical code Cleanly separate business logic from application code Let business rules have their own lifecycle 45 www.devoxx.com
  • 52. Groovy agenda A bit of history and background Syntax basics Interesting Groovy APIs Domain-Specific Languages What’s new in Groovy 1.6? The Groovy ecosystem www.devoxx.com
  • 53. Groovy 1.6 Main focus on performance to make Groovy the fastest dynamic language Multiple assignment def (a, b) = [1, 2] def (int i, String s) = [1, ‘Groovy’] (a, b) = functionReturningAList() AST Transformations @Lazy, @Immutable, @Singleton, @Delegate Annotation definition 47 www.devoxx.com
  • 54. Groovy agenda A bit of history and background Syntax basics Interesting Groovy APIs Domain-Specific Languages What’s new in Groovy 1.6? The Groovy ecosystem www.devoxx.com
  • 55. More than just Groovy... First major Groovy child: Grails, but there’s more... Griffon: a Grails-like MVC framework for building rich Swing applications Gradle: a new build system learning from the good ideas and mistakes of Ant, Maven and Ivy Easyb: a Behavior Driven Development toolkit which lets you write user stories with a Groovy DSL All three will be presented at Devoxx, check your agenda! 49 www.devoxx.com
  • 56. Groovy Summary The Groovy dynamic language for the JVM simplifies the life of developers Groovy opens up some interesting perspectives towards extending and enhancing your applications Groovy provides the most seamless Java integration experience Groovy lets you create Domain-Specific Languages Groovy protects your investment in skills, tools, libraries and application servers 50 www.devoxx.com
  • 57. Grails in Action A bit of history and background The Grails stack Getting started with scaffolding The layers: persistence, controllers & services, views The plugin ecosystem What’s new in Grails 1.1? www.devoxx.com
  • 58. Grails agenda A bit of history and background The Grails stack Getting started with scaffolding The various layers The plugin ecosystem What’s new in Grails 1.1? www.devoxx.com
  • 59. Guillaume Laforge on the Groovy lists in 2005: Ruby on Rails is all the rage these days, but you compromise on your past investment, if you’re a Java shop: developer and IT team skills, training, app servers, the great JVM platform, third-party libraries... Can’t we leverage Groovy and proven technologies like Spring and Hibernate to bring the “Convention over Configuration” paradigm on the Java platform, without compromising on your investment? www.devoxx.com
  • 60. The Holy Grail(s) Observation: lack of productivity in webapp development We have all the tools at our disposal to change that Back in 2005, Graeme Rocher, Steven Devijsver and myself launched Grails Apache licensed OSS project, hosted at Codehaus Goal similar to Groovy: simplify the life of developers So what’s under the hood? 54 www.devoxx.com
  • 61. Grails agenda A bit of history and background The Grails stack Getting started with scaffolding The various layers The plugin ecosystem What’s new in Grails 1.1? www.devoxx.com
  • 62. From 10,000 feet Grails is an MVC action-based framework Grails follows good principles popularized by Rails CoC: Convention over Configuration DRY: Don’t Repeat Yourself The essence of Rails but with tight integration with the Java platform to protect your investment! 56 www.devoxx.com
  • 63. From 1,000 feet = + + 57 www.devoxx.com
  • 64. Near the ground... Grails is built on rock-solid and proven technologies the JVM, the Java EE specs, existing app servers, and... Spring: IoC, DI, Spring MVC, Spring WebFlow Hibernate: Object-Relational Mapping SiteMesh: page layout and composition Quartz: for job scheduling Jetty and HSQLDB: for fast development cycles Productive out of the box with a full development stack 58 www.devoxx.com
  • 65. Grails agenda A bit of history and background The Grails stack Getting started with scaffolding The various layers The plugin ecosystem What’s new in Grails 1.1? www.devoxx.com
  • 66. First step, download & install Go to http://grails.org/Download Download the latest archive Unzip it somewhere Create GRAILS_HOME Add $GRAILS_HOME/bin to your PATH You’re ready to go! Next step: grails create-app 60 www.devoxx.com
  • 67. DEMO Getting started with scaffolding Remember scaffolding is nice for CRUD, admin interfaces, prototyping, getting up and running quickly, but Grails is more than just a CRUD framework! www.devoxx.com
  • 68. Layout and naming convention 62 www.devoxx.com
  • 69. Did you notice? Where are my configuration files? Why haven’t I written any XML file? Where are my DAOs? Where are my mapping files? No database to configure? Nor a servlet container or app server to install? Or tons of jars to download from Maven repositories? There must be some magic under the hood :-) www.devoxx.com
  • 70. Grails agenda A bit of history and background The Grails stack Getting started with scaffolding The various layers The plugin ecosystem What’s new in Grails 1.1? www.devoxx.com
  • 71. The usual problems When you start a project, you have to setup everything The build, wire all components together You suffer from impedance mismatch You have to handle the ORM mapping manually It’s hard to write clean views Taglibs are a pain to develop 65 www.devoxx.com
  • 72. Persistence Enters GORM: Grails Object Relational Mapping Hibernate under the hood Your domain model is a set of POGOs Your domain classes are transparentely mapped Although you can use legacy schemas with GORM DSL No conf: hibernate.cfg.xml, no *.hbm.xml files! But you can bring your own existing ones if needed Always a path to configuration when in need 66 www.devoxx.com
  • 73. Persistence Enters GORM: Grails Object Relational Mapping Hibernate under the hood Not limited by Your domain model is a set of POGOs conventions? Your domain classes are transparentely mapped Although you can use legacy schemas with GORM DSL No conf: hibernate.cfg.xml, no *.hbm.xml files! But you can bring your own existing ones if needed Always a path to configuration when in need 66 www.devoxx.com
  • 74. Dynamic finders All domain classes have got injected methods like Book.count(), Book.list(), Book.get(id) book.save(), book.delete(), etc... Dynamic finders Book.findByTitle(“Harry Potter”) Book.findAllByAuthorLike(“%Rowlins”) Book.findAllByTitleLikeAndReleaseDateLessThan( ‘%Grails%’, 2007 ) // don’t do that :-) 67 www.devoxx.com
  • 75. Dynamic finders All domain classes have got injected methods like Book.count(), Book.list(), Book.get(id) book.save(), book.delete(), etc... Dynamic finders Book.findByTitle(“Harry Potter”) Book.findAllByAuthorLike(“%Rowlins”) Book.findAllByTitleLikeAndReleaseDateLessThan( ‘%Grails%’, 2007 ) // don’t do that :-) Where’s my DAO? 67 www.devoxx.com
  • 76. Queries You can use raw HQL queries Book.find(“from Book b where b.title = ?”, [‘Shining’]) Grails wraps the Hibernate Criteria API def results = Account.list { like “holderFirstName”, “Fred%” and { between “balance”, 500, 1000 eq “branch”, “London” } order “holderLastName”, “desc” } 68 www.devoxx.com
  • 77. Constraints Constraints can be added to domain classes through a static constraints field static constraints = { isbn matches: /[0-9]{9}[0-9X]/ } Many constraints available blank, creditcard, email, nullable, matches, range, unique Create your own validator myIntField = { it % 2 == 0 } You can also register your own constraints 69 www.devoxx.com
  • 78. Controllers In the controller directory, name ending with Controller http://myserver:8080/app/controller/action Handy things at your disposal redirect, chain, render, flash scope Controllers return Maps as models for the view to render Possible access to the raw output stream Easy databinding from form fields book.properties = params 70 www.devoxx.com
  • 79. Controllers In the controller directory, name ending with Controller http://myserver:8080/app/controller/action a d Handy things at your disposal e lo redirect, chain, render, flash scope R Controllers return Maps as models for the view to render Possible access to the raw output stream Easy databinding from form fields book.properties = params 70 www.devoxx.com
  • 80. Services Another naming convention and placement Transactional by default Just declare your service, it’ll be transparently injected! no need to configure it in some XML fle 71 www.devoxx.com
  • 81. The view tier The view tier is essentially composed of two things The Groovy Server Pages Similar to JSPs But with GString interpolation The Grails Tag Libraries Useful existing tag libraries So easy to write your own! Templates, URL mapping, conversations and more 72 www.devoxx.com
  • 82. GSPs Auto-reloading <html> <head> <meta name=quot;layoutquot; content=quot;mainquot; /> <title>Book List</title> </head> <body> <a href=quot;${createLinkTo(dir:'')}quot;>Home</a> <g:link action=quot;createquot;>New Book</g:link> <g:if test=quot;${flash.message}quot;> ${flash.message} </g:if> <g:each in=quot;${bookList}quot;>${it.title}</g:each> </body> </html> 73 www.devoxx.com
  • 83. GSPs Auto-reloading <html> a d <head> e lo R <meta name=quot;layoutquot; content=quot;mainquot; /> <title>Book List</title> </head> <body> <a href=quot;${createLinkTo(dir:'')}quot;>Home</a> <g:link action=quot;createquot;>New Book</g:link> <g:if test=quot;${flash.message}quot;> ${flash.message} </g:if> <g:each in=quot;${bookList}quot;>${it.title}</g:each> </body> </html> 73 www.devoxx.com
  • 84. Taglibs Lots of existing taglibs Logical: if, else, elseif Iterative: each, collect, findAll Linking: createLink, createLinkTo Ajax: remoteLink, remoteForm, remoteFunction Form: select, datePicker, currencySelect Validation: hasError, eachError UI: rich text editor 74 www.devoxx.com
  • 85. Create your own taglib Yet another Grails convention class MyTaglib { def isAdmin = { attrs, body -> def user = attrs[‘user’] if (user && checkUserPrivs(user)) { body() } } } Use it in your GSP <g:isAdmin user=”${user}”> Some restricted content 75 www.devoxx.com
  • 86. Create your own taglib Yet another Grails convention class MyTaglib { def isAdmin = { attrs, body -> def user = attrs[‘user’] if (user && checkUserPrivs(user)) { body() } } a d } e lo Use it in your GSP R <g:isAdmin user=”${user}”> Some restricted content 75 www.devoxx.com
  • 87. Custom URL mappings Not satisfied with the default URL mapping? Define your URLs yourself! class UrlMapping { static mappings = { “$blog/$yeah?/$month?/$day?” (controller: ‘blog’, action: ‘show’) { constraints { year matches: /d{4}/ } } } } 76 www.devoxx.com
  • 88. What have I not shown? Conversation concept using Spring WebFlow Templates for reusing view logic and presentation Internationalization You can reuse JSP tag libraries (in Grails 1.1) SiteMesh layouts and page componentization Handling of REST style architecture Unit and integration tests Reuse legacy schemas or Spring configurations 77 www.devoxx.com
  • 89. What have I not shown? Conversation concept using Spring WebFlow Templates for reusing view logic and presentation Internationalization You can reuse JSP tag libraries (in Grails 1.1) SiteMesh layouts and page componentization Handling of REST style architecture Unit and integration tests Not limited by conventions? Reuse legacy schemas or Spring configurations 77 www.devoxx.com
  • 90. Grails agenda A bit of history and background The Grails stack Getting started with scaffolding The various layers The plugin ecosystem What’s new in Grails 1.1? www.devoxx.com
  • 91. A wealth of plugins Grails is built on top of a core plugin system 100+ plugins already available Testing: Webtest, Easyb, Selenium, jsUnit, Fitnesse Rich client / AJAX: Yahoo, Ext-JS, GWT, jQuery, iUI Web Services: XFire, remoting, Axis2, Metro Security: Spring Security, JSecurity Search: Compass integration Other integration: Drools, Struts, GridGain, Terracotta 79 www.devoxx.com
  • 92. Grails agenda A bit of history and background The Grails stack Getting started with scaffolding The various layers The plugin ecosystem What’s new in Grails 1.1? www.devoxx.com
  • 93. Grails 1.1 JSP tag library support and reuse New GORM events Improvements to data binding Read-only access to domain objects More options for the GORM DSL Improvements to dynamic finders More support for legacy mappings New testing plugin included for easier testing 81 www.devoxx.com
  • 94. Grails Summary Grails is not just a web framework, but a full-blown development stack Grails is not a clone of Ruby on Rails Grails is built on proven rock-solid technologies Grails brings back the productivity to Java developers Grails is a new weapon for the war on Java complexity 82 www.devoxx.com
  • 95. Q&A www.devoxx.com
  • 96. Thanks for your attention! http://groovy.codehaus.org http://grails.org http://www.springsource.com/g2one http://glaforge.free.fr/blog/groovy glaforge@gmail.com www.devoxx.com
  • 97. Pictures from the web used in this presentation: Question marks: http://weblogs.newsday.com Agenda: http://www.jouy.inra.fr Mop: http://www.spitjack.com Harry Potter: http://madhavgopalkrish.files.wordpress.com www.devoxx.com