• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
G*ワークショップ in 仙台 Grails(とことん)入門
 

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

on

  • 3,379 views

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

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

Statistics

Views

Total Views
3,379
Views on SlideShare
3,359
Embed Views
20

Actions

Likes
5
Downloads
22
Comments
0

2 Embeds 20

http://www.slideshare.net 19
http://webcache.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

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

    • 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