You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by jd...@apache.org on 2025/07/12 03:21:18 UTC

(grails-core) 02/09: removal: remove old, deprecated LazyBeanMap

This is an automated email from the ASF dual-hosted git repository.

jdaugherty pushed a commit to branch deprecationRemovals
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 2d462e6838fd07d77e9795139f3325bc305a4a04
Author: James Daugherty <jd...@jdresources.net>
AuthorDate: Fri Jul 11 22:59:54 2025 -0400

    removal: remove old, deprecated LazyBeanMap
---
 .../groovy/grails/beans/util/LazyBeanMap.groovy    | 136 ---------------------
 .../src/en/guide/upgrading/upgrading60x.adoc       |   1 +
 2 files changed, 1 insertion(+), 136 deletions(-)

diff --git a/grails-core/src/main/groovy/grails/beans/util/LazyBeanMap.groovy b/grails-core/src/main/groovy/grails/beans/util/LazyBeanMap.groovy
deleted file mode 100644
index d662659a24..0000000000
--- a/grails-core/src/main/groovy/grails/beans/util/LazyBeanMap.groovy
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- *  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.beans.util
-
-import groovy.transform.CompileStatic
-import org.grails.datastore.mapping.reflect.ClassPropertyFetcher
-
-
-/**
- * <p>A map that backs onto a bean. The map is not initialized from the beans property values on creation, but instead lazily reads the values on demand.
- * No caching is applied, so each read results in a reflective call to retrieve the property. Users of this API should apply their own caching strategy if necessary.
- * </p>
- * <p>
- * Note that the {@link Map#values()} and {@link Map#entrySet()} implementations are expensive operations as they will read all properties of the target bean and should be used with caution.
- * </p>
- * <p>
- * Additionally the {@link Map#remove(java.lang.Object)} and {@link Map#clear()} methods are not implemented and will throw {@link UnsupportedOperationException}.
- * </p>
- * @since 2.4
- * @author Graeme Rocher
- * @deprecated use {@link LazyMetaPropertyMap} instead
- */
-@CompileStatic
-class LazyBeanMap implements Map<String,Object>{
-    final private ClassPropertyFetcher cpf
-    final Object target
-
-    /**
-     * Creates a bean map
-     *
-     * @param target The target bean
-     */
-    LazyBeanMap(Object target) {
-        this.target = target
-        if(target != null) {
-            this.cpf = ClassPropertyFetcher.forClass(target.getClass())
-        }
-    }
-
-    @Override
-    int size() {
-        return cpf ? cpf.metaProperties.size() : 0
-    }
-
-    @Override
-    boolean isEmpty() { cpf ? false : true}
-
-    @Override
-    boolean containsKey(Object key) {
-        cpf != null && cpf.getPropertyType(key.toString(), true) != null
-    }
-
-    @Override
-    boolean containsValue(Object value) {
-        cpf != null && values().contains(value)
-    }
-
-    @Override
-    def get(Object key) {
-        if(!cpf) return null
-        def property = key.toString()
-        if(cpf.isReadableProperty(property))
-            cpf.getPropertyValue target, property
-        else
-            return null
-    }
-
-    @Override
-    def put(String key, def value) {
-        if(!cpf) return null
-        def old = get(key)
-        def mc = GroovySystem.metaClassRegistry.getMetaClass(target.getClass())
-        mc.setProperty(target, key, value)
-        return old
-    }
-
-    @Override
-    Object remove(Object key) {
-        throw new UnsupportedOperationException("Method remove(key) not implemented")
-    }
-
-    @Override
-    void putAll(Map<? extends String, ?> m) {
-        if(!cpf) return
-        for(String property in m.keySet()) {
-            put(property, m.get(property))
-        }
-    }
-
-    @Override
-    void clear() {
-        throw new UnsupportedOperationException("Method clear() not implemented")
-    }
-
-    @Override
-    Set<String> keySet() {
-        if(!cpf) return [] as Set<String>
-        else {
-            return new HashSet<String>( cpf.metaProperties.collect { MetaProperty pd -> pd.name} )
-        }
-    }
-
-    @Override
-    Collection<Object> values() {
-        if(!cpf) return []
-        else {
-            keySet().collect() { String property -> ((ClassPropertyFetcher) /*Cast needed after upgrade to Groovy 4.0.22*/ cpf).getPropertyValue(property) }
-        }
-    }
-
-    @Override
-    Set<Map.Entry<String, Object>> entrySet() {
-        if(!cpf) return [] as Set<Map.Entry<String, Object>>
-        else {
-            return new HashSet<Map.Entry<String, Object>>(
-                    keySet().collect() { String property -> new AbstractMap.SimpleEntry<String, Object>(property, ((ClassPropertyFetcher) /*Cast needed after upgrade to Groovy 4.0.22*/ cpf).getPropertyValue(property)) }
-            )
-        }
-    }
-}
diff --git a/grails-doc/src/en/guide/upgrading/upgrading60x.adoc b/grails-doc/src/en/guide/upgrading/upgrading60x.adoc
index 1cf8cda84a..681cb9c4af 100644
--- a/grails-doc/src/en/guide/upgrading/upgrading60x.adoc
+++ b/grails-doc/src/en/guide/upgrading/upgrading60x.adoc
@@ -243,6 +243,7 @@ jakartaeeMigration {
 3. `org.grails.core.DefaultGrailsTagLibClass` -> `org.grails.core.gsp.DefaultGrailsTagLibClass`
 4. `org.grails.plugins.CodecsGrailsPlugin` -> `org.grails.plugins.codecs.CodecsGrailsPlugin`
 5. `grails.artefact.AsyncController` -> `grails.async.web.AsyncController`
+6. `grails.beans.util.LazyBeanMap` -> `grails.beans.util.LazyMetaPropertyMap`
 
 ===== 12.4 Micronaut in Grails is now supported via the Micronaut Spring Boot Starter
 - This change was made based on community input: https://github.com/orgs/grails/discussions/13517