Standalone GORM

Post on 04-Jul-2015

1.955 views 3 download

Transcript of Standalone GORM

What is Hibernate?

Object –Relational mapping tool

Object-Oriented querying

Database agnostic query language

XML configuration or annotations

Event.hbm.xml

Typical Hibernate Java bean and configuration

Event.java

What is GORM?

Groovy layer over Hibernate

Convention over configuration mapping

Dynamic finder/persistence methods

DSL based querying

Equivalent GORM entity definition

Event.groovv

GORM in Java

Hurdles

No dynamic methods in Java

No dynamic typing in Java

Cross-compilation

Semicolons

Solutions

Maven groovy plugin

Intermediary entity manager

Configure Maven build

pom.xml

GORM XML namespace

Set up GORM in Spring

Add sessionFactory bean and dependencies

TestBean.groovy

Create TestBean entity

Create TestBean entity

EntityManager.java

TestBeanManager.java

Use Java interface to bridge Java - Groovy

TestBeanManagerImpl.groovy

Using GORM dynamic methods

This works… but…

My database schema

looks like this:

Groovy Metaprogramming

Use JDK Proxy to implement interfaces

Use Groovy MetaMethods to call GORM methods

dynamically

invokeMethod

methodMissing

DynamicManagerImpl.groovy

Demo