SlideShare a Scribd company logo
def speaker = new Cast(name:"T.Yamamoto",version:"G*-2010-04-24")




                                                                1
2
3
4
5
6
7
8
9
10
View
            MVC2




       DI


11
12
ur ity
                                             S ec




                     low
    Controller
                              i1 8n
                                                              Flex




                      bF
                   We
                 Codec                   Quartz
    Domain

Grails                                      lug
                                               in
                                                              JMS
                                         MyP
     Core                  Quartz

                                                     ag gin
               Service          UrlMapping          T
     Filters
                                                                     13
14
15
16
17
18
19
20
% export GRAILS_HOME=/opt/grails-1.2.2
% export PATH=$GRAILS_HOME/bin:$PATH

% grails
Welcome to Grails 1.2.2 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /opt/grails-1.2.2
                       21
% grails run-app
% grails test-app




                    22
23
|--   application.properties
|--   grails-app
|     |-- conf        -
|     |-- controllers -
|     |-- domain      -
|     |-- i18n
|     |-- services    -
|     |-- taglib      -
|     |-- utils
|     `-- views       -
|--   lib
|--   scripts         -
|--   src             -
|--   test            -
`--   web-app         -
                           24
25
package com.pack

     class Book {

       String title
       String author
       int    rate
       String comment
       
       Date dateCreated
       Date lastUpdated
       
       static constraints = {
       }
     }
26
  static constraints = {
         title nullable:false,blank:false
         author nullable:false,blank:false
         rate range:0..10
         comment maxSize:1000
         price shared:'myShared'
         withTax display:false
       }

     grails.gorm.default.constraints = {
         '*'(nullable:true, size:1..20)
         myShared(nullable:true)
     }
27
class Book implements Serializable{
  static mapping = {
    table 'T_BOOK'
    id generator:'uuid.hex', params:[type:'string']
    columns {
      comment column:'F_COMMENT',sqlType:'varchar(1000)'
    }
    withTax formula: 'price * 1.05'
  }
                           28
29
Account.executeQuery(
    "select distinct a.number from Account a where a.branch = :branch",
    [branch:'London'],
    [max:10, offset:5]
)
Book.findAll("from Book as b where b.author=?",['               '])

                                   30
def results = Book.findAllByTitle("           ",
    [max:10, sort:"title", order:"desc", offset:100] )

def results = Book.findAllByTitleAndAuthor(
                        "             ", "         ")




                                                         31
def c = Account.createCriteria()
def results = c.list {  
    like("holderFirstName", "Fred%")  
    and {   
        between("balance", 500, 1000)   
        eq("branch", "London")  
    }  
    maxResults(10)
    order("holderLastName", "desc")
}

                    32
dataSource {
  pooled = true
  driverClassName = "org.hsqldb.jdbcDriver"
  username = "sa"
  password = ""
}

hibernate {
  cache.use_second_level_cache=true
  cache.use_query_cache=true
  cache.provider_class='net.sf.ehcache.hibernate.EhCacheProvider'
}

environments {
  development {
    dataSource {
      dbCreate = "update"
      url = "jdbc:hsqldb:file:devDB;shutdown=true"
    }
  }
  test {
    dataSource {
....   ....
                                       33
import javax.persistence.*
      
      @Entity
      @Table(name = "animal")
      class Animal {
      
        @Id 
        @GeneratedValue
        int id
        String name
        @ManyToOne
        @JoinColumn
        Owner owner
      
        static constraints = {
          name blank:false
        }
      }

34
35
http://localhost:8080/myapp/book/index

package com.pack
//
class BookController {
    //
    def index = {
        //
        render text:"Hello"
    }
}
             36
params
           servletContext,session,request,response
                beforeInterceptor afterInterceptor
def create = {
    def bookInstance = new Book()
    bookInstance.properties = params
    [bookInstance: bookInstance]
}

def save = {
    def bookInstance = new Book(params)
    if (bookInstance.save(flush: true)) {
        flash.message = "                 "
        redirect(action: "show", id: bookInstance.id)
    }
    else {
        render(view: "create", model: [bookInstance: bookInstance])
    }
}
                                                                      37
class BookController {


    def scaffold = true
}




              38
39
40
class SimpleWikiTagLib {
  static namespace = "wiki"
  static returnObjectForTags = ['content'] 
  def tagname = {attrs, body ->
    out<<"Hello"
  }
  
  def content = {attrs, body ->
    CmsContent.findByCode(attrs.code)?.content
  }
}



                            41
class UrlMappings {
  static mappings = {
    "/$controller/$action?/$id?"{
      constraints { }
    }
    "/"(view:"/index")
    "500"(view:'/error')
    //     URL      /blogname/2007/01/10/my_funky_blog_entry
    "/$blog/$year?/$month?/$day?/$id?"(
                controller:"blog", action:"show")
    //
      "/$blog/$year?/$month?/$day?/$id?" {
          controller = "blog"
          action = "show"
          constraints {
              year(matches:/d{4}/)
              month(matches:/d{2}/)     //
              day(matches:/d{2}/)       "/images/**.jpg"(controller:"image")
          }                           
      }
                                       42
name productDetail:"/showProduct/$productName/$flavor?"{
  controller = "product"
  action = "show"
}

<link:productDetail productName="licorice"
          flavor="strawberry"> Strawberry Licorice </link:productDetail>




                                       43
static mappings = {
   "/product/$id"(controller:"product"){
       action = [GET:"show",
            PUT:"update",
            DELETE:"delete",
            POST:"save"]
   }
}




                         44
import grails.converters.*
class BookController {  

      def list = {   
                                          /book/list
          def books = Book.list()   
          withFormat {    
              html bookList:books            /book/list.json
              json { render books as JSON }   
              xml { render books as XML }   
          }  
      }
                                           /book/list.xml
}

                                                               45
46
47
class BookStoreService {
    
    boolean transactional = true
    
    def allList(params) {
      return Book.list(params)
    }
}


       class BookController {

             def bookStoreService
             def list = {
                 [bookInstanceList:bookStoreService.allList(params),
                     bookInstanceTotal: Book.count()]
             }
                                   48
49
50
mockFor(class, loose = false)
     mockDomain(class, testInstances = )
     mockForConstraintsTests(class, testInstances = )
     mockLogging(class, enableDebug = false)
     mockController(class)
     mockTagLib(class)
                     def testInstances=[]
                     mockDomain(Song, testInstances)
                     assertEquals(0, Song.count())
                     new Song(name:"Supper's Ready").save()
                     assertEquals(1, Song.count())
51
class FooController {
   def someRedirect = { 
     redirect(action:"bar") 
   }
   def text = {      class FooControllerTests extends GrailsUnitTestCase {
     render "bar"      void testText(){ 
   }                     def fc = new FooController() 
 }                       fc.text() 
                         assertEquals "bar", fc.response.contentAsString 
                       }
                       void testSomeRedirect() {
                         def fc = new FooController() 
                         fc.someRedirect() 
                         assertEquals "/foo/bar", fc.response.redirectedUrl 
                       } 
52
53
54
55
56
57
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
  <property name="host" value="127.0.0.1"/>
 </bean>
 <bean id="mailMessageMe" class="org.springframework.mail.SimpleMailMessage">
  <property name="from" value="tyam@xmldo.jp"/>
 </bean>
 <bean id="mailMessageYou" class="org.springframework.mail.SimpleMailMessage">
  <property name="from" value="you@xmldo.jp"/>
 </bean>

                 mailSender(org.springframework.mail.javamail.JavaMailSenderImpl) {
                  host = '127.0.0.1'
                 }
                 def map = ["Me":"tyam@xmldo.jp","You":"you@xmldo.jp"]
                 map.each{k,v->
                  "mailMessage${k}"(org.springframework.mail.SimpleMailMessage) {
                   from = v
                  }
58               }
import org.springframework.context.ApplicationContext
import grails.spring.BeanBuilder
// BeanBuilder
def builder = new BeanBuilder()
builder.beans {
  //
}
// ApplicationContext
ApplicationContext ctx = builder.createApplicationContext()
                                                              59
60
log4j = {
  appenders {
    console name:'stdout',
    layout:pattern(conversionPattern: '%c{2} %m%n')
  }
  error  'org.codehaus.groovy.grails.web.servlet'
}




                 61
62
63
64
65
66
67
grails.plugin.location."auth-domains"="/path/to/modules/auth-domains"

grails.plugin.location."business-domains"="/path/to/modules/business-domains"

grails.plugin.location."common-tags"="/path/to/commons/common-tags"

grails.plugin.location."shop-cart"="/path/to/functionals/shop-cart"


                                      68
%grails maven-install
"
%grails maven-deploy
"
                69
grails.plugin.repos.discovery.local="http://127.0.0.1/gp"
   grails.plugin.repos.distribution.local="http://127.0.0.1/gp"



grails.plugin.repos.discovery.           ="        Http      URL"
grails.plugin.repos.distribution.             ="      Http        URL"

                                    70
app.version=0.1
plugins.acegi=0.5.7
app.servlet.version=2.4
app.grails.version=1.3.RC2
                                           =
plugins.hibernate=1.3.RC2             s.
app.name=relationsample      plugin




                              71
72
73
grails.project.dependency.resolution = {
   ...
   repositories { //
     mavenRepo "http://repository.codehaus.org"
    }
    dependencies {
      runtime 'net.homeip.yusuke:twitter4j:2.0.9'
    }
    ...
                                         ls -al ~/.ivy2/cache
}




% grails install-dependency net.homeip.yusuke:twitter4j:2.0.9

                               74
75
tomcat.deploy.username="manager" 
tomcat.deploy.password="secret" 
tomcat.deploy.url="http://myserver.com/manager"




                         76
77
appenders{null name:'stacktrace'}

                 78
79
80
81
82
83
84

More Related Content

What's hot

(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)
Jacek Laskowski
 
Say Hello To Ecmascript 5
Say Hello To Ecmascript 5Say Hello To Ecmascript 5
Say Hello To Ecmascript 5Juriy Zaytsev
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
rstankov
 
Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots
DeepAnshu Sharma
 
Source Code for Dpilot
Source Code for Dpilot Source Code for Dpilot
Source Code for Dpilot
Nidhi Chauhan
 
Rich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 ApplicationRich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 Application
Kirill Chebunin
 
Functional streams with Kafka - A comparison between Akka-streams and FS2
Functional streams with Kafka - A comparison between Akka-streams and FS2Functional streams with Kafka - A comparison between Akka-streams and FS2
Functional streams with Kafka - A comparison between Akka-streams and FS2
Luis Miguel Reis
 
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Leonardo Soto
 
Funcitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional WayFuncitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional Way
Natasha Murashev
 
groovy & grails - lecture 12
groovy & grails - lecture 12groovy & grails - lecture 12
groovy & grails - lecture 12
Alexandre Masselot
 
Declarative Internal DSLs in Lua: A Game Changing Experience
Declarative Internal DSLs in Lua: A Game Changing ExperienceDeclarative Internal DSLs in Lua: A Game Changing Experience
Declarative Internal DSLs in Lua: A Game Changing ExperienceAlexander Gladysh
 
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2
eugenio pombi
 
Building High Perf Web Apps - IE8 Firestarter
Building High Perf Web Apps - IE8 FirestarterBuilding High Perf Web Apps - IE8 Firestarter
Building High Perf Web Apps - IE8 Firestarter
Mithun T. Dhar
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Kacper Gunia
 
Deconstructing the Functional Web with Clojure
Deconstructing the Functional Web with ClojureDeconstructing the Functional Web with Clojure
Deconstructing the Functional Web with Clojure
Norman Richards
 
Writing Your App Swiftly
Writing Your App SwiftlyWriting Your App Swiftly
Writing Your App Swiftly
Sommer Panage
 
Persistent Memoization with HTML5 indexedDB and jQuery Promises
Persistent Memoization with HTML5 indexedDB and jQuery PromisesPersistent Memoization with HTML5 indexedDB and jQuery Promises
Persistent Memoization with HTML5 indexedDB and jQuery PromisesRay Bellis
 
Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)Leonardo Soto
 

What's hot (19)

(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)
 
Say Hello To Ecmascript 5
Say Hello To Ecmascript 5Say Hello To Ecmascript 5
Say Hello To Ecmascript 5
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots
 
Source Code for Dpilot
Source Code for Dpilot Source Code for Dpilot
Source Code for Dpilot
 
Rich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 ApplicationRich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 Application
 
Functional streams with Kafka - A comparison between Akka-streams and FS2
Functional streams with Kafka - A comparison between Akka-streams and FS2Functional streams with Kafka - A comparison between Akka-streams and FS2
Functional streams with Kafka - A comparison between Akka-streams and FS2
 
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)
 
Funcitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional WayFuncitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional Way
 
groovy & grails - lecture 12
groovy & grails - lecture 12groovy & grails - lecture 12
groovy & grails - lecture 12
 
Declarative Internal DSLs in Lua: A Game Changing Experience
Declarative Internal DSLs in Lua: A Game Changing ExperienceDeclarative Internal DSLs in Lua: A Game Changing Experience
Declarative Internal DSLs in Lua: A Game Changing Experience
 
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2
 
Building High Perf Web Apps - IE8 Firestarter
Building High Perf Web Apps - IE8 FirestarterBuilding High Perf Web Apps - IE8 Firestarter
Building High Perf Web Apps - IE8 Firestarter
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
 
Not your Grandma's XQuery
Not your Grandma's XQueryNot your Grandma's XQuery
Not your Grandma's XQuery
 
Deconstructing the Functional Web with Clojure
Deconstructing the Functional Web with ClojureDeconstructing the Functional Web with Clojure
Deconstructing the Functional Web with Clojure
 
Writing Your App Swiftly
Writing Your App SwiftlyWriting Your App Swiftly
Writing Your App Swiftly
 
Persistent Memoization with HTML5 indexedDB and jQuery Promises
Persistent Memoization with HTML5 indexedDB and jQuery PromisesPersistent Memoization with HTML5 indexedDB and jQuery Promises
Persistent Memoization with HTML5 indexedDB and jQuery Promises
 
Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)
 

Viewers also liked

G * magazine 0
G * magazine 0G * magazine 0
G * magazine 0
Tsuyoshi Yamamoto
 
Apache Archiva を試す
Apache Archiva を試すApache Archiva を試す
Apache Archiva を試す
bouzuya
 
Groovy Grails eXchage 2014 報告
Groovy Grails eXchage 2014 報告Groovy Grails eXchage 2014 報告
Groovy Grails eXchage 2014 報告
Tsuyoshi Yamamoto
 
G * magazine 1
G * magazine 1G * magazine 1
G * magazine 1
Tsuyoshi Yamamoto
 
Eclipse Tips #1 ショートカットキー
Eclipse Tips #1 ショートカットキーEclipse Tips #1 ショートカットキー
Eclipse Tips #1 ショートカットキーbouzuya
 
JGGUG grails-spring-boot
JGGUG grails-spring-bootJGGUG grails-spring-boot
JGGUG grails-spring-boot
Tsuyoshi Yamamoto
 
簡単!Groovy入門
簡単!Groovy入門簡単!Groovy入門
簡単!Groovy入門
Lee Choong Geun
 

Viewers also liked (10)

Grailsx@London 2011 報告
Grailsx@London 2011 報告Grailsx@London 2011 報告
Grailsx@London 2011 報告
 
G * magazine 0
G * magazine 0G * magazine 0
G * magazine 0
 
Apache Archiva を試す
Apache Archiva を試すApache Archiva を試す
Apache Archiva を試す
 
Groovy Grails eXchage 2014 報告
Groovy Grails eXchage 2014 報告Groovy Grails eXchage 2014 報告
Groovy Grails eXchage 2014 報告
 
G * magazine 1
G * magazine 1G * magazine 1
G * magazine 1
 
Eclipse Tips #1 ショートカットキー
Eclipse Tips #1 ショートカットキーEclipse Tips #1 ショートカットキー
Eclipse Tips #1 ショートカットキー
 
Grails 1.4.0.M1 メモLT
Grails 1.4.0.M1 メモLTGrails 1.4.0.M1 メモLT
Grails 1.4.0.M1 メモLT
 
JGGUG grails-spring-boot
JGGUG grails-spring-bootJGGUG grails-spring-boot
JGGUG grails-spring-boot
 
Grails 2.0.0.M1の話
Grails 2.0.0.M1の話 Grails 2.0.0.M1の話
Grails 2.0.0.M1の話
 
簡単!Groovy入門
簡単!Groovy入門簡単!Groovy入門
簡単!Groovy入門
 

Similar to G*ワークショップ in 仙台 Grails(とことん)入門

Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Tsuyoshi Yamamoto
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
Daniel Cukier
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Frameworkvhazrati
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
IndicThreads
 
Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift Framework
Xebia IT Architects
 
Deeply Declarative Data Pipelines
Deeply Declarative Data PipelinesDeeply Declarative Data Pipelines
Deeply Declarative Data Pipelines
HostedbyConfluent
 
Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScript
Andrew Dupont
 
DataMapper
DataMapperDataMapper
DataMapper
Yehuda Katz
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
pootsbook
 
DOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A RideDOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A Ride
Matthew McCullough
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
Bartosz Kosarzycki
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
Alexandre Morgaut
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 SpringKiyotaka Oku
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
Caridy Patino
 
Kick your database_to_the_curb_reston_08_27_19
Kick your database_to_the_curb_reston_08_27_19Kick your database_to_the_curb_reston_08_27_19
Kick your database_to_the_curb_reston_08_27_19
confluent
 
Architecting Alive Apps
Architecting Alive AppsArchitecting Alive Apps
Architecting Alive Apps
Jorge Ortiz
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
MongoDB
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
Siarzh Miadzvedzeu
 

Similar to G*ワークショップ in 仙台 Grails(とことん)入門 (20)

Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
XQuery Rocks
XQuery RocksXQuery Rocks
XQuery Rocks
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
 
Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift Framework
 
Deeply Declarative Data Pipelines
Deeply Declarative Data PipelinesDeeply Declarative Data Pipelines
Deeply Declarative Data Pipelines
 
Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScript
 
DataMapper
DataMapperDataMapper
DataMapper
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
DOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A RideDOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A Ride
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
 
Kick your database_to_the_curb_reston_08_27_19
Kick your database_to_the_curb_reston_08_27_19Kick your database_to_the_curb_reston_08_27_19
Kick your database_to_the_curb_reston_08_27_19
 
Architecting Alive Apps
Architecting Alive AppsArchitecting Alive Apps
Architecting Alive Apps
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 

More from Tsuyoshi Yamamoto

JJUG CCC 20150411 grails3 Spring-boot
JJUG CCC 20150411 grails3 Spring-bootJJUG CCC 20150411 grails3 Spring-boot
JJUG CCC 20150411 grails3 Spring-boot
Tsuyoshi Yamamoto
 
Grailsx@ロンドンへ行ってきた報告。
Grailsx@ロンドンへ行ってきた報告。Grailsx@ロンドンへ行ってきた報告。
Grailsx@ロンドンへ行ってきた報告。
Tsuyoshi Yamamoto
 
多治見IT勉強会 Groovy Grails
多治見IT勉強会 Groovy Grails多治見IT勉強会 Groovy Grails
多治見IT勉強会 Groovy Grails
Tsuyoshi Yamamoto
 
Grailsのススメ(仮)
Grailsのススメ(仮)Grailsのススメ(仮)
Grailsのススメ(仮)
Tsuyoshi Yamamoto
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Tsuyoshi Yamamoto
 
groovyプラプラとか「はやい、はやいよ」
groovyプラプラとか「はやい、はやいよ」groovyプラプラとか「はやい、はやいよ」
groovyプラプラとか「はやい、はやいよ」
Tsuyoshi Yamamoto
 
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
Tsuyoshi Yamamoto
 
第1回名古屋Grails/Groogy勉強会「Grailsを始めてみよう!」
第1回名古屋Grails/Groogy勉強会「Grailsを始めてみよう!」第1回名古屋Grails/Groogy勉強会「Grailsを始めてみよう!」
第1回名古屋Grails/Groogy勉強会「Grailsを始めてみよう!」
Tsuyoshi Yamamoto
 
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、GaelykでハンズオンTsuyoshi Yamamoto
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Tsuyoshi Yamamoto
 
G*なクラウド 雲のかなたに ショートバージョン
G*なクラウド 雲のかなたに ショートバージョンG*なクラウド 雲のかなたに ショートバージョン
G*なクラウド 雲のかなたに ショートバージョン
Tsuyoshi Yamamoto
 
JGGUG Camp 2009 いっぽう熱海では、
JGGUG Camp 2009 いっぽう熱海では、JGGUG Camp 2009 いっぽう熱海では、
JGGUG Camp 2009 いっぽう熱海では、
Tsuyoshi Yamamoto
 
G*なクラウド ~雲のかなたに~
G*なクラウド ~雲のかなたに~G*なクラウド ~雲のかなたに~
G*なクラウド ~雲のかなたに~
Tsuyoshi Yamamoto
 
はじめてのGroovy
はじめてのGroovyはじめてのGroovy
はじめてのGroovy
Tsuyoshi Yamamoto
 
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
Tsuyoshi Yamamoto
 
GrailsでSpringをGroovyにしよう!
GrailsでSpringをGroovyにしよう!GrailsでSpringをGroovyにしよう!
GrailsでSpringをGroovyにしよう!
Tsuyoshi Yamamoto
 
Grails-1.1を斬る!~Grails-1.1からのチーム開発~ in Tokyo
Grails-1.1を斬る!~Grails-1.1からのチーム開発~ in TokyoGrails-1.1を斬る!~Grails-1.1からのチーム開発~ in Tokyo
Grails-1.1を斬る!~Grails-1.1からのチーム開発~ in Tokyo
Tsuyoshi Yamamoto
 

More from Tsuyoshi Yamamoto (20)

JJUG CCC 20150411 grails3 Spring-boot
JJUG CCC 20150411 grails3 Spring-bootJJUG CCC 20150411 grails3 Spring-boot
JJUG CCC 20150411 grails3 Spring-boot
 
JGGUG 2011-02 LT
JGGUG 2011-02 LTJGGUG 2011-02 LT
JGGUG 2011-02 LT
 
Grailsx@ロンドンへ行ってきた報告。
Grailsx@ロンドンへ行ってきた報告。Grailsx@ロンドンへ行ってきた報告。
Grailsx@ロンドンへ行ってきた報告。
 
多治見IT勉強会 Groovy Grails
多治見IT勉強会 Groovy Grails多治見IT勉強会 Groovy Grails
多治見IT勉強会 Groovy Grails
 
Grailsのススメ(仮)
Grailsのススメ(仮)Grailsのススメ(仮)
Grailsのススメ(仮)
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
 
groovyプラプラとか「はやい、はやいよ」
groovyプラプラとか「はやい、はやいよ」groovyプラプラとか「はやい、はやいよ」
groovyプラプラとか「はやい、はやいよ」
 
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
 
第1回名古屋Grails/Groogy勉強会「Grailsを始めてみよう!」
第1回名古屋Grails/Groogy勉強会「Grailsを始めてみよう!」第1回名古屋Grails/Groogy勉強会「Grailsを始めてみよう!」
第1回名古屋Grails/Groogy勉強会「Grailsを始めてみよう!」
 
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
 
G*なクラウド 雲のかなたに ショートバージョン
G*なクラウド 雲のかなたに ショートバージョンG*なクラウド 雲のかなたに ショートバージョン
G*なクラウド 雲のかなたに ショートバージョン
 
JGGUG Camp 2009 いっぽう熱海では、
JGGUG Camp 2009 いっぽう熱海では、JGGUG Camp 2009 いっぽう熱海では、
JGGUG Camp 2009 いっぽう熱海では、
 
ExtJS勉強会@名古屋
ExtJS勉強会@名古屋ExtJS勉強会@名古屋
ExtJS勉強会@名古屋
 
G*なクラウド ~雲のかなたに~
G*なクラウド ~雲のかなたに~G*なクラウド ~雲のかなたに~
G*なクラウド ~雲のかなたに~
 
はじめてのGroovy
はじめてのGroovyはじめてのGroovy
はじめてのGroovy
 
G* on GAE/J 挑戦編
G* on GAE/J 挑戦編G* on GAE/J 挑戦編
G* on GAE/J 挑戦編
 
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
 
GrailsでSpringをGroovyにしよう!
GrailsでSpringをGroovyにしよう!GrailsでSpringをGroovyにしよう!
GrailsでSpringをGroovyにしよう!
 
Grails-1.1を斬る!~Grails-1.1からのチーム開発~ in Tokyo
Grails-1.1を斬る!~Grails-1.1からのチーム開発~ in TokyoGrails-1.1を斬る!~Grails-1.1からのチーム開発~ in Tokyo
Grails-1.1を斬る!~Grails-1.1からのチーム開発~ in Tokyo
 

G*ワークショップ in 仙台 Grails(とことん)入門

  • 2. 2
  • 3. 3
  • 4. 4
  • 5. 5
  • 6. 6
  • 7. 7
  • 8. 8
  • 9. 9
  • 10. 10
  • 11. View MVC2 DI 11
  • 12. 12
  • 13. ur ity S ec low Controller i1 8n Flex bF We Codec Quartz Domain Grails lug in JMS MyP Core Quartz ag gin Service UrlMapping T Filters 13
  • 14. 14
  • 15. 15
  • 16. 16
  • 17. 17
  • 18. 18
  • 19. 19
  • 20. 20
  • 21. % export GRAILS_HOME=/opt/grails-1.2.2 % export PATH=$GRAILS_HOME/bin:$PATH % grails Welcome to Grails 1.2.2 - http://grails.org/ Licensed under Apache Standard License 2.0 Grails home is set to: /opt/grails-1.2.2 21
  • 22. % grails run-app % grails test-app 22
  • 23. 23
  • 24. |-- application.properties |-- grails-app | |-- conf - | |-- controllers - | |-- domain - | |-- i18n | |-- services - | |-- taglib - | |-- utils | `-- views - |-- lib |-- scripts - |-- src - |-- test - `-- web-app - 24
  • 25. 25
  • 26. package com.pack class Book {   String title   String author   int rate   String comment      Date dateCreated   Date lastUpdated      static constraints = {   } } 26
  • 27.   static constraints = {     title nullable:false,blank:false     author nullable:false,blank:false     rate range:0..10     comment maxSize:1000     price shared:'myShared'     withTax display:false   } grails.gorm.default.constraints = {     '*'(nullable:true, size:1..20)     myShared(nullable:true) } 27
  • 28. class Book implements Serializable{   static mapping = {     table 'T_BOOK'     id generator:'uuid.hex', params:[type:'string']     columns {       comment column:'F_COMMENT',sqlType:'varchar(1000)'     }     withTax formula: 'price * 1.05'   } 28
  • 29. 29
  • 30. Account.executeQuery(     "select distinct a.number from Account a where a.branch = :branch",     [branch:'London'],     [max:10, offset:5] ) Book.findAll("from Book as b where b.author=?",[' ']) 30
  • 31. def results = Book.findAllByTitle(" ",     [max:10, sort:"title", order:"desc", offset:100] ) def results = Book.findAllByTitleAndAuthor( " ", " ") 31
  • 32. def c = Account.createCriteria() def results = c.list {       like("holderFirstName", "Fred%")       and {            between("balance", 500, 1000)            eq("branch", "London")       }       maxResults(10)     order("holderLastName", "desc") } 32
  • 33. dataSource {   pooled = true   driverClassName = "org.hsqldb.jdbcDriver"   username = "sa"   password = "" } hibernate {   cache.use_second_level_cache=true   cache.use_query_cache=true   cache.provider_class='net.sf.ehcache.hibernate.EhCacheProvider' } environments {   development {     dataSource {       dbCreate = "update"       url = "jdbc:hsqldb:file:devDB;shutdown=true"     }   }   test {     dataSource { .... .... 33
  • 34. import javax.persistence.*    @Entity  @Table(name = "animal")  class Animal {      @Id     @GeneratedValue    int id    String name    @ManyToOne    @JoinColumn    Owner owner      static constraints = {      name blank:false    }  } 34
  • 35. 35
  • 36. http://localhost:8080/myapp/book/index package com.pack // class BookController {     //     def index = {         //         render text:"Hello"     } } 36
  • 37. params servletContext,session,request,response beforeInterceptor afterInterceptor def create = {     def bookInstance = new Book()     bookInstance.properties = params     [bookInstance: bookInstance] } def save = {     def bookInstance = new Book(params)     if (bookInstance.save(flush: true)) {         flash.message = " "         redirect(action: "show", id: bookInstance.id)     }     else {         render(view: "create", model: [bookInstance: bookInstance])     } } 37
  • 38. class BookController {     def scaffold = true } 38
  • 39. 39
  • 40. 40
  • 41. class SimpleWikiTagLib {   static namespace = "wiki"   static returnObjectForTags = ['content']    def tagname = {attrs, body ->     out<<"Hello"   }      def content = {attrs, body ->     CmsContent.findByCode(attrs.code)?.content   } } 41
  • 42. class UrlMappings {   static mappings = {     "/$controller/$action?/$id?"{       constraints { }     }     "/"(view:"/index")     "500"(view:'/error')     //   URL /blogname/2007/01/10/my_funky_blog_entry     "/$blog/$year?/$month?/$day?/$id?"( controller:"blog", action:"show")     //     "/$blog/$year?/$month?/$day?/$id?" {         controller = "blog"         action = "show"         constraints {             year(matches:/d{4}/)             month(matches:/d{2}/)     //             day(matches:/d{2}/)     "/images/**.jpg"(controller:"image")         }        } 42
  • 43. name productDetail:"/showProduct/$productName/$flavor?"{ controller = "product" action = "show" } <link:productDetail productName="licorice" flavor="strawberry"> Strawberry Licorice </link:productDetail> 43
  • 44. static mappings = {    "/product/$id"(controller:"product"){        action = [GET:"show",             PUT:"update",             DELETE:"delete",             POST:"save"]    } } 44
  • 45. import grails.converters.* class BookController {       def list = {    /book/list         def books = Book.list()            withFormat {                 html bookList:books     /book/list.json             json { render books as JSON }                xml { render books as XML }            }       } /book/list.xml } 45
  • 46. 46
  • 47. 47
  • 48. class BookStoreService {          boolean transactional = true          def allList(params) {       return Book.list(params)     } } class BookController {     def bookStoreService     def list = {         [bookInstanceList:bookStoreService.allList(params),             bookInstanceTotal: Book.count()]     } 48
  • 49. 49
  • 50. 50
  • 51. mockFor(class, loose = false) mockDomain(class, testInstances = ) mockForConstraintsTests(class, testInstances = ) mockLogging(class, enableDebug = false) mockController(class) mockTagLib(class) def testInstances=[] mockDomain(Song, testInstances) assertEquals(0, Song.count()) new Song(name:"Supper's Ready").save() assertEquals(1, Song.count()) 51
  • 52. class FooController {   def someRedirect = {      redirect(action:"bar")    }   def text = {  class FooControllerTests extends GrailsUnitTestCase {     render "bar"    void testText(){    }     def fc = new FooController()  }     fc.text()      assertEquals "bar", fc.response.contentAsString    }   void testSomeRedirect() {     def fc = new FooController()      fc.someRedirect()      assertEquals "/foo/bar", fc.response.redirectedUrl    }  52
  • 53. 53
  • 54. 54
  • 55. 55
  • 56. 56
  • 57. 57
  • 58. <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="host" value="127.0.0.1"/> </bean> <bean id="mailMessageMe" class="org.springframework.mail.SimpleMailMessage"> <property name="from" value="tyam@xmldo.jp"/> </bean> <bean id="mailMessageYou" class="org.springframework.mail.SimpleMailMessage"> <property name="from" value="you@xmldo.jp"/> </bean> mailSender(org.springframework.mail.javamail.JavaMailSenderImpl) { host = '127.0.0.1' } def map = ["Me":"tyam@xmldo.jp","You":"you@xmldo.jp"] map.each{k,v-> "mailMessage${k}"(org.springframework.mail.SimpleMailMessage) { from = v } 58 }
  • 59. import org.springframework.context.ApplicationContext import grails.spring.BeanBuilder // BeanBuilder def builder = new BeanBuilder() builder.beans { // } // ApplicationContext ApplicationContext ctx = builder.createApplicationContext() 59
  • 60. 60
  • 61. log4j = {   appenders {     console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')   }   error  'org.codehaus.groovy.grails.web.servlet' } 61
  • 62. 62
  • 63. 63
  • 64. 64
  • 65. 65
  • 66. 66
  • 67. 67
  • 70. grails.plugin.repos.discovery.local="http://127.0.0.1/gp" grails.plugin.repos.distribution.local="http://127.0.0.1/gp" grails.plugin.repos.discovery. =" Http URL" grails.plugin.repos.distribution. =" Http URL" 70
  • 71. app.version=0.1 plugins.acegi=0.5.7 app.servlet.version=2.4 app.grails.version=1.3.RC2 = plugins.hibernate=1.3.RC2 s. app.name=relationsample plugin 71
  • 72. 72
  • 73. 73
  • 74. grails.project.dependency.resolution = { ... repositories { // mavenRepo "http://repository.codehaus.org" } dependencies { runtime 'net.homeip.yusuke:twitter4j:2.0.9' } ... ls -al ~/.ivy2/cache } % grails install-dependency net.homeip.yusuke:twitter4j:2.0.9 74
  • 75. 75
  • 77. 77
  • 79. 79
  • 80. 80
  • 81. 81
  • 82. 82
  • 83. 83
  • 84. 84