From e1b38faee9d925af0708b61db053838b86c931a3 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 26 Nov 2014 09:10:00 +0100 Subject: [PATCH] DATACMNS-601 - Fixes for most of the SonarQube warnings. --- .../auditing/AnnotationAuditingMetadata.java | 2 +- .../auditing/AuditableBeanWrapperFactory.java | 2 +- .../AuditingHandlerBeanDefinitionParser.java | 4 +- .../BytecodeGeneratingEntityInstantiator.java | 77 ++++++++++--------- .../data/convert/CollectionFactory.java | 2 +- .../convert/SimpleTypeInformationMapper.java | 6 +- .../data/domain/jaxb/SpringDataJaxb.java | 4 +- .../org/springframework/data/geo/GeoPage.java | 30 ++++++++ .../mapping/PersistentPropertyAccessor.java | 8 +- .../data/mapping/PropertyPath.java | 8 +- .../DefaultPersistentPropertyPath.java | 6 +- .../AnnotationBasedPersistentProperty.java | 7 +- .../data/mapping/model/BeanWrapper.java | 4 +- .../querydsl/QueryDslPredicateExecutor.java | 4 +- .../RepositoryConfigurationDelegate.java | 6 +- .../config/RepositoryConfigurationUtils.java | 2 +- .../support/PersistentEntityInformation.java | 3 +- .../data/repository/query/Parameters.java | 2 +- .../data/repository/query/QueryMethod.java | 6 +- .../support/CrudRepositoryInvoker.java | 8 +- .../PagingAndSortingRepositoryInvoker.java | 5 +- .../support/ReflectionRepositoryInvoker.java | 3 +- .../data/repository/support/Repositories.java | 16 ++-- .../repository/support/RepositoryInvoker.java | 26 ++++--- .../util/QueryExecutionConverters.java | 4 +- .../AnnotationDetectionMethodCallback.java | 8 +- .../DirectFieldAccessFallbackBeanWrapper.java | 2 +- .../util/ParameterizedTypeInformation.java | 8 +- .../data/util/ReflectionUtils.java | 2 +- .../data/util/TypeDiscoverer.java | 22 +++--- .../data/web/SpringDataAnnotationUtils.java | 2 +- 31 files changed, 158 insertions(+), 131 deletions(-) diff --git a/src/main/java/org/springframework/data/auditing/AnnotationAuditingMetadata.java b/src/main/java/org/springframework/data/auditing/AnnotationAuditingMetadata.java index 40b624b5a..69319ac26 100644 --- a/src/main/java/org/springframework/data/auditing/AnnotationAuditingMetadata.java +++ b/src/main/java/org/springframework/data/auditing/AnnotationAuditingMetadata.java @@ -39,7 +39,7 @@ import org.springframework.util.Assert; * @author Oliver Gierke * @since 1.5 */ -class AnnotationAuditingMetadata { +final class AnnotationAuditingMetadata { private static final AnnotationFieldFilter CREATED_BY_FILTER = new AnnotationFieldFilter(CreatedBy.class); private static final AnnotationFieldFilter CREATED_DATE_FILTER = new AnnotationFieldFilter(CreatedDate.class); diff --git a/src/main/java/org/springframework/data/auditing/AuditableBeanWrapperFactory.java b/src/main/java/org/springframework/data/auditing/AuditableBeanWrapperFactory.java index 7fea361e4..e90bf799d 100644 --- a/src/main/java/org/springframework/data/auditing/AuditableBeanWrapperFactory.java +++ b/src/main/java/org/springframework/data/auditing/AuditableBeanWrapperFactory.java @@ -115,7 +115,7 @@ class AuditableBeanWrapperFactory { * @author Oliver Gierke * @since 1.8 */ - static abstract class DateConvertingAuditableBeanWrapper implements AuditableBeanWrapper { + abstract static class DateConvertingAuditableBeanWrapper implements AuditableBeanWrapper { private static final boolean IS_JODA_TIME_PRESENT = ClassUtils.isPresent("org.joda.time.DateTime", ReflectionAuditingBeanWrapper.class.getClassLoader()); diff --git a/src/main/java/org/springframework/data/auditing/config/AuditingHandlerBeanDefinitionParser.java b/src/main/java/org/springframework/data/auditing/config/AuditingHandlerBeanDefinitionParser.java index 1348d148d..dfdcad44a 100644 --- a/src/main/java/org/springframework/data/auditing/config/AuditingHandlerBeanDefinitionParser.java +++ b/src/main/java/org/springframework/data/auditing/config/AuditingHandlerBeanDefinitionParser.java @@ -19,7 +19,6 @@ import static org.springframework.beans.factory.support.BeanDefinitionBuilder.*; import org.springframework.aop.framework.ProxyFactoryBean; import org.springframework.aop.target.LazyInitTargetSource; -import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; @@ -110,8 +109,7 @@ public class AuditingHandlerBeanDefinitionParser extends AbstractSingleBeanDefin * @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#resolveId(org.w3c.dom.Element, org.springframework.beans.factory.support.AbstractBeanDefinition, org.springframework.beans.factory.xml.ParserContext) */ @Override - protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) - throws BeanDefinitionStoreException { + protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) { this.resolvedBeanName = super.resolveId(element, definition, parserContext); return resolvedBeanName; diff --git a/src/main/java/org/springframework/data/convert/BytecodeGeneratingEntityInstantiator.java b/src/main/java/org/springframework/data/convert/BytecodeGeneratingEntityInstantiator.java index 96152d8c4..657bb6d13 100644 --- a/src/main/java/org/springframework/data/convert/BytecodeGeneratingEntityInstantiator.java +++ b/src/main/java/org/springframework/data/convert/BytecodeGeneratingEntityInstantiator.java @@ -55,7 +55,7 @@ public enum BytecodeGeneratingEntityInstantiator implements EntityInstantiator { INSTANCE; - private final ObjectInstantiatorClassGenerator classGenerator = ObjectInstantiatorClassGenerator.INSTANCE; + private static final ObjectInstantiatorClassGenerator GENERATOR = ObjectInstantiatorClassGenerator.INSTANCE; private volatile Map, EntityInstantiator> entityInstantiators = new HashMap, EntityInstantiator>( 32); @@ -149,47 +149,14 @@ public enum BytecodeGeneratingEntityInstantiator implements EntityInstantiator { * @return */ private ObjectInstantiator createObjectInstantiator(PersistentEntity entity) { + try { - return (ObjectInstantiator) classGenerator.generateCustomInstantiatorClass(entity).newInstance(); - } catch (Throwable e) { + return (ObjectInstantiator) GENERATOR.generateCustomInstantiatorClass(entity).newInstance(); + } catch (Exception e) { throw new RuntimeException(e); } } - /** - * A {@link ClassLoader} that can load classes from {@code byte[]} representations. - * - * @author Thomas Darimont - */ - private static class ByteArrayClassLoader extends ClassLoader { - - public ByteArrayClassLoader(ClassLoader parent) { - super(parent); - } - - /** - * Tries to load a class given {@code byte[]}. - * - * @param name must not be {@literal null} - * @param bytes must not be {@literal null} - * @return - */ - public Class loadClass(String name, byte[] bytes) { - - Assert.notNull(name, "name must not be null"); - Assert.notNull(bytes, "bytes must not be null"); - - try { - Class clazz = findClass(name); - if (clazz != null) { - return clazz; - } - } catch (ClassNotFoundException ignore) {} - - return defineClass(name, bytes, 0, bytes.length); - } - } - /** * Adapter to forward an invocation of the {@link EntityInstantiator} API to an {@link ObjectInstantiator}. * @@ -256,7 +223,7 @@ public enum BytecodeGeneratingEntityInstantiator implements EntityInstantiator { /** * @author Thomas Darimont */ - public static interface ObjectInstantiator { + interface ObjectInstantiator { Object newInstance(Object... args); } @@ -495,5 +462,39 @@ public enum BytecodeGeneratingEntityInstantiator implements EntityInstantiator { throw new IllegalArgumentException("Unboxing should not be attempted for descriptor '" + ch + "'"); } } + + /** + * A {@link ClassLoader} that can load classes from {@code byte[]} representations. + * + * @author Thomas Darimont + */ + private class ByteArrayClassLoader extends ClassLoader { + + public ByteArrayClassLoader(ClassLoader parent) { + super(parent); + } + + /** + * Tries to load a class given {@code byte[]}. + * + * @param name must not be {@literal null} + * @param bytes must not be {@literal null} + * @return + */ + public Class loadClass(String name, byte[] bytes) { + + Assert.notNull(name, "name must not be null"); + Assert.notNull(bytes, "bytes must not be null"); + + try { + Class clazz = findClass(name); + if (clazz != null) { + return clazz; + } + } catch (ClassNotFoundException ignore) {} + + return defineClass(name, bytes, 0, bytes.length); + } + } } } diff --git a/src/main/java/org/springframework/data/convert/CollectionFactory.java b/src/main/java/org/springframework/data/convert/CollectionFactory.java index 28591a04a..059735e19 100644 --- a/src/main/java/org/springframework/data/convert/CollectionFactory.java +++ b/src/main/java/org/springframework/data/convert/CollectionFactory.java @@ -28,7 +28,7 @@ import org.springframework.util.Assert; * * @author Oliver Gierke */ -public class CollectionFactory { +public abstract class CollectionFactory { private CollectionFactory() {} diff --git a/src/main/java/org/springframework/data/convert/SimpleTypeInformationMapper.java b/src/main/java/org/springframework/data/convert/SimpleTypeInformationMapper.java index 4e0097ba4..9fe19ba6d 100644 --- a/src/main/java/org/springframework/data/convert/SimpleTypeInformationMapper.java +++ b/src/main/java/org/springframework/data/convert/SimpleTypeInformationMapper.java @@ -33,7 +33,7 @@ import org.springframework.util.StringUtils; public class SimpleTypeInformationMapper implements TypeInformationMapper { public static final SimpleTypeInformationMapper INSTANCE = new SimpleTypeInformationMapper(); - private static final Map> cache = new ConcurrentHashMap>(); + private static final Map> CACHE = new ConcurrentHashMap>(); /** * Returns the {@link TypeInformation} that shall be used when the given {@link String} value is found as type hint. @@ -56,7 +56,7 @@ public class SimpleTypeInformationMapper implements TypeInformationMapper { return null; } - ClassTypeInformation information = cache.get(value); + ClassTypeInformation information = CACHE.get(value); if (information != null) { return information; @@ -69,7 +69,7 @@ public class SimpleTypeInformationMapper implements TypeInformationMapper { } if (information != null) { - cache.put(value, information); + CACHE.put(value, information); } return information; diff --git a/src/main/java/org/springframework/data/domain/jaxb/SpringDataJaxb.java b/src/main/java/org/springframework/data/domain/jaxb/SpringDataJaxb.java index 7b86ababd..ec8d0b707 100644 --- a/src/main/java/org/springframework/data/domain/jaxb/SpringDataJaxb.java +++ b/src/main/java/org/springframework/data/domain/jaxb/SpringDataJaxb.java @@ -44,10 +44,12 @@ import org.springframework.util.Assert; * * @author Oliver Gierke */ -public class SpringDataJaxb { +public abstract class SpringDataJaxb { public static final String NAMESPACE = "http://www.springframework.org/schema/data/jaxb"; + private SpringDataJaxb() {} + /** * The DTO for {@link Pageable}s/{@link PageRequest}s. * diff --git a/src/main/java/org/springframework/data/geo/GeoPage.java b/src/main/java/org/springframework/data/geo/GeoPage.java index e0603360e..f0d25489b 100644 --- a/src/main/java/org/springframework/data/geo/GeoPage.java +++ b/src/main/java/org/springframework/data/geo/GeoPage.java @@ -18,6 +18,7 @@ package org.springframework.data.geo; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.util.ObjectUtils; /** * Custom {@link Page} to carry the average distance retrieved from the {@link GeoResults} the {@link GeoPage} is set up @@ -66,4 +67,33 @@ public class GeoPage extends PageImpl> { public Distance getAverageDistance() { return averageDistance; } + + /* + * (non-Javadoc) + * @see org.springframework.data.domain.PageImpl#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + + if (this == obj) { + return true; + } + + if (!(obj instanceof GeoPage)) { + return false; + } + + GeoPage that = (GeoPage) obj; + + return super.equals(obj) && ObjectUtils.nullSafeEquals(this.averageDistance, that.averageDistance); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.domain.PageImpl#hashCode() + */ + @Override + public int hashCode() { + return super.hashCode() + ObjectUtils.nullSafeHashCode(this.averageDistance); + } } diff --git a/src/main/java/org/springframework/data/mapping/PersistentPropertyAccessor.java b/src/main/java/org/springframework/data/mapping/PersistentPropertyAccessor.java index edac609e0..48e896281 100644 --- a/src/main/java/org/springframework/data/mapping/PersistentPropertyAccessor.java +++ b/src/main/java/org/springframework/data/mapping/PersistentPropertyAccessor.java @@ -15,9 +15,6 @@ */ package org.springframework.data.mapping; -import org.springframework.core.convert.ConversionService; -import org.springframework.data.mapping.model.MappingException; - /** * Domain service to allow accessing and setting {@link PersistentProperty}s of an entity. * @@ -27,11 +24,12 @@ public interface PersistentPropertyAccessor { /** * Sets the given {@link PersistentProperty} to the given value. Will do type conversion if a - * {@link ConversionService} is configured. + * {@link org.springframework.core.convert.ConversionService} is configured. * * @param property must not be {@literal null}. * @param value can be {@literal null}. - * @throws MappingException in case an exception occurred when setting the property value. + * @throws org.springframework.data.mapping.model.MappingException in case an exception occurred when setting the + * property value. */ void setProperty(PersistentProperty property, Object value); diff --git a/src/main/java/org/springframework/data/mapping/PropertyPath.java b/src/main/java/org/springframework/data/mapping/PropertyPath.java index 79d133d8c..95bc57afd 100644 --- a/src/main/java/org/springframework/data/mapping/PropertyPath.java +++ b/src/main/java/org/springframework/data/mapping/PropertyPath.java @@ -69,15 +69,15 @@ public class PropertyPath implements Iterable { Assert.notNull(owningType); String propertyName = name.matches(ALL_UPPERCASE) ? name : StringUtils.uncapitalize(name); - TypeInformation type = owningType.getProperty(propertyName); + TypeInformation propertyType = owningType.getProperty(propertyName); - if (type == null) { + if (propertyType == null) { throw new PropertyReferenceException(propertyName, owningType, base); } this.owningType = owningType; - this.isCollection = type.isCollectionLike(); - this.type = type.getActualType(); + this.isCollection = propertyType.isCollectionLike(); + this.type = propertyType.getActualType(); this.name = propertyName; } diff --git a/src/main/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPath.java b/src/main/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPath.java index 94239f755..64604f540 100644 --- a/src/main/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPath.java +++ b/src/main/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPath.java @@ -158,7 +158,7 @@ class DefaultPersistentPropertyPath> implements return this; } - List properties = new ArrayList(); + List result = new ArrayList(); Iterator iterator = iterator(); for (int i = 0; i < base.getLength(); i++) { @@ -166,10 +166,10 @@ class DefaultPersistentPropertyPath> implements } while (iterator.hasNext()) { - properties.add(iterator.next()); + result.add(iterator.next()); } - return new DefaultPersistentPropertyPath(properties); + return new DefaultPersistentPropertyPath(result); } /* diff --git a/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java b/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java index 17efb3ebd..36c1f6649 100644 --- a/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java +++ b/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java @@ -158,9 +158,10 @@ public abstract class AnnotationBasedPersistentProperty

implements PersistentPropertyAccessor { * @param bean must not be {@literal null}. * @param conversionService can be {@literal null}. * @return - * @deprecated use {@link PersistentEntity#getPropertyAccessor(Object)} instead. Will be removed in 1.10 RC1. + * @deprecated use {@link org.springframework.data.mapping.PersistentEntity#getPropertyAccessor(Object)} instead. Will + * be removed in 1.10 RC1. */ @Deprecated public static BeanWrapper create(T bean, ConversionService conversionService) { diff --git a/src/main/java/org/springframework/data/querydsl/QueryDslPredicateExecutor.java b/src/main/java/org/springframework/data/querydsl/QueryDslPredicateExecutor.java index 5160b79cf..696334452 100644 --- a/src/main/java/org/springframework/data/querydsl/QueryDslPredicateExecutor.java +++ b/src/main/java/org/springframework/data/querydsl/QueryDslPredicateExecutor.java @@ -15,7 +15,6 @@ */ package org.springframework.data.querydsl; -import org.springframework.dao.IncorrectResultSizeDataAccessException; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -35,7 +34,8 @@ public interface QueryDslPredicateExecutor { * * @param predicate * @return a single entity matching the given {@link Predicate} or {@literal null} if none was found. - * @throws IncorrectResultSizeDataAccessException if the predicate yields more than one result. + * @throws org.springframework.dao.IncorrectResultSizeDataAccessException if the predicate yields more than one + * result. */ T findOne(Predicate predicate); diff --git a/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java b/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java index 3af8983ce..57f9bce08 100644 --- a/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java +++ b/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java @@ -56,7 +56,7 @@ public class RepositoryConfigurationDelegate { private final RepositoryConfigurationSource configurationSource; private final ResourceLoader resourceLoader; private final Environment environment; - private final BeanNameGenerator generator; + private final BeanNameGenerator beanNameGenerator; private final boolean isXml; private final boolean inMultiStoreMode; @@ -81,7 +81,7 @@ public class RepositoryConfigurationDelegate { RepositoryBeanNameGenerator generator = new RepositoryBeanNameGenerator(); generator.setBeanClassLoader(resourceLoader.getClassLoader()); - this.generator = generator; + this.beanNameGenerator = generator; this.configurationSource = configurationSource; this.resourceLoader = resourceLoader; this.environment = defaultEnvironment(environment, resourceLoader); @@ -136,7 +136,7 @@ public class RepositoryConfigurationDelegate { } AbstractBeanDefinition beanDefinition = definitionBuilder.getBeanDefinition(); - String beanName = generator.generateBeanName(beanDefinition, registry); + String beanName = beanNameGenerator.generateBeanName(beanDefinition, registry); if (LOGGER.isDebugEnabled()) { LOGGER.debug(REPOSITORY_REGISTRATION, extension.getModuleName(), beanName, diff --git a/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationUtils.java b/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationUtils.java index 7d30c4e89..cdbce7d3f 100644 --- a/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationUtils.java +++ b/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationUtils.java @@ -28,7 +28,7 @@ import org.springframework.util.Assert; * * @author Oliver Gierke */ -public class RepositoryConfigurationUtils { +public abstract class RepositoryConfigurationUtils { private RepositoryConfigurationUtils() {} diff --git a/src/main/java/org/springframework/data/repository/core/support/PersistentEntityInformation.java b/src/main/java/org/springframework/data/repository/core/support/PersistentEntityInformation.java index 6cc9577ba..1e11779db 100644 --- a/src/main/java/org/springframework/data/repository/core/support/PersistentEntityInformation.java +++ b/src/main/java/org/springframework/data/repository/core/support/PersistentEntityInformation.java @@ -18,12 +18,11 @@ package org.springframework.data.repository.core.support; import java.io.Serializable; import org.springframework.data.mapping.PersistentEntity; -import org.springframework.data.mapping.model.BeanWrapper; import org.springframework.data.repository.core.EntityInformation; /** * {@link EntityInformation} implementation that uses a {@link PersistentEntity} to obtain id type information and uses - * a {@link BeanWrapper} to access the property value if requested. + * a {@link org.springframework.data.mapping.IdentifierAccessor} to access the property value if requested. * * @author Oliver Gierke */ diff --git a/src/main/java/org/springframework/data/repository/query/Parameters.java b/src/main/java/org/springframework/data/repository/query/Parameters.java index d73c79886..2965f0b3d 100644 --- a/src/main/java/org/springframework/data/repository/query/Parameters.java +++ b/src/main/java/org/springframework/data/repository/query/Parameters.java @@ -253,7 +253,7 @@ public abstract class Parameters, T extends Parameter * * @param method */ - private void assertEitherAllParamAnnotatedOrNone() { + private final void assertEitherAllParamAnnotatedOrNone() { boolean nameFound = false; int index = 0; diff --git a/src/main/java/org/springframework/data/repository/query/QueryMethod.java b/src/main/java/org/springframework/data/repository/query/QueryMethod.java index a15a9a20a..f1c704f3a 100644 --- a/src/main/java/org/springframework/data/repository/query/QueryMethod.java +++ b/src/main/java/org/springframework/data/repository/query/QueryMethod.java @@ -119,9 +119,7 @@ public class QueryMethod { * @return */ public String getNamedQueryName() { - - Class domainClass = getDomainClass(); - return String.format("%s.%s", domainClass.getSimpleName(), method.getName()); + return String.format("%s.%s", getDomainClass().getSimpleName(), method.getName()); } /** @@ -181,7 +179,7 @@ public class QueryMethod { * * @return */ - public boolean isPageQuery() { + public final boolean isPageQuery() { Class returnType = method.getReturnType(); return org.springframework.util.ClassUtils.isAssignable(Page.class, returnType); diff --git a/src/main/java/org/springframework/data/repository/support/CrudRepositoryInvoker.java b/src/main/java/org/springframework/data/repository/support/CrudRepositoryInvoker.java index 9b928bd7f..b43b70149 100644 --- a/src/main/java/org/springframework/data/repository/support/CrudRepositoryInvoker.java +++ b/src/main/java/org/springframework/data/repository/support/CrudRepositoryInvoker.java @@ -23,7 +23,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.core.CrudMethods; -import org.springframework.data.repository.core.RepositoryInformation; import org.springframework.data.repository.core.RepositoryMetadata; /** @@ -36,7 +35,6 @@ import org.springframework.data.repository.core.RepositoryMetadata; class CrudRepositoryInvoker extends ReflectionRepositoryInvoker { private final CrudRepository repository; - private final CrudMethods crudMethods; private final boolean customSaveMethod; private final boolean customFindOneMethod; @@ -44,7 +42,7 @@ class CrudRepositoryInvoker extends ReflectionRepositoryInvoker { private final boolean customDeleteMethod; /** - * Creates a new {@link CrudRepositoryInvoker} for the given {@link CrudRepository}, {@link RepositoryInformation} and + * Creates a new {@link CrudRepositoryInvoker} for the given {@link CrudRepository}, {@link RepositoryMetadata} and * {@link ConversionService}. * * @param repository must not be {@literal null}. @@ -56,13 +54,13 @@ class CrudRepositoryInvoker extends ReflectionRepositoryInvoker { super(repository, metadata, conversionService); - this.repository = repository; - this.crudMethods = metadata.getCrudMethods(); + CrudMethods crudMethods = metadata.getCrudMethods(); this.customSaveMethod = isRedeclaredMethod(crudMethods.getSaveMethod()); this.customFindOneMethod = isRedeclaredMethod(crudMethods.getFindOneMethod()); this.customDeleteMethod = isRedeclaredMethod(crudMethods.getDeleteMethod()); this.customFindAllMethod = isRedeclaredMethod(crudMethods.getFindAllMethod()); + this.repository = repository; } /* diff --git a/src/main/java/org/springframework/data/repository/support/PagingAndSortingRepositoryInvoker.java b/src/main/java/org/springframework/data/repository/support/PagingAndSortingRepositoryInvoker.java index 16800d32e..dba30d465 100644 --- a/src/main/java/org/springframework/data/repository/support/PagingAndSortingRepositoryInvoker.java +++ b/src/main/java/org/springframework/data/repository/support/PagingAndSortingRepositoryInvoker.java @@ -23,7 +23,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.core.CrudMethods; -import org.springframework.data.repository.core.RepositoryInformation; import org.springframework.data.repository.core.RepositoryMetadata; /** @@ -40,8 +39,8 @@ class PagingAndSortingRepositoryInvoker extends CrudRepositoryInvoker { private final boolean customFindAll; /** - * Creates a new {@link PagingAndSortingRepositoryInvoker} using the given repository, {@link RepositoryInformation} - * and {@link ConversionService}. + * Creates a new {@link PagingAndSortingRepositoryInvoker} using the given repository, {@link RepositoryMetadata} and + * {@link ConversionService}. * * @param repository must not be {@literal null}. * @param metadata must not be {@literal null}. diff --git a/src/main/java/org/springframework/data/repository/support/ReflectionRepositoryInvoker.java b/src/main/java/org/springframework/data/repository/support/ReflectionRepositoryInvoker.java index a0087bbbf..f2a341758 100644 --- a/src/main/java/org/springframework/data/repository/support/ReflectionRepositoryInvoker.java +++ b/src/main/java/org/springframework/data/repository/support/ReflectionRepositoryInvoker.java @@ -27,7 +27,6 @@ import org.springframework.core.convert.TypeDescriptor; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.repository.core.CrudMethods; -import org.springframework.data.repository.core.RepositoryInformation; import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.query.Param; import org.springframework.hateoas.core.AnnotationAttribute; @@ -52,7 +51,7 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker { private final ConversionService conversionService; /** - * Creates a new {@link ReflectionRepositoryInvoker} for the given repository, {@link RepositoryInformation} and + * Creates a new {@link ReflectionRepositoryInvoker} for the given repository, {@link RepositoryMetadata} and * {@link ConversionService}. * * @param repository must not be {@literal null}. diff --git a/src/main/java/org/springframework/data/repository/support/Repositories.java b/src/main/java/org/springframework/data/repository/support/Repositories.java index 9602eea53..5542eb939 100644 --- a/src/main/java/org/springframework/data/repository/support/Repositories.java +++ b/src/main/java/org/springframework/data/repository/support/Repositories.java @@ -43,7 +43,9 @@ import org.springframework.util.ClassUtils; public class Repositories implements Iterable> { static final Repositories NONE = new Repositories(); + private static final RepositoryFactoryInformation EMPTY_REPOSITORY_FACTORY_INFO = EmptyRepositoryFactoryInformation.INSTANCE; + private static final String DOMAIN_TYPE_MUST_NOT_BE_NULL = "Domain type must not be null!"; private final BeanFactory beanFactory; private final Map, String> repositoryBeanNames; @@ -100,7 +102,7 @@ public class Repositories implements Iterable> { */ public boolean hasRepositoryFor(Class domainClass) { - Assert.notNull(domainClass, "Domain class must not be null!"); + Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL); return repositoryFactoryInfos.containsKey(domainClass); } @@ -113,7 +115,7 @@ public class Repositories implements Iterable> { */ public Object getRepositoryFor(Class domainClass) { - Assert.notNull(domainClass, "Domain class must not be null!"); + Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL); String repositoryBeanName = repositoryBeanNames.get(domainClass); return repositoryBeanName == null || beanFactory == null ? null : beanFactory.getBean(repositoryBeanName); @@ -129,7 +131,7 @@ public class Repositories implements Iterable> { */ private RepositoryFactoryInformation getRepositoryFactoryInfoFor(Class domainClass) { - Assert.notNull(domainClass, "Domain class must not be null!"); + Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL); RepositoryFactoryInformation repositoryInfo = repositoryFactoryInfos.get(ClassUtils .getUserClass(domainClass)); @@ -145,7 +147,7 @@ public class Repositories implements Iterable> { @SuppressWarnings("unchecked") public EntityInformation getEntityInformationFor(Class domainClass) { - Assert.notNull(domainClass, "Domain class must not be null!"); + Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL); return (EntityInformation) getRepositoryFactoryInfoFor(domainClass).getEntityInformation(); } @@ -159,7 +161,7 @@ public class Repositories implements Iterable> { */ public RepositoryInformation getRepositoryInformationFor(Class domainClass) { - Assert.notNull(domainClass, "Domain class must not be null!"); + Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL); RepositoryFactoryInformation information = getRepositoryFactoryInfoFor(domainClass); return information == EMPTY_REPOSITORY_FACTORY_INFO ? null : information.getRepositoryInformation(); @@ -175,7 +177,7 @@ public class Repositories implements Iterable> { */ public PersistentEntity getPersistentEntity(Class domainClass) { - Assert.notNull(domainClass, "Domain class must not be null!"); + Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL); return getRepositoryFactoryInfoFor(domainClass).getPersistentEntity(); } @@ -187,7 +189,7 @@ public class Repositories implements Iterable> { */ public List getQueryMethodsFor(Class domainClass) { - Assert.notNull(domainClass, "Domain class must not be null!"); + Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL); return getRepositoryFactoryInfoFor(domainClass).getQueryMethods(); } diff --git a/src/main/java/org/springframework/data/repository/support/RepositoryInvoker.java b/src/main/java/org/springframework/data/repository/support/RepositoryInvoker.java index d0e008249..c779575cc 100644 --- a/src/main/java/org/springframework/data/repository/support/RepositoryInvoker.java +++ b/src/main/java/org/springframework/data/repository/support/RepositoryInvoker.java @@ -21,8 +21,6 @@ import java.util.Map; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; /** * API to invoke (CRUD) methods on Spring Data repository instances independently of the base interface they expose. @@ -35,7 +33,8 @@ import org.springframework.data.repository.PagingAndSortingRepository; public interface RepositoryInvoker extends RepositoryInvocationInformation { /** - * Invokes the method equivalent to {@link CrudRepository#save(Object)} on the repository. + * Invokes the method equivalent to {@link org.springframework.data.repository.CrudRepository#save(Object)} on the + * repository. * * @param object * @return the result of the invocation of the save method @@ -44,7 +43,7 @@ public interface RepositoryInvoker extends RepositoryInvocationInformation { T invokeSave(T object); /** - * Invokes the method equivalent to {@link CrudRepository#findOne(Serializable)}. + * Invokes the method equivalent to {@link org.springframework.data.repository.CrudRepository#findOne(Serializable)}. * * @param id must not be {@literal null}. * @return the entity with the given id. @@ -54,10 +53,12 @@ public interface RepositoryInvoker extends RepositoryInvocationInformation { /** * Invokes the find-all method of the underlying repository using the method taking a {@link Pageable} as parameter if - * available (i.e. the equivalent to {@link PagingAndSortingRepository#findAll(Pageable)}), using the method taking a - * {@link Sort} if available (i.e. the equivalent to {@link PagingAndSortingRepository#findAll(Sort)} by extracting - * the {@link Sort} contained in the given {@link Pageable}) or the plain equivalent to - * {@link CrudRepository#findAll()}. + * available (i.e. the equivalent to + * {@link org.springframework.data.repository.PagingAndSortingRepository#findAll(Pageable)}), using the method taking + * a {@link Sort} if available (i.e. the equivalent to + * {@link org.springframework.data.repository.PagingAndSortingRepository#findAll(Sort)} by extracting the {@link Sort} + * contained in the given {@link Pageable}) or the plain equivalent to + * {@link org.springframework.data.repository.CrudRepository#findAll()}. * * @param pageable can be {@literal null}. * @return the result of the invocation of the find-all method. @@ -67,8 +68,9 @@ public interface RepositoryInvoker extends RepositoryInvocationInformation { /** * Invokes the find-all method of the underlying repository using the method taking a {@link Sort} as parameter if - * available (i.e. the equivalent to {@link PagingAndSortingRepository#findAll(Sort)}) or the plain equivalent to - * {@link CrudRepository#findAll()}. + * available (i.e. the equivalent to + * {@link org.springframework.data.repository.PagingAndSortingRepository#findAll(Sort)}) or the plain equivalent to + * {@link org.springframework.data.repository.CrudRepository#findAll()}. * * @param pageable can be {@literal null}. * @return the result of the invocation of the find-all method. @@ -77,8 +79,8 @@ public interface RepositoryInvoker extends RepositoryInvocationInformation { Iterable invokeFindAll(Sort sort); /** - * Invokes the method equivalent to {@link CrudRepository#delete(Serializable)}. The given id is assumed to be of a - * type convertable into the actual identifier type of the backing repository. + * Invokes the method equivalent to {@link org.springframework.data.repository.CrudRepository#delete(Serializable)}. + * The given id is assumed to be of a type convertable into the actual identifier type of the backing repository. * * @param id must not be {@literal null}. throws {@link IllegalStateException} if the repository does not expose a * delete-method. diff --git a/src/main/java/org/springframework/data/repository/util/QueryExecutionConverters.java b/src/main/java/org/springframework/data/repository/util/QueryExecutionConverters.java index f0104e236..c57c7f7ac 100644 --- a/src/main/java/org/springframework/data/repository/util/QueryExecutionConverters.java +++ b/src/main/java/org/springframework/data/repository/util/QueryExecutionConverters.java @@ -38,14 +38,14 @@ import com.google.common.base.Optional; * @author Oliver Gierke * @since 1.8 */ -public class QueryExecutionConverters { +public abstract class QueryExecutionConverters { private static final boolean GUAVA_PRESENT = ClassUtils.isPresent("com.google.common.base.Optional", QueryExecutionConverters.class.getClassLoader()); private static final boolean JDK_PRESENT = ClassUtils.isPresent("java.util.Optional", QueryExecutionConverters.class.getClassLoader()); - private static Set> WRAPPER_TYPES = new HashSet>(); + private static final Set> WRAPPER_TYPES = new HashSet>(); static { diff --git a/src/main/java/org/springframework/data/util/AnnotationDetectionMethodCallback.java b/src/main/java/org/springframework/data/util/AnnotationDetectionMethodCallback.java index 2c5b46d38..82c1ac6fa 100644 --- a/src/main/java/org/springframework/data/util/AnnotationDetectionMethodCallback.java +++ b/src/main/java/org/springframework/data/util/AnnotationDetectionMethodCallback.java @@ -94,16 +94,16 @@ public class AnnotationDetectionMethodCallback implements return; } - A annotation = AnnotationUtils.findAnnotation(method, annotationType); + A foundAnnotation = AnnotationUtils.findAnnotation(method, annotationType); - if (annotation != null) { + if (foundAnnotation != null) { if (foundMethod != null && enforceUniqueness) { - throw new IllegalStateException(String.format(MULTIPLE_FOUND, annotation.getClass().getName(), foundMethod, + throw new IllegalStateException(String.format(MULTIPLE_FOUND, foundAnnotation.getClass().getName(), foundMethod, method)); } - this.annotation = annotation; + this.annotation = foundAnnotation; this.foundMethod = method; } } diff --git a/src/main/java/org/springframework/data/util/DirectFieldAccessFallbackBeanWrapper.java b/src/main/java/org/springframework/data/util/DirectFieldAccessFallbackBeanWrapper.java index 5234559ca..28f1710b9 100644 --- a/src/main/java/org/springframework/data/util/DirectFieldAccessFallbackBeanWrapper.java +++ b/src/main/java/org/springframework/data/util/DirectFieldAccessFallbackBeanWrapper.java @@ -77,7 +77,7 @@ public class DirectFieldAccessFallbackBeanWrapper extends BeanWrapperImpl { if (field == null) { throw new NotWritablePropertyException(getWrappedClass(), propertyName, - "Could not find field for property during fallback access!"); + "Could not find field for property during fallback access!", e); } makeAccessible(field); diff --git a/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java b/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java index 61e0554fb..01a0a2647 100644 --- a/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java +++ b/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java @@ -200,15 +200,15 @@ class ParameterizedTypeInformation extends ParentTypeAwareTypeInformation return resolved; } - Type[] types = type.getActualTypeArguments(); + Type[] typeArguments = type.getActualTypeArguments(); - if (types.length == 0) { + if (typeArguments.length == 0) { return cacheAndReturn(false); } - for (Type type : types) { + for (Type typeArgument : typeArguments) { - TypeInformation info = createInfo(type); + TypeInformation info = createInfo(typeArgument); if (info instanceof ParameterizedTypeInformation) { if (!((ParameterizedTypeInformation) info).isResolvedCompletely()) { diff --git a/src/main/java/org/springframework/data/util/ReflectionUtils.java b/src/main/java/org/springframework/data/util/ReflectionUtils.java index b1255f5eb..3570c9aa9 100644 --- a/src/main/java/org/springframework/data/util/ReflectionUtils.java +++ b/src/main/java/org/springframework/data/util/ReflectionUtils.java @@ -32,7 +32,7 @@ import org.springframework.util.ReflectionUtils.FieldFilter; * @author Oliver Gierke * @since 1.5 */ -public class ReflectionUtils { +public abstract class ReflectionUtils { private ReflectionUtils() {} diff --git a/src/main/java/org/springframework/data/util/TypeDiscoverer.java b/src/main/java/org/springframework/data/util/TypeDiscoverer.java index 28aac5766..04cf28818 100644 --- a/src/main/java/org/springframework/data/util/TypeDiscoverer.java +++ b/src/main/java/org/springframework/data/util/TypeDiscoverer.java @@ -159,8 +159,8 @@ class TypeDiscoverer implements TypeInformation { Assert.notNull(constructor); List> result = new ArrayList>(); - for (Type type : constructor.getGenericParameterTypes()) { - result.add(createInfo(type)); + for (Type parameterType : constructor.getGenericParameterTypes()) { + result.add(createInfo(parameterType)); } return result; @@ -201,14 +201,14 @@ class TypeDiscoverer implements TypeInformation { */ private TypeInformation getPropertyInformation(String fieldname) { - Class type = getType(); - Field field = ReflectionUtils.findField(type, fieldname); + Class rawType = getType(); + Field field = ReflectionUtils.findField(rawType, fieldname); if (field != null) { return createInfo(field.getGenericType()); } - PropertyDescriptor descriptor = findPropertyDescriptor(type, fieldname); + PropertyDescriptor descriptor = findPropertyDescriptor(rawType, fieldname); return descriptor == null ? null : createInfo(getGenericType(descriptor)); } @@ -417,8 +417,8 @@ class TypeDiscoverer implements TypeInformation { Type[] parameterTypes = method.getGenericParameterTypes(); List> result = new ArrayList>(parameterTypes.length); - for (Type type : parameterTypes) { - result.add(createInfo(type)); + for (Type parameterType : parameterTypes) { + result.add(createInfo(parameterType)); } return result; @@ -430,9 +430,9 @@ class TypeDiscoverer implements TypeInformation { */ public TypeInformation getSuperTypeInformation(Class superType) { - Class type = getType(); + Class rawType = getType(); - if (!superType.isAssignableFrom(type)) { + if (!superType.isAssignableFrom(rawType)) { return null; } @@ -442,11 +442,11 @@ class TypeDiscoverer implements TypeInformation { List candidates = new ArrayList(); - Type genericSuperclass = type.getGenericSuperclass(); + Type genericSuperclass = rawType.getGenericSuperclass(); if (genericSuperclass != null) { candidates.add(genericSuperclass); } - candidates.addAll(Arrays.asList(type.getGenericInterfaces())); + candidates.addAll(Arrays.asList(rawType.getGenericInterfaces())); for (Type candidate : candidates) { diff --git a/src/main/java/org/springframework/data/web/SpringDataAnnotationUtils.java b/src/main/java/org/springframework/data/web/SpringDataAnnotationUtils.java index 1bcbc4552..0a4905913 100644 --- a/src/main/java/org/springframework/data/web/SpringDataAnnotationUtils.java +++ b/src/main/java/org/springframework/data/web/SpringDataAnnotationUtils.java @@ -32,7 +32,7 @@ import org.springframework.util.ObjectUtils; * * @author Oliver Gierke */ -class SpringDataAnnotationUtils { +abstract class SpringDataAnnotationUtils { private SpringDataAnnotationUtils() {}