SlideShare a Scribd company logo
1 of 28
© Catalysts GmbH

Magic with Groovy & Grails
The Search is over
© Catalysts GmbH
What is Groovy?
•

Dynamic language

•

It can leverage Java's enterprise capabilities but also has cool productivity
features like closures, builders and dynamic typing

•

1.0 released on 02.01.2007

•

Dynamically compiled to JVM bytecode

•

99% of Java code is also valid

•

Groovy = Java +
dynamic typing +

additional methods & operators + closures
© Catalysts GmbH
Dynamic Typing
Java
ArrayList<String> list = new ArrayList<String>() {
{

Groovy
add("A");
add("B");
add("C");

}
};
HashMap<Integer, String> map = new HashMap<Integer, String>() {
{
put(1, "A");
put(2, "B");
put(3, "C");
}
};

© Catalysts GmbH

?
Dynamic Method Invocation
class Dog {
def bark() { println "woof!" }
def sit() { println "(sitting)" }
def jump() { println "boing!" }
}
def doAction( animal, action ) {
animal."$action"() //action name is passed at invocation
}
def rex = new Dog()
doAction( rex, "bark" ) //prints 'woof!'
doAction( rex, "jump" ) //prints 'boing!'

© Catalysts GmbH
Additional Operators
•

Spread *.

parent*.action //equivalent to:

parent.collect{ child -> child?.action }
•

Elvis ?:

assert ['cat', 'elephant']*.size() == [3, 8]
•

Safe navigation ?.

•

Equals ==

© Catalysts GmbH
Closures
“A Groovy Closure is like a ‘code block’ or a method pointer. It is a piece of
code that is defined and then executed at a later point.”

http://groovy.codehaus.org/Closures

© Catalysts GmbH
Functional Programming(1)
•

Closures as functions

def multiply = { x, y -> return x * y }

println multiply.call(3, 4)
def triple = {x -> return 3*x }
•

Closures as function compositions

//like LISP, Haskell lambda functions
def composition = { f, g, x, y-> return f(g(x, y)) }
composition.call(triple, multiply, 5, 6)

© Catalysts GmbH
Functional Programming(2)
•

Fibonacci

def fibonacci

fibonacci = { n ->
n <= 1 ? n : fibonacci(n-1) + fibonacci(n-2)
}.memoize()
println fibonacci.call(35)

© Catalysts GmbH
What is Grails?
Grails is a full stack framework and attempts to solve as many pieces of the web development puzzle through the core technology
and its associated plugins. Included out the box are things like:
1. An easy to use Object Relational Mapping (ORM) layer built on Hibernate

2. An expressive view technology called Groovy Server Pages (GSP) ~ JSP
3. A controller layer built on Spring MVC
4. A command line scripting environment built on the Groovy-powered Gant
5. An embedded Tomcat container which is configured for on the fly reloading

6. Dependency injection with the inbuilt Spring container
7. Support for internationalization (i18n) built on Spring's core MessageSource concept
8. A transactional service layer built on Spring's transaction abstraction
All of these are made easy to use through the power of the Groovy language and the extensive
use of Domain Specific Languages (DSLs)

© Catalysts GmbH
What is Grails?
•

Web application framework

•

Convention over configuration

•

Spring MVC

•

Fast prototyping and development

© Catalysts GmbH
Convention over configuration
This typically means that the name and location of files is used instead of explicit configuration

© Catalysts GmbH
© Catalysts GmbH
© Catalysts GmbH
What does all these means?(1)
What does mean all these features of Grails?
1. An easy to use Object Relational

Mapping (ORM) layer built on

Hibernate
That means that you just have to define your domain classes, with all the attributes that you
want. These domain classes will be automatically mapped by Hibernate to tables inside the
database you have specified in Datasource.groovy, and the domain class attributes will be
mapped to table fields.
Having this domain classes mapped, you can now perform all CRUD operations on them, with
the usage of dynamic methods added by GORM to the domain classes such as “save(),
delete(), findAll, findAllBy, findAllWhere, count etc.”
These dynamic methods instantly boost your productivity since you dont have to worry anymore
about writing sql queries or managing the data layer. Grails does all of these for you! (*
however if you still want to customize how things are mapped, sql queries, you can dive into the
deep of Hibernate configs)
© Catalysts GmbH
2. An expressive view technology called
Groovyall these features of Grails? (GSP)
Server Pages
What does mean
Groovy Servers Pages (or GSP for short) is Grails' view technology. It is designed to be familiar
for users of technologies such as ASP and JSP, but to be far more flexible and intuitive.
You can be more flexible because you can use groovy code inside the pages, that is executed
before the page is sent, or use specific reusable componets - taglibs.

© Catalysts GmbH
3. A controller layer built on Spring MVC

Controllers are the classes that responds and handle requests from the
front-end.
A controller can generate the response directly or delegate it to a view.
Controller methods and views are tightened together, thus a controller
method called “search” will by default render the view “search”.

© Catalysts GmbH
4. A command line scripting environment
built on the Groovy-powered Gant
That means that you can use groovy console to run the application, the
tests, install plugins and so on.

© Catalysts GmbH
5. An embedded Tomcat container which
is configured for on the fly reloading
Grails provides an embedded Tomcat instance, where your application is
deployed automatically when you want it to run. This means that you don't
have to worry about a separate Tomcat container and deploy
configurations that takes time.
Also, you can make changes to your application on the fly, without the
need to redeploy the app. However, when changing domain classes, the
database will change too, so the application has to be deployed again.

© Catalysts GmbH
6. Dependency injection with the inbuilt
Spring container
Grails leverages Spring MVC in the following areas:
Basic controller logic - Grails subclasses Spring's DispatcherServlet and uses it
to delegate to Grails controllers
Data Binding and Validation - Grails' validation and data binding capabilities are
built on those provided by Spring
Runtime configuration - Grails' entire runtime convention based system is wired
together by a Spring ApplicationContext
Transactions - Grails uses Spring's transaction management in GORM
In other words Grails has Spring embedded running all the way through it.

© Catalysts GmbH
7. Support for internationalization (i18n)
built on Spring's core MessageSource
This means that your application can be written in as many languages as you want.
All you have to do is to use specific codes for each message that you use, and
provide different translations for these codes.
You can split and organise your language files as you like.

© Catalysts GmbH
8. A transactional service layer built on
Spring's transaction abstraction
The Grails team discourages the embedding of core application logic inside
controllers, as it does not promote reuse and a clean separation of concerns.

Services in Grails are the place to put the majority of the logic in your application,
leaving controllers responsible for handling request flow with redirects and so on.
Services are transactional by default. This means that if an operation on the
database fails, and this operations is performed in a service, that operation will be
automatically rolled back due to default transactional behaviour of services.

© Catalysts GmbH
Why would I use it?
1- Grails is Spring and Hibernate
Grails was a good replacement for vanilla Spring/Hibernate, but it’s even better. In
the real world it means that you can bootstrap a new project very quickly by using
default settings, but you have all the power of Spring and Hibernate under the
hood. If you really need to do some really specific stuff, you can easily go into deep
of configurations.
The best of both worlds! And it also means that you can use all the Spring modules
you already love and integrate with all the databases you are used to, without any
problem.
You just have to define your domain classes and with the usage of dynamic
scaffolding your application is ready to go with all the CRUD operations (views,
controllers ) already implemented.

© Catalysts GmbH
Why would I use it?
2- Groovy is actually Java
Java is a statically-typed language and it was designed to be, because it’s just easier to
understand. But recently, we have all come to envy the expressivity and power of dynamic
languages like Ruby and Python. The problem is that they are completely new languages,
which means 2 things: the learning curve is pretty steep, and it’s hard to find good developers
for those languages. Well, fear no more, because Groovy is here to save you.
Groovy is essentially a superset of Java as a language, which means that you don’t need to
learn an entirely new language, and it’s really easy to turn any Java developer into a Groovy
developer. Sure Groovy offers much more than Java in terms of power, and it can take some
time to get a good grasp of all the ins and outs of closures, dynamic typing or even metaprogramming.
But the good news is that you don’t need to master all those right away in order to leverage a lot
of the productivity you can get out of Groovy.
© Catalysts GmbH
Why would I use it?
3- And it runs on the JVM
And it gets even further than that: Groovy is so Java-rooted that it actually compiles
to run on a Java runtime. Groovy code compiles into JVM bytecode, which means
you can still make Groovy and Grails applications run on your favorite application
server (simplest is Tomcat, but I’ve made it run on JBoss and even Weblogic) AND
you can reuse all the awesome libraries available in the Java ecosystem in an
instant.
Just plug your environment with your Maven or Ivy repository of choice, or copy
some JARs over and you’re good to go! How amazing is that?

© Catalysts GmbH
Why would I use it?
4- Groovy is not just for scripting
I mean sure, Groovy is great for system scripting, in the same way as Ruby and
Python are. Not everything needs to be a class so you can write scripts in no time.
But a lot of people use Groovy just for that, and think it’s not ready for prime-time
big-fuss applications yet
Yes, Groovy is a dynamic language, which also means that there is a lot less stuff
checked at compilation time than with mere Java, but since your code is much
more expressive, there is a lot less opportunity for errors too, and unit tests are a
lot easier to write, especially thanks to DSL’s.

© Catalysts GmbH
Why would I use it?
5- A very dynamic ecosystem
Every experienced developer knows that a good framework is nothing without good
documentation, serious support and a large community of contributors.
Well, of course Groovy and Grails have all that. First of all, they are part of the portfolio of
SpringSource, the very company that brought you the Spring Framework and that is now a
division of VMWare. The documentation is really good, like most Spring documentations by the
way, and there are some excellent books out there. As for helpers and contributors, whether it is
on the mailing list or on StackOverflow, helpers are everywhere.
And in terms of ecosystem: Grails has a plugin mechanism that makes it really easy to extend
the framework in a lot of different ways. Now I won’t lie, all of the available plugins are not
necessarily supported or kept up-to-date on the long run, but they are so easy to write and fix,
that it’s not really an issue.

© Catalysts GmbH
Why would I use it?
Liquibase integration

When you already have your application in production, you need a way to modify your db
automatically, thus Liquibase.

© Catalysts GmbH
Why would I use it?
5- A very dynamic ecosystem
Every experienced developer knows that a good framework is nothing without good
documentation, serious support and a large community of contributors.
Well, of course Groovy and Grails have all that. First of all, they are part of the portfolio of
SpringSource, the very company that brought you the Spring Framework and that is now a
division of VMWare. The documentation is really good, like most Spring documentations by the
way, and there are some excellent books out there. As for helpers and contributors, whether it is
on the mailing list or on StackOverflow, helpers are everywhere.
And in terms of ecosystem: Grails has a plugin mechanism that makes it really easy to extend
the framework in a lot of different ways. Now I won’t lie, all of the available plugins are not
necessarily supported or kept up-to-date on the long run, but they are so easy to write and fix,
that it’s not really an issue.

© Catalysts GmbH

More Related Content

What's hot

Scripting Oracle Develop 2007
Scripting Oracle Develop 2007Scripting Oracle Develop 2007
Scripting Oracle Develop 2007Tugdual Grall
 
Spring5 New Features - Nov, 2017
Spring5 New Features - Nov, 2017Spring5 New Features - Nov, 2017
Spring5 New Features - Nov, 2017VMware Tanzu Korea
 
Flux is incubating + the road ahead
Flux is incubating + the road aheadFlux is incubating + the road ahead
Flux is incubating + the road aheadLibbySchulze
 
Demystify LDAP and OIDC Providing Security to Your App on Kubernetes
Demystify LDAP and OIDC Providing Security to Your App on KubernetesDemystify LDAP and OIDC Providing Security to Your App on Kubernetes
Demystify LDAP and OIDC Providing Security to Your App on KubernetesVMware Tanzu
 
The Chef Prince of Azure - ChefConf 2015
The Chef Prince of Azure - ChefConf 2015The Chef Prince of Azure - ChefConf 2015
The Chef Prince of Azure - ChefConf 2015Chef
 
Containerizing ContentBox CMS
Containerizing ContentBox CMSContainerizing ContentBox CMS
Containerizing ContentBox CMSGavin Pickin
 
Introducing Spring Framework 5.3
Introducing Spring Framework 5.3Introducing Spring Framework 5.3
Introducing Spring Framework 5.3VMware Tanzu
 
From Spring Framework 5.3 to 6.0
From Spring Framework 5.3 to 6.0From Spring Framework 5.3 to 6.0
From Spring Framework 5.3 to 6.0VMware Tanzu
 
Migrating from Grails 2 to Grails 3
Migrating from Grails 2 to Grails 3Migrating from Grails 2 to Grails 3
Migrating from Grails 2 to Grails 3Michael Plöd
 
Cloud Native Java GraalVM 이상과 현실
Cloud Native Java GraalVM 이상과 현실Cloud Native Java GraalVM 이상과 현실
Cloud Native Java GraalVM 이상과 현실Taewan Kim
 
Polyglot on the JVM with Graal (Japanese)
Polyglot on the JVM with Graal (Japanese)Polyglot on the JVM with Graal (Japanese)
Polyglot on the JVM with Graal (Japanese)Logico
 
Building Distributed Systems with Netflix OSS and Spring Cloud
Building Distributed Systems with Netflix OSS and Spring CloudBuilding Distributed Systems with Netflix OSS and Spring Cloud
Building Distributed Systems with Netflix OSS and Spring CloudMatt Stine
 
Leveraging Gradle @ Netflix (Madrid GUG Feb 2, 2021)
Leveraging Gradle @ Netflix (Madrid GUG Feb 2, 2021)Leveraging Gradle @ Netflix (Madrid GUG Feb 2, 2021)
Leveraging Gradle @ Netflix (Madrid GUG Feb 2, 2021)Roberto Pérez Alcolea
 
Cloud-Native Modernization or Death? A false dichotomy. | DevNation Tech Talk
Cloud-Native Modernization or Death? A false dichotomy. | DevNation Tech TalkCloud-Native Modernization or Death? A false dichotomy. | DevNation Tech Talk
Cloud-Native Modernization or Death? A false dichotomy. | DevNation Tech TalkRed Hat Developers
 
Mete Atamel "Resilient microservices with kubernetes"
Mete Atamel "Resilient microservices with kubernetes"Mete Atamel "Resilient microservices with kubernetes"
Mete Atamel "Resilient microservices with kubernetes"IT Event
 
Rene Groeschke
Rene GroeschkeRene Groeschke
Rene GroeschkeCodeFest
 
TechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance InteroperabilityTechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance InteroperabilityTrivadis
 
Microsoft, java and you!
Microsoft, java and you!Microsoft, java and you!
Microsoft, java and you!George Adams
 

What's hot (20)

Scripting Oracle Develop 2007
Scripting Oracle Develop 2007Scripting Oracle Develop 2007
Scripting Oracle Develop 2007
 
Spring5 New Features - Nov, 2017
Spring5 New Features - Nov, 2017Spring5 New Features - Nov, 2017
Spring5 New Features - Nov, 2017
 
Flux is incubating + the road ahead
Flux is incubating + the road aheadFlux is incubating + the road ahead
Flux is incubating + the road ahead
 
Demystify LDAP and OIDC Providing Security to Your App on Kubernetes
Demystify LDAP and OIDC Providing Security to Your App on KubernetesDemystify LDAP and OIDC Providing Security to Your App on Kubernetes
Demystify LDAP and OIDC Providing Security to Your App on Kubernetes
 
The Chef Prince of Azure - ChefConf 2015
The Chef Prince of Azure - ChefConf 2015The Chef Prince of Azure - ChefConf 2015
The Chef Prince of Azure - ChefConf 2015
 
Containerizing ContentBox CMS
Containerizing ContentBox CMSContainerizing ContentBox CMS
Containerizing ContentBox CMS
 
Spring boot wednesday
Spring boot wednesdaySpring boot wednesday
Spring boot wednesday
 
Introducing Spring Framework 5.3
Introducing Spring Framework 5.3Introducing Spring Framework 5.3
Introducing Spring Framework 5.3
 
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
 
From Spring Framework 5.3 to 6.0
From Spring Framework 5.3 to 6.0From Spring Framework 5.3 to 6.0
From Spring Framework 5.3 to 6.0
 
Migrating from Grails 2 to Grails 3
Migrating from Grails 2 to Grails 3Migrating from Grails 2 to Grails 3
Migrating from Grails 2 to Grails 3
 
Cloud Native Java GraalVM 이상과 현실
Cloud Native Java GraalVM 이상과 현실Cloud Native Java GraalVM 이상과 현실
Cloud Native Java GraalVM 이상과 현실
 
Polyglot on the JVM with Graal (Japanese)
Polyglot on the JVM with Graal (Japanese)Polyglot on the JVM with Graal (Japanese)
Polyglot on the JVM with Graal (Japanese)
 
Building Distributed Systems with Netflix OSS and Spring Cloud
Building Distributed Systems with Netflix OSS and Spring CloudBuilding Distributed Systems with Netflix OSS and Spring Cloud
Building Distributed Systems with Netflix OSS and Spring Cloud
 
Leveraging Gradle @ Netflix (Madrid GUG Feb 2, 2021)
Leveraging Gradle @ Netflix (Madrid GUG Feb 2, 2021)Leveraging Gradle @ Netflix (Madrid GUG Feb 2, 2021)
Leveraging Gradle @ Netflix (Madrid GUG Feb 2, 2021)
 
Cloud-Native Modernization or Death? A false dichotomy. | DevNation Tech Talk
Cloud-Native Modernization or Death? A false dichotomy. | DevNation Tech TalkCloud-Native Modernization or Death? A false dichotomy. | DevNation Tech Talk
Cloud-Native Modernization or Death? A false dichotomy. | DevNation Tech Talk
 
Mete Atamel "Resilient microservices with kubernetes"
Mete Atamel "Resilient microservices with kubernetes"Mete Atamel "Resilient microservices with kubernetes"
Mete Atamel "Resilient microservices with kubernetes"
 
Rene Groeschke
Rene GroeschkeRene Groeschke
Rene Groeschke
 
TechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance InteroperabilityTechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance Interoperability
 
Microsoft, java and you!
Microsoft, java and you!Microsoft, java and you!
Microsoft, java and you!
 

Viewers also liked

Introduction to Varnish VCL
Introduction to Varnish VCLIntroduction to Varnish VCL
Introduction to Varnish VCLPax Dickinson
 
Caching solutions with Varnish
Caching solutions  with VarnishCaching solutions  with Varnish
Caching solutions with VarnishGeorge Platon
 
Varnish Cache Plus. Random notes for wise web developers
Varnish Cache Plus. Random notes for wise web developersVarnish Cache Plus. Random notes for wise web developers
Varnish Cache Plus. Random notes for wise web developersCarlos Abalde
 
Supercharging Content Delivery with Varnish
Supercharging Content Delivery with VarnishSupercharging Content Delivery with Varnish
Supercharging Content Delivery with VarnishSamantha Quiñones
 

Viewers also liked (6)

Introduction to Varnish VCL
Introduction to Varnish VCLIntroduction to Varnish VCL
Introduction to Varnish VCL
 
Caching solutions with Varnish
Caching solutions  with VarnishCaching solutions  with Varnish
Caching solutions with Varnish
 
Varnish 4 cool features
Varnish 4 cool featuresVarnish 4 cool features
Varnish 4 cool features
 
Varnish Cache Plus. Random notes for wise web developers
Varnish Cache Plus. Random notes for wise web developersVarnish Cache Plus. Random notes for wise web developers
Varnish Cache Plus. Random notes for wise web developers
 
Varnish Cache
Varnish CacheVarnish Cache
Varnish Cache
 
Supercharging Content Delivery with Varnish
Supercharging Content Delivery with VarnishSupercharging Content Delivery with Varnish
Supercharging Content Delivery with Varnish
 

Similar to Magic with groovy & grails

Introduction To Groovy And Grails - SpringPeople
Introduction To Groovy And Grails - SpringPeopleIntroduction To Groovy And Grails - SpringPeople
Introduction To Groovy And Grails - SpringPeopleSpringPeople
 
intoduction to Grails Framework
intoduction to Grails Frameworkintoduction to Grails Framework
intoduction to Grails FrameworkHarshdeep Kaur
 
Adopting Grails - GR8Conf Europe
Adopting Grails - GR8Conf EuropeAdopting Grails - GR8Conf Europe
Adopting Grails - GR8Conf EuropeKlausBaumecker
 
Griffon: Re-imaging Desktop Java Technology
Griffon: Re-imaging Desktop Java TechnologyGriffon: Re-imaging Desktop Java Technology
Griffon: Re-imaging Desktop Java TechnologyJames Williams
 
Curious Coders Java Web Frameworks Comparison
Curious Coders Java Web Frameworks ComparisonCurious Coders Java Web Frameworks Comparison
Curious Coders Java Web Frameworks ComparisonHamed Hatami
 
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and DataflowHow to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and DataflowDaniel Zivkovic
 
How and why GraalVM is quickly becoming relevant for you (DOAG 2020)
How and why GraalVM is quickly becoming relevant for you (DOAG 2020)How and why GraalVM is quickly becoming relevant for you (DOAG 2020)
How and why GraalVM is quickly becoming relevant for you (DOAG 2020)Lucas Jellema
 
GROOVY ON GRAILS
GROOVY ON GRAILSGROOVY ON GRAILS
GROOVY ON GRAILSziyaaskerov
 
Advantages of golang development services &amp; 10 most used go frameworks
Advantages of golang development services &amp; 10 most used go frameworksAdvantages of golang development services &amp; 10 most used go frameworks
Advantages of golang development services &amp; 10 most used go frameworksKaty Slemon
 
Introduction to Grails 2013
Introduction to Grails 2013Introduction to Grails 2013
Introduction to Grails 2013Gavin Hogan
 
ALPHA Script - Presentation
ALPHA Script - PresentationALPHA Script - Presentation
ALPHA Script - PresentationPROBOTEK
 
Flex on Grails - Rich Internet Applications With Rapid Application Development
Flex on Grails - Rich Internet Applications With Rapid Application DevelopmentFlex on Grails - Rich Internet Applications With Rapid Application Development
Flex on Grails - Rich Internet Applications With Rapid Application DevelopmentTalentica Software
 
Java @ Cloud - Setor Público SP
Java @ Cloud - Setor Público SPJava @ Cloud - Setor Público SP
Java @ Cloud - Setor Público SPIlan Salviano
 
Spring Northwest Usergroup Grails Presentation
Spring Northwest Usergroup Grails PresentationSpring Northwest Usergroup Grails Presentation
Spring Northwest Usergroup Grails Presentationajevans
 
2013 05-multicloud-paas-interop-scenarios-fia-dublin
2013 05-multicloud-paas-interop-scenarios-fia-dublin2013 05-multicloud-paas-interop-scenarios-fia-dublin
2013 05-multicloud-paas-interop-scenarios-fia-dublinAlex Heneveld
 
Meet Magento Spain 2019 - Our Experience with Magento Cloud
Meet Magento Spain 2019 - Our Experience with Magento CloudMeet Magento Spain 2019 - Our Experience with Magento Cloud
Meet Magento Spain 2019 - Our Experience with Magento CloudLyzun Oleksandr
 

Similar to Magic with groovy & grails (20)

Introduction To Groovy And Grails - SpringPeople
Introduction To Groovy And Grails - SpringPeopleIntroduction To Groovy And Grails - SpringPeople
Introduction To Groovy And Grails - SpringPeople
 
intoduction to Grails Framework
intoduction to Grails Frameworkintoduction to Grails Framework
intoduction to Grails Framework
 
Groovy & Grails
Groovy & GrailsGroovy & Grails
Groovy & Grails
 
Adopting Grails - GR8Conf Europe
Adopting Grails - GR8Conf EuropeAdopting Grails - GR8Conf Europe
Adopting Grails - GR8Conf Europe
 
Griffon: Re-imaging Desktop Java Technology
Griffon: Re-imaging Desktop Java TechnologyGriffon: Re-imaging Desktop Java Technology
Griffon: Re-imaging Desktop Java Technology
 
GROOVY ON GRAILS
GROOVY ON GRAILSGROOVY ON GRAILS
GROOVY ON GRAILS
 
Curious Coders Java Web Frameworks Comparison
Curious Coders Java Web Frameworks ComparisonCurious Coders Java Web Frameworks Comparison
Curious Coders Java Web Frameworks Comparison
 
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and DataflowHow to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
 
GraphQL for Native Apps
GraphQL for Native AppsGraphQL for Native Apps
GraphQL for Native Apps
 
How and why GraalVM is quickly becoming relevant for you (DOAG 2020)
How and why GraalVM is quickly becoming relevant for you (DOAG 2020)How and why GraalVM is quickly becoming relevant for you (DOAG 2020)
How and why GraalVM is quickly becoming relevant for you (DOAG 2020)
 
GROOVY ON GRAILS
GROOVY ON GRAILSGROOVY ON GRAILS
GROOVY ON GRAILS
 
Advantages of golang development services &amp; 10 most used go frameworks
Advantages of golang development services &amp; 10 most used go frameworksAdvantages of golang development services &amp; 10 most used go frameworks
Advantages of golang development services &amp; 10 most used go frameworks
 
Introduction to Grails 2013
Introduction to Grails 2013Introduction to Grails 2013
Introduction to Grails 2013
 
ALPHA Script - Presentation
ALPHA Script - PresentationALPHA Script - Presentation
ALPHA Script - Presentation
 
Flex on Grails - Rich Internet Applications With Rapid Application Development
Flex on Grails - Rich Internet Applications With Rapid Application DevelopmentFlex on Grails - Rich Internet Applications With Rapid Application Development
Flex on Grails - Rich Internet Applications With Rapid Application Development
 
Java @ Cloud - Setor Público SP
Java @ Cloud - Setor Público SPJava @ Cloud - Setor Público SP
Java @ Cloud - Setor Público SP
 
Spring Northwest Usergroup Grails Presentation
Spring Northwest Usergroup Grails PresentationSpring Northwest Usergroup Grails Presentation
Spring Northwest Usergroup Grails Presentation
 
2013 05-multicloud-paas-interop-scenarios-fia-dublin
2013 05-multicloud-paas-interop-scenarios-fia-dublin2013 05-multicloud-paas-interop-scenarios-fia-dublin
2013 05-multicloud-paas-interop-scenarios-fia-dublin
 
Grails
GrailsGrails
Grails
 
Meet Magento Spain 2019 - Our Experience with Magento Cloud
Meet Magento Spain 2019 - Our Experience with Magento CloudMeet Magento Spain 2019 - Our Experience with Magento Cloud
Meet Magento Spain 2019 - Our Experience with Magento Cloud
 

Recently uploaded

Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Recently uploaded (20)

Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Magic with groovy & grails

  • 1. © Catalysts GmbH Magic with Groovy & Grails The Search is over © Catalysts GmbH
  • 2. What is Groovy? • Dynamic language • It can leverage Java's enterprise capabilities but also has cool productivity features like closures, builders and dynamic typing • 1.0 released on 02.01.2007 • Dynamically compiled to JVM bytecode • 99% of Java code is also valid • Groovy = Java + dynamic typing + additional methods & operators + closures © Catalysts GmbH
  • 3. Dynamic Typing Java ArrayList<String> list = new ArrayList<String>() { { Groovy add("A"); add("B"); add("C"); } }; HashMap<Integer, String> map = new HashMap<Integer, String>() { { put(1, "A"); put(2, "B"); put(3, "C"); } }; © Catalysts GmbH ?
  • 4. Dynamic Method Invocation class Dog { def bark() { println "woof!" } def sit() { println "(sitting)" } def jump() { println "boing!" } } def doAction( animal, action ) { animal."$action"() //action name is passed at invocation } def rex = new Dog() doAction( rex, "bark" ) //prints 'woof!' doAction( rex, "jump" ) //prints 'boing!' © Catalysts GmbH
  • 5. Additional Operators • Spread *. parent*.action //equivalent to: parent.collect{ child -> child?.action } • Elvis ?: assert ['cat', 'elephant']*.size() == [3, 8] • Safe navigation ?. • Equals == © Catalysts GmbH
  • 6. Closures “A Groovy Closure is like a ‘code block’ or a method pointer. It is a piece of code that is defined and then executed at a later point.” http://groovy.codehaus.org/Closures © Catalysts GmbH
  • 7. Functional Programming(1) • Closures as functions def multiply = { x, y -> return x * y } println multiply.call(3, 4) def triple = {x -> return 3*x } • Closures as function compositions //like LISP, Haskell lambda functions def composition = { f, g, x, y-> return f(g(x, y)) } composition.call(triple, multiply, 5, 6) © Catalysts GmbH
  • 8. Functional Programming(2) • Fibonacci def fibonacci fibonacci = { n -> n <= 1 ? n : fibonacci(n-1) + fibonacci(n-2) }.memoize() println fibonacci.call(35) © Catalysts GmbH
  • 9. What is Grails? Grails is a full stack framework and attempts to solve as many pieces of the web development puzzle through the core technology and its associated plugins. Included out the box are things like: 1. An easy to use Object Relational Mapping (ORM) layer built on Hibernate 2. An expressive view technology called Groovy Server Pages (GSP) ~ JSP 3. A controller layer built on Spring MVC 4. A command line scripting environment built on the Groovy-powered Gant 5. An embedded Tomcat container which is configured for on the fly reloading 6. Dependency injection with the inbuilt Spring container 7. Support for internationalization (i18n) built on Spring's core MessageSource concept 8. A transactional service layer built on Spring's transaction abstraction All of these are made easy to use through the power of the Groovy language and the extensive use of Domain Specific Languages (DSLs) © Catalysts GmbH
  • 10. What is Grails? • Web application framework • Convention over configuration • Spring MVC • Fast prototyping and development © Catalysts GmbH
  • 11. Convention over configuration This typically means that the name and location of files is used instead of explicit configuration © Catalysts GmbH
  • 14. What does all these means?(1) What does mean all these features of Grails? 1. An easy to use Object Relational Mapping (ORM) layer built on Hibernate That means that you just have to define your domain classes, with all the attributes that you want. These domain classes will be automatically mapped by Hibernate to tables inside the database you have specified in Datasource.groovy, and the domain class attributes will be mapped to table fields. Having this domain classes mapped, you can now perform all CRUD operations on them, with the usage of dynamic methods added by GORM to the domain classes such as “save(), delete(), findAll, findAllBy, findAllWhere, count etc.” These dynamic methods instantly boost your productivity since you dont have to worry anymore about writing sql queries or managing the data layer. Grails does all of these for you! (* however if you still want to customize how things are mapped, sql queries, you can dive into the deep of Hibernate configs) © Catalysts GmbH
  • 15. 2. An expressive view technology called Groovyall these features of Grails? (GSP) Server Pages What does mean Groovy Servers Pages (or GSP for short) is Grails' view technology. It is designed to be familiar for users of technologies such as ASP and JSP, but to be far more flexible and intuitive. You can be more flexible because you can use groovy code inside the pages, that is executed before the page is sent, or use specific reusable componets - taglibs. © Catalysts GmbH
  • 16. 3. A controller layer built on Spring MVC Controllers are the classes that responds and handle requests from the front-end. A controller can generate the response directly or delegate it to a view. Controller methods and views are tightened together, thus a controller method called “search” will by default render the view “search”. © Catalysts GmbH
  • 17. 4. A command line scripting environment built on the Groovy-powered Gant That means that you can use groovy console to run the application, the tests, install plugins and so on. © Catalysts GmbH
  • 18. 5. An embedded Tomcat container which is configured for on the fly reloading Grails provides an embedded Tomcat instance, where your application is deployed automatically when you want it to run. This means that you don't have to worry about a separate Tomcat container and deploy configurations that takes time. Also, you can make changes to your application on the fly, without the need to redeploy the app. However, when changing domain classes, the database will change too, so the application has to be deployed again. © Catalysts GmbH
  • 19. 6. Dependency injection with the inbuilt Spring container Grails leverages Spring MVC in the following areas: Basic controller logic - Grails subclasses Spring's DispatcherServlet and uses it to delegate to Grails controllers Data Binding and Validation - Grails' validation and data binding capabilities are built on those provided by Spring Runtime configuration - Grails' entire runtime convention based system is wired together by a Spring ApplicationContext Transactions - Grails uses Spring's transaction management in GORM In other words Grails has Spring embedded running all the way through it. © Catalysts GmbH
  • 20. 7. Support for internationalization (i18n) built on Spring's core MessageSource This means that your application can be written in as many languages as you want. All you have to do is to use specific codes for each message that you use, and provide different translations for these codes. You can split and organise your language files as you like. © Catalysts GmbH
  • 21. 8. A transactional service layer built on Spring's transaction abstraction The Grails team discourages the embedding of core application logic inside controllers, as it does not promote reuse and a clean separation of concerns. Services in Grails are the place to put the majority of the logic in your application, leaving controllers responsible for handling request flow with redirects and so on. Services are transactional by default. This means that if an operation on the database fails, and this operations is performed in a service, that operation will be automatically rolled back due to default transactional behaviour of services. © Catalysts GmbH
  • 22. Why would I use it? 1- Grails is Spring and Hibernate Grails was a good replacement for vanilla Spring/Hibernate, but it’s even better. In the real world it means that you can bootstrap a new project very quickly by using default settings, but you have all the power of Spring and Hibernate under the hood. If you really need to do some really specific stuff, you can easily go into deep of configurations. The best of both worlds! And it also means that you can use all the Spring modules you already love and integrate with all the databases you are used to, without any problem. You just have to define your domain classes and with the usage of dynamic scaffolding your application is ready to go with all the CRUD operations (views, controllers ) already implemented. © Catalysts GmbH
  • 23. Why would I use it? 2- Groovy is actually Java Java is a statically-typed language and it was designed to be, because it’s just easier to understand. But recently, we have all come to envy the expressivity and power of dynamic languages like Ruby and Python. The problem is that they are completely new languages, which means 2 things: the learning curve is pretty steep, and it’s hard to find good developers for those languages. Well, fear no more, because Groovy is here to save you. Groovy is essentially a superset of Java as a language, which means that you don’t need to learn an entirely new language, and it’s really easy to turn any Java developer into a Groovy developer. Sure Groovy offers much more than Java in terms of power, and it can take some time to get a good grasp of all the ins and outs of closures, dynamic typing or even metaprogramming. But the good news is that you don’t need to master all those right away in order to leverage a lot of the productivity you can get out of Groovy. © Catalysts GmbH
  • 24. Why would I use it? 3- And it runs on the JVM And it gets even further than that: Groovy is so Java-rooted that it actually compiles to run on a Java runtime. Groovy code compiles into JVM bytecode, which means you can still make Groovy and Grails applications run on your favorite application server (simplest is Tomcat, but I’ve made it run on JBoss and even Weblogic) AND you can reuse all the awesome libraries available in the Java ecosystem in an instant. Just plug your environment with your Maven or Ivy repository of choice, or copy some JARs over and you’re good to go! How amazing is that? © Catalysts GmbH
  • 25. Why would I use it? 4- Groovy is not just for scripting I mean sure, Groovy is great for system scripting, in the same way as Ruby and Python are. Not everything needs to be a class so you can write scripts in no time. But a lot of people use Groovy just for that, and think it’s not ready for prime-time big-fuss applications yet Yes, Groovy is a dynamic language, which also means that there is a lot less stuff checked at compilation time than with mere Java, but since your code is much more expressive, there is a lot less opportunity for errors too, and unit tests are a lot easier to write, especially thanks to DSL’s. © Catalysts GmbH
  • 26. Why would I use it? 5- A very dynamic ecosystem Every experienced developer knows that a good framework is nothing without good documentation, serious support and a large community of contributors. Well, of course Groovy and Grails have all that. First of all, they are part of the portfolio of SpringSource, the very company that brought you the Spring Framework and that is now a division of VMWare. The documentation is really good, like most Spring documentations by the way, and there are some excellent books out there. As for helpers and contributors, whether it is on the mailing list or on StackOverflow, helpers are everywhere. And in terms of ecosystem: Grails has a plugin mechanism that makes it really easy to extend the framework in a lot of different ways. Now I won’t lie, all of the available plugins are not necessarily supported or kept up-to-date on the long run, but they are so easy to write and fix, that it’s not really an issue. © Catalysts GmbH
  • 27. Why would I use it? Liquibase integration When you already have your application in production, you need a way to modify your db automatically, thus Liquibase. © Catalysts GmbH
  • 28. Why would I use it? 5- A very dynamic ecosystem Every experienced developer knows that a good framework is nothing without good documentation, serious support and a large community of contributors. Well, of course Groovy and Grails have all that. First of all, they are part of the portfolio of SpringSource, the very company that brought you the Spring Framework and that is now a division of VMWare. The documentation is really good, like most Spring documentations by the way, and there are some excellent books out there. As for helpers and contributors, whether it is on the mailing list or on StackOverflow, helpers are everywhere. And in terms of ecosystem: Grails has a plugin mechanism that makes it really easy to extend the framework in a lot of different ways. Now I won’t lie, all of the available plugins are not necessarily supported or kept up-to-date on the long run, but they are so easy to write and fix, that it’s not really an issue. © Catalysts GmbH