You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@grails.apache.org by "codeconsole (via GitHub)" <gi...@apache.org> on 2025/08/29 22:16:37 UTC

[PR] Support for Gorm Entities with same name, but different packages [grails-core]

codeconsole opened a new pull request, #15036:
URL: https://github.com/apache/grails-core/pull/15036

   Currently RestfulServiceController will not work for situations where you have domain objects with the same name.
   
   This scenario is more likely for complex websites that use plugins with domain objects.
   
   For instance:
   
   ```
   grails-app/domain/org/website/User.groovy
   grails-app/domain/org/website/plugin/User.groovy
   ```
   
   This introduces a fix that will resolve the appropriate service class for the respective GormService
   
   


-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on PR #15036:
URL: https://github.com/apache/grails-core/pull/15036#issuecomment-3258631192

   @jdaugherty 
   > DomainServiceLocator appears more complex than it should be. 
   I've simplified it to its original intent. It now just only uses services of type GormService
   
   > How do we know an existing workflow didn't break without a test?
   RestfulServiceController is a new class that is just an example of the **Service Layer** pattern.  There are no existing workflows and it would be silly to just add 1 test to the entire plugin that only tests this. 


-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on PR #15036:
URL: https://github.com/apache/grails-core/pull/15036#issuecomment-3282067826

   > For the scaffolding functional tests, the following existing test projects are a good place to copy as a quick starting point. These all use Geb w/ TestContainers.
   > 
   > https://github.com/apache/grails-core/tree/7.0.x/grails-test-examples/geb https://github.com/apache/grails-core/tree/7.0.x/grails-test-examples/gsp-layout https://github.com/apache/grails-core/tree/7.0.x/grails-test-examples/app1
   
   @jamesfredley are there already functional tests for the scaffolding plugin in those examples? Where exactly are you saying to put it?


-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on code in PR #15036:
URL: https://github.com/apache/grails-core/pull/15036#discussion_r2341899901


##########
grails-scaffolding/src/main/groovy/grails/plugin/scaffolding/DomainServiceLocator.java:
##########
@@ -0,0 +1,98 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package grails.plugin.scaffolding;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.springframework.context.ApplicationContext;
+
+import grails.util.Holders;
+import org.grails.datastore.gorm.GormEntity;
+
+/**
+ * Resolves the appropriate service bean for a given domain class by:
+ *   - Scanning only beans of type GormService
+ *   - Matching via: ((GormEntity<?>) service.getResource()).instanceOf(domainClass)
+ *
+ * Keeps a single shared cache for the whole app.
+ */
+public final class DomainServiceLocator {
+
+    private static final ConcurrentMap<Class<?>, GormService<?>> CACHE = new ConcurrentHashMap<>();
+
+    private DomainServiceLocator() {}
+
+    /** Resolve (and cache) a service bean for the given domain class. */
+    public static <T extends GormEntity<T>> GormService<T> resolve(Class<T> domainClass) {
+        @SuppressWarnings("unchecked")
+        GormService<T> cached = (GormService<T>) CACHE.get(domainClass);
+        if (cached != null) return cached;
+
+        GormService<T> found = findService(domainClass);
+        CACHE.put(domainClass, found);
+        return found;
+    }
+
+    /** Clear cache (useful in tests/dev reloads). */
+    public static void clear() {
+        CACHE.clear();
+    }
+
+    private static <T extends GormEntity<T>> GormService<T> findService(Class<T> domainClass) {
+        ApplicationContext ctx = Holders.getGrailsApplication().getMainContext();

Review Comment:
   @jdaugherty it's a utility class that is only used post initialization.   There is no need for it to be a bean.



-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on PR #15036:
URL: https://github.com/apache/grails-core/pull/15036#issuecomment-3286430763

   I took the app you created at https://github.com/codeconsole/scaffold-app and integrated it under grails-test-examples/scaffolding.  
   
   I added a test to invoke the user/index and it works correctly.  `community/user/index` though is erroring: 
   
   <img width="1206" height="538" alt="image" src="https://github.com/user-attachments/assets/3b68f1f6-66a7-4238-9e7b-2e665bbfbc66" />
   


-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty merged PR #15036:
URL: https://github.com/apache/grails-core/pull/15036


-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on code in PR #15036:
URL: https://github.com/apache/grails-core/pull/15036#discussion_r2330943789


##########
grails-scaffolding/src/main/groovy/grails/plugin/scaffolding/DomainServiceLocator.java:
##########
@@ -0,0 +1,98 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package grails.plugin.scaffolding;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.springframework.context.ApplicationContext;
+
+import grails.util.Holders;
+import org.grails.datastore.gorm.GormEntity;
+
+/**
+ * Resolves the appropriate service bean for a given domain class by:
+ *   - Scanning only beans of type GormService
+ *   - Matching via: ((GormEntity<?>) service.getResource()).instanceOf(domainClass)
+ *
+ * Keeps a single shared cache for the whole app.
+ */
+public final class DomainServiceLocator {
+
+    private static final ConcurrentMap<Class<?>, GormService<?>> CACHE = new ConcurrentHashMap<>();

Review Comment:
   GormService will be a bean, what if someone has reloading enabled?  Won't this then break their ability to reload?  One solution would be to move this to a bean itself.



##########
grails-scaffolding/src/main/groovy/grails/plugin/scaffolding/DomainServiceLocator.java:
##########
@@ -0,0 +1,98 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package grails.plugin.scaffolding;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.springframework.context.ApplicationContext;
+
+import grails.util.Holders;
+import org.grails.datastore.gorm.GormEntity;
+
+/**
+ * Resolves the appropriate service bean for a given domain class by:
+ *   - Scanning only beans of type GormService
+ *   - Matching via: ((GormEntity<?>) service.getResource()).instanceOf(domainClass)
+ *
+ * Keeps a single shared cache for the whole app.
+ */
+public final class DomainServiceLocator {

Review Comment:
   We should add a functional test for scaffolding - we should be able to easily add 2 examples of this scenario to prove this works.



##########
grails-scaffolding/src/main/groovy/grails/plugin/scaffolding/DomainServiceLocator.java:
##########
@@ -0,0 +1,98 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package grails.plugin.scaffolding;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.springframework.context.ApplicationContext;
+
+import grails.util.Holders;
+import org.grails.datastore.gorm.GormEntity;
+
+/**
+ * Resolves the appropriate service bean for a given domain class by:
+ *   - Scanning only beans of type GormService
+ *   - Matching via: ((GormEntity<?>) service.getResource()).instanceOf(domainClass)
+ *
+ * Keeps a single shared cache for the whole app.
+ */
+public final class DomainServiceLocator {
+
+    private static final ConcurrentMap<Class<?>, GormService<?>> CACHE = new ConcurrentHashMap<>();
+
+    private DomainServiceLocator() {}
+
+    /** Resolve (and cache) a service bean for the given domain class. */
+    public static <T extends GormEntity<T>> GormService<T> resolve(Class<T> domainClass) {
+        @SuppressWarnings("unchecked")
+        GormService<T> cached = (GormService<T>) CACHE.get(domainClass);
+        if (cached != null) return cached;
+
+        GormService<T> found = findService(domainClass);
+        CACHE.put(domainClass, found);
+        return found;
+    }
+
+    /** Clear cache (useful in tests/dev reloads). */
+    public static void clear() {
+        CACHE.clear();
+    }
+
+    private static <T extends GormEntity<T>> GormService<T> findService(Class<T> domainClass) {
+        ApplicationContext ctx = Holders.getGrailsApplication().getMainContext();

Review Comment:
   If we're going to rely on beans, why is this class itself not a bean?  Is it used earlier in the init process? 



##########
grails-scaffolding/src/main/groovy/grails/plugin/scaffolding/RestfulServiceController.groovy:
##########
@@ -19,45 +19,52 @@
 
 package grails.plugin.scaffolding
 
+import groovy.transform.CompileStatic
 import grails.artefact.Artefact
 import grails.gorm.transactions.ReadOnly
 import grails.rest.RestfulController
-import grails.util.Holders
-import org.grails.datastore.gorm.GormEntityApi
+import org.grails.datastore.gorm.GormEntity
 
 @Artefact('Controller')
 @ReadOnly
-class RestfulServiceController<T> extends RestfulController<T> {
+@CompileStatic
+class RestfulServiceController<T extends GormEntity<T>> extends RestfulController<T> {

Review Comment:
   By changing a definition of this class that's widely extended, this may potentially break every subclass and require recompilation. We've stated we would not make these changes after RC2.



-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on code in PR #15036:
URL: https://github.com/apache/grails-core/pull/15036#discussion_r2341919769


##########
grails-scaffolding/src/main/groovy/grails/plugin/scaffolding/DomainServiceLocator.java:
##########
@@ -0,0 +1,98 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package grails.plugin.scaffolding;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.springframework.context.ApplicationContext;
+
+import grails.util.Holders;
+import org.grails.datastore.gorm.GormEntity;
+
+/**
+ * Resolves the appropriate service bean for a given domain class by:
+ *   - Scanning only beans of type GormService
+ *   - Matching via: ((GormEntity<?>) service.getResource()).instanceOf(domainClass)
+ *
+ * Keeps a single shared cache for the whole app.
+ */
+public final class DomainServiceLocator {

Review Comment:
   Are there existing functional tests for scaffolding?  if so, do you have an explanation how they work?



##########
grails-scaffolding/src/main/groovy/grails/plugin/scaffolding/DomainServiceLocator.java:
##########
@@ -0,0 +1,98 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package grails.plugin.scaffolding;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.springframework.context.ApplicationContext;
+
+import grails.util.Holders;
+import org.grails.datastore.gorm.GormEntity;
+
+/**
+ * Resolves the appropriate service bean for a given domain class by:
+ *   - Scanning only beans of type GormService
+ *   - Matching via: ((GormEntity<?>) service.getResource()).instanceOf(domainClass)
+ *
+ * Keeps a single shared cache for the whole app.
+ */
+public final class DomainServiceLocator {

Review Comment:
   @jdaugherty Are there existing functional tests for scaffolding?  if so, do you have an explanation how they work?



-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on PR #15036:
URL: https://github.com/apache/grails-core/pull/15036#issuecomment-3246673790

   @jdaugherty the scaffolding plugin doesn't have any tests? Do you know of any?  
   
   This is a fix.  If there are no existing tests, it is better to merge than to leave broken, no?


-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on code in PR #15036:
URL: https://github.com/apache/grails-core/pull/15036#discussion_r2342434113


##########
grails-scaffolding/src/main/groovy/grails/plugin/scaffolding/DomainServiceLocator.java:
##########
@@ -0,0 +1,98 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package grails.plugin.scaffolding;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.springframework.context.ApplicationContext;
+
+import grails.util.Holders;
+import org.grails.datastore.gorm.GormEntity;
+
+/**
+ * Resolves the appropriate service bean for a given domain class by:
+ *   - Scanning only beans of type GormService
+ *   - Matching via: ((GormEntity<?>) service.getResource()).instanceOf(domainClass)
+ *
+ * Keeps a single shared cache for the whole app.
+ */
+public final class DomainServiceLocator {

Review Comment:
   For example: 
   
   Add a subproject: `grails-test-examples/scaffolding` (can copy gsp or sitemesh if you want as a basis, the only thing that needs updated is settings.gradle & adding the files from grails-test-examples/scaffolding).  Then just add your domain scenario & a geb test that calls the screen / makes sure it doesn't error.  
   
   We're not asking you to test every functionality of scaffolding.  Just to grow the test coverage in this area as we make enhancements.
   



-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on code in PR #15036:
URL: https://github.com/apache/grails-core/pull/15036#discussion_r2342430194


##########
grails-scaffolding/src/main/groovy/grails/plugin/scaffolding/RestfulServiceController.groovy:
##########
@@ -19,45 +19,52 @@
 
 package grails.plugin.scaffolding
 
+import groovy.transform.CompileStatic
 import grails.artefact.Artefact
 import grails.gorm.transactions.ReadOnly
 import grails.rest.RestfulController
-import grails.util.Holders
-import org.grails.datastore.gorm.GormEntityApi
+import org.grails.datastore.gorm.GormEntity
 
 @Artefact('Controller')
 @ReadOnly
-class RestfulServiceController<T> extends RestfulController<T> {
+@CompileStatic
+class RestfulServiceController<T extends GormEntity<T>> extends RestfulController<T> {

Review Comment:
   We discussed the risk on Wednesday; we're willing to put this in 7.0.0 without changing this given the low adoptance of this.



-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on code in PR #15036:
URL: https://github.com/apache/grails-core/pull/15036#discussion_r2341891325


##########
grails-scaffolding/src/main/groovy/grails/plugin/scaffolding/DomainServiceLocator.java:
##########
@@ -0,0 +1,98 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package grails.plugin.scaffolding;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.springframework.context.ApplicationContext;
+
+import grails.util.Holders;
+import org.grails.datastore.gorm.GormEntity;
+
+/**
+ * Resolves the appropriate service bean for a given domain class by:
+ *   - Scanning only beans of type GormService
+ *   - Matching via: ((GormEntity<?>) service.getResource()).instanceOf(domainClass)
+ *
+ * Keeps a single shared cache for the whole app.
+ */
+public final class DomainServiceLocator {
+
+    private static final ConcurrentMap<Class<?>, GormService<?>> CACHE = new ConcurrentHashMap<>();

Review Comment:
   @jdaugherty cache is not used in development mode.



-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on code in PR #15036:
URL: https://github.com/apache/grails-core/pull/15036#discussion_r2342431320


##########
grails-scaffolding/src/main/groovy/grails/plugin/scaffolding/DomainServiceLocator.java:
##########
@@ -0,0 +1,98 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package grails.plugin.scaffolding;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.springframework.context.ApplicationContext;
+
+import grails.util.Holders;
+import org.grails.datastore.gorm.GormEntity;
+
+/**
+ * Resolves the appropriate service bean for a given domain class by:
+ *   - Scanning only beans of type GormService
+ *   - Matching via: ((GormEntity<?>) service.getResource()).instanceOf(domainClass)
+ *
+ * Keeps a single shared cache for the whole app.
+ */
+public final class DomainServiceLocator {

Review Comment:
   our functional test apps are under `grails-test-examples/*`.  We do not have an existing app.  We only want you to generate one and test the 2 scenarios.  We do not think we need to test all of scaffolding, but as we add more features we need to start enhancing the tests.



-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on PR #15036:
URL: https://github.com/apache/grails-core/pull/15036#issuecomment-3286919127

   @jdaugherty you missed https://github.com/codeconsole/scaffold-app/commit/60cc372383a9e81b134907c684fa42eab566c883


-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on PR #15036:
URL: https://github.com/apache/grails-core/pull/15036#issuecomment-3246797308

   @codeconsole We should add a functional test project.  DomainServiceLocator appears more complex than it should be.  How do we know an existing workflow didn't break without a test? 


-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "jamesfredley (via GitHub)" <gi...@apache.org>.
jamesfredley commented on PR #15036:
URL: https://github.com/apache/grails-core/pull/15036#issuecomment-3275838067

   For the scaffolding functional tests, the following existing test projects are a good place to copy as a quick starting point.  These all use Geb w/ TestContainers.
   
   https://github.com/apache/grails-core/tree/7.0.x/grails-test-examples/geb
   https://github.com/apache/grails-core/tree/7.0.x/grails-test-examples/gsp-layout
   https://github.com/apache/grails-core/tree/7.0.x/grails-test-examples/app1
   
   
   


-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on code in PR #15036:
URL: https://github.com/apache/grails-core/pull/15036#discussion_r2341831860


##########
grails-scaffolding/src/main/groovy/grails/plugin/scaffolding/RestfulServiceController.groovy:
##########
@@ -19,45 +19,52 @@
 
 package grails.plugin.scaffolding
 
+import groovy.transform.CompileStatic
 import grails.artefact.Artefact
 import grails.gorm.transactions.ReadOnly
 import grails.rest.RestfulController
-import grails.util.Holders
-import org.grails.datastore.gorm.GormEntityApi
+import org.grails.datastore.gorm.GormEntity
 
 @Artefact('Controller')
 @ReadOnly
-class RestfulServiceController<T> extends RestfulController<T> {
+@CompileStatic
+class RestfulServiceController<T extends GormEntity<T>> extends RestfulController<T> {

Review Comment:
   @jdaugherty where is a scenario where T does not extend GormEntity<T> ?



-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support for Gorm Entities with same name, but different packages [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on PR #15036:
URL: https://github.com/apache/grails-core/pull/15036#issuecomment-3293632291

   @jamesfredley  can you please review? 


-- 
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: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org