colloquial model-driven development (nichijou kaiwa teki moderu kudou kaihatsu) masaki@metabolics.co.jp 2007.06.27 1
grails web applications plug-ins grails groovy spring, hibernate,... jdk libraries JVM 2
groovy JVM Java 3
Java ( ) Java groovy groovy Java groovy Java implement/extend 4
';', imports, return,... GString, collections, ranges switch-case,... (class ) 5
GroovyBeans expando 6
grails http://grails.org/, Eclipse 0.5.6 10 1.0 7
grails % grails create-app % grails create-domain-class JUnit % grails create-controller scaffolding JUnit & Canoo / JUnit & Canoo 8
grails % grails bootstrap % grails bug-report % grails clean % grails compile % grails console % grails create-app % grails create-controller % grails create-domain-class % grails create-job % grails create-plugin % grails create-script % grails create-service % grails create-tag-lib % grails create-test-suite % grails create-webtest % grails generate-all % grails generate-controller % grails generate-views % grails generate-webtest % grails get-dependencies % grails help % grails init % grails install-dojo % grails install-ivy % grails install-plugin % grails install-templates % grails package % grails package-plugin % grails package-plugins % grails run-app % grails run-webtest % grails set-version % grails shell % grails stats % grails test-app % grails upgrade % grails war 9
grails o/r map GORM hibernate quartz xfire model sitemesh ajax... create, refer, update, delete fetch http req controller render view w/ taglibs GSP spring junit canoo wicket 10
% grails create-domain-class book GroovyBean RDB GORM (= groovy Hibernate, RDB ) 11
static belongsto = [ Class,... ] static hasmany = [ property:class,... ] addtoprop(bar) static mappedby = [ property:"property",... ] static embedded = [ "property",... ] 12
static constraints = { property(key:value,...)... } validator:{... } //! 13
blank creditcard email inlist length matches max maxlength maxsize min minlength minsize notequal nullable range scale size unique url validator 14
CRUD new Book(title:'book of tea',...).save() def b = Book.get(1) b.author = 'Okakura Tenshin'; b.save() b.delete() 15
Book.exist(1) Book.count() Book.list() max:, offset:, sort:, order: Book.listOrderByDateCreated() 16
groovy 17
Book.find('HQL query') Book.findAll('HQL query') Book.findByAuthorAndDateCreatedBetween('Jon Doe', new Date()-30, new Date()) 'And' 'Or' 'find' 'findall' Between, GreaterThan, GreaterThanOrEqual, IsNull, IsNotNull, LessThan, LessThanOrEuqal, Like, NotEqual 'Equal' 18
def c = Book.createCriteria() def results = c.list { like('title', 'Grails%') between('datecreated', new Date()-10, new Date ()) } Hibnernate Qeury 19
% grails create-controller book Book BookController http request/post/get def index = {... } // http://example.com/app/book/index/params 20
CRUD / def scaffold = Book list, show, delete, edit, update, save <grails-0.5>/src/grails/templates/scaffolding/controller.groovy - *Controller.groovy - / 21
redirect(action:list, params:params), / ( <app>/grails-app/views/ book/show.gsp), render "..." 22
23
grails GSP(groovy JSP) <%... %> "${...}" <g:...></g:...>.gsp <grails-0.5>/src/grails/templates/scaffolding/*.gsp GSP ( wicket ) 24
gsp Logical Tags * if * else * elseif Iterative Tags * while * each * collect * findall * grep Assignment Tags * def * set Linking Tags * link * createlink * createlinkto Ajax Tags * remotefield * remotefunction * remotelink * formremote * submittoremote Form Tags * actionsubmit * actionsubmitimage * checkbox * currencyselect * form * hiddenfield * datepicker * select * localeselect * textfield * textarea * timezoneselect UI Tags * richtexteditor Rendering & Layout Tags * render * rendererrors * layouthead * layoutbody * layouttitle * pageproperty * paginate * sortablecolumn (Since 0.5) Validation Tags * eacherror * haserrors * message 25
% grails create-tag-lib foo <app>/grails-app/taglib/footaglib.groovy def isadmin = { attrs, body ->... } <g:isadmin> body </g:isadmin> 26
grails grails Spring, Hibernate, JSP, JUnit, Canoo, Mesh, Quartz, XFire, Acegi Security,...,, 27
% grails create-plugin grails grails grails wicket plugin 28
<plugin>/scripts/_{install,upgrade}.groovy <plugin>/grails-app/{controllers,...} <plugin>/foograilsplugin.groovy def version = 0.1 def name = "foo" def dependson = [ bar:1.0 ] def dowithspring = {... } def dowithwebdescriptor = {... } def dowithapplicationcontext = {... } def dowithdynamicmethods = {... } def artefacts = [ FooArtefactHander,... ]... 29
org.codehaus.groovy.grails.plugins GrailsPlugin (interface) extends ApplicationContextAware (Spring) AbstractGrailsPlugin (abstract class) extends GroovyObjectSupport (groovy) DefaultGrailsPlugin (concrete class) : groovy Java 30
FooPlugin plugin 31
grails grails groovy MOP grails taglib... groovy DSL 32
MDD grails grails MDD ( ) 33
MDD MDD EMF, OMG MDA, xuml grails 34
: : web taglib: :,... 35
MDD,???... 36
grails c-mdd grails/c-mdd ( ) grails/c-mdd ( ) 37