Skip to content

Commit

Permalink
guide 85% done
Browse files Browse the repository at this point in the history
  • Loading branch information
benrhine committed Jul 19, 2017
1 parent 64264f7 commit 7686f87
Show file tree
Hide file tree
Showing 37 changed files with 314 additions and 256 deletions.
14 changes: 11 additions & 3 deletions complete/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
buildscript {
buildscript { //<1>
repositories {
mavenCentral()
}
Expand All @@ -9,7 +9,7 @@ buildscript {

apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'idea' //<2>
apply plugin: 'org.springframework.boot'

version = '0.0.1-SNAPSHOT'
Expand All @@ -23,13 +23,21 @@ repositories {
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.codehaus.groovy:groovy')

/** Add GORM */ //<3>
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:1.4.192')

runtime('com.h2database:h2')

/** Add additional dependencies so our database works properly with GORM at runtime*/ //<4>
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')

/** Add additional testing dependencies so we can use Spock */ //<5>
testCompile 'org.spockframework:spock-core:1.1-groovy-2.4'
testCompile 'org.spockframework:spock-spring:1.1-groovy-2.4'
}
2 changes: 1 addition & 1 deletion complete/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +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
grailsVersion=N/A - Spring Boot Version: 1.5.4.RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,8 @@ class MakeController {

@Autowired MakeService makeService

// PostController(MakeService makeService) {
// this.makeService = makeService
// }

@RequestMapping("/")
String list(){
String index(){
makeService.list()
}

// @RequestMapping("/{id}")
// public String get(@PathVariable(value = "id") int id){
// makeService.get(id)
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,8 @@ class ModelController {

@Autowired ModelService modelService

// PostController(MakeService makeService) {
// this.makeService = makeService
// }

@RequestMapping("/")
String list(){
String index(){
modelService.list()
}

// @RequestMapping("/{id}")
// public String get(@PathVariable(value = "id") int id){
// makeService.get(id)
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,8 @@ class VehicleController {

@Autowired VehicleService vehicleService

// PostController(MakeService makeService) {
// this.makeService = makeService
// }

@RequestMapping("/")
String list(){
String index(){
vehicleService.list()
}

// @RequestMapping("/{id}")
// public String get(@PathVariable(value = "id") int id){
// makeService.get(id)
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import grails.gorm.annotation.Entity
@Entity
class Driver extends User {

/** Properties */
String name

static hasMany = [ vehicles: Vehicle ]

/** Required in order to bootstrap data */
static mapping = {
version false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import org.grails.datastore.gorm.GormEntity
@Entity
class Make implements GormEntity<Make> {

/** Properties */
String name

/** Required in order to bootstrap data */
static mapping = {
version false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import org.grails.datastore.gorm.GormEntity
@Entity
class Model implements GormEntity<Model> {

/** Properties */
String name

/** Required in order to bootstrap data */
static mapping = {
version false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class User implements Serializable, GormEntity<User> {

private static final long serialVersionUID = 1

/** Properties */
String username
String password
boolean enabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import org.grails.datastore.gorm.GormEntity

@Entity
class Vehicle implements GormEntity<Vehicle> {

/** Properties */
String name

/** Objects */
Make make
Model model

/** Required in order to bootstrap data */
static mapping = {
version false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.springframework.transaction.annotation.Transactional
@Transactional
class MakeServiceImpl implements MakeService {

@Transactional(readOnly = true)
@Override
List<Make> list() {
Make.list()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.springframework.transaction.annotation.Transactional
@Transactional
class ModelServiceImpl implements ModelService {

@Transactional(readOnly = true)
@Override
List<Model> list() {
Model.list()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.springframework.transaction.annotation.Transactional
@Transactional
class VehicleServiceImpl implements VehicleService {

@Transactional(readOnly = true)
@Override
List<Vehicle> list() {
Vehicle.list()
Expand Down
5 changes: 3 additions & 2 deletions complete/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Enable h2 console access via browser
spring.h2.console.enabled=true
spring.h2.console.path=/console
spring.datasource.platform=h2
#spring.jpa.properties.hibernate.hbm2ddl=auto
#spring.jpa.hibernate.ddl-auto=create-drop

# Turn on hibernate bootstrap data
spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop
14 changes: 0 additions & 14 deletions src/main/docs/guide/aboutVaadin.adoc

This file was deleted.

46 changes: 0 additions & 46 deletions src/main/docs/guide/addingToVaadin.adoc

This file was deleted.

74 changes: 0 additions & 74 deletions src/main/docs/guide/addingView.adoc

This file was deleted.

25 changes: 25 additions & 0 deletions src/main/docs/guide/configuringTheApp.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,28 @@ as your `build.gradle` file.

image::gradleProperties.png[]

Now lets edit your new properties file and add the following to it.

[source,groovy]
./gradle.properties
----
include::{sourceDir}/gradle.properties[indent=0, lines="1..3"]
----

This sets us up for our next step of editing our build config and adding some necessary
dependencies to our project.

[source,groovy]
./build.gradle
----
include::{sourceDir}/build.gradle[indent=0, lines="1..43"]
----

<1> We have removed the ext block in favor of using one of our properties in the
`gradle.properties` file we just created.
<2> Apply an IDE specific plugin for IntelliJ since that is what we are using (Not Required).
<3> Add the required dependencies to add GORM to our project.
<4> Add additional tomcat dependencies, without these the database will not work correctly when running.
<5> Extra testing dependencies so we can use Spock with Spring Boot.


21 changes: 16 additions & 5 deletions src/main/docs/guide/creatingTestData.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
Now that our domain is in place, lets preload some data to work with.
Now that all our app config is complete and we should be able to view our tables at
http://localhost:8080/console lets go ahead and bootstrap some data. Since we don't have a
built in bootstraping construct like we do in Grails we make use of a hibernate feature that
allows us to auto import a sql file.

[source,groovy]
./grails-app/init/vaadin/Bootstrap.groovy
First lets create a new file `import.sql` in `src/main/resources`. Once you have created
the sql file go ahead and edit it and add the following.

[source,sql]
./src/main/resources/import.sql
----
include::{sourceDir}/src/main/resources/import.sql[]
----
include::{sourceDir}/grails-app/init/vaadin/Bootstrap.groovy[]
----

Now as mentioned in the last section make sure that in
your `application.properties` file you have `spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop`.
Without that line hibernate will not pickup on your `import.sql` and will not bootstrap
your data.
Loading

0 comments on commit 7686f87

Please sign in to comment.