jamesfredley commented on code in PR #15771:
URL: https://github.com/apache/grails-core/pull/15771#discussion_r3484035028


##########
grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/GormEnhancer.groovy:
##########
@@ -261,13 +309,31 @@ class GormEnhancer implements Closeable {
      * @throws IllegalStateException if no instance API is found for the type
      */
     static <D> GormInstanceApi<D> findInstanceApi(Class<D> entity, String 
qualifier = findTenantId(entity)) {
-        def instanceApi = 
INSTANCE_APIS.get(qualifier)?.get(NameUtils.getClassName(entity))
+        String className = NameUtils.getClassName(entity)
+        def instanceApi = INSTANCE_APIS.get(qualifier)?.get(className)
+        if (instanceApi == null) {
+            instanceApi = initializeInstanceApi(entity, qualifier, className)
+        }
         if (instanceApi == null) {
             throw stateException(entity)
         }
         return instanceApi
     }
 
+    private static <D> GormInstanceApi<D> initializeInstanceApi(Class<D> 
entity, String qualifier, String className) {
+        GormEnhancer enhancer = findEnhancer(entity, qualifier, className)
+        if (enhancer == null) {
+            return null
+        }
+        GormInstanceApi<D> instanceApi = 
INSTANCE_APIS.get(qualifier)?.get(className)
+        if (instanceApi != null) {
+            return instanceApi
+        }
+        instanceApi = enhancer.getInstanceApi(entity, qualifier)
+        INSTANCE_APIS.get(qualifier).put(className, instanceApi)
+        return instanceApi

Review Comment:
   Valid. Addressed in 1bdcc9a019 by changing instance API lazy initialization 
to use computeIfAbsent on the per-qualifier map, preventing duplicate 
GormInstanceApi allocation for the same qualifier and class race. Verified with 
the focused datamapping spec and the mirrored Hibernate allocation specs.



##########
grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/GormEnhancer.groovy:
##########
@@ -245,12 +276,29 @@ class GormEnhancer implements Closeable {
     static <D> GormStaticApi<D> findStaticApi(Class<D> entity, String 
qualifier = findTenantId(entity)) {
         String className = NameUtils.getClassName(entity)
         def staticApi = STATIC_APIS.get(qualifier)?.get(className)
+        if (staticApi == null) {
+            staticApi = initializeStaticApi(entity, qualifier, className)
+        }
         if (staticApi == null) {
             throw stateException(entity)
         }
         return staticApi
     }
 
+    private static <D> GormStaticApi<D> initializeStaticApi(Class<D> entity, 
String qualifier, String className) {
+        GormEnhancer enhancer = findEnhancer(entity, qualifier, className)
+        if (enhancer == null) {
+            return null
+        }
+        GormStaticApi<D> staticApi = STATIC_APIS.get(qualifier)?.get(className)
+        if (staticApi != null) {
+            return staticApi
+        }
+        staticApi = enhancer.getStaticApi(entity, qualifier)
+        STATIC_APIS.get(qualifier).put(className, staticApi)
+        return staticApi

Review Comment:
   Valid. Addressed in 1bdcc9a019 by changing static API lazy initialization to 
use computeIfAbsent on the per-qualifier map, so only one GormStaticApi is 
cached for a qualifier and class under concurrent first access. Verified with 
the focused datamapping spec and the mirrored Hibernate allocation specs.



-- 
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]

Reply via email to