Skip to content

Commit 22c435c

Browse files
committed
grails/grails-data-hibernate5#202 Update AbstractDatastoreInitializer
Improvements to logic for deriving the Data Service name from the implementation class name.
1 parent 2d96f76 commit 22c435c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/bootstrap/AbstractDatastoreInitializer.groovy

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,10 @@ abstract class AbstractDatastoreInitializer implements ResourceLoaderAware{
298298
if (serviceDefinition.isPresent()) {
299299
final Class<Service> clazz = serviceDefinition.getType()
300300
if (clazz.simpleName.startsWith('$') && clazz.simpleName.endsWith('Implementation')) {
301-
String serviceClassName = clazz.name - '$' - 'Implementation'
301+
String dataServiceName = clazz.simpleName
302+
dataServiceName = removeDollarChar(dataServiceName)
303+
dataServiceName = removeImplementationString(dataServiceName)
304+
String serviceClassName = clazz.name.replace(clazz.simpleName, dataServiceName)
302305
final ClassLoader cl = org.grails.datastore.mapping.reflect.ClassUtils.classLoader
303306
final Class<?> serviceClass = cl.loadClass(serviceClassName)
304307

@@ -353,6 +356,14 @@ abstract class AbstractDatastoreInitializer implements ResourceLoaderAware{
353356
throw new UnsupportedOperationException("Method getGrailsValidatorClass no longer supported")
354357
}
355358

359+
protected String removeImplementationString(String dataServiceImplementationClassName) {
360+
dataServiceImplementationClassName.substring(0, dataServiceImplementationClassName.length() - 14)
361+
}
362+
363+
protected String removeDollarChar(String dataServiceImplementationClassName) {
364+
dataServiceImplementationClassName.substring(1)
365+
}
366+
356367
@CompileDynamic
357368
static class GroovyBeanReaderInit {
358369
static boolean isAvailable() {

0 commit comments

Comments
 (0)