JGGUG
                                             japan grails/groovy user group




def speaker = new Cast(name:”T.Yamamoto”,version:”G*-2009-12-18”)
Grails/Groovy
http://www.jggug.org/
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>
}
% grails uninstall-plugin tomcat
% grails install-plugin jetty
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
@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')
   )
}
Grails-1.1.x   Grails-1.2
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')
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=
render(contentType:"text/json") {
  categories = [ { a = "A" }, { b = "B" } ]
}




{"categories":[ {"a":"A"} , {"b":"B"}] }
name productDetail:"/showProduct/$productName/$flavor?"{
  controller = "product"
  action = "show"
}

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




             "/hello"(uri:"/hello.dispatch")
import org.springframework.transaction.annotation.*
class BookService {
  @Transactional(readOnly = true)
  def listBooks() {
    Book.list()
  }
  @Transactional
  def updateBook() {
   // …
 }
}
beans {                  Config.groovy
  someService {
    someProperty = new SomeObject()
  }
}
BootStrap.groovy
def init = { ServletContext ctx ->
  environments {
    production {
      ctx.setAttribute("env", "prod")
    }
    development {
      ctx.setAttribute("env", "dev")
    }
  }
  ctx.setAttribute("foo", "bar")
}
class Book {
   String title
   String author
   Boolean paperback
 }


Book.findAllPaperbackByAuthor("      ")

Book.findAllNotPaperbackByAuthor("        ")
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)
                         )
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()
try {
     book.save(failOnError:true)
}catch(ValidationException e) {
   // handle
}
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"
           }
def c = Person.createCriteria()
def peopleWithShortFirstNames = c.list {
    sqlRestriction "char_length( first_name ) <= 4"
}
import javax.persistence.*

@Entity
@Table(name = "animal")
class Animal {

    @Id
    @GeneratedValue
    int id
    String name
    @ManyToOne
    @JoinColumn
    Owner owner

    static constraints = {
      name blank:false
    }
}
chat.label=
chat.message.label=
chat.name.label=
chat.id.label=
chat.dateCreated.label=
chat.lastUpdated.label=
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
% grails release-plugin --skipMetadata




  % grails release-plugin --zipOnly
% 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()
        }
% grails test-app -echoOut -echoErr
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
PermGen




1.0   1.1.x   1.2




                      1.0   1.1.x   1.2
grails deploy-to-cloud --app-servers=4 --db-servers=2
Grails/Groovy
http://www.jggug.org/

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