Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-

2,688 views

Published on

Grails 1.2 探検隊
-新たな聖杯をもとめて・・・-
Grails 1.2 新機能などの紹介。
2009/12/8 Japan Grails Groovy Users Group G*ワークショップ 7 at Tokyo

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

No Downloads
Views
Total views
2,688
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
22
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-

  1. 1. JGGUG japan grails/groovy user group def speaker = new Cast(name:”T.Yamamoto”,version:”G*-2009-12-18”)
  2. 2. Grails/Groovy http://www.jggug.org/
  3. 3. package my.domain HelloController.groovy import org.springframework.stereotype.* import org.springframework.web.bind.annotation.* import org.springframework.beans.factory.annotation.* import org.hibernate.* import org.springframework.ui.* beans = {   resources.groovy @Controller   xmlns context:"http://www.springframework.org/schema/context" class HelloController {   context.'component-scan'( 'base-package' :"my.domain" ) }   @Autowired   SessionFactory sessionFactory      @RequestMapping("/hello.dispatch")   ModelMap handleRequest() {     def session = sessionFactory.getCurrentSession()     println "hit"     return new ModelMap(session.get(Person, 1L))   hello.gsp   } <h1 id="hello"> ${person.name}</h1> }
  4. 4. % grails uninstall-plugin tomcat % grails install-plugin jetty
  5. 5. JNDI Config.groovy grails.naming.entries = [foo:"bar"] resources.groovy beans = { xmlns jee:"http://www.springframework.org/schema/jee" jee.'jndi-lookup'(id:"foo", 'jndi-name':"java:comp/env/foo") } grails tomcat deploy grails tomcat undeploy Config.groovy (tomcat-users.xml ) tomcat.deploy.username="manager" tomcat.deploy.password="secret" tomcat.deploy.url="http://myserver.com/manager" grails tomcat list
  6. 6. @Grapes([    @Grab("org.grails:grails-docs:1.2.0.RC2"),    @Grab("radeox:radeox:1.0-b2"),    @Grab("ant:ant-nodeps:1.6.5"), Directory   @GrabConfig(systemClassLoader=true) ]) import grails.doc.ant.* new AntBuilder().sequential {    native2ascii(src:"conf",dest:"src/docs", includes:"**/*.properties",encoding:"UTF-8")    taskdef(name:'docs',classname:'grails.doc.ant.DocPublisherTask')    docs(src:"src/docs", dest:"build/docs", properties:"src/docs/doc.properties",      styleDir:new File('src/resources/style'),      cssDir:new File('src/resources/css'),      imagesDir:new File('src/resources/img')    ) }
  7. 7. Grails-1.1.x Grails-1.2
  8. 8. def foo = { def hoge = params.some def foo = { if(hoge) println hoge.toInteger() def hoge = params.long('some') } if(hoge) println hoge.toInteger() } //int(' ') long(' ') boolean(' ') def total = params.int('total') // def names = params.list('names')
  9. 9. default.paginate.prev= default.paginate.next= default.boolean.true= default.boolean.false= default.date.format=yyyy/MM/dd HH:mm:ss z default.number.format=0 default.created.message={0}(id:{1}) default.updated.message={0}(id:{1}) default.deleted.message={0}(id:{1}) default.not.deleted.message={0}(id:{1}) default.not.found.message={0}(id:{1}) default.optimistic.locking.failure= {0} default.home.label= default.list.label={0} default.add.label={0} default.new.label={0} default.create.label={0} default.show.label={0} default.edit.label={0} default.button.create.label=
  10. 10. render(contentType:"text/json") {   categories = [ { a = "A" }, { b = "B" } ] } {"categories":[ {"a":"A"} , {"b":"B"}] }
  11. 11. name productDetail:"/showProduct/$productName/$flavor?"{ controller = "product" action = "show" } <link:productDetail productName="licorice" flavor="strawberry"> Strawberry Licorice </link:productDetail> "/hello"(uri:"/hello.dispatch")
  12. 12. import org.springframework.transaction.annotation.* class BookService {   @Transactional(readOnly = true)   def listBooks() {     Book.list()   }   @Transactional def updateBook() {    // …  } }
  13. 13. beans { Config.groovy someService { someProperty = new SomeObject() } }
  14. 14. BootStrap.groovy def init = { ServletContext ctx -> environments { production { ctx.setAttribute("env", "prod") } development { ctx.setAttribute("env", "dev") } } ctx.setAttribute("foo", "bar") }
  15. 15. class Book { String title String author Boolean paperback } Book.findAllPaperbackByAuthor(" ") Book.findAllNotPaperbackByAuthor(" ")
  16. 16. class Person { String name static hasOne = [address: Address] } create table address ( class Address { id bigint ... , String street version bigint not null, String postCode person_id bigint not null, street varchar(255) not null, Person person post_code varchar(255) not null, } primary key (id), unique (person_id)) create table person ( id bigint ... , version bigint not null, name varchar(255) not null, primary key (id) )
  17. 17. class Publication { String title Date datePublished static namedQueries = { recentPublications { def now = new Date() gt 'datePublished',now-365 } publicationsWithBookInTitle { like 'title','%Book%' } } } def list = Publication.recentPublications.list() def list = Publication.recentPublications.list( max: 10, offset: 5) Publication.recentPublications.count()
  18. 18. try { book.save(failOnError:true) }catch(ValidationException e) { // handle }
  19. 19. grails.gorm.default.mapping = { cache true id generator:'sequence' 'user-type'( type:org.hibernate.type.YesNoType,class:Boolean ) } grails.gorm.default.constraints = { '*'(nullable:true, blank:false, size:1..20) } grails.gorm.default.constraints = { myConstraints(nullable:true, blank:false, size:1..20) } static constraints = { myProperty shared:"myConstraints" }
  20. 20. def c = Person.createCriteria() def peopleWithShortFirstNames = c.list { sqlRestriction "char_length( first_name ) <= 4" }
  21. 21. import javax.persistence.* @Entity @Table(name = "animal") class Animal { @Id @GeneratedValue int id String name @ManyToOne @JoinColumn Owner owner static constraints = { name blank:false } }
  22. 22. chat.label= chat.message.label= chat.name.label= chat.id.label= chat.dateCreated.label= chat.lastUpdated.label=
  23. 23. 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
  24. 24. % grails release-plugin --skipMetadata % grails release-plugin --zipOnly
  25. 25. % grails install-plugin webflow def searchFlow = {   onStart {      println "started"    }    onEnd {      println "ended"    }     displaySearchForm {       onRender { println "rendering" }       onEntry { println "entered" }       onExit { println "exited" }       on("submit") {         [results: Book.findAllByTitle(params.title)]       }.to "displayResults"     }     displayResults() }
  26. 26. % grails test-app -echoOut -echoErr
  27. 27. grails test-app <phase>:<type> //‘spock’ ‘unit’ grails test-app unit:spock //‘unit’ grails test-app unit: // ‘spock’ grails test-app :spock ‘SomeController’ ‘unit’ grails test-app unit: SomeController ‘unit’ ‘integration’ grails test-app unit: integration: grails test-app unit: grails test-app --unit grails test-app -clean
  28. 28. PermGen 1.0 1.1.x 1.2 1.0 1.1.x 1.2
  29. 29. grails deploy-to-cloud --app-servers=4 --db-servers=2
  30. 30. Grails/Groovy http://www.jggug.org/

×