Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Andre Steingres on Grails

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

Andre Steingres on Grails

More Decks by Enterprise Java User Group Austria

Other Decks in Technology

Transcript

  1. YAWAFW (?) Let‘s make a step backwards So you like

    coding stuff, huh? If yes, what coding related work bothers you the most? If no, time to leave now.
  2. • Ruby on Rails hits the road in 2004 •

    Innovative Philosophies • Convention over Configuration • Don‘t Repeat Yourself • Code Templates • Easy DB Integration • Ruby as Dynamic Programming Language YAWAFW (?)
  3. • Grails hits the road in 2006 • Taking full

    advantage of Groovy, a dynamic language for the JVM • Built on JEE, Spring, Hibernate and other popular libraries/frameworks you love (or hate) • Turbo-Charging Existing Development Knowledge • Current Version: 1.3.2
  4. • grails-app - „Convention over Configuration“ • lib - additional

    libraries • scripts - custom Grails scripts/commands • src - Java/Groovy source • test - integration, unit tests • web-app - CSS, images, JS, custom context.xml, etc. A Generated Grails App
  5. • Next Steps: • generate-all ... generates views + controller

    • run-app ... runs app in embedded tomcat • war ... generates WAR archive grails
  6. grails haz command? • grails <some GAnt script name> •

    help, create-app, create-domain-class, etc. • implemented as GAnt scripts • $GRAILS_HOME/scripts
  7. • building blocks: Spring Framework, Hibernate and Groovy • GORM

    - Extension to Hibernate • Dynamic Finders: Blog.findByTitleLike, Blog.findByDateCreatedBetween(x, y) • Criteria DSL • HQL: Blog.findAll(„from Blog b where b.title like ?“, [title]) • GSPs, Tag Libraries, Filters • Grails provides configuration DSLs for Spring, Log4J, DataSource, WebFlow, etc. • Environments: development, test, production
  8. • Bootstrap Script in conf/BootStrap.groovy • Codecs: encodeAsHtml, encodeAsJavascript, encodeAsMD5,

    ... • XML/JSON Marshalling • Plugin System • Dependency Management with Ivy (conf/BuildConfig.groovy)
  9. • Convention over Configuration • def. Artefact: „is any object

    made or modified by a human“ • important Grails Artefacts: Domain Classes, Services, Controllers • subfolders: domain, controllers, services • each Grails artefact has a distinguished artefact handler • command line tools: create-domain-class, create-service, create-controller • Plugins might register other Grails artefacts: e.g. Quartz registers the „job“ artefact
  10. Domain Classes • POGOs == Plain Old Groovy Objects •

    holds constraints and GORM configurations
  11. Services • public methods run in transactional contexts • fine-grained

    configuration with @Transactional • scoped services: prototype, request, flash, etc.
  12. So what? • Spring, Hibernate & Groovy are the underlying

    foundation of Grails • Java is the underlying foundation of Groovy
  13. • DSL == Domain Specific Language • Groovy has a

    MOP, makes building custom DSLs super easy! • Meta Object Protocol • adaptable runtime behavior through the metaClass property • GroovyObject, ExpandoMetaClass, custom MetaClass, Categories, ... • methodMissing/propertyMissing • Support for compile-time meta-programming: AST transformations
  14. • Structuring applications with Grails plugins • Since 1.3: support

    for publishing to Maven/SVN repos • http://grails.org/plugin/home - 435 plugins, SVN based repo
  15. • GrailsApplication • main interface representing a running Grails application

    • artefact management • implements GroovyObjectSupport: application.domainClasses, application.controllerClasses etc. • GrailsRuntimeConfigurator • creates the application‘s WebApplicationContext • registers/inits additional plugin artefact handler instances • executes plugin runtime configuration: doWithSpring • loads legacy Spring application contexts from conf/spring/resources.xml
  16. • Like • fast bootstrapping of new projects • large

    plugin ecosystem • component modularization with versioning out-of-the-box • Groovy, a real dynamic programming language, kicks ass • built on top of Spring Framework and Hibernate • GORM saves a lot of DAOs • Testing using a dynamic programming language is fun • Reuse existing Spring/Hibernate artefacts (resources.xml, *.hbm.xml, etc.)
  17. • Dislike • tool support is needed for larger projects

    • Groovy means performance overhead • exaggerated use of dynamic typing needs extensive testing
  18. GContracts • Design by Contract(tm) for Groovy/Grails • Features •

    support for pre-/postconditions, class invariants • class invariants inheritance • pre-/postcondition inheritance • old and result variable in postcondition expressions
  19. Want it? • use Groovy‘s @Grab • or define a

    [Maven|Ivy|...] dependency • or via direct download from http://github.com/andresteingress/gcontracts