Standalone GORM

19

Transcript of Standalone GORM

Page 1: Standalone GORM
Page 2: Standalone GORM

What is Hibernate?

Object –Relational mapping tool

Object-Oriented querying

Database agnostic query language

XML configuration or annotations

Page 3: Standalone GORM

Event.hbm.xml

Typical Hibernate Java bean and configuration

Event.java

Page 4: Standalone GORM
Page 5: Standalone GORM

What is GORM?

Groovy layer over Hibernate

Convention over configuration mapping

Dynamic finder/persistence methods

DSL based querying

Page 6: Standalone GORM

Equivalent GORM entity definition

Event.groovv

Page 7: Standalone GORM
Page 8: Standalone GORM

GORM in Java

Hurdles

No dynamic methods in Java

No dynamic typing in Java

Cross-compilation

Semicolons

Solutions

Maven groovy plugin

Intermediary entity manager

Page 9: Standalone GORM

Configure Maven build

pom.xml

Page 10: Standalone GORM

GORM XML namespace

Set up GORM in Spring

Page 11: Standalone GORM

Add sessionFactory bean and dependencies

Page 12: Standalone GORM

TestBean.groovy

Create TestBean entity

Page 13: Standalone GORM

Create TestBean entity

Page 14: Standalone GORM

EntityManager.java

TestBeanManager.java

Use Java interface to bridge Java - Groovy

Page 15: Standalone GORM

TestBeanManagerImpl.groovy

Using GORM dynamic methods

Page 16: Standalone GORM

This works… but…

My database schema

looks like this:

Page 17: Standalone GORM

Groovy Metaprogramming

Use JDK Proxy to implement interfaces

Use Groovy MetaMethods to call GORM methods

dynamically

invokeMethod

methodMissing

Page 18: Standalone GORM

DynamicManagerImpl.groovy

Page 19: Standalone GORM

Demo