Important Subprojects • grails-datastore-core! – Core low level API • grails-datastore-gorm! – GORM API layer • grails-datastore-gorm-tck! – Test Suite 8
Contribute to GORM • GORM is huge and sprawling • Covers loads of data stores • Great area to contribute to the community. Some ideas: • Multi Tenancy • Elastic Search • Hadoop / HBase 10
What is GORM Standalone? • Easy initialisation of GORM outside of Grails • And a set of Spring Boot plugins • Required modularisation of codebase • Reduction of external dependencies • Simplification of GORM setup 12
GORM for Hibernate in Spring Boot • Add gorm-hibernate4-spring-boot as a dependency ! ! ! ! • Then add persistent entities that are annotated with grails.persistence.Entity 17 compile
"org.grails:gorm-‐hibernate4-‐ spring-‐boot:1.0.0.RELEASE"
GORM for MongoDB in Spring Boot • Add gorm-mongodb-spring-boot as a dependency ! ! ! ! • Then add persistent entities that are annotated with grails.persistence.Entity 18 compile
"org.grails:gorm-‐mongodb-‐spring-‐ boot:1.1.0.RELEASE"
Hibernate Column Formula • A column can be a read-only formula 25 class
Product
{
Float
price
Float
taxRate
Float
tax
static
mapping
=
{
tax
formula:
'PRICE
*
TAX_RATE'
}
}
Hibernate Column Readers/Writers • New in 2.4: Implement custom column readers and writers to transform data when written or read from the database. 26 class
Name
{
String
title
static
mapping
=
{
title
write:'UPPER(?)',
read:'REPEAT(title,
2)'
}
}
Asynchronous GORM • Database operations are blocking • Can be helpful to isolate these blocking operations on a separately managed thread • Work underway in some NoSQL datastore on fully asynchronous drivers (MongoDB, CouchDB etc.) • No usable asynchronous SQL/JDBC drivers on the horizon (to my knowledge) 27
MongoDB Text Search • Create text indices and use methods 36 Product.search('"Coffee
Cake"')
.size()
==
1
Product.searchTop("cake").size()
==
4
Product.searchTop("cake",3).size()
==
3
Product.countHits('coffee')
==
5
Hibernate in Unit Tests • Add a dependency on grails-datastore-test- support ! ! ! • Provides HibernateTestMixin that will load Hibernate inside a unit test 41 test
"org.grails:grails-‐datastore-‐test-‐ support:1.0-‐grails-‐2.4"
Summary • GORM provides a rich and diverse ecosystem • Goes far beyond relational databases • Can be used standalone or within Grails • Great area to contribute to! 43