Grails – The search is over       Aécio Costa      Felipe Coutinho
Grails – The search is overGroovy   Características   Groovy x Java   Regra dos 80/20Grails   Cenário Atual do Desenvo...
Grails – The search is overGroovy - Características  Inspirada no Python, Ruby...;  Linguagem Dinâmica;  Plataforma Jav...
Grails – The search is overO que Groovy tem de diferente de Java?  Tipagem dinâmica;  Recurso: attribute accessor;  Closur...
Grails – The search is overTipagem dinâmicadef name = “João”def names = [“João”, “José”, “Geraldo”]
Grails – The search is overAtribute accessorclass User{    String nome    Integer idade}def user = new User(name:”João”, a...
Grails – The search is overClosuredef name = “Paulo”def printName = {println “Hello, ${name}”}printName()def listNames = [...
Grails – The search is overMétodos Dinâmicosdef methodName = “getYearBorn”user.”${methodName}”()new User().”getDayBorn”()
Grails – The search is overAlém de...Sobre carga de operadores;Ranges;MetaPrograming;e etc...
Grails – The search is overGroovy veio acabar com a Regra dos 80/20           (Princípio de Pareto)
Grails – The search is overimport java.util.ArrayList;import java.util.List;class Seletor {   private List selectBooksName...
Grails – The search is overO que realmente interessa no código anterior?
Grails – The search is overimport java.util.ArrayList;import java.util.List;class Seletor {   private List selectBooksName...
Grails – The search is over
Grails – The search is overClosure e import implícito
Grails – The search is overimport java.util.ArrayList;import java.util.List;class Seletor {   private List selectBooksName...
Grails – The search is overclass Seletor {    private List selectBooksNameLessThan(List bookNames, int length) {       Lis...
Grails – The search is overClosure e import implícitoDeclaração e Assinatura de Métodos
Grails – The search is overclass Seletor {    private List selectBooksNameLessThan(List bookNames, int length) {       Lis...
Grails – The search is overList selectBooksNameLessThan(List bookNames, int length) {    List resultado = new ArrayList();...
Grails – The search is overClosure e import implícitoDeclaração e Assinatura de MétodosTipagem Estática
Grails – The search is overList selectBooksNameLessThan(List bookNames, int length) {    List resultado = new ArrayList();...
Grails – The search is overdef selectBooksNameLessThan(bookNames, length) {    def resultado = new ArrayList();    bookNam...
Grails – The search is overClosure e import implícitoDeclaração e Assinatura de MétodosTipagem EstáticaInstância simpl...
Grails – The search is overdef selectBooksNameLessThan(bookNames, length) {    def resultado = new ArrayList();    bookNam...
Grails – The search is overdef selectBooksNameLessThan(bookNames, length) {    def resultado = [];    bookNames.each { can...
Grails – The search is overClosure e import implícitoDeclaração e Assinatura de MétodosTipagem EstáticaInstância simpl...
Grails – The search is overdef selectBooksNameLessThan(bookNames, length) {    def resultado = [];    bookNames.each { can...
Grails – The search is overdef selectBooksNameLessThan(bookNames, length) {    bookNames.findAll { it.size() < length }}de...
Grails – The search is overdef selectBooksNameLessThan(bookNames, length) {    bookNames.findAll { it.size() < length }}de...
Grails – The search is overdef books = ["Harry Potter”, "A Vila”, “O Exorcista”]def selected = books. findAll { it.size() ...
Grails – The search is overdef books = ["Harry Potter”, "A Vila”, “O Exorcista”]def selected = books. findAll { it.size() ...
Grails – The search is overdef books = ["Harry Potter”, "A Vila”, “O Exorcista”]def selected = books. findAll { it.size() ...
Grails – The search is overCenário Atual Web   Persistência   Validações   Logs   Visualização   Controladores   Con...
Grails – The search is over
Grails – The search is over   Welcome to
Grails – The search is over Framework Web de Alta produtividade para plataforma Java; Programação por convenção; MVC na...
Grails – The search is overArquitetura do Grails
Grails – The search is overPassos para criar a Aplicação   $ grails create-app booklibrary   $ grails run-app
Grails – The search is overClasses de domínio   $ grails create-domain-class cesar.example.Bookclass Book {   String title...
Grails – The search is overScaffoldingINSERT, UPDATE, DELETE, SEARCH$ grails generate-all cesar.example.Book
Grails – The search is overValidations (Constraints)DSL interna baseada no recurso builder da linguagem Groovy;Constraints...
Grails – The search is overRelacionamento$ grails create-domain-class cesar.example.Personclass Person {   static hasMany ...
Grails – The search is overView.gspi18n# Bookbook.label=Livrobook.title.label=Titulobook.person.label=Pessoabook.releaseDa...
Grails – The search is overGORMdef books = Book.list(max:10, order:”name”)def books = Book.findByName(“The Developer”)def ...
Grails – The search is overGORMclass BookController {  def find() {     def books = Book.findAllByTitleLike("%"+params.lik...
Grails – The search is overWebService RESTimport grails.converters.*  def showRest() {    def bookInstance = Book.get(para...
Grails – The search is overConfiguração por ambiente   BuildConfig.groovy   DataSource.groovy   development {      dataSou...
Grails – The search is overPluginsGWTLDAPSpring SecuritySpring WSMaillFeedsQuartzAxis2Wicket
Grails – The search is overDeploy$ grails warhttp://ec2-184-73-69-212.compute-1.amazonaws.com:8080/managerhttp://ec2-184-7...
bibliografia sugeridahttp://groovy.codehaus.org/http://grails.org/
perguntas ???
contatoAécio Costa – aecio.costa@cesar.org.br – www.aeciocosta.com.brFelipe Coutinho – flc@cesar.org.br – www.felipelc.com
Upcoming SlideShare
Loading in …5
×

Grails: The search is over

746 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
746
On SlideShare
0
From Embeds
0
Number of Embeds
54
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Grails: The search is over

  1. 1. Grails – The search is over Aécio Costa Felipe Coutinho
  2. 2. Grails – The search is overGroovy  Características  Groovy x Java  Regra dos 80/20Grails  Cenário Atual do Desenvolvimento Web  Características  Arquitetura  Demo
  3. 3. Grails – The search is overGroovy - Características Inspirada no Python, Ruby...; Linguagem Dinâmica; Plataforma Java; Especificação do JCP (JSR 241); Copy/Paste Compatibilty.
  4. 4. Grails – The search is overO que Groovy tem de diferente de Java? Tipagem dinâmica; Recurso: attribute accessor; Closure; Métodos Dinâmicos; e mais...
  5. 5. Grails – The search is overTipagem dinâmicadef name = “João”def names = [“João”, “José”, “Geraldo”]
  6. 6. Grails – The search is overAtribute accessorclass User{ String nome Integer idade}def user = new User(name:”João”, age: 23)user.nome = “Pedro”
  7. 7. Grails – The search is overClosuredef name = “Paulo”def printName = {println “Hello, ${name}”}printName()def listNames = [“Gabriela”, “Maria”]def sayHello = {println it}listNames.each(sayHello)
  8. 8. Grails – The search is overMétodos Dinâmicosdef methodName = “getYearBorn”user.”${methodName}”()new User().”getDayBorn”()
  9. 9. Grails – The search is overAlém de...Sobre carga de operadores;Ranges;MetaPrograming;e etc...
  10. 10. Grails – The search is overGroovy veio acabar com a Regra dos 80/20 (Princípio de Pareto)
  11. 11. Grails – The search is overimport 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); } }
  12. 12. Grails – The search is overO que realmente interessa no código anterior?
  13. 13. Grails – The search is overimport 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); } }
  14. 14. Grails – The search is over
  15. 15. Grails – The search is overClosure e import implícito
  16. 16. Grails – The search is overimport 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); } }
  17. 17. Grails – The search is overclass 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); } }}
  18. 18. Grails – The search is overClosure e import implícitoDeclaração e Assinatura de Métodos
  19. 19. Grails – The search is overclass 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); } }}
  20. 20. Grails – The search is overList 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);}
  21. 21. Grails – The search is overClosure e import implícitoDeclaração e Assinatura de MétodosTipagem Estática
  22. 22. Grails – The search is overList 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);}
  23. 23. Grails – The search is overdef 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);}
  24. 24. 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
  25. 25. Grails – The search is overdef 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);}
  26. 26. Grails – The search is overdef 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}
  27. 27. 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
  28. 28. Grails – The search is overdef 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}
  29. 29. Grails – The search is overdef 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}
  30. 30. Grails – The search is overdef 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}
  31. 31. Grails – The search is overdef books = ["Harry Potter”, "A Vila”, “O Exorcista”]def selected = books. findAll { it.size() <= 5}println "Total ${selecionados.size()}”selected.each { sel -> println sel}
  32. 32. Grails – The search is overdef 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
  33. 33. Grails – The search is overdef books = ["Harry Potter”, "A Vila”, “O Exorcista”]def selected = books. findAll { it.size() <= 5}println "Total ${selecionados.size()}”selected.each { sel -> println sel Groovy é Java}Seletor.groovy
  34. 34. Grails – The search is overCená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
  35. 35. Grails – The search is over
  36. 36. Grails – The search is over Welcome to
  37. 37. 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...
  38. 38. Grails – The search is overArquitetura do Grails
  39. 39. Grails – The search is overPassos para criar a Aplicação $ grails create-app booklibrary $ grails run-app
  40. 40. Grails – The search is overClasses de domínio $ grails create-domain-class cesar.example.Bookclass Book { String title Date releaseDate String ISBN}
  41. 41. Grails – The search is overScaffoldingINSERT, UPDATE, DELETE, SEARCH$ grails generate-all cesar.example.Book
  42. 42. Grails – The search is overValidations (Constraints)DSL interna baseada no recurso builder da linguagem Groovy;Constraints: http://grails.org/doc/latest/ref/Constraints/Usage.htmlstatic constraints = { title(blank: false) ISBN(blank: false, unique: true) }
  43. 43. Grails – The search is overRelacionamento$ grails create-domain-class cesar.example.Personclass 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]
  44. 44. Grails – The search is overView.gspi18n# Bookbook.label=Livrobook.title.label=Titulobook.person.label=Pessoabook.releaseDate.label=Data de lancamento# Personperson.label=Pessoaperson.name.label=Nomeperson.password.label=Senha
  45. 45. Grails – The search is overGORMdef 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)
  46. 46. Grails – The search is overGORMclass 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>
  47. 47. Grails – The search is overWebService RESTimport grails.converters.* def showRest() { def bookInstance = Book.get(params.id) if(!bookInstance){ render new Book() as JSON return } render bookInstance as JSON }
  48. 48. Grails – The search is overConfiguração por ambiente BuildConfig.groovy DataSource.groovy development { dataSource { pooled = true driverClassName = "com.mysql.jdbc.Driver” username = "book" password = "book123" 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
  49. 49. Grails – The search is overPluginsGWTLDAPSpring SecuritySpring WSMaillFeedsQuartzAxis2Wicket
  50. 50. Grails – The search is overDeploy$ grails warhttp://ec2-184-73-69-212.compute-1.amazonaws.com:8080/managerhttp://ec2-184-73-69-212.compute-1.amazonaws.com:8080/booklibrary-0.1/
  51. 51. bibliografia sugeridahttp://groovy.codehaus.org/http://grails.org/
  52. 52. perguntas ???
  53. 53. contatoAécio Costa – aecio.costa@cesar.org.br – www.aeciocosta.com.brFelipe Coutinho – flc@cesar.org.br – www.felipelc.com

×