GR8Conf 2011: Grails Enterprise Integration by Peter Ledbrook

  • 1,780 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,780
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
56
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Grails in the Enterprise Peter LedbrookMonday, 30 May 2011 1
  • 2. Integration Points • Build • Dependencies • Database • Deployment • Spring 2Monday, 30 May 2011 2
  • 3. Integration Points • Build • Dependencies • Database • Deployment • Spring 3Monday, 30 May 2011 3
  • 4. Build 4Monday, 30 May 2011 4
  • 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. 6Monday, 30 May 2011 6
  • 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. 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. 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. 10Monday, 30 May 2011 10
  • 11. Maven & Grails Plugins > grails release-plugin == > mvn deploy 11Monday, 30 May 2011 11
  • 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. Maven & Grails Plugins Or: grails.project.dependency.resolution = { ... plugins { compile ":hibernate:1.3.6" } ... } 13Monday, 30 May 2011 13
  • 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. 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. Integration Points • Build • Dependencies • Database • Deployment • Spring 16Monday, 30 May 2011 16
  • 17. Dependency DSL grails.project.dependency.resolution = { inherits "global" log "warn" repositories { grailsHome() mavenCentral() mavenRepo "http://localhost:8081/..." } ... } 17Monday, 30 May 2011 17
  • 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. Integration Points • Build • Dependencies • Database • Deployment • Spring 19Monday, 30 May 2011 19
  • 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. Option 1: Custom ORM mapping class Book { ... static mapping = { table "books" title type: "books" author column: "author_ref" } } 21Monday, 30 May 2011 21
  • 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. 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. 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. 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. Share your model! 26Monday, 30 May 2011 26
  • 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. Integration Points • Build • Dependencies • Database • Deployment • Spring 28Monday, 30 May 2011 28
  • 29. grails war • Build properties: – grails.war.copyToWebApp – grails.war.dependencies – grails.war.resources – grails.project.war.file 29Monday, 30 May 2011 29
  • 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. Data Source JNDI: dataSource { jndiName = "java:comp/env/myDataSource" } System property: dataSource { url = System.getProperty("JDBC_STRING") } 31Monday, 30 May 2011 31
  • 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. Integration Points • Build • Dependencies • Database • Deployment • Spring 33Monday, 30 May 2011 33
  • 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. 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. 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. Grails Plugins • Routing • JMS, RabbitMQ • CXF, Spring-WS, WS-Client • REST 37Monday, 30 May 2011 37
  • 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. Thank you! Q&A 39Monday, 30 May 2011 39