5 Step by Step Guide to Creating and Implementation - Reference Documentation
Authors: Graeme Rocher
Version: 6.0.0.M1
5 Step by Step Guide to Creating and Implementation
To get started with your a new GORM implementation the following steps are required:Initial Directory Creation
$ git clone git@github.com:grails/grails-data-mapping.git $ cd grails-data-mapping $ mkdir grails-datastore-gorm-xyz
Setup Gradle Build
Create build.gradle:$ vi grails-datastore-gorm-xyz/build.gradle
dependencies {
compile project(':grails-datastore-gorm'),
project(':grails-datastore-web'),
project(':grails-datastore-gorm-support') testCompile project(':grails-datastore-gorm-tck')
testRuntime "javax.servlet:javax.servlet-api:$servletApiVersion"}$ vi settings.gradle
// GORM Implementations 'grails-datastore-gorm-neo4j', 'grails-datastore-gorm-xyz', ....
Create Project Source Directories
$ mkdir grails-datastore-gorm-xyz/src/main/groovy $ mkdir grails-datastore-gorm-xyz/src/test/groovy
Generate IDE Project Files and Import into IDE
$ gradlew grails-datastore-gorm-xyz:idea
$ gradlew grails-datastore-gorm-xyz:eclipse
Implement Required Interfaces
Insrc/main/groovy create implementations:
org.grails.datastore.xyz.XyzDatastoreextends and implementsorg.grails.datastore.mapping.core.AbstractDatastoreorg.grails.datastore.xyz.XyzSessionextends and implementsorg.grails.datastore.mapping.core.AbstractSessionorg.grails.datastore.xyz.engine.XyzEntityPersisterextends and implementsorg.grails.datastore.mapping.engine.NativeEntryEntityPersisterorg.grails.datastore.xyz.query.XyzQueryextends and implementsorg.grails.datastore.mapping.query.Query
Create Test Suite
Insrc/test/groovy create org.grails.datastore.gorm.Setup class to configure TCK:class Setup { static xyz
static destroy() {
xyz.disconnect()
}
static Session setup(classes) {
def ctx = new GenericApplicationContext()
ctx.refresh()
xyz = new XyzDatastore(ctx)
for (cls in classes) {
xyz.mappingContext.addPersistentEntity(cls)
}
def enhancer = new GormEnhancer(xyz, new DatastoreTransactionManager(datastore: xyz))
enhancer.enhance() xyz.mappingContext.addMappingContextListener({ e -> enhancer.enhance e } as MappingContext.Listener)
xyz.applicationContext.addApplicationListener new DomainEventListener(xyz)
xyz.applicationContext.addApplicationListener new AutoTimestampEventListener(xyz) xyz.connect()
}
}src/test/groovy create test suite class to allow running tests in IDE (without this you won't be able to run TCK tests from the IDE). Example test suite:package org.grails.datastore.gormimport org.junit.runners.Suite.SuiteClasses import org.junit.runners.Suite import org.junit.runner.RunWith import grails.gorm.tests.*/** * @author graemerocher */ @RunWith(Suite) @SuiteClasses([ FindByMethodSpec, ListOrderBySpec ]) class XyzTestSuite { }