codeconsole commented on code in PR #15195:
URL: https://github.com/apache/grails-core/pull/15195#discussion_r2491291863
##########
grails-scaffolding/src/main/groovy/grails/plugin/scaffolding/GormService.groovy:
##########
@@ -34,28 +35,37 @@ import org.grails.datastore.gorm.GormEntityApi
@CompileStatic
class GormService<T extends GormEntity<T>> {
- GormAllOperations<T> resource
+ GormAllOperations<T> gormStaticApi
+ Class<T> resource
String resourceName
String resourceClassName
boolean readOnly
GormService(Class<T> resource, boolean readOnly) {
- this.resource = resource.getDeclaredConstructor().newInstance() as
GormAllOperations<T>
+ this.resource = resource
this.readOnly = readOnly
resourceClassName = resource.simpleName
resourceName = GrailsNameUtils.getPropertyName(resource)
}
+ protected GormAllOperations<T> getGormStaticApi() {
+ if (gormStaticApi == null) {
+ // Lazy initialization - happens on first access when GORM is ready
+ gormStaticApi = GormEnhancer.findStaticApi(resource) as
GormAllOperations<T>
+ }
+ return gormStaticApi
+ }
Review Comment:
It could be for redundancy. Worst case scenario an old reference would be
replaced, but I just made it @Lazy to prevent the possibility
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]