diff --git a/Spring Data Commons.sonargraph b/Spring Data Commons.sonargraph index 54f37a727..a7846f654 100644 --- a/Spring Data Commons.sonargraph +++ b/Spring Data Commons.sonargraph @@ -10,14 +10,12 @@ - - diff --git a/src/main/java/org/springframework/data/mapping/PersistentEntity.java b/src/main/java/org/springframework/data/mapping/PersistentEntity.java index c0b773af1..3bc2024f4 100644 --- a/src/main/java/org/springframework/data/mapping/PersistentEntity.java +++ b/src/main/java/org/springframework/data/mapping/PersistentEntity.java @@ -140,10 +140,14 @@ public interface PersistentEntity> { */ void doWithProperties(PropertyHandler

handler); + void doWithProperties(SimplePropertyHandler handler); + /** * Applies the given {@link AssociationHandler} to all {@link Association} contained in this {@link PersistentEntity}. * * @param handler must not be {@literal null}. */ void doWithAssociations(AssociationHandler

handler); + + void doWithAssociations(SimpleAssociationHandler handler); } diff --git a/src/main/java/org/springframework/data/mapping/SimpleAssociationHandler.java b/src/main/java/org/springframework/data/mapping/SimpleAssociationHandler.java new file mode 100644 index 000000000..1827600b3 --- /dev/null +++ b/src/main/java/org/springframework/data/mapping/SimpleAssociationHandler.java @@ -0,0 +1,32 @@ +/* + * Copyright 2013 the original author or authors. + * + * Licensed 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 + * + * http://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 org.springframework.data.mapping; + +/** + * Association handler to work with the untyped {@link PersistentProperty} based {@link Association}. + * + * @author Oliver Gierke + * @see PropertyHandler + */ +public interface SimpleAssociationHandler { + + /** + * Handle the given {@link Association}. + * + * @param association will never be {@literal null}. + */ + void doWithAssociation(Association> association); +} diff --git a/src/main/java/org/springframework/data/mapping/SimplePropertyHandler.java b/src/main/java/org/springframework/data/mapping/SimplePropertyHandler.java new file mode 100644 index 000000000..fb4c5e3dd --- /dev/null +++ b/src/main/java/org/springframework/data/mapping/SimplePropertyHandler.java @@ -0,0 +1,31 @@ +/* + * Copyright 2013 the original author or authors. + * + * Licensed 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 + * + * http://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 org.springframework.data.mapping; + +/** + * A property handler to work with untyped {@link PersistentProperty} instances. + * + * @author Oliver Gierke + */ +public interface SimplePropertyHandler { + + /** + * Handle the given {@link PersistentProperty}. + * + * @param property will never be {@literal null}. + */ + void doWithPersistentProperty(PersistentProperty property); +} diff --git a/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java b/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java index 3488be45e..d95b607cc 100644 --- a/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java +++ b/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java @@ -30,6 +30,8 @@ import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.PreferredConstructor; import org.springframework.data.mapping.PropertyHandler; +import org.springframework.data.mapping.SimpleAssociationHandler; +import org.springframework.data.mapping.SimplePropertyHandler; import org.springframework.data.util.TypeInformation; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -251,7 +253,9 @@ public class BasicPersistentEntity> implement * @see org.springframework.data.mapping.PersistentEntity#doWithProperties(org.springframework.data.mapping.PropertyHandler) */ public void doWithProperties(PropertyHandler

handler) { + Assert.notNull(handler); + for (P property : properties) { if (!property.isTransient() && !property.isAssociation()) { handler.doWithPersistentProperty(property); @@ -259,17 +263,48 @@ public class BasicPersistentEntity> implement } } + /* + * (non-Javadoc) + * @see org.springframework.data.mapping.PersistentEntity#doWithProperties(org.springframework.data.mapping.PropertyHandler.Simple) + */ + @Override + public void doWithProperties(SimplePropertyHandler handler) { + + Assert.notNull(handler); + + for (PersistentProperty property : properties) { + if (!property.isTransient() && !property.isAssociation()) { + handler.doWithPersistentProperty(property); + } + } + } + /* * (non-Javadoc) * @see org.springframework.data.mapping.PersistentEntity#doWithAssociations(org.springframework.data.mapping.AssociationHandler) */ public void doWithAssociations(AssociationHandler

handler) { + Assert.notNull(handler); + for (Association

association : associations) { handler.doWithAssociation(association); } } + /* + * (non-Javadoc) + * @see org.springframework.data.mapping.PersistentEntity#doWithAssociations(org.springframework.data.mapping.SimpleAssociationHandler) + */ + public void doWithAssociations(SimpleAssociationHandler handler) { + + Assert.notNull(handler); + + for (Association> association : associations) { + handler.doWithAssociation(association); + } + } + /* (non-Javadoc) * @see org.springframework.data.mapping.MutablePersistentEntity#verify() */ diff --git a/src/main/java/org/springframework/data/repository/cdi/CdiRepositoryExtensionSupport.java b/src/main/java/org/springframework/data/repository/cdi/CdiRepositoryExtensionSupport.java index 1c35c5d48..c65b52b0b 100644 --- a/src/main/java/org/springframework/data/repository/cdi/CdiRepositoryExtensionSupport.java +++ b/src/main/java/org/springframework/data/repository/cdi/CdiRepositoryExtensionSupport.java @@ -124,12 +124,14 @@ public abstract class CdiRepositoryExtensionSupport implements Extension { return repositoryTypes.entrySet(); } + @SuppressWarnings("all") static class DefaultAnnotationLiteral extends AnnotationLiteral implements Default { private static final long serialVersionUID = 511359421048623933L; private static final DefaultAnnotationLiteral INSTANCE = new DefaultAnnotationLiteral(); } + @SuppressWarnings("all") static class AnyAnnotationLiteral extends AnnotationLiteral implements Any { private static final long serialVersionUID = 7261821376671361463L; diff --git a/src/main/java/org/springframework/data/util/ClassTypeInformation.java b/src/main/java/org/springframework/data/util/ClassTypeInformation.java index 944a52dbc..266a9d73a 100644 --- a/src/main/java/org/springframework/data/util/ClassTypeInformation.java +++ b/src/main/java/org/springframework/data/util/ClassTypeInformation.java @@ -97,6 +97,7 @@ public class ClassTypeInformation extends TypeDiscoverer { * * @param type */ + @SuppressWarnings("deprecation") ClassTypeInformation(Class type) { this(type, GenericTypeResolver.getTypeVariableMap(type)); } diff --git a/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java b/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java index 1d11fa730..c466c275f 100644 --- a/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java +++ b/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java @@ -53,6 +53,7 @@ class ParameterizedTypeInformation extends ParentTypeAwareTypeInformation * @see org.springframework.data.util.TypeDiscoverer#getMapValueType() */ @Override + @SuppressWarnings("deprecation") public TypeInformation getMapValueType() { if (Map.class.equals(getType())) { diff --git a/src/main/java/org/springframework/data/util/TypeDiscoverer.java b/src/main/java/org/springframework/data/util/TypeDiscoverer.java index 67e979c98..1d20a55f4 100644 --- a/src/main/java/org/springframework/data/util/TypeDiscoverer.java +++ b/src/main/java/org/springframework/data/util/TypeDiscoverer.java @@ -47,8 +47,7 @@ import org.springframework.util.ReflectionUtils; class TypeDiscoverer implements TypeInformation { private final Type type; - @SuppressWarnings("rawtypes") - private final Map typeVariableMap; + @SuppressWarnings("rawtypes") private final Map typeVariableMap; private final Map> fieldTypes = new ConcurrentHashMap>(); private Class resolvedType; @@ -95,6 +94,7 @@ class TypeDiscoverer implements TypeInformation { return new ClassTypeInformation((Class) fieldType); } + @SuppressWarnings("deprecation") Map variableMap = GenericTypeResolver.getTypeVariableMap(resolveType(fieldType)); if (fieldType instanceof ParameterizedType) { @@ -136,9 +136,8 @@ class TypeDiscoverer implements TypeInformation { * @param type * @return */ - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "deprecation" }) protected Class resolveType(Type type) { - return (Class) GenericTypeResolver.resolveType(type, getTypeVariableMap()); }