Practical Grails

1,966 views

Published on

Grails presentation given at Denver Open Source User Group April 2009

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,966
On SlideShare
0
From Embeds
0
Number of Embeds
57
Actions
Shares
0
Downloads
37
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Practical Grails

  1. 1. Practical Grails Denver Open Source User's Group April 2009 Scott Ryan Soaring Eagle L.L.C. [email_address]
  2. 2. Agenda <ul><li>Grails Overview </li></ul><ul><li>Grails Architecture </li></ul><ul><li>Domain Layer </li></ul><ul><li>Controller Layer </li></ul><ul><li>Service Layer </li></ul><ul><li>Presentation Layer </li></ul><ul><li>Build, Develop and Deploy </li></ul><ul><li>Security </li></ul><ul><li>Plugins </li></ul>
  3. 3. Overview <ul><li>Groovy Based </li></ul><ul><li>Convention over configuration </li></ul><ul><li>Don’t Repeat Yourself (DRY) </li></ul><ul><li>Lots of code generation and scaffolding </li></ul><ul><li>Leverages Leading Java Frameworks </li></ul><ul><ul><li>Spring, Hibernate, Quartz, JSP, Ajax, Sitemesh,... </li></ul></ul>
  4. 4. Overview <ul><li>Wide IDE Support </li></ul><ul><ul><li>Intellij, Netbeans, Eclipse, .... </li></ul></ul><ul><li>Wide Server Support </li></ul><ul><ul><li>Jetty, Tomcat, Websphere, Weblogic, Glassfish, Geronimo </li></ul></ul><ul><li>Very Dynamic development Environment </li></ul><ul><li>Two Current Versions </li></ul><ul><ul><li>1.0.4 (Groovy 1.5) and 1.1 (Groovy 1.6) </li></ul></ul><ul><li>Huge Productivity Benefits </li></ul><ul><li>Leverages Java and JVM (Scalable) </li></ul>
  5. 5. Demo <ul><li>Trading system </li></ul>
  6. 6. Architecture <ul><li>Domain Layer </li></ul><ul><ul><li>Gorm </li></ul></ul><ul><li>Controller Layer </li></ul><ul><li>Service Layer </li></ul><ul><li>Presentation Layer </li></ul><ul><li>Configuration Layer </li></ul><ul><li>Environment and Build layer </li></ul><ul><li>Plugin Layer </li></ul>
  7. 7. Domain Sample Code <ul><li>Sample Domain Code </li></ul><ul><ul><li>Column Definition </li></ul></ul><ul><ul><li>Relationships (one to one, many to many, etc.) </li></ul></ul><ul><ul><ul><li>BelongsTo </li></ul></ul></ul><ul><ul><li>Constraints </li></ul></ul><ul><ul><li>Custom Hibernate Definitions </li></ul></ul><ul><ul><ul><li>Indexes ( Simple or Complex ), Blobs </li></ul></ul></ul><ul><ul><li>Base Domain Class </li></ul></ul>
  8. 8. Reference Data Handling <ul><li>Table Based </li></ul><ul><ul><li>One or many </li></ul></ul><ul><li>String Based </li></ul><ul><li>Enum Based </li></ul><ul><ul><li>1.0.4 Stores Ordinal </li></ul></ul><ul><ul><ul><li>Temporary trick </li></ul></ul></ul><ul><ul><li>1.1 Can store String </li></ul></ul><ul><li>Plugins </li></ul>
  9. 9. Domain Environment Setup <ul><li>Based on environment </li></ul><ul><ul><li>Runtime or Build controlled </li></ul></ul><ul><li>Sample Configuration File </li></ul><ul><li>Sample Bootstrap File </li></ul>
  10. 10. Transactions <ul><li>Uses Open Session in View </li></ul><ul><ul><li>Modify data with care (discard) </li></ul></ul><ul><li>Spring Controlled Transactions </li></ul><ul><li>Can open transactions manually </li></ul><ul><li>Complex Transactions best done in Service layer </li></ul><ul><li>Batch inserts are problematic but easily addressed </li></ul>
  11. 11. Queries <ul><li>Dynamic Generated GORM Queries </li></ul><ul><ul><li>Simple and compound </li></ul></ul><ul><li>Criteria Framework </li></ul><ul><ul><li>Sorting </li></ul></ul><ul><li>Hand Coded SQL </li></ul><ul><ul><li>Hibernate Based </li></ul></ul><ul><ul><li>Custom SQL </li></ul></ul>
  12. 12. Criteria Query <ul><li>// returns first 10 users who have an active </li></ul><ul><li>// account that has been created in the last </li></ul><ul><li>// 30 days and that have Grails-like </li></ul><ul><li>// bookmarks created in the last 7 days </li></ul><ul><li>def now = new Date() </li></ul><ul><li>def users = Bookmark.withCriteria { </li></ul><ul><li>comments { </li></ul><ul><li>like( &quot;text&quot; , &quot;%Grails%&quot; ) </li></ul><ul><li>between( &quot;dateCreated&quot; , now- 7 , now) </li></ul><ul><li>} </li></ul><ul><li>between( &quot;dateCreated&quot; ,now- 30 , now) </li></ul><ul><li>maxResults( 10 ) </li></ul>
  13. 13. Controllers <ul><li>Should be light weight </li></ul><ul><li>Push business logic to the service layer </li></ul><ul><li>Remember security as REST is king </li></ul><ul><li>Download and upload is supported </li></ul><ul><li>Graphics and Reporting </li></ul>
  14. 14. Service Layer <ul><li>Reusable business logic </li></ul><ul><li>Complex transactions </li></ul><ul><li>Can be injected anywhere </li></ul><ul><ul><li>Domain, Controller, View </li></ul></ul><ul><li>Spring Beans </li></ul>
  15. 15. Presentation Layer <ul><li>Layouts </li></ul><ul><li>Templates </li></ul><ul><li>Tags </li></ul><ul><li>Link Building </li></ul><ul><li>Images and CSS </li></ul><ul><li>Custom Taglibs </li></ul>
  16. 16. Ajax <ul><li>Built in with prototype </li></ul><ul><li>Can use other frameworks </li></ul><ul><li>Best practices to use shared templates </li></ul>
  17. 17. Build and Configuration <ul><li>Multiple Environments </li></ul><ul><ul><li>3 defaults </li></ul></ul><ul><li>Gant Based and Maven (1.1) </li></ul><ul><li>BIG War's but can make them smaller with some work </li></ul><ul><li>Lots of targets </li></ul>
  18. 18. Security <ul><li>Use a framework to start </li></ul><ul><li>Remember this is a REST Application </li></ul><ul><li>Leverage Custom filters </li></ul><ul><li>Encrypt what you need to </li></ul>
  19. 19. Plugins <ul><li>Framework for adding functionality </li></ul><ul><li>Can be used to optimize applications </li></ul><ul><li>Can be used to add functionality to base framework </li></ul><ul><li>Easy to install </li></ul><ul><ul><li>1.1 improves the architecture </li></ul></ul><ul><li>Hard to tell what is useful and supported </li></ul>
  20. 20. Favorite Plugins <ul><li>Spring Security </li></ul><ul><li>Quartz </li></ul><ul><li>Grails UI and Charting </li></ul><ul><li>Mail </li></ul><ul><li>Settings </li></ul><ul><li>Help Balloons </li></ul><ul><li>mor.ph </li></ul><ul><li>Testing (Included in 1.1) </li></ul>
  21. 21. Questions <ul><li>Contact Me </li></ul><ul><ul><li>Scott Ryan </li></ul></ul><ul><ul><li>[email_address] </li></ul></ul><ul><ul><li>www.soaringeagleco.com </li></ul></ul>

×