Skip to content

Commit

Permalink
Use GORM Data Service
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Scott Brown committed Dec 24, 2017
1 parent 2fba8d1 commit 0ba9b60
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -27,7 +27,7 @@ dependencies {
compile localGroovy()

compile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
compile group: 'org.grails', name: 'grails-datastore-gorm-hibernate5', version: '6.0.12.RELEASE'
compile group: 'org.grails', name: 'grails-datastore-gorm-hibernate5', version: '6.1.8.RELEASE'
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"
Expand Down
7 changes: 5 additions & 2 deletions src/main/groovy/com/foo/utils/EntityInitializerUtils.groovy
Expand Up @@ -20,7 +20,7 @@ class EntityInitializerUtils {
// @Transactional
void initializeDomains() {
Map configuration = [
// 'hibernate.hbm2ddl.auto':'create-drop',
'hibernate.hbm2ddl.auto':'create-drop',
// 'hibernate.enable_lazy_load_no_trans':false,
'dataSource.url':'jdbc:h2:mem:myDB',
// 'dataSource.pooled':true,
Expand All @@ -30,6 +30,9 @@ class EntityInitializerUtils {
]
HibernateDatastore datastore = new HibernateDatastore( configuration, User)

println User.count()
// In a real app you would probably have this injected and not have to retrieve it yourself...
UserService userService = datastore.getService(UserService)

println userService.count()
}
}
11 changes: 11 additions & 0 deletions src/main/groovy/com/foo/utils/UserService.groovy
@@ -0,0 +1,11 @@
package com.foo.utils

import com.foo.user.User
import grails.gorm.services.Service

@Service(User)
interface UserService {
int count()

User saveUser(User user)
}

1 comment on commit 0ba9b60

@hardikdesai-causecode
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeffbrown can you please add documentation for the use of GORM method like delete and deleteAll

Please sign in to comment.