Grails in the Enterprise                       Peter LedbrookMonday, 30 May 2011                              1
Integration Points     • Build     • Dependencies     • Database     • Deployment     • Spring                          2M...
Integration Points     • Build     • Dependencies     • Database     • Deployment     • Spring                          3M...
Build                      4Monday, 30 May 2011       4
Ant Integration     • An Ant task built in (grails.ant.GrailsTask)     • Template Ant build:         grails integrate-with...
6Monday, 30 May 2011       6
Maven     • Maven Grails Plugin:          https://github.com/grails/grails-maven     • Use Maven 2 to build Grails project...
Getting Started                               mvn archetype-generate ...                                      mvn initiali...
Packaging Types     • ‘war’          – Must configure execution section          – Works with plugins that depend on ‘war’...
10Monday, 30 May 2011        10
Maven & Grails Plugins                      > grails release-plugin                                ==                     ...
Maven & Grails Plugins          Either:                      <dependency>                       <groupId>org.grails.plugin...
Maven & Grails Plugins              Or:                      grails.project.dependency.resolution = {                     ...
Customise the Build     • Create new commands in <proj>/scripts     • Package the commands in a plugin!     • Create <proj...
What the future holds...     • Grails 2.0 will move to Gradle          – More powerful and more flexible          – Standa...
Integration Points     • Build     • Dependencies     • Database     • Deployment     • Spring                          16...
Dependency DSL           grails.project.dependency.resolution = {             inherits "global"             log "warn"    ...
Dependency DSL           grails.project.dependency.resolution = {             inherits "global"             log "warn"    ...
Integration Points     • Build     • Dependencies     • Database     • Deployment     • Spring                          19...
‘Legacy’ Databases     • Grails can create a database from your domain model...     • ...but what if you don’t own the dat...
Option 1: Custom ORM mapping            class Book {               ...               static mapping = {                   ...
Option 2: JPA annotations      <?xml version=1.0 encoding=UTF-8?>      <!DOCTYPE ...>      <hibernate-configuration>      ...
Option 3: Hibernate XML Mappings      <?xml version=1.0 encoding=UTF-8?>      <!DOCTYPE ...>      <hibernate-configuration...
Constraints        Given domain class:                  org.example.myapp.domain.Book        Then:                  src/ja...
Option 4: GORM JPA Plugin     • GORM layer over JPA     • Use your own JPA provider     • Useful for cloud services that o...
Share your model!                         26Monday, 30 May 2011           26
Database Management     • Hibernate auto-DDL          – Good for dev & test          – Bad for production!     • Data migr...
Integration Points     • Build     • Dependencies     • Database     • Deployment     • Spring                          28...
grails war     • Build properties:          – grails.war.copyToWebApp          – grails.war.dependencies          – grails...
Control of JARs           grails.project.dependency.resolution = {             defaultDependenciesProvided true           ...
Data Source        JNDI:               dataSource {                 jndiName = "java:comp/env/myDataSource"               ...
Data Source       Config.groovy:               grails.config.locations = [                 "file:./${appName}-config.groov...
Integration Points     • Build     • Dependencies     • Database     • Deployment     • Spring                          33...
Grails is Spring     • Spring MVC under the hood     • Grails provides many useful beans          – e.g. grailsApplication...
Example      import ...      beans = {        credentialMatcher(Sha1CredentialsMatcher) {           storedCredentialsHexEn...
Enterprise Integration     • Spring opens up a world of possibilities          – Spring Integration/Camel          – Messa...
Grails Plugins     •   Routing     •   JMS, RabbitMQ     •   CXF, Spring-WS, WS-Client     •   REST                       ...
Summary     • Various options for integrating Grails with:           – Development/build           – Deployment processes ...
Thank you!                      Q&A                            39Monday, 30 May 2011              39
Upcoming SlideShare
Loading in...5
×

GR8Conf 2011: Grails Enterprise Integration by Peter Ledbrook

1,858

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,858
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
58
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

GR8Conf 2011: Grails Enterprise Integration by Peter Ledbrook

  1. 1. Grails in the Enterprise Peter LedbrookMonday, 30 May 2011 1
  2. 2. Integration Points • Build • Dependencies • Database • Deployment • Spring 2Monday, 30 May 2011 2
  3. 3. Integration Points • Build • Dependencies • Database • Deployment • Spring 3Monday, 30 May 2011 3
  4. 4. Build 4Monday, 30 May 2011 4
  5. 5. Ant Integration • An Ant task built in (grails.ant.GrailsTask) • Template Ant build: grails integrate-with --ant • Uses Ivy for dependency management • Not compatible with Ant 1.8 5Monday, 30 May 2011 5
  6. 6. 6Monday, 30 May 2011 6
  7. 7. Maven • Maven Grails Plugin: https://github.com/grails/grails-maven • Use Maven 2 to build Grails projects • Declare dependencies in POM • Works for both applications and plugins! • Integration test framework: https://github.com/grails/grails_maven_plugin_testing_tests 7Monday, 30 May 2011 7
  8. 8. Getting Started mvn archetype-generate ... mvn initialize -Xmx256m e.g. -XX:MaxPermSize=256m Set MAVEN_OPTS Optional: add ‘pom true’ to dependency DSL 8Monday, 30 May 2011 8
  9. 9. Packaging Types • ‘war’ – Must configure execution section – Works with plugins that depend on ‘war’ • ‘grails-app’ – Less configuration • ‘grails-plugin’ – For plugins! 9Monday, 30 May 2011 9
  10. 10. 10Monday, 30 May 2011 10
  11. 11. Maven & Grails Plugins > grails release-plugin == > mvn deploy 11Monday, 30 May 2011 11
  12. 12. Maven & Grails Plugins Either: <dependency> <groupId>org.grails.plugins<groupId> <artifactId>hibernate</artifactId> <type>grails-plugin</type> </dependency> Use ‘mvn deploy’ or Release plugin! And ‘pom: false’ 12Monday, 30 May 2011 12
  13. 13. Maven & Grails Plugins Or: grails.project.dependency.resolution = { ... plugins { compile ":hibernate:1.3.6" } ... } 13Monday, 30 May 2011 13
  14. 14. Customise the Build • Create new commands in <proj>/scripts • Package the commands in a plugin! • Create <proj>/scripts/_Events.groovy – Interact with standard build steps – Add test types – Configure embedded Tomcat 14Monday, 30 May 2011 14
  15. 15. What the future holds... • Grails 2.0 will move to Gradle – More powerful and more flexible – Standard, well documented API – Ant & Maven support 15Monday, 30 May 2011 15
  16. 16. Integration Points • Build • Dependencies • Database • Deployment • Spring 16Monday, 30 May 2011 16
  17. 17. Dependency DSL grails.project.dependency.resolution = { inherits "global" log "warn" repositories { grailsHome() mavenCentral() mavenRepo "http://localhost:8081/..." } ... } 17Monday, 30 May 2011 17
  18. 18. Dependency DSL grails.project.dependency.resolution = { inherits "global" log "warn" ... dependencies { compile "org.tmatesoft.svnkit:svnkit:1.3.3" test "org.gmock:gmock:0.8.1" } ... } 18Monday, 30 May 2011 18
  19. 19. Integration Points • Build • Dependencies • Database • Deployment • Spring 19Monday, 30 May 2011 19
  20. 20. ‘Legacy’ Databases • Grails can create a database from your domain model... • ...but what if you don’t own the database? – DBA determines structure – Company conventions – Existing ‘legacy’ database 20Monday, 30 May 2011 20
  21. 21. Option 1: Custom ORM mapping class Book { ... static mapping = { table "books" title type: "books" author column: "author_ref" } } 21Monday, 30 May 2011 21
  22. 22. Option 2: JPA annotations <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE ...> <hibernate-configuration> <session-factory> <mapping class="org.ex.Book"/> <mapping class="org.ex.Author"/> ... </session-factory> </hibernate-configuration> 22Monday, 30 May 2011 22
  23. 23. Option 3: Hibernate XML Mappings <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE ...> <hibernate-configuration> <session-factory> <mapping resource="org.ex.Book.hbm.xml"/> <mapping resource="org.ex.Author.hbm.xml"/> ... </session-factory> </hibernate-configuration> 23Monday, 30 May 2011 23
  24. 24. Constraints Given domain class: org.example.myapp.domain.Book Then: src/java/org/example/myapp/domain/BookConstraints.groovy constraints = { title blank: false, unique: true ... } 24Monday, 30 May 2011 24
  25. 25. Option 4: GORM JPA Plugin • GORM layer over JPA • Use your own JPA provider • Useful for cloud services that only work with JPA, not Hibernate 25Monday, 30 May 2011 25
  26. 26. Share your model! 26Monday, 30 May 2011 26
  27. 27. Database Management • Hibernate auto-DDL – Good for dev & test – Bad for production! • Data migration – http://grails.org/plugin/database-migration • Reverse engineer a model – http://grails.org/plugin/db-reverse-engineer 27Monday, 30 May 2011 27
  28. 28. Integration Points • Build • Dependencies • Database • Deployment • Spring 28Monday, 30 May 2011 28
  29. 29. grails war • Build properties: – grails.war.copyToWebApp – grails.war.dependencies – grails.war.resources – grails.project.war.file 29Monday, 30 May 2011 29
  30. 30. Control of JARs grails.project.dependency.resolution = { defaultDependenciesProvided true inherits "global" log "warn" ... } grails war --nojars => WEB-INF/lib/<empty> => No Grails JARs in WEB-INF/lib 30Monday, 30 May 2011 30
  31. 31. Data Source JNDI: dataSource { jndiName = "java:comp/env/myDataSource" } System property: dataSource { url = System.getProperty("JDBC_STRING") } 31Monday, 30 May 2011 31
  32. 32. Data Source Config.groovy: grails.config.locations = [ "file:./${appName}-config.groovy", "classpath:${appName}-config.groovy" ] For run-app: ./<app>-config.groovy For Tomcat: tomcat/lib/<app>-config.groovy 32Monday, 30 May 2011 32
  33. 33. Integration Points • Build • Dependencies • Database • Deployment • Spring 33Monday, 30 May 2011 33
  34. 34. Grails is Spring • Spring MVC under the hood • Grails provides many useful beans – e.g. grailsApplication • Define your own beans! – resources.xml/groovy – In a plugin 34Monday, 30 May 2011 34
  35. 35. Example import ... beans = { credentialMatcher(Sha1CredentialsMatcher) { storedCredentialsHexEncoded = true } sessionFactory(ConfigurableLocalSessionFactoryBean) { dataSource = ref("dataSource") hibernateProperties = [ "hibernate.hbm2ddl.auto": "create-drop", "hibernate.show_sql": true ] } } 35Monday, 30 May 2011 35
  36. 36. Enterprise Integration • Spring opens up a world of possibilities – Spring Integration/Camel – Messaging (JMS/AMQP) – ESB – RMI, HttpInvoker, etc. • Web services & REST 36Monday, 30 May 2011 36
  37. 37. Grails Plugins • Routing • JMS, RabbitMQ • CXF, Spring-WS, WS-Client • REST 37Monday, 30 May 2011 37
  38. 38. Summary • Various options for integrating Grails with: – Development/build – Deployment processes • Works with many external systems – Solid support for non-Grailsy DB schemas – Flexible messaging & web service support 38Monday, 30 May 2011 38
  39. 39. Thank you! Q&A 39Monday, 30 May 2011 39
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×