Top Banner
Practical Grails Denver Open Source User's Group April 2009 Scott Ryan Soaring Eagle L.L.C. [email protected] m
21

Practical Grails

May 13, 2015

Download

Technology

Grails presentation given at Denver Open Source User Group April 2009
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Practical Grails

Practical Grails

Denver Open Source User's GroupApril 2009

Scott RyanSoaring Eagle [email protected]

Page 2: Practical Grails

Agenda

• Grails Overview• Grails Architecture• Domain Layer• Controller Layer• Service Layer• Presentation Layer• Build, Develop and Deploy• Security• Plugins

Page 3: Practical Grails

Overview

• Groovy Based

• Convention over configuration

• Don’t Repeat Yourself (DRY)

• Lots of code generation and scaffolding

• Leverages Leading Java Frameworks– Spring, Hibernate, Quartz, JSP, Ajax, Sitemesh,...

Page 4: Practical Grails

Overview• Wide IDE Support

– Intellij, Netbeans, Eclipse, ....

• Wide Server Support– Jetty, Tomcat, Websphere, Weblogic, Glassfish, Geronimo

• Very Dynamic development Environment• Two Current Versions

– 1.0.4 (Groovy 1.5) and 1.1 (Groovy 1.6)

• Huge Productivity Benefits• Leverages Java and JVM (Scalable)

Page 5: Practical Grails

Demo

• Trading system

Page 6: Practical Grails

Architecture

• Domain Layer– Gorm

• Controller Layer• Service Layer• Presentation Layer• Configuration Layer• Environment and Build layer• Plugin Layer

Page 7: Practical Grails

Domain Sample Code

• Sample Domain Code– Column Definition– Relationships (one to one, many to many, etc.)

• BelongsTo

– Constraints– Custom Hibernate Definitions

• Indexes (Simple or Complex), Blobs– Base Domain Class

Page 8: Practical Grails

Reference Data Handling

• Table Based– One or many

• String Based• Enum Based

– 1.0.4 Stores Ordinal• Temporary trick

– 1.1 Can store String• Plugins

Page 9: Practical Grails

Domain Environment Setup

• Based on environment– Runtime or Build controlled

• Sample Configuration File• Sample Bootstrap File

Page 10: Practical Grails

Transactions

• Uses Open Session in View– Modify data with care (discard)

• Spring Controlled Transactions• Can open transactions manually• Complex Transactions best done in Service

layer• Batch inserts are problematic but easily

addressed

Page 11: Practical Grails

Queries

• Dynamic Generated GORM Queries– Simple and compound

• Criteria Framework– Sorting

• Hand Coded SQL– Hibernate Based– Custom SQL

Page 12: Practical Grails

Criteria Query

// returns first 10 users who have an active

// account that has been created in the last

// 30 days and that have Grails-like

// bookmarks created in the last 7 days

def now = new Date()

def users = Bookmark.withCriteria {

comments {

like("text","%Grails%")

between("dateCreated", now-7, now)

}

between("dateCreated",now-30, now)

maxResults(10)

Page 13: Practical Grails

Controllers

• Should be light weight• Push business logic to the service layer• Remember security as REST is king• Download and upload is supported• Graphics and Reporting

Page 14: Practical Grails

Service Layer

• Reusable business logic• Complex transactions• Can be injected anywhere

– Domain, Controller, View• Spring Beans

Page 15: Practical Grails

Presentation Layer

• Layouts• Templates• Tags• Link Building• Images and CSS• Custom Taglibs

Page 16: Practical Grails

Ajax

• Built in with prototype• Can use other frameworks• Best practices to use shared templates

Page 17: Practical Grails

Build and Configuration

• Multiple Environments– 3 defaults

• Gant Based and Maven (1.1)• BIG War's but can make them smaller with

some work• Lots of targets

Page 18: Practical Grails

Security

• Use a framework to start• Remember this is a REST Application• Leverage Custom filters• Encrypt what you need to

Page 19: Practical Grails

Plugins

• Framework for adding functionality• Can be used to optimize applications• Can be used to add functionality to base

framework• Easy to install

– 1.1 improves the architecture• Hard to tell what is useful and supported

Page 20: Practical Grails

Favorite Plugins

• Spring Security• Quartz• Grails UI and Charting• Mail• Settings• Help Balloons• mor.ph• Testing (Included in 1.1)

Page 21: Practical Grails

Questions

• Contact Me– Scott Ryan– [email protected]– www.soaringeagleco.com