Browse Source

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.
pull/57/merge
Oliver Gierke 13 years ago
parent
commit
c0fc0f905a
  1. 2
      Spring Data Commons.sonargraph
  2. 4
      src/main/java/org/springframework/data/mapping/PersistentEntity.java
  3. 32
      src/main/java/org/springframework/data/mapping/SimpleAssociationHandler.java
  4. 31
      src/main/java/org/springframework/data/mapping/SimplePropertyHandler.java
  5. 35
      src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java
  6. 2
      src/main/java/org/springframework/data/repository/cdi/CdiRepositoryExtensionSupport.java
  7. 1
      src/main/java/org/springframework/data/util/ClassTypeInformation.java
  8. 1
      src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java
  9. 7
      src/main/java/org/springframework/data/util/TypeDiscoverer.java

2
Spring Data Commons.sonargraph

@ -10,14 +10,12 @@ @@ -10,14 +10,12 @@
<element type="TypeFilter" name="Assignment">
<element type="IncludeTypePattern" name="**.config.**"/>
</element>
<dependency toName="External|External::Subsystem|Logging" type="AllowedDependency"/>
<dependency toName="Project|spring-data-commons::Layer|Repositories::Subsystem|Support" type="AllowedDependency"/>
<dependency toName="External|External::Subsystem|Spring" type="AllowedDependency"/>
</element>
<dependency toName="Project|spring-data-commons::Layer|Application" type="AllowedDependency"/>
<dependency toName="Project|spring-data-commons::Layer|Repositories" type="AllowedDependency"/>
<dependency toName="External|External::Subsystem|Java Beans" type="AllowedDependency"/>
<dependency toName="External|External::Subsystem|Logging" type="AllowedDependency"/>
<dependency toName="External|External::Subsystem|Reflection" type="AllowedDependency"/>
<dependency toName="External|External::Subsystem|Servlet API" type="AllowedDependency"/>
<dependency toName="External|External::Subsystem|Spring" type="AllowedDependency"/>

4
src/main/java/org/springframework/data/mapping/PersistentEntity.java

@ -140,10 +140,14 @@ public interface PersistentEntity<T, P extends PersistentProperty<P>> { @@ -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);
}

32
src/main/java/org/springframework/data/mapping/SimpleAssociationHandler.java

@ -0,0 +1,32 @@ @@ -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);
}

31
src/main/java/org/springframework/data/mapping/SimplePropertyHandler.java

@ -0,0 +1,31 @@ @@ -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);
}

35
src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java

@ -30,6 +30,8 @@ import org.springframework.data.mapping.PersistentEntity; @@ -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 @@ -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 @@ -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()
*/

2
src/main/java/org/springframework/data/repository/cdi/CdiRepositoryExtensionSupport.java

@ -124,12 +124,14 @@ public abstract class CdiRepositoryExtensionSupport implements Extension { @@ -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;

1
src/main/java/org/springframework/data/util/ClassTypeInformation.java

@ -97,6 +97,7 @@ public class ClassTypeInformation<S> extends TypeDiscoverer<S> { @@ -97,6 +97,7 @@ public class ClassTypeInformation<S> extends TypeDiscoverer<S> {
*
* @param type
*/
@SuppressWarnings("deprecation")
ClassTypeInformation(Class<S> type) {
this(type, GenericTypeResolver.getTypeVariableMap(type));
}

1
src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java

@ -53,6 +53,7 @@ class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T> @@ -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())) {

7
src/main/java/org/springframework/data/util/TypeDiscoverer.java

@ -47,8 +47,7 @@ import org.springframework.util.ReflectionUtils; @@ -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> { @@ -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> { @@ -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());
}

Loading…
Cancel
Save