DATACMNS-72 - A lot of improvements related to Sonar results.
Fixed quite a lot of FindBugs and Checkstyle warnings. Removed unused classes, polished JavaDoc.
This commit is contained in:
@@ -2,8 +2,6 @@ package org.springframework.data.mapping;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
@@ -61,10 +59,10 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
|
||||
boolean isEntity();
|
||||
|
||||
/**
|
||||
* Returns the component type of the type if it is a {@link Collection}. Will return the type of the key if the
|
||||
* property is a {@link Map}.
|
||||
* Returns the component type of the type if it is a {@link java.util.Collection}. Will return the type of the key if the
|
||||
* property is a {@link java.util.Map}.
|
||||
*
|
||||
* @return the component type, the map's key type or {@literal null} if neither {@link Collection} nor {@link Map}.
|
||||
* @return the component type, the map's key type or {@literal null} if neither {@link java.util.Collection} nor {@link java.util.Map}.
|
||||
*/
|
||||
Class<?> getComponentType();
|
||||
|
||||
@@ -76,9 +74,9 @@ public interface PersistentProperty<P extends PersistentProperty<P>> {
|
||||
Class<?> getRawType();
|
||||
|
||||
/**
|
||||
* Returns the type of the values if the property is a {@link Map}.
|
||||
* Returns the type of the values if the property is a {@link java.util.Map}.
|
||||
*
|
||||
* @return the map's value type or {@literal null} if no {@link Map}
|
||||
* @return the map's value type or {@literal null} if no {@link java.util.Map}
|
||||
*/
|
||||
Class<?> getMapValueType();
|
||||
|
||||
|
||||
@@ -241,35 +241,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
descriptors.put(descriptor.getName(), descriptor);
|
||||
}
|
||||
|
||||
ReflectionUtils.doWithFields(type, new FieldCallback() {
|
||||
|
||||
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
|
||||
|
||||
PropertyDescriptor descriptor = descriptors.get(field.getName());
|
||||
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
P property = createPersistentProperty(field, descriptor, entity, simpleTypeHolder);
|
||||
|
||||
if (property.isTransient()) {
|
||||
return;
|
||||
}
|
||||
|
||||
entity.addPersistentProperty(property);
|
||||
|
||||
if (property.isAssociation()) {
|
||||
entity.addAssociation(property.getAssociation());
|
||||
}
|
||||
|
||||
if (property.isIdProperty()) {
|
||||
entity.setIdProperty(property);
|
||||
}
|
||||
|
||||
TypeInformation<?> nestedType = getNestedTypeToAdd(property, entity);
|
||||
if (nestedType != null) {
|
||||
addPersistentEntity(nestedType);
|
||||
}
|
||||
}
|
||||
}, new ReflectionUtils.FieldFilter() {
|
||||
ReflectionUtils.doWithFields(type, new PersistentPropertyCreator(entity, descriptors), new ReflectionUtils.FieldFilter() {
|
||||
public boolean matches(Field field) {
|
||||
return !Modifier.isStatic(field.getModifiers()) && !UNMAPPED_FIELDS.contains(field.getName());
|
||||
}
|
||||
@@ -372,4 +344,54 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
addPersistentEntity(initialEntity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link FieldCallback} to create {@link PersistentProperty} instances.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
private final class PersistentPropertyCreator implements FieldCallback {
|
||||
|
||||
private final E entity;
|
||||
private final Map<String, PropertyDescriptor> descriptors;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PersistentPropertyCreator} for the given {@link PersistentEntity} and
|
||||
* {@link PropertyDescriptor}s.
|
||||
*
|
||||
* @param entity
|
||||
* @param descriptors
|
||||
*/
|
||||
private PersistentPropertyCreator(E entity, Map<String, PropertyDescriptor> descriptors) {
|
||||
this.entity = entity;
|
||||
this.descriptors = descriptors;
|
||||
}
|
||||
|
||||
public void doWith(Field field) {
|
||||
|
||||
PropertyDescriptor descriptor = descriptors.get(field.getName());
|
||||
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
P property = createPersistentProperty(field, descriptor, entity, simpleTypeHolder);
|
||||
|
||||
if (property.isTransient()) {
|
||||
return;
|
||||
}
|
||||
|
||||
entity.addPersistentProperty(property);
|
||||
|
||||
if (property.isAssociation()) {
|
||||
entity.addAssociation(property.getAssociation());
|
||||
}
|
||||
|
||||
if (property.isIdProperty()) {
|
||||
entity.setIdProperty(property);
|
||||
}
|
||||
|
||||
TypeInformation<?> nestedType = getNestedTypeToAdd(property, entity);
|
||||
if (nestedType != null) {
|
||||
addPersistentEntity(nestedType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011 by the original author(s).
|
||||
*
|
||||
* 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.context;
|
||||
|
||||
/**
|
||||
* An interface to make beans aware of the active MappingContext in the current ApplicationContext.
|
||||
*
|
||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||
*/
|
||||
public interface MappingContextAware {
|
||||
|
||||
/**
|
||||
* The active MappingContext for the environment.
|
||||
*
|
||||
* @param mappingContext
|
||||
*/
|
||||
void setMappingContext(MappingContext<?, ?> mappingContext);
|
||||
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011 by the original author(s).
|
||||
*
|
||||
* 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.context;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
|
||||
/**
|
||||
* BeanPostProcessor to make Spring beans aware of the current MappingContext. If a MappingContext exists with the
|
||||
* default bean name ("mappingContext"), then that bean is used. If there is no MappingContext registered under the
|
||||
* default bean name, then the first MappingContext it finds is the one it chooses.
|
||||
*
|
||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||
*/
|
||||
public class MappingContextAwareBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware {
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
private String mappingContextBeanName = "mappingContext";
|
||||
private MappingContext<?, ?> mappingContext;
|
||||
|
||||
public MappingContextAwareBeanPostProcessor() {
|
||||
}
|
||||
|
||||
public MappingContextAwareBeanPostProcessor(MappingContext<?, ?> mappingContext) {
|
||||
this.mappingContext = mappingContext;
|
||||
}
|
||||
|
||||
public String getMappingContextBeanName() {
|
||||
return mappingContextBeanName;
|
||||
}
|
||||
|
||||
public void setMappingContextBeanName(String mappingContextBeanName) {
|
||||
this.mappingContextBeanName = mappingContextBeanName;
|
||||
}
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (bean instanceof MappingContextAware) {
|
||||
if (null == mappingContext) {
|
||||
Map<String, MappingContext> mappingContexts = applicationContext.getBeansOfType(MappingContext.class);
|
||||
if (mappingContexts.containsKey(mappingContextBeanName)) {
|
||||
this.mappingContext = mappingContexts.get(mappingContextBeanName);
|
||||
} else {
|
||||
String firstBean = mappingContexts.keySet().iterator().next();
|
||||
this.mappingContext = applicationContext.getBean(firstBean, MappingContext.class);
|
||||
}
|
||||
}
|
||||
((MappingContextAware) bean).setMappingContext(mappingContext);
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.mapping.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -186,8 +187,9 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
private static final class AssociationComparator<P extends PersistentProperty<P>> implements
|
||||
Comparator<Association<P>> {
|
||||
Comparator<Association<P>>, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 4508054194886854513L;
|
||||
private final Comparator<P> delegate;
|
||||
|
||||
public AssociationComparator(Comparator<P> delegate) {
|
||||
|
||||
@@ -104,6 +104,9 @@ public class BeanWrapper<E extends PersistentEntity<T, ?>, T> {
|
||||
} catch (BeanInstantiationException e) {
|
||||
throw new MappingInstantiationException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
this.bean = bean;
|
||||
return;
|
||||
}
|
||||
|
||||
List<Object> params = new LinkedList<Object>();
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011 by the original author(s).
|
||||
*
|
||||
* 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.model;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||
*/
|
||||
public class MappingConfigurationException extends Throwable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MappingConfigurationException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
public MappingConfigurationException(String s, Throwable throwable) {
|
||||
super(s, throwable);
|
||||
}
|
||||
}
|
||||
@@ -16,10 +16,16 @@
|
||||
package org.springframework.data.querydsl;
|
||||
|
||||
/**
|
||||
* Utility class for Querydsl.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class QueryDslUtils {
|
||||
public abstract class QueryDslUtils {
|
||||
|
||||
public static final boolean QUERY_DSL_PRESENT = org.springframework.util.ClassUtils.isPresent(
|
||||
"com.mysema.query.types.Predicate", QueryDslUtils.class.getClassLoader());
|
||||
|
||||
private QueryDslUtils() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class PropertiesBasedNamedQueries implements NamedQueries {
|
||||
|
||||
public static NamedQueries EMPTY = new PropertiesBasedNamedQueries(new Properties());
|
||||
public static final NamedQueries EMPTY = new PropertiesBasedNamedQueries(new Properties());
|
||||
|
||||
private final Properties properties;
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class OrderBySource {
|
||||
|
||||
private final String BLOCK_SPLIT = "(?<=Asc|Desc)(?=[A-Z])";
|
||||
private final Pattern DIRECTION_SPLIT = Pattern.compile("(.+)(Asc|Desc)$");
|
||||
private static final String BLOCK_SPLIT = "(?<=Asc|Desc)(?=[A-Z])";
|
||||
private static final Pattern DIRECTION_SPLIT = Pattern.compile("(.+)(Asc|Desc)$");
|
||||
|
||||
private final List<Order> orders;
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ public class Part {
|
||||
* Creates a new {@link Part} from the given method name part, the {@link Class} the part originates from and the
|
||||
* start parameter index.
|
||||
*
|
||||
* @param part
|
||||
* @param clazz
|
||||
* @param part must not be {@literal null}.
|
||||
* @param clazz must not be {@l
|
||||
*/
|
||||
public Part(String part, Class<?> clazz) {
|
||||
|
||||
@@ -54,28 +54,31 @@ public class Part {
|
||||
* Creates a new {@link Part} from the given method name part, the {@link Class} the part originates from and the
|
||||
* start parameter index.
|
||||
*
|
||||
* @param part
|
||||
* @param clazz
|
||||
* @param part must not be {@literal null}.
|
||||
* @param clazz must not be {@literal null}.
|
||||
* @param alwaysIgnoreCase
|
||||
*/
|
||||
public Part(String part, Class<?> clazz, boolean alwaysIgnoreCase) {
|
||||
|
||||
part = detectAndSetIgnoreCase(part);
|
||||
String partToUse = detectAndSetIgnoreCase(part);
|
||||
if (alwaysIgnoreCase && ignoreCase != IgnoreCaseType.ALWAYS) {
|
||||
this.ignoreCase = IgnoreCaseType.WHEN_POSSIBLE;
|
||||
}
|
||||
this.type = Type.fromProperty(part, clazz);
|
||||
this.property = Property.from(type.extractProperty(part), clazz);
|
||||
this.type = Type.fromProperty(partToUse);
|
||||
this.property = Property.from(type.extractProperty(partToUse), clazz);
|
||||
}
|
||||
|
||||
private String detectAndSetIgnoreCase(String part) {
|
||||
|
||||
Matcher matcher = IGNORE_CASE.matcher(part);
|
||||
String result = part;
|
||||
|
||||
if (matcher.find()) {
|
||||
ignoreCase = IgnoreCaseType.ALWAYS;
|
||||
part = part.substring(0, matcher.start()) + part.substring(matcher.end(), part.length());
|
||||
result = part.substring(0, matcher.start()) + part.substring(matcher.end(), part.length());
|
||||
}
|
||||
return part;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean getParameterRequired() {
|
||||
@@ -221,18 +224,17 @@ public class Part {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Type} of the {@link Part} for the given raw property and the given {@link Class}. This will
|
||||
* Returns the {@link Type} of the {@link Part} for the given raw property. This will
|
||||
* try to detect e.g. keywords contained in the raw property that trigger special query creation. Returns
|
||||
* {@link #SIMPLE_PROPERTY} by default.
|
||||
*
|
||||
* @param rawProperty
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
public static Part.Type fromProperty(String rawProperty, Class<?> clazz) {
|
||||
public static Part.Type fromProperty(String rawProperty) {
|
||||
|
||||
for (Part.Type type : ALL) {
|
||||
if (type.supports(rawProperty, clazz)) {
|
||||
if (type.supports(rawProperty)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@@ -245,10 +247,9 @@ public class Part {
|
||||
* ends with the registered keyword. Does not support the keyword if the property is a valid field as is.
|
||||
*
|
||||
* @param property
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
protected boolean supports(String property, Class<?> clazz) {
|
||||
protected boolean supports(String property) {
|
||||
|
||||
if (keywords == null) {
|
||||
return true;
|
||||
|
||||
@@ -202,17 +202,16 @@ public class PartTree implements Iterable<OrPart> {
|
||||
*/
|
||||
private static class Predicate {
|
||||
|
||||
private static Pattern ALL_IGNORE_CASE = Pattern.compile("AllIgnor(ing|e)Case");
|
||||
private static final Pattern ALL_IGNORE_CASE = Pattern.compile("AllIgnor(ing|e)Case");
|
||||
private static final String ORDER_BY = "OrderBy";
|
||||
|
||||
private final List<OrPart> nodes = new ArrayList<OrPart>();
|
||||
private OrderBySource orderBySource;
|
||||
private final OrderBySource orderBySource;
|
||||
private boolean alwaysIgnoreCase;
|
||||
|
||||
public Predicate(String predicate, Class<?> domainClass) {
|
||||
|
||||
predicate = detectAndSetAllIgnoreCase(predicate);
|
||||
String[] parts = split(predicate, ORDER_BY);
|
||||
String[] parts = split(detectAndSetAllIgnoreCase(predicate), ORDER_BY);
|
||||
|
||||
if (parts.length > 2) {
|
||||
throw new IllegalArgumentException("OrderBy must not be used more than once in a method name!");
|
||||
|
||||
@@ -190,7 +190,7 @@ public class Property {
|
||||
|
||||
Property that = (Property) obj;
|
||||
|
||||
return this.name.equals(that.name) && this.type.equals(type);
|
||||
return this.name.equals(that.name) && this.type.equals(that.type);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -41,14 +41,15 @@ public class DomainClassPropertyEditor<T, ID extends Serializable> extends Prope
|
||||
* Creates a new {@link DomainClassPropertyEditor} for the given {@link CrudRepository}, {@link EntityInformation} and
|
||||
* {@link PropertyEditorRegistry}.
|
||||
*
|
||||
* @param repository
|
||||
* @param information
|
||||
* @param registry
|
||||
* @param repository must not be {@literal null}.
|
||||
* @param information must not be {@literal null}.
|
||||
* @param registry must not be {@literal null}.
|
||||
*/
|
||||
public DomainClassPropertyEditor(CrudRepository<T, ID> repository, EntityInformation<T, ID> information,
|
||||
PropertyEditorRegistry registry) {
|
||||
|
||||
Assert.notNull(repository);
|
||||
Assert.notNull(information);
|
||||
Assert.notNull(registry);
|
||||
|
||||
this.repository = repository;
|
||||
@@ -57,12 +58,11 @@ public class DomainClassPropertyEditor<T, ID extends Serializable> extends Prope
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
|
||||
*/
|
||||
* (non-Javadoc)
|
||||
* @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void setAsText(String idAsString) throws IllegalArgumentException {
|
||||
public void setAsText(String idAsString) {
|
||||
|
||||
if (!StringUtils.hasText(idAsString)) {
|
||||
setValue(null);
|
||||
@@ -73,10 +73,9 @@ public class DomainClassPropertyEditor<T, ID extends Serializable> extends Prope
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.beans.PropertyEditorSupport#getAsText()
|
||||
*/
|
||||
* (non-Javadoc)
|
||||
* @see java.beans.PropertyEditorSupport#getAsText()
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getAsText() {
|
||||
@@ -127,10 +126,9 @@ public class DomainClassPropertyEditor<T, ID extends Serializable> extends Prope
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
@@ -149,10 +147,9 @@ public class DomainClassPropertyEditor<T, ID extends Serializable> extends Prope
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -18,10 +18,8 @@ package org.springframework.data.util;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.core.GenericCollectionTypeResolver;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,9 +40,10 @@ class GenericArrayTypeInformation<S> extends ParameterizedTypeInformation<S> {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.util.TypeDiscoverer#getType()
|
||||
*/
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.util.TypeDiscoverer#getType()
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Class<S> getType() {
|
||||
@@ -50,9 +51,10 @@ class GenericArrayTypeInformation<S> extends ParameterizedTypeInformation<S> {
|
||||
return (Class<S>) Array.newInstance(resolveType(type.getGenericComponentType()), 0).getClass();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.util.TypeDiscoverer#getComponentType()
|
||||
*/
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.util.TypeDiscoverer#getComponentType()
|
||||
*/
|
||||
@Override
|
||||
public TypeInformation<?> getComponentType() {
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
*/
|
||||
public TypeInformation<?> getProperty(String fieldname) {
|
||||
|
||||
int separatorIndex = fieldname.indexOf(".");
|
||||
int separatorIndex = fieldname.indexOf('.');
|
||||
|
||||
if (separatorIndex == -1) {
|
||||
if (fieldTypes.containsKey(fieldname)) {
|
||||
@@ -235,8 +235,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
* @see org.springframework.data.util.TypeInformation#isMap()
|
||||
*/
|
||||
public boolean isMap() {
|
||||
Class<?> rawType = getType();
|
||||
return rawType == null ? false : Map.class.isAssignableFrom(rawType);
|
||||
return Map.class.isAssignableFrom(getType());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -267,7 +266,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
public boolean isCollectionLike() {
|
||||
|
||||
Class<?> rawType = getType();
|
||||
return rawType == null ? null : rawType.isArray() || Iterable.class.isAssignableFrom(rawType);
|
||||
return rawType.isArray() || Iterable.class.isAssignableFrom(rawType);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
@@ -1,10 +1,23 @@
|
||||
/*
|
||||
* Copyright 2008-2011 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.util;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Collection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Interface to access property types and resolving generics on the way. Starting with a {@link ClassTypeInformation}
|
||||
@@ -27,22 +40,22 @@ public interface TypeInformation<S> {
|
||||
|
||||
/**
|
||||
* Returns whether the type can be considered a collection, which means it's a container of elements, e.g. a
|
||||
* {@link Collection} and {@link Array} or anything implementing {@link Iterable}. If this returns {@literal true} you
|
||||
* can expect {@link #getComponentType()} to return a non-{@literal null} value.
|
||||
* {@link java.util.Collection} and {@link java.lang.reflect.Array} or anything implementing {@link Iterable}. If this
|
||||
* returns {@literal true} you can expect {@link #getComponentType()} to return a non-{@literal null} value.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean isCollectionLike();
|
||||
|
||||
/**
|
||||
* Returns the component type for {@link Collection}s or the key type for {@link Map}s.
|
||||
* Returns the component type for {@link java.util.Collection}s or the key type for {@link java.util.Map}s.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
TypeInformation<?> getComponentType();
|
||||
|
||||
/**
|
||||
* Returns whether the property is a {@link Map}. If this returns {@literal true} you can expect
|
||||
* Returns whether the property is a {@link java.util.Map}. If this returns {@literal true} you can expect
|
||||
* {@link #getComponentType()} as well as {@link #getMapValueType()} to return something not {@literal null}.
|
||||
*
|
||||
* @return
|
||||
@@ -50,7 +63,7 @@ public interface TypeInformation<S> {
|
||||
boolean isMap();
|
||||
|
||||
/**
|
||||
* Will return the type of the value in case the underlying type is a {@link Map}.
|
||||
* Will return the type of the value in case the underlying type is a {@link java.util.Map}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@@ -64,8 +77,8 @@ public interface TypeInformation<S> {
|
||||
Class<S> getType();
|
||||
|
||||
/**
|
||||
* Transparently returns the {@link Map} value type if the type is a {@link Map}, returns the component type if the
|
||||
* type {@link #isCollectionLike()} or the simple type if none of this applies.
|
||||
* Transparently returns the {@link java.util.Map} value type if the type is a {@link java.util.Map}, returns the
|
||||
* component type if the type {@link #isCollectionLike()} or the simple type if none of this applies.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@@ -261,12 +261,11 @@ public class PageableArgumentResolver implements WebArgumentResolver {
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
|
||||
*/
|
||||
* (non-Javadoc)
|
||||
* @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
public void setAsText(String text) {
|
||||
|
||||
PropertyValue rawOrder = values.getPropertyValue(orderProperty);
|
||||
Direction order = null == rawOrder ? Direction.ASC : Direction.fromString(rawOrder.getValue().toString());
|
||||
|
||||
Reference in New Issue
Block a user