Skip to content

Commit

Permalink
correctly working example, guide start
Browse files Browse the repository at this point in the history
  • Loading branch information
benrhine committed Jul 19, 2017
1 parent 0a8df15 commit 64264f7
Show file tree
Hide file tree
Showing 38 changed files with 229 additions and 145 deletions.
47 changes: 4 additions & 43 deletions complete/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}
repositories {
mavenCentral()
}
Expand All @@ -25,50 +22,14 @@ repositories {

dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile "org.springframework.boot:spring-boot-autoconfigure"
compile('org.codehaus.groovy:groovy')
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
//compile("org.grails:gorm-hibernate4-spring-boot:5.0.10.RELEASE")
compile("org.grails:gorm-hibernate5-spring-boot:6.1.5.RELEASE")
compile "org.hibernate:hibernate-core:5.1.0.Final"
compile "org.hibernate:hibernate-ehcache:5.1.0.Final"
runtime('com.h2database:h2')
runtime('com.h2database:h2:1.4.192')
runtime "org.apache.tomcat:tomcat-jdbc:8.5.0"
runtime "org.apache.tomcat.embed:tomcat-embed-logging-log4j:8.5.0"
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile 'org.spockframework:spock-core:1.1-groovy-2.4'
testCompile 'org.spockframework:spock-spring:1.1-groovy-2.4'
}

//buildscript {
// ext {
// springBootVersion = '1.3.8.RELEASE'
// }
// repositories {
// mavenCentral()
// }
// dependencies {
// classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
// }
//}
//
//apply plugin: 'groovy'
//apply plugin: 'eclipse'
//apply plugin: 'idea'
//apply plugin: 'spring-boot'
//
//version = '0.0.1-SNAPSHOT'
//sourceCompatibility = 1.8
//targetCompatibility = 1.8
//
//repositories {
// mavenCentral()
//}
//
//
//dependencies {
// compile('org.springframework.boot:spring-boot-starter-web')
// compile('org.codehaus.groovy:groovy')
// compile("org.grails:gorm-hibernate4-spring-boot:5.0.10.RELEASE")
// runtime('com.h2database:h2')
// testCompile('org.springframework.boot:spring-boot-starter-test')
//}
}
4 changes: 4 additions & 0 deletions complete/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
springBootVersion=1.5.4.RELEASE
grailsVersion=N/A - Spring Boot Version: 1.5.4.RELEASE
gormVersion=6.1.5
gradleWrapperVersion=3.5.1
Binary file modified complete/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions complete/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Mon Nov 23 22:21:31 EST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement
class GormWithoutGrailsApplication {

static void main(String[] args) {

SpringApplication.run GormWithoutGrailsApplication, args
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package demo.GORMwithoutGrails.config

import org.hibernate.SessionFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.orm.hibernate4.support.OpenSessionInViewInterceptor
import org.springframework.context.annotation.Configuration
import org.springframework.orm.hibernate5.support.OpenSessionInViewInterceptor
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter

class WebMvcConfig extends WebMvcConfigurerAdapter {
@Configuration
class WebMvc extends WebMvcConfigurerAdapter {

@Autowired SessionFactory sessionFactory
@Autowired
SessionFactory sessionFactory

@Override
void addInterceptors(InterceptorRegistry registry) {
Expand All @@ -17,4 +20,4 @@ class WebMvcConfig extends WebMvcConfigurerAdapter {
registry.addWebRequestInterceptor( openSessionInViewInterceptor )
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package demo.GORMwithoutGrails.controller

import demo.GORMwithoutGrails.service.MakeService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package demo.GORMwithoutGrails.domain

import grails.gorm.annotation.Entity

@Entity
class Driver extends User {

String name

static hasMany = [ vehicles: Vehicle ]

static mapping = {
version false
}

static constraints = {
vehicles nullable: true
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package demo.GORMwithoutGrails.domain

import grails.gorm.annotation.Entity
import org.grails.datastore.gorm.GormEntity

@Entity
class Make {
class Make implements GormEntity<Make> {

String name

static mapping = {
version false
}

static constraints = {
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package demo.GORMwithoutGrails.domain

import grails.gorm.annotation.Entity
import org.grails.datastore.gorm.GormEntity

@Entity
class Model {
class Model implements GormEntity<Model> {

String name

static mapping = {
version false
}

static constraints = {
}
}

This file was deleted.

28 changes: 28 additions & 0 deletions complete/src/main/groovy/demo/GORMwithoutGrails/domain/User.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package demo.GORMwithoutGrails.domain

import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import org.grails.datastore.gorm.GormEntity

@EqualsAndHashCode(includes='username')
@ToString(includes='username', includeNames=true, includePackage=false)
class User implements Serializable, GormEntity<User> {

private static final long serialVersionUID = 1

String username
String password
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired

static constraints = {
password nullable: false, blank: false, password: true
username nullable: false, blank: false, unique: true
}

static mapping = {
password column: '`password`'
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package demo.GORMwithoutGrails.domain

import grails.gorm.annotation.Entity
import org.grails.datastore.gorm.GormEntity

@Entity
class Vehicle {
class Vehicle implements GormEntity<Vehicle> {

String name

Make make
Model model

static mapping = {
version false
}

static constraints = {
}
Expand Down
5 changes: 4 additions & 1 deletion complete/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
spring.h2.console.enabled=true
spring.h2.console.path=/console
spring.datasource.platform=h2
spring.datasource.platform=h2
#spring.jpa.properties.hibernate.hbm2ddl=auto
#spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop
13 changes: 13 additions & 0 deletions complete/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
dataSource:
pooled: true
dbCreate: create-drop
url: jdbc:h2:mem:devDb
driverClassName: org.h2.Driver
username: sa
password:
hibernate:
cache:
queries: false
use_second_level_cache: true
use_query_cache: false
region.factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package demo.GORMwithoutGrails.domain

import grails.gorm.transactions.Rollback
import org.grails.orm.hibernate.HibernateDatastore
import spock.lang.AutoCleanup
import spock.lang.Shared
import spock.lang.Specification

class DriverSpec extends Specification {

@Shared @AutoCleanup HibernateDatastore datastore = new HibernateDatastore(getClass().getPackage())

@Rollback
def "Driver created with name"() {
when:
final driverInstance = new Driver(name: 'Test Driver', username: 'td', password: 'password1')
driverInstance.save(flush: true)

then:
Driver.count()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import spock.lang.AutoCleanup
import spock.lang.Shared
import spock.lang.Specification

class PersonSpec extends Specification {

class MakeSpec extends Specification {
@Shared @AutoCleanup HibernateDatastore datastore = new HibernateDatastore(getClass().getPackage())

@Rollback
def "person can be safed with firstname and lastname"() {
def "Make created with name"() {
when:
def p = new Person(firstName: 'Sergio', lastName: 'del Amo')
p.save(flush: true)
final makeInstance = new Make(name: 'Ford')
makeInstance.save(flush: true)

then:
Person.count()
Make.count()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package demo.GORMwithoutGrails.domain

import grails.gorm.transactions.Rollback
import org.grails.orm.hibernate.HibernateDatastore
import spock.lang.AutoCleanup
import spock.lang.Shared
import spock.lang.Specification

class ModelSpec extends Specification {
@Shared @AutoCleanup HibernateDatastore datastore = new HibernateDatastore(getClass().getPackage())

@Rollback
def "Model created with name"() {
when:
final modelInstance = new Model(name: 'Test Model')
modelInstance.save(flush: true)

then:
Model.count()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package demo.GORMwithoutGrails.domain

import grails.gorm.transactions.Rollback
import org.grails.orm.hibernate.HibernateDatastore
import spock.lang.AutoCleanup
import spock.lang.Shared
import spock.lang.Specification

class VehicleSpec extends Specification {
@Shared @AutoCleanup HibernateDatastore datastore = new HibernateDatastore(getClass().getPackage())

@Rollback
def "Vehicle created with a name"() {
when:
final makeInstance = new Make(name: 'Ford')
final modelInstance = new Model(name: 'Test Model')
final vehicleInstance = new Vehicle(name: 'Test Vehicle', make: makeInstance, model: modelInstance)
vehicleInstance.save(flush: true)

then:
Vehicle.count()
}
}
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
title=Build a Grails 3 application with the Vaadin 8 Framework
subtitle=Learn how to build a Grails 3 application with the Vaadin 8 Framework
title=Build a Spring Boot application with GORM
subtitle=Learn how to build a Spring Boot using GORM
authors=Ben Rhine
copyright=Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically. All guides are released with an ASLv2 license for the code, and Creative Commons license for the writing.
githubSlug=grails-guides/vaadin-grails
githubSlug=grails-guides/GORM-without-Grails
githubBranch=master
tags=vaadin,frontend,framework
category=Grails + Frontend Framework
tags=spring boot,backend,GORM, hibernate
category=Spring Boot + GORM
13 changes: 13 additions & 0 deletions src/main/docs/guide/configuringTheApp.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Since this is Spring Boot and not Grails we have to do a little bit more setup that we
are used to. In your top level project directory create a `gradle.properties` file.

[source,bash]
----
$ touch gradle.properties
----

After you have created run the above command your new file should be on the same level
as your `build.gradle` file.

image::gradleProperties.png[]

2 changes: 1 addition & 1 deletion src/main/docs/guide/gettingStarted.adoc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
In this guide you are going to build a Grails 3 application with the Vaadin 8 Framework.
In this guide you are going to build a Spring Boot application using GORM.
Loading

0 comments on commit 64264f7

Please sign in to comment.