Upload
gr8conf
View
1.830
Download
2
Tags:
Embed Size (px)
Citation preview
Peter Ledbrook
Grails in the Enterprise
1Monday, 30 May 2011
Integration Points
• Build• Dependencies• Database• Deployment• Spring
2
2Monday, 30 May 2011
Integration Points
• Build• Dependencies• Database• Deployment• Spring
3
3Monday, 30 May 2011
Build
4
4Monday, 30 May 2011
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
5
5Monday, 30 May 2011
6
6Monday, 30 May 2011
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
7
7Monday, 30 May 2011
Getting Started
mvn archetype-generate ...
mvn initialize
Set MAVEN_OPTS
Optional: add ‘pom true’ to dependency DSL
e.g. -Xmx256m -XX:MaxPermSize=256m
8
8Monday, 30 May 2011
Packaging Types
• ‘war’– Must configure execution section– Works with plugins that depend on ‘war’
• ‘grails-app’– Less configuration
• ‘grails-plugin’– For plugins!
9
9Monday, 30 May 2011
10
10Monday, 30 May 2011
Maven & Grails Plugins
> grails release-plugin
==
> mvn deploy
11
11Monday, 30 May 2011
Maven & Grails Plugins
<dependency> <groupId>org.grails.plugins<groupId> <artifactId>hibernate</artifactId> <type>grails-plugin</type></dependency>
Either:
Use ‘mvn deploy’ or Release plugin!
12
And ‘pom: false’
12Monday, 30 May 2011
Maven & Grails Plugins
grails.project.dependency.resolution = { ... plugins { compile ":hibernate:1.3.6" } ...}
Or:
13
13Monday, 30 May 2011
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
14
14Monday, 30 May 2011
What the future holds...
• Grails 2.0 will move to Gradle– More powerful and more flexible– Standard, well documented API– Ant & Maven support
15
15Monday, 30 May 2011
Integration Points
• Build• Dependencies• Database• Deployment• Spring
16
16Monday, 30 May 2011
Dependency DSL
grails.project.dependency.resolution = { inherits "global" log "warn" repositories { grailsHome() mavenCentral() mavenRepo "http://localhost:8081/..." } ...}
17
17Monday, 30 May 2011
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" } ...}
18
18Monday, 30 May 2011
Integration Points
• Build• Dependencies• Database• Deployment• Spring
19
19Monday, 30 May 2011
‘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
20
20Monday, 30 May 2011
class Book { ... static mapping = { table "books" title type: "books" author column: "author_ref" }}
21
Option 1: Custom ORM mapping
21Monday, 30 May 2011
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>
22
22Monday, 30 May 2011
<?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>
23
Option 3: Hibernate XML Mappings
23Monday, 30 May 2011
constraints = { title blank: false, unique: true ...}
Constraints
Given domain class:
Then:
org.example.myapp.domain.Book
src/java/org/example/myapp/domain/BookConstraints.groovy
24
24Monday, 30 May 2011
• GORM layer over JPA• Use your own JPA provider• Useful for cloud services that only work with JPA, not
Hibernate
25
Option 4: GORM JPA Plugin
25Monday, 30 May 2011
Share your model!
26
26Monday, 30 May 2011
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
27
27Monday, 30 May 2011
Integration Points
• Build• Dependencies• Database• Deployment• Spring
28
28Monday, 30 May 2011
grails war
• Build properties:– grails.war.copyToWebApp– grails.war.dependencies– grails.war.resources– grails.project.war.file
29
29Monday, 30 May 2011
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
30
30Monday, 30 May 2011
Data Source
dataSource { jndiName = "java:comp/env/myDataSource"}
JNDI:
dataSource { url = System.getProperty("JDBC_STRING")}
System property:
31
31Monday, 30 May 2011
Data Source
grails.config.locations = [ "file:./${appName}-config.groovy", "classpath:${appName}-config.groovy" ]
Config.groovy:
For run-app: ./<app>-config.groovy
For Tomcat: tomcat/lib/<app>-config.groovy
32
32Monday, 30 May 2011
Integration Points
• Build• Dependencies• Database• Deployment• Spring
33
33Monday, 30 May 2011
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
34
34Monday, 30 May 2011
Example
import ...beans = { credentialMatcher(Sha1CredentialsMatcher) { storedCredentialsHexEncoded = true }
sessionFactory(ConfigurableLocalSessionFactoryBean) { dataSource = ref("dataSource") hibernateProperties = [ "hibernate.hbm2ddl.auto": "create-drop", "hibernate.show_sql": true ] }}
35
35Monday, 30 May 2011
Enterprise Integration
• Spring opens up a world of possibilities– Spring Integration/Camel– Messaging (JMS/AMQP)– ESB– RMI, HttpInvoker, etc.
• Web services & REST
36
36Monday, 30 May 2011
Grails Plugins
• Routing• JMS, RabbitMQ• CXF, Spring-WS, WS-Client• REST
37
37Monday, 30 May 2011
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
38
38Monday, 30 May 2011
Thank you!
Q & A
39
39Monday, 30 May 2011