practical grails
DESCRIPTION
Grails presentation given at Denver Open Source User Group April 2009TRANSCRIPT
Practical Grails
Denver Open Source User's GroupApril 2009
Scott RyanSoaring Eagle [email protected]
Agenda
• Grails Overview• Grails Architecture• Domain Layer• Controller Layer• Service Layer• Presentation Layer• Build, Develop and Deploy• Security• Plugins
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,...
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)
Demo
• Trading system
Architecture
• Domain Layer– Gorm
• Controller Layer• Service Layer• Presentation Layer• Configuration Layer• Environment and Build layer• Plugin Layer
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
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
Domain Environment Setup
• Based on environment– Runtime or Build controlled
• Sample Configuration File• Sample Bootstrap File
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
Queries
• Dynamic Generated GORM Queries– Simple and compound
• Criteria Framework– Sorting
• Hand Coded SQL– Hibernate Based– Custom SQL
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)
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
Service Layer
• Reusable business logic• Complex transactions• Can be injected anywhere
– Domain, Controller, View• Spring Beans
Presentation Layer
• Layouts• Templates• Tags• Link Building• Images and CSS• Custom Taglibs
Ajax
• Built in with prototype• Can use other frameworks• Best practices to use shared templates
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
Security
• Use a framework to start• Remember this is a REST Application• Leverage Custom filters• Encrypt what you need to
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
Favorite Plugins
• Spring Security• Quartz• Grails UI and Charting• Mail• Settings• Help Balloons• mor.ph• Testing (Included in 1.1)
Questions
• Contact Me– Scott Ryan– [email protected]– www.soaringeagleco.com