groovy and grails intro

Download Groovy and Grails intro

If you can't read please download the document

Upload: miguel-pastor

Post on 16-Apr-2017

3.465 views

Category:

Technology


0 download

TRANSCRIPT

Fresh Morning

Groovy and Grails introduction

A pragmatic view

Miguel ngel Pastor Olivarmiguelinlas3 at gmail dot comhttp://miguelinlas3.blogspot.comhttp://twitter.com/miguelinlas3

Spring

Jetty

Database

Eclipse

Web Architecture

Java

IntelliJ

DSL's

Software Patterns

Maven

Groovy

Tomcat

Unit Testing

ByteCode

Agile

Netbeans

Dynamic Languages

Domain Design

Dependency Injection

Grails

Sitemesh

Hibernate

Plugin Architecture

Java Platform

Java Platform

Java is a platform, not a language

Interprets bytecode (.class files)

Multiple platform support (Linux, OSx,...)

Garbage collection

Java Language

. . .

Java Platform

JSR 924: Virtual Machine Specification

JSR 901: Java Language Specification

JSR 241: Groovy Language Specification

JSR 274: Bean Shell Scripting Language

JSR 292: Supporting Dynamically Typed Languages (JavaScript,Scala,Python, . . .)

Java Platform

DaVinci Machine: OpenJDK subproject

Multiple Language support (especially dynamic)

JVM Extensions

Co-existing with Java

Common base model (garbage collection, model execution, . . . )

Groovy Features

Groovy

Dynamic Language for the JVM

Additional power features like Python, Ruby and Smalltalk

Modern programming features to Java developers

DSLs: easy to read and maintain

Writing shell and build script easy (Ant DSL,OO)

Groovy

Strong typing (optional)

Duck typing

Java Object Model

Closures: High Order Functions

Easy Java Integration

Similar to Java syntax

Installing Groovy

Download latest release: download

Set environment variable GROOVY_HOME

Add GROOVY_HOME\bin to the path

Open a console and type: groovy -v

Ready to work!

Groovy Datatypes

Everything is a object

Optional typing

Overriding operators

Working with strings

Working with regular expressions

Working with numbers

Groovy Collections

Working with ranges

Working with lists

Working with maps

Concurrent modifications

Working with closures

Piece of code wrapped up as an object

Syntax: code in curly braces

Assign it to a variable

Using methods as closures reference.&someMethod

Calling them explicitly

Return from closures

Control Structures

Working with if-else

Working with switch

Working with while

Iterating over closures

Return values from if/else

Return values from exception handlers

Object Orientation

Similar to Java Model

Methods and fields: modifiers are not needed

Positional and named parameters

Dynamics: ObjReference.'method-name'

Coercion with as operator

Coercion in assignment

Type aliasing

Database programming

SQL easier

SQL more Groovy

Performing read queries

Performing write queries

A practical example

Working with builders

Domain Specific Languages hype

Easy to read and maintain

Building DSL: outside the limits

Using DSL: building RCP apps

References

http://groovy.codehaus.org/Documentation

Groovy in Action (Second Edition Early Access)

Programming Groovy

Neo Metrics products: AquaBM, UserMgmt

Surf the web!

Grails Features

Motivations and pros

Unnecessary complexity (DRY)

Grails,Rails,Django, TurboGears

Reduce complexity

Built on top proven technologies

Full stack development

SpringSource

Architecture (I)

ORM built on Hibernate

Views technologies: Groovy Server Pages

Controller layer built on Spring MVC

Command layer based on Gant

Embedded Tomcat (and Jetty). Fly reloading

Depedency Injection based on Spring

Support for internazionalitation

Architecture (II)

Transactional service layer (Springs transactions)

Groovy power

Extensive use of Domain Specific Languages

Plugins architecture

Installing Grails

Download latest release: download

Set environment variable GRAILS_HOME

Add GRAILS_HOME\bin to the path

Open a console and type: grails help

Ready to work!

Beginning Grails

Our first Grails application

Setting up an IDE: Spring Tool Suite

Convention over configuration

Beginning Grails

Running application: grails run-app

Testing application: grails test-app

Deploying application: grails war

Servlet 2.4+ container

GORM (I)

Creating domain class: grails create-domain-class

Create operation

Read operation

Update operation

Delete operation

GORM (II)

Domain modeling: POGO

Asocciation: one to one

Association: one to many

Association: many to many

Inheritance

Performance tips

Cascading updates and deletes

GORM (III)

Basics querying: List, retrieve by id

Dynamic finders: findBy, findByAll

Method expressions: findBy([Property][Comparator][Boolean Operator])?[Property][Comparator]

Criteria: building complex queries

Programmatic transactions: withTransaction

Controllers (I)

Handling requests, preparing responses

Class *Controller in grails-app/controllers

Each closure maps to a URI

Available scopes ServletContext

Session

Request

Params

Flash

Controllers (II)

Model and View: a model is a map

Explicit model return or controller properties

Rendering views: grails-app/views/controller/actionName.gsp

Use of render. Rendering xml, json

More concepts: interceptors, filters

Groovy Server Pages (I)

View technology: similar to JSP or ASP

HTML + tags

embed code (discouraged!!)

Prefedined variables Application

ApplicationContext

Flash

GrailsApplication

Out, params, request, response, session webrequest

Groovy Server Pages (II)

Page directives: import classes

Views and templates.

GSP Builting Tags: Logic and iteration

Search and filtering

Links and resources

Form and fields

The service layer (I)

Not embed application logic in controllers

New service: grails create-service

Transacional by default: static transactional = false

Depedency injection by convention

Reusable logic

Use from Java classes

References

http://grails.org/doc/latest/

Grails in action: http://www.manning.com/gsmith/

The Definitive Guide to Grails, Second Edition

http://www.grailstutorials.com/home/

Real examples

Some real examples

Cronos: sample management app

Doing REST in Grails

Thank you very much all for coming!