+ All Categories
Home > Software > Grails - The search is over

Grails - The search is over

Date post: 27-May-2015
Category:
Upload: felipe-coutinho
View: 107 times
Download: 1 times
Share this document with a friend
Description:
Apresentação criada para o Intervalo Técnico do CESAR realizado em 07/03/2012. Grails é um framework web de alta produtividade para a plataforma Java. Para isso ele utiliza tecnologias maduras do mundo Java, como os frameworks Hibernate e Spring, através de uma interface simples e consistente. Com pouca codificação e configuração, graças a linguagem Groovy, é possível criar aplicações web de forma fácil e ágil.
Popular Tags:
55
Instituto de Inovação com Inovação é a gente! INTERVALO CESAR
Transcript
Page 1: Grails - The search is over

Instituto de Inovação com TIC

Inovação é a gente!

INTERVALO CESAR

Page 2: Grails - The search is over

Grails – The search is over

Aécio Costa

Felipe Coutinho

Page 3: Grails - The search is over

Grails – The search is over

GroovyCaracterísticasGroovy x JavaRegra dos 80/20

Grails Cenário Atual do Desenvolvimento WebCaracterísticasArquiteturaDemo

Page 4: Grails - The search is over

Groovy - Características

Inspirada no Python, Ruby...;

Linguagem Dinâmica;

Plataforma Java;

Especificação do JCP (JSR 241);

Copy/Paste Compatibilty.

Grails – The search is over

Page 5: Grails - The search is over

O que Groovy tem de diferente de Java?

Tipagem dinâmica;

Recurso: attribute accessor;

Closure;

Métodos Dinâmicos;

e mais...

Grails – The search is over

Page 6: Grails - The search is over

Tipagem dinâmica

def name = “João”

def names = [“João”, “José”, “Geraldo”]

Grails – The search is over

Page 7: Grails - The search is over

Atribute accessor

class User{

String nome Integer idade

}

def user = new User(name:”João”, age: 23)

user.nome = “Pedro”

Grails – The search is over

Page 8: Grails - The search is over

Closure

def name = “Paulo”

def printName = {println “Hello, ${name}”}

printName()

def listNames = [“Gabriela”, “Maria”]

def sayHello = {println it}

listNames.each(sayHello)

Grails – The search is over

Page 9: Grails - The search is over

Métodos Dinâmicos

def methodName = “getYearBorn”

user.”${methodName}”()

new User().”getDayBorn”()

Grails – The search is over

Page 10: Grails - The search is over

Além de...

Sobre carga de operadores;

Ranges;

MetaPrograming;

e etc...

Grails – The search is over

Page 11: Grails - The search is over

Groovy veio acabar com a Regra dos 80/20 (Princípio de Pareto)

Grails – The search is over

Page 12: Grails - The search is over

import java.util.ArrayList;

import java.util.List;

class Seletor {

private List selectBooksNameLessThan(List bookNames, int length) {

List resultado = new ArrayList();

for (int i = 0; i < bookNames.size(); i++) {

String candidate = (String) bookNames.get(i);

if (candidate.length() < length) {

resultado.add(candidate);

}

}

return resultado;

}

public static void main(String[] args) {

List books = new ArrayList();

books.add("Harry Potter");

books.add("A Vila");

books.add(“O Exorcista");

Seletor s = new Seletor();

List selected = s.selectBooksNameLessThan(books, 10);

System.out.println("Total Selecionados: " + selecionados.size());

for (int i = 0; i < selected.size(); i++) {

String sel = (String) selecionados.get(i);

System.out.println(sel);

}

}

}

Grails – The search is over

Page 13: Grails - The search is over

O que realmente interessa no código anterior?

Grails – The search is over

Page 14: Grails - The search is over

import java.util.ArrayList;

import java.util.List;

class Seletor {

private List selectBooksNameLessThan(List bookNames, int length) {

List resultado = new ArrayList();

for (int i = 0; i < bookNames.size(); i++) {

String candidate = (String) bookNames.get(i);

if (candidate.length() < length) {

resultado.add(candidate);

}

}

return resultado;

}

public static void main(String[] args) {

List books = new ArrayList();

books.add("Harry Potter");

books.add("A Vila");

books.add(“O Exorcista");

Seletor s = new Seletor();

List selected = s.selectBooksNameLessThan(books, 10);

System.out.println("Total Selecionados: " + selecionados.size());

for (int i = 0; i < selected.size(); i++) {

String sel = (String) selecionados.get(i);

System.out.println(sel);

}

}

}

Grails – The search is over

Page 15: Grails - The search is over

Grails – The search is over

Page 16: Grails - The search is over

Closure e import implícito

Grails – The search is over

Page 17: Grails - The search is over

import java.util.ArrayList;

import java.util.List;

class Seletor {

private List selectBooksNameLessThan(List bookNames, int length) {

List resultado = new ArrayList();

for (int i = 0; i < bookNames.size(); i++) {

String candidate = (String) bookNames.get(i);

if (candidate.length() < length) {

resultado.add(candidate);

}

}

return resultado;

}

public static void main(String[] args) {

List books = new ArrayList();

books.add("Harry Potter");

books.add("A Vila");

books.add(“O Exorcista");

Seletor s = new Seletor();

List selected = s.selectBooksNameLessThan(books, 10);

System.out.println("Total Selecionados: " + selecionados.size());

for (int i = 0; i < selected.size(); i++) {

String sel = (String) selecionados.get(i);

System.out.println(sel);

}

}

}

Grails – The search is over

Page 18: Grails - The search is over

class Seletor {

private List selectBooksNameLessThan(List bookNames, int length) {

List resultado = new ArrayList();

bookNames.each { String candidate ->

if (candidate.length() < length) {

resultado.add(candidate);

}

}

return resultado;

}

public static void main(String[] args) {

List books = new ArrayList();

books.add("Harry Potter");

books.add("A Vila");

books.add(“O Exorcista");

Seletor s = new Seletor();

List selected = s.selectBooksNameLessThan(books, 10);

System.out.println("Total Selecionados: " + selecionados.size());

selected.each { String sel ->

System.out.println(sel);

}

}

}

Grails – The search is over

Page 19: Grails - The search is over

Closure e import implícito

Declaração e Assinatura de Métodos

Grails – The search is over

Page 20: Grails - The search is over

class Seletor {

private List selectBooksNameLessThan(List bookNames, int length) {

List resultado = new ArrayList();

bookNames.each { String candidate ->

if (candidate.length() < length) {

resultado.add(candidate);

}

}

return resultado;

}

public static void main(String[] args) {

List books = new ArrayList();

books.add("Harry Potter");

books.add("A Vila");

books.add(“O Exorcista");

Seletor s = new Seletor();

List selected = s.selectBooksNameLessThan(books, 10);

System.out.println("Total Selecionados: " + selecionados.size());

selected.each { String sel ->

System.out.println(sel);

}

}

}

Grails – The search is over

Page 21: Grails - The search is over

List selectBooksNameLessThan(List bookNames, int length) {

List resultado = new ArrayList();

bookNames.each { String candidate ->

if (candidate.length() < length) {

resultado.add(candidate);

}

}

return resultado;

}

List books = new ArrayList();

books.add("Harry Potter");

books.add("A Vila");

books.add(“O Exorcista");

Seletor s = new Seletor();

List selected = s.selectBooksNameLessThan(books, 10);

System.out.println("Total Selecionados: " + selecionados.size());

selected.each { String sel ->

System.out.println(sel);

}

Grails – The search is over

Page 22: Grails - The search is over

Closure e import implícito

Declaração e Assinatura de Métodos

Tipagem Estática

Grails – The search is over

Page 23: Grails - The search is over

List selectBooksNameLessThan(List bookNames, int length) {

List resultado = new ArrayList();

bookNames.each { String candidate ->

if (candidate.length() < length) {

resultado.add(candidate);

}

}

return resultado;

}

List books = new ArrayList();

books.add("Harry Potter");

books.add("A Vila");

books.add(“O Exorcista");

Seletor s = new Seletor();

List selected = s.selectBooksNameLessThan(books, 10);

System.out.println("Total Selecionados: " + selecionados.size());

selected.each { String sel ->

System.out.println(sel);

}

Grails – The search is over

Page 24: Grails - The search is over

def selectBooksNameLessThan(bookNames, length) {

def resultado = new ArrayList();

bookNames.each { candidate ->

if (candidate.size() < length) {

resultado.add(candidate);

}

}

return resultado;

}

def books = new ArrayList();

books.add("Harry Potter");

books.add("A Vila");

books.add(“O Exorcista");

def selected = s.selectBooksNameLessThan(books, 10);

System.out.println("Total Selecionados: " + selecionados.size());

selected.each { sel ->

System.out.println(sel);

}

Grails – The search is over

Page 25: Grails - The search is over

Closure e import implícito

Declaração e Assinatura de Métodos

Tipagem Estática

Instância simplificada de Listas

Não necessidade de “return”

“;” não obrigatório

Impressão simples

Grails – The search is over

Page 26: Grails - The search is over

def selectBooksNameLessThan(bookNames, length) {

def resultado = new ArrayList();

bookNames.each { candidate ->

if (candidate.size() < length) {

resultado.add(candidate);

}

}

return resultado;

}

def books = new ArrayList();

books.add("Harry Potter");

books.add("A Vila");

books.add(“O Exorcista");

def selected = s.selectBooksNameLessThan(books, 10);

System.out.println("Total Selecionados: " + selecionados.size());

selected.each { sel ->

System.out.println(sel);

}

Grails – The search is over

Page 27: Grails - The search is over

def selectBooksNameLessThan(bookNames, length) {

def resultado = [];

bookNames.each { candidate ->

if (candidate.size) < length) {

resultado.add(candidate)

}

}

resultado

}

def books = ["Harry Potter”, "A Vila”, “O Exorcista”]

def selected = s.selectBooksNameLessThan(books, 10)

println "Total ${selecionados.size()}”

selected.each { sel ->

println sel

}

Grails – The search is over

Page 28: Grails - The search is over

Closure e import implícito

Declaração e Assinatura de Métodos

Tipagem Estática

Instância simplificada de Listas

Não necessidade de “return”

“;” não obrigatório

Impressão simples

Métódos Dinâmicos

Grails – The search is over

Page 29: Grails - The search is over

def selectBooksNameLessThan(bookNames, length) {

def resultado = [];

bookNames.each { candidate ->

if (candidate.size) < length) {

resultado.add(candidate)

}

}

resultado

}

def books = ["Harry Potter”, "A Vila”, “O Exorcista”]

def selected = s.selectBooksNameLessThan(books, 10)

println "Total ${selecionados.size()}”

selected.each { sel ->

println sel

}

Grails – The search is over

Page 30: Grails - The search is over

def selectBooksNameLessThan(bookNames, length) {

bookNames.findAll { it.size() < length }

}

def books = ["Harry Potter”, "A Vila”, “O Exorcista”]

def selected = s.selectBooksNameLessThan(books, 10)

println "Total ${selecionados.size()}”

selected.each { sel ->

println sel

}

Grails – The search is over

Page 31: Grails - The search is over

def selectBooksNameLessThan(bookNames, length) {

bookNames.findAll { it.size() < length }

}

def books = ["Harry Potter”, "A Vila”, “O Exorcista”]

def selected = s.selectBooksNameLessThan(books, 10)

println "Total ${selecionados.size()}”

selected.each { sel ->

println sel

}

Grails – The search is over

Page 32: Grails - The search is over

def books = ["Harry Potter”, "A Vila”, “O Exorcista”]

def selected = books. findAll { it.size() <= 5}

println "Total ${selecionados.size()}”

selected.each { sel ->

println sel

}

Grails – The search is over

Page 33: Grails - The search is over

def books = ["Harry Potter”, "A Vila”, “O Exorcista”]

def selected = books. findAll { it.size() <= 5}

println "Total ${selecionados.size()}”

selected.each { sel ->

println sel

}

Seletor.groovy

Grails – The search is over

Page 34: Grails - The search is over

def books = ["Harry Potter”, "A Vila”, “O Exorcista”]

def selected = books. findAll { it.size() <= 5}

println "Total ${selecionados.size()}”

selected.each { sel ->

println sel

}

Seletor.groovy

Grails – The search is over

Groovy é Java

Page 35: Grails - The search is over

Cenário Atual Web

Persistência Validações Logs Visualização Controladores Controle Transacional Injeção de Dependências Ajax Redirecionador de URL’s Configuração por ambiente Internacionalização

Grails – The search is over

Page 36: Grails - The search is over

Grails – The search is over

Page 37: Grails - The search is over

Grails – The search is over

Welcome to

Page 38: Grails - The search is over

Framework Web de Alta produtividade para plataforma

Java;

Programação por convenção;

MVC nativo;

Fácil bootstrap;

GORM;

Scaffolding;

Plugins;

e tudo que você viu lá atras...

Grails – The search is over

Page 39: Grails - The search is over

Arquitetura do Grails

Grails – The search is over

Page 40: Grails - The search is over

Passos para criar a Aplicação

$ grails create-app booklibrary

$ grails run-app

Grails – The search is over

Page 41: Grails - The search is over

Classes de domínio

$ grails create-domain-class cesar.example.Book

class Book { String title Date releaseDate String ISBN }

Grails – The search is over

Page 42: Grails - The search is over

Scaffolding

INSERT, UPDATE, DELETE, SEARCH

$ grails generate-all cesar.example.Book

Grails – The search is over

Page 43: Grails - The search is over

Validations (Constraints)

DSL interna baseada no recurso builder da linguagem Groovy;

Constraints: http://grails.org/doc/latest/ref/Constraints/Usage.html

static constraints = { title(blank: false) ISBN(blank: false, unique: true) }

Grails – The search is over

Page 44: Grails - The search is over

Relacionamento

$ grails create-domain-class cesar.example.Person

class Person { static hasMany = [books: Book] String name String email String password

static constraints = { name(blank: false) email(blank: false, email: true) password(blank: false, password: true) } }

Na classe Book:static belongsTo = [person: Person]

Grails – The search is over

Page 45: Grails - The search is over

View

.gsp

i18n# Bookbook.label=Livrobook.title.label=Titulobook.person.label=Pessoabook.releaseDate.label=Data de lancamento

# Personperson.label=Pessoaperson.name.label=Nomeperson.password.label=Senha

Grails – The search is over

Page 46: Grails - The search is over

GORM

def books = Book.list(max:10, order:”name”)

def books = Book.findByName(“The Developer”)

def books = Book.findAllByPriceLessThan(10.0)

def books = Book.findAllByTitleLikeAndPriceBetween(“Harry %”, 40.0, 70.0)

Grails – The search is over

Page 47: Grails - The search is over

GORM

class BookController { def find() { def books = Book.findAllByTitleLike("%"+params.like+"%") render(view: "list", model: [bookInstanceList: books, bookInstanceTotal: books.size()]) }}

<div> <br/> <g:form name="myForm" url="[controller:'book',action:'find']"> <g:actionSubmit value="Find" /> <g:textField name="like" value="" /> </g:form></div>

Grails – The search is over

Page 48: Grails - The search is over

WebService REST

import grails.converters.*

def showRest() { def bookInstance = Book.get(params.id) if(!bookInstance){ render new Book() as JSON return } render bookInstance as JSON }

Grails – The search is over

Page 49: Grails - The search is over

Configuração por ambiente

BuildConfig.groovyDataSource.groovy

development { dataSource { pooled = true driverClassName = "com.mysql.jdbc.Driver” username = “root" password = “root" dbCreate = "create-drop" dialect = "org.hibernate.dialect.MySQL5InnoDBDialect" url = "jdbc:mysql://localhost:3306/book_dev?autoreconnect=true" }}

$ grails install-dependency mysql:mysql-connector-java:5.1.16

Grails – The search is over

Page 50: Grails - The search is over

Plugins

GWT

LDAP

Spring Security

Spring WS

Maill

Feeds

Quartz

Axis2

Wicket

Grails – The search is over

Page 51: Grails - The search is over

Deploy

$ grails war

Grails – The search is over

Page 52: Grails - The search is over

bibliografia sugerida

http://groovy.codehaus.org/http://grails.org/

Page 53: Grails - The search is over

perguntas ???

Page 54: Grails - The search is over

Aécio Costa – [email protected]

www.aeciocosta.com.br

Felipe Coutinho – [email protected] – www.felipelc.com

contato

Page 55: Grails - The search is over

Recommended