grails overview
DESCRIPTION
Overview of Grails, a Groovy and Java based web development platform.TRANSCRIPT
WhatisGrailsandwhyshouldIcare?
BuildingonJava’sstrengths
TheGroovylanguage
AtourofGrails
AncillarytoolsusefulinGrails©2009DevJam‐Allrightsreserved.
Webapplicationdevelopmentenvironment BuiltontheJavaPlatform Groovyastheprimarylanguage
JavacanalsobeusedandintermixedwithGroovyseamlessly
FavorsConventionoverConfiguration SimilarinspirittoRubyonRails
©2009DevJam‐Allrightsreserved.
Javawebdevelopmentcanbetedious TheJVM,classlibraries,andframeworksaretherealstrengthoftheJavaPlatform
GroovyisanexcellentdynamiclanguagefortheJVM CompilestoJavabytecode(.classfiles)
Favorconventionoverconfiguration Grailsisanopinionatedframework
Enhancesproductivity©2009DevJam‐Allrightsreserved.
BuiltontopoftheJavaVirtualMachine Maturity Optimizationandperformance Runtimefamiliarity
IntegrationwithJavaapplications GroovyclassesareJavaclasses ReusewhatworksfromtraditionalJavastack▪ JavaEE:ServletAPI,JDBC,JMS▪ Hibernate,SpringFramework,SpringMVC,SiteMesh
©2009DevJam‐Allrightsreserved.
©2009DevJam‐Allrightsreserved.
Hibernate Object/relationalmapping(ORM)
SpringFramework Dependencyinjectionservices Applicationlifecyclefacilities
SpringMVC Webframework
SiteMesh Userinterfacelayoutandthemingfacilities
©2009DevJam‐Allrightsreserved.
Grailsconventiondictates… Wherecomponentsresideintheapplication Howthecomponentisnamed Howthecomponentiswiredandcollaborateswithotherapplicationcomponents
Howapplicationscanbeextendedthroughtheuseofthird‐partyplugins
©2009DevJam‐Allrightsreserved.
Standardizedconfiguration Log4j,databasedatasources Autowiringanddependencyinjectionofcomponents
Standardizedbuild Gantscripts
Standardizeddomainmodel GORMfacilitiesinjectedintodomainobjects
Standardizedservices Automatictransactionsupport
©2009DevJam‐Allrightsreserved.
FeaturesinspiredfromPython,Ruby,andSmalltalk
CanbecompiledtoJavabytecode GroovyclassesareJavaclasses
GroovycanseamlesslyuseJavaclasses JavacanseamlesslyuseGroovyclasses*
Lotsofnewlanguagesfeatures GPath,GString,internaliterators,closures,Meta‐ObjectProtocol(MOP),andmanyothers
©2009DevJam‐Allrightsreserved.
JDBCisusedforcommunicatingwithdatabases
HSQLDB:defaultdatasource DataSource.groovy
ConfigurationofDataSourcesforallyourenvironments
Easytoswitchtoadifferentdatabase,evenacrossdifferentdeployments
©2009DevJam‐Allrightsreserved.
DomainclassesarecentraltoaGrailsapplication
Locatedingrails‐app/domain Allattributespersistentunlessmarkedinthetransientsproperty
Nogettersandsettersnecessary Validators:specifiedinconstraintsproperty GORMmapping:customizedinthemappingproperty
©2009DevJam‐Allrightsreserved.
GrailsObjectRelationalMapping LeveragesHibernate
Automaticallymapsdomainobjectstodatabase
Providesqueryandupdatefacilities Findingobjectsinthepersistencestore(findBy…methods).
Persistencelifecyclemethods(save,update,delete).
CriteriaandHQLqueryfacilities.©2009DevJam‐Allrightsreserved.
Noneedtoextendacommonpersistentbaseclass GrailsinjectsGORMfunctionalityintoobjectsatrun‐time.
Declarepropertiesforyourdomainobjects Theidorversionpropertiesareinjectedautomatically.
Allpropertiesarenotnull/requiredbydefault
©2009DevJam‐Allrightsreserved.
Associations One‐to‐one,one‐to‐many,many‐to‐many Uni‐directionalandbi‐directional OwnersdefinedbyusingbelongsToproperty
Inheritancehierarchies Table‐per‐hierarchy:Allclassesmaptoasingletable
Table‐per‐subclass:EachclassmapstoitsowntableandJOINsareused
©2009DevJam‐Allrightsreserved.
Retrievingobjects get(), getAll(), read()
Listingobjects list(), listOrderBy*() methods order, sort, offset, andmaxnamedarguments
Dynamicfinders(findBy*()) Usepropertynamesoftheclass Supportformanyexpressionsinfindermethod
©2009DevJam‐Allrightsreserved.
BuiltonHibernate’sCriteriaAPI Groovybuilderisusedtobuildupthecriteria
Hierarchyofmethodcallsandclosuresforbuildingtree‐likestructures
EachdomainclasshasacreateCriteria()method Callget,list,scroll,orcountoncriteria Thecriteriabuilderisusedtorestrictthequery
Supportsassociationsandprojections©2009DevJam‐Allrightsreserved.
SupportforHibernateQueryLanguage find(hql), findAll(hql), andexecuteQuery(hql) forqueries
executeUpdate(hql)forDML‐styleopera3ons(setsofupdatesordeletes)
Supportforpositionalandnamedparameters
©2009DevJam‐Allrightsreserved.
HandlesHTTPrequestsanddeterminesrenderingresponsibility
Manyobjectsareavailabletoyourcontrollerclosures log,params,request,response,session,servletContext,flash
Interceptorsonacontroller beforeInterceptorandafterInterceptorclosures
©2009DevJam‐Allrightsreserved.
Fileupload/multipartrequests Automaticbindingtodomainobjects <g:uploadForm />
Binaryresponsewriting response.outputStream response.contentType Overloaded<<operatortoappendcontent
RequestInputStreamreading def incomingText = request.inputStream.text
©2009DevJam‐Allrightsreserved.
BuiltuponSpring’svalidationframework org.springframework.validationpackage
Domainobjectshavevalidationbakedin save()andvalidate()methodstriggervalidation Validationerrorspopulateerrorspropertyondomainobject
Errors Interrogatethedomainobjectinstance hasErrors()methodanderrorsproperty
©2009DevJam‐Allrightsreserved.
SimilartoJSPs UtilizesGPathandGStringsandothercoolGroovylanguagefeatures
AutomaticdiscoveryofGrailstaglibs Supportfortemplates
Smallsnippetsofviewcodethatotherviewscanuse
UsefulforAJAXresponses
©2009DevJam‐Allrightsreserved.
Grailsshipswithastandardsetoftaglibs Iteration,filtering,switching,logicaltaglibs HTMLmarkupcreation:links,forms,formfields,datepicker
Validationerrorcheckingandrendering Paginatingviews Viewtemplaterendering(reusablesub‐views)
Customtaglibsareeasy GroovyclasswithaTagLibsuffixandresidesingrails‐app/taglibdirectory
©2009DevJam‐Allrightsreserved.
GrailsusesPrototypelibrarybydefault EasilychangedtoanotherJavaScriptproviderthroughGrailspluginsystem
GrailstaglibsinsulateyoufromtherawJavaScript Remotelinks,remoteforms,remoteformfields,beforeandaftercallbacks,eventhandling,effects,animations
©2009DevJam‐Allrightsreserved.
Grailshasbuilt‐insupportformanagingmessagebundles,locales
Messagefilesaremanagedinthegrails‐app/i18ndirectory
Grailstaglibcanbeusedtoretrievemessagesfrommessagebundles Supportsparameterizedmessaging
SupportforspecialURLmappingstosupportencodinglocaleinformationintheURI
©2009DevJam‐Allrightsreserved.
Allowsforcentralizationofapplicationbehavior Necessarycomponentinanynon‐trivialGrailsapplication
Transactionalbydefault,setthroughthetransactionalproperty
Usetheexposepropertytoexposeaserviceviaremotingtootherprocesses Usewithvariousremotingplugins
©2009DevJam‐Allrightsreserved.
ReflectionandtheGroovyMetaClassareusedtoscaffoldCRUDfunctionality
Enableinthecontrollerclass…
class UserController {
def scaffold = User … }
©2009DevJam‐Allrightsreserved.
Extensionmechanismforintegratingthird‐partyfunctionality
About80orsopluginstodayandmanymorecomingonboard AJAX,JavaScript,Flex/Flash,UIwidgets Security,Crypto,CAPTCHA,CAS Databasemigration,codecoverage,functionaltesting
Manyothers…findatgrails.org/plugin/list©2009DevJam‐Allrightsreserved.
SwingGUIconsole AllowsexecutionofarbitraryGroovystatements
YourGrailsdomainmodelisaccessibleinthisenvironment GORMfacilitiesareavailable Greatwaytotinkerandplaywithyourdomainobjectmodel
©2009DevJam‐Allrightsreserved.
Eclipse Pluginavailable,butthestoryisnotgoodatthemoment
NetBeans GroovyandGrailssupportinversion6.5
IntelliJIDEA JetGroovypluginbyJetBrainsoffersgoodsupportforGrails
Seemstobetheleaderatthemoment
©2009DevJam‐Allrightsreserved.
TakeGrailsonatestdrive! grails.org
Books GroovyinAction TheDefinitiveGuidetoGrails,SecondEdition BeginningGroovyandGrails GrailsinAction GroovyandGrailsRecipes GrailsPersistencewithGORMandGSQL
©2009DevJam‐Allrightsreserved.
CoachingandDevelopingAgility
www.devjam.com
©2009DevJam‐Allrightsreserved.