Skip to content

Commit

Permalink
move save to GORM data service
Browse files Browse the repository at this point in the history
  • Loading branch information
sdelamo committed Dec 9, 2019
1 parent b167103 commit d77a856
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions complete/src/main/groovy/demo/init/BootStrap.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@ package demo.init

import demo.domain.Manufacturer
import demo.domain.Vehicle
import demo.service.ManufacturerService
import grails.gorm.transactions.Transactional
import groovy.transform.CompileStatic
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

@Component
@CompileStatic
class BootStrap {

@Autowired
ManufacturerService manufacturerService

@Transactional
void init() {
Manufacturer audi = new Manufacturer(name: 'audi')
audi.addToVehicles(new Vehicle(name: 'A3', year: 1996))
audi.addToVehicles(new Vehicle(name: 'A4', year: 1994))
audi.save()
manufacturerService.save(audi)

Manufacturer ford = new Manufacturer(name: 'ford')
ford.addToVehicles(new Vehicle(name: 'Ford KA', year: 1996))
ford.save()
manufacturerService.save(ford)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package demo.service

import demo.domain.Manufacturer
import grails.gorm.transactions.ReadOnly
import grails.gorm.transactions.Transactional
import groovy.transform.CompileStatic
import org.springframework.stereotype.Service

@CompileStatic
@grails.gorm.services.Service(Manufacturer)
@Service
interface ManufacturerService {

List<Manufacturer> findAll()

Manufacturer save(Manufacturer manufacturer)
}

0 comments on commit d77a856

Please sign in to comment.