DATACMNS-401 - Some cleanups regarding generics and deprecations.
Suppress deprecation warnings for GenericTypeResolver for now. Added Simple(Property|Association)Handler to ease working with untyped PersistentProperty instances without having to fall back to raw types. Polished Sonargraph architecture description.
This commit is contained in:
@@ -140,10 +140,14 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> {
|
||||
*/
|
||||
void doWithProperties(PropertyHandler<P> 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<P> handler);
|
||||
|
||||
void doWithAssociations(SimpleAssociationHandler handler);
|
||||
}
|
||||
|
||||
@@ -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<? extends PersistentProperty<?>> association);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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<T, P extends PersistentProperty<P>> implement
|
||||
* @see org.springframework.data.mapping.PersistentEntity#doWithProperties(org.springframework.data.mapping.PropertyHandler)
|
||||
*/
|
||||
public void doWithProperties(PropertyHandler<P> handler) {
|
||||
|
||||
Assert.notNull(handler);
|
||||
|
||||
for (P property : properties) {
|
||||
if (!property.isTransient() && !property.isAssociation()) {
|
||||
handler.doWithPersistentProperty(property);
|
||||
@@ -259,17 +263,48 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> 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<P> handler) {
|
||||
|
||||
Assert.notNull(handler);
|
||||
|
||||
for (Association<P> 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<? extends PersistentProperty<?>> association : associations) {
|
||||
handler.doWithAssociation(association);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.mapping.MutablePersistentEntity#verify()
|
||||
*/
|
||||
|
||||
@@ -124,12 +124,14 @@ public abstract class CdiRepositoryExtensionSupport implements Extension {
|
||||
return repositoryTypes.entrySet();
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
static class DefaultAnnotationLiteral extends AnnotationLiteral<Default> implements Default {
|
||||
|
||||
private static final long serialVersionUID = 511359421048623933L;
|
||||
private static final DefaultAnnotationLiteral INSTANCE = new DefaultAnnotationLiteral();
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
static class AnyAnnotationLiteral extends AnnotationLiteral<Any> implements Any {
|
||||
|
||||
private static final long serialVersionUID = 7261821376671361463L;
|
||||
|
||||
@@ -97,6 +97,7 @@ public class ClassTypeInformation<S> extends TypeDiscoverer<S> {
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
ClassTypeInformation(Class<S> type) {
|
||||
this(type, GenericTypeResolver.getTypeVariableMap(type));
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T>
|
||||
* @see org.springframework.data.util.TypeDiscoverer#getMapValueType()
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public TypeInformation<?> getMapValueType() {
|
||||
|
||||
if (Map.class.equals(getType())) {
|
||||
|
||||
@@ -47,8 +47,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
|
||||
private final Type type;
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final Map<TypeVariable, Type> typeVariableMap;
|
||||
@SuppressWarnings("rawtypes") private final Map<TypeVariable, Type> typeVariableMap;
|
||||
private final Map<String, TypeInformation<?>> fieldTypes = new ConcurrentHashMap<String, TypeInformation<?>>();
|
||||
|
||||
private Class<S> resolvedType;
|
||||
@@ -95,6 +94,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
return new ClassTypeInformation((Class<?>) fieldType);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
Map<TypeVariable, Type> variableMap = GenericTypeResolver.getTypeVariableMap(resolveType(fieldType));
|
||||
|
||||
if (fieldType instanceof ParameterizedType) {
|
||||
@@ -136,9 +136,8 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({ "unchecked", "deprecation" })
|
||||
protected Class<S> resolveType(Type type) {
|
||||
|
||||
return (Class<S>) GenericTypeResolver.resolveType(type, getTypeVariableMap());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user