jamesfredley commented on code in PR #16721:
URL: https://github.com/apache/grails-core/pull/16721#discussion_r4406459387
##########
grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/proxy/ByteBuddyGroovyProxyFactorySpec.groovy:
##########
@@ -41,6 +43,29 @@ class ByteBuddyGroovyProxyFactorySpec extends Specification {
ByteBuddyState state = new ByteBuddyState()
ByteBuddyProxyHelper helper = new ByteBuddyProxyHelper(state)
+ void "a wrapped Hibernate proxy resolves the entity name and validation
API without initialization"() {
+ given:
+ Session session = datastore.sessionFactory.openSession()
+ Class entityAlias = GroovyProxyFactoryEntity
+
+ when:
+ def proxy = session.getReference(entityAlias, 1L)
+ Class proxyClass = proxy.getClass()
+
+ then:
+ proxyClass.superclass.superclass == entityAlias
Review Comment:
Dropped the superclass-depth assertion. The spec now checks that the proxy
class is not the entity and that NameUtils.getClassName resolves it to the
entity name.
##########
grails-data-hibernate5/core/src/test/groovy/org/grails/orm/hibernate/proxy/ByteBuddyGroovyProxyFactorySpec.groovy:
##########
@@ -39,6 +41,29 @@ class ByteBuddyGroovyProxyFactorySpec extends Specification {
ByteBuddyProxyHelper helper = new
GrailsBytecodeProvider().getByteBuddyProxyHelper()
+ void "a wrapped Hibernate proxy resolves the entity name and validation
API without initialization"() {
+ given:
+ Session session = datastore.sessionFactory.openSession()
+ Class entityAlias = GroovyProxyFactoryEntity
+
+ when:
+ def proxy = session.getReference(entityAlias, 1L)
+ Class proxyClass = proxy.getClass()
+
+ then:
+ proxyClass.superclass.superclass == entityAlias
+ NameUtils.getClassName(entityAlias) == entityAlias.name
+ NameUtils.getClassName(proxyClass.superclass) == entityAlias.name
+ NameUtils.getClassName(proxyClass) == entityAlias.name
+ GormEnhancer.findValidationApi(proxyClass) != null
+
GormEnhancer.findValidationApi(proxyClass).is(GormEnhancer.findValidationApi(entityAlias))
Review Comment:
The validation APIs are stored in proxyValidationApi and entityValidationApi
before the identity assertion.
##########
grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/reflect/NameUtils.java:
##########
@@ -104,9 +104,8 @@ public static String getGetterName(String propertyName,
boolean useBooleanPrefix
* @return The class name
*/
public static String getClassName(Class clazz) {
- final String sn = clazz.getSimpleName();
- if (sn.contains(DOLLAR_SEPARATOR)) {
- return clazz.getSuperclass().getName();
+ while (clazz.getSimpleName().contains(DOLLAR_SEPARATOR) &&
clazz.getSuperclass() != null) {
+ clazz = clazz.getSuperclass();
}
return clazz.getName();
Review Comment:
getClassName now takes Class<?>.
##########
grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/reflect/NameUtils.java:
##########
@@ -104,9 +104,8 @@ public static String getGetterName(String propertyName,
boolean useBooleanPrefix
* @return The class name
*/
public static String getClassName(Class clazz) {
- final String sn = clazz.getSimpleName();
- if (sn.contains(DOLLAR_SEPARATOR)) {
- return clazz.getSuperclass().getName();
+ while (clazz.getSimpleName().contains(DOLLAR_SEPARATOR) &&
clazz.getSuperclass() != null) {
Review Comment:
isDomainClass(Class, boolean) now walks every generated layer.
DomainClassArtefactHandlerSpec covers a one-layer proxy, a two-layer wrapper, a
plain class, and null.
##########
grails-datastore-core/src/test/groovy/org/grails/datastore/mapping/reflect/NameUtilsSpec.groovy:
##########
@@ -23,6 +23,24 @@ import spock.lang.Unroll
class NameUtilsSpec extends Specification {
+ @Unroll
+ void "getClassName unwraps every proxy layer for #type.simpleName"() {
+ expect:
+ NameUtils.getClassName(type) == NameUtilsEntity.name
+
+ where:
+ type << [NameUtilsEntity, NameUtilsEntity$Proxy,
NameUtilsEntity$Proxy$Wrapper,
+ NameUtilsEntity$Proxy$Wrapper$Outer]
+ }
+
+ void "getClassName preserves a real entity referenced by a local alias"() {
Review Comment:
Removed the alias feature and the entityAlias locals in both Hibernate specs.
##########
grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/proxy/ByteBuddyGroovyProxyFactorySpec.groovy:
##########
@@ -41,6 +43,29 @@ class ByteBuddyGroovyProxyFactorySpec extends Specification {
ByteBuddyState state = new ByteBuddyState()
ByteBuddyProxyHelper helper = new ByteBuddyProxyHelper(state)
+ void "a wrapped Hibernate proxy resolves the entity name and validation
API without initialization"() {
+ given:
+ Session session = datastore.sessionFactory.openSession()
+ Class entityAlias = GroovyProxyFactoryEntity
+
+ when:
+ def proxy = session.getReference(entityAlias, 1L)
+ Class proxyClass = proxy.getClass()
+
+ then:
+ proxyClass.superclass.superclass == entityAlias
+ NameUtils.getClassName(entityAlias) == entityAlias.name
+ NameUtils.getClassName(proxyClass.superclass) == entityAlias.name
+ NameUtils.getClassName(proxyClass) == entityAlias.name
+ GormEnhancer.findValidationApi(proxyClass) != null
Review Comment:
Both Hibernate specs now assert findStaticApi and findInstanceApi identity
with the entity.
--
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]