diff --git a/src/main/java/org/springframework/data/auditing/AuditableBeanWrapperFactory.java b/src/main/java/org/springframework/data/auditing/AuditableBeanWrapperFactory.java index 54b1bb506..7fea361e4 100644 --- a/src/main/java/org/springframework/data/auditing/AuditableBeanWrapperFactory.java +++ b/src/main/java/org/springframework/data/auditing/AuditableBeanWrapperFactory.java @@ -117,7 +117,7 @@ class AuditableBeanWrapperFactory { */ static abstract class DateConvertingAuditableBeanWrapper implements AuditableBeanWrapper { - private static boolean IS_JODA_TIME_PRESENT = ClassUtils.isPresent("org.joda.time.DateTime", + private static final boolean IS_JODA_TIME_PRESENT = ClassUtils.isPresent("org.joda.time.DateTime", ReflectionAuditingBeanWrapper.class.getClassLoader()); private final ConversionService conversionService; diff --git a/src/main/java/org/springframework/data/convert/CollectionFactory.java b/src/main/java/org/springframework/data/convert/CollectionFactory.java index 67fcce6e8..28591a04a 100644 --- a/src/main/java/org/springframework/data/convert/CollectionFactory.java +++ b/src/main/java/org/springframework/data/convert/CollectionFactory.java @@ -30,6 +30,8 @@ import org.springframework.util.Assert; */ public class CollectionFactory { + private CollectionFactory() {} + /** * Creates a new collection instance for the given collection type. Might also inspect the element type in case * special collections are requested (e.g. {@link EnumSet}). diff --git a/src/main/java/org/springframework/data/domain/SliceImpl.java b/src/main/java/org/springframework/data/domain/SliceImpl.java index d66a9229a..2b957fe59 100644 --- a/src/main/java/org/springframework/data/domain/SliceImpl.java +++ b/src/main/java/org/springframework/data/domain/SliceImpl.java @@ -74,7 +74,7 @@ public class SliceImpl extends Chunk { contentType = content.get(0).getClass().getName(); } - return String.format("Slice %s of %d containing %s instances", getNumber(), contentType); + return String.format("Slice %d containing %s instances", getNumber(), contentType); } /* 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 e0e4a4244..5db6a9a65 100644 --- a/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java +++ b/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java @@ -175,10 +175,10 @@ public class BasicPersistentEntity> implement propertyCache.put(property.getName(), property); } - P idProperty = returnPropertyIfBetterIdPropertyCandidateOrNull(property); + P candidate = returnPropertyIfBetterIdPropertyCandidateOrNull(property); - if (idProperty != null) { - this.idProperty = idProperty; + if (candidate != null) { + this.idProperty = candidate; } if (property.isVersionProperty()) { diff --git a/src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java b/src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java index 9973c8d75..0f089b18d 100644 --- a/src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java +++ b/src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java @@ -69,9 +69,9 @@ public class PreferredConstructorDiscoverer> int numberOfArgConstructors = 0; Class rawOwningType = type.getType(); - for (Constructor constructor : rawOwningType.getDeclaredConstructors()) { + for (Constructor candidate : rawOwningType.getDeclaredConstructors()) { - PreferredConstructor preferredConstructor = buildPreferredConstructor(constructor, type, entity); + PreferredConstructor preferredConstructor = buildPreferredConstructor(candidate, type, entity); // Explicitly defined constructor trumps all if (preferredConstructor.isExplicitlyAnnotated()) { diff --git a/src/main/java/org/springframework/data/mapping/model/SimpleTypeHolder.java b/src/main/java/org/springframework/data/mapping/model/SimpleTypeHolder.java index 7a4e24a77..dab3f9ece 100644 --- a/src/main/java/org/springframework/data/mapping/model/SimpleTypeHolder.java +++ b/src/main/java/org/springframework/data/mapping/model/SimpleTypeHolder.java @@ -115,15 +115,19 @@ public class SimpleTypeHolder { * @return */ public boolean isSimpleType(Class type) { + Assert.notNull(type); + if (Object.class.equals(type)) { return true; } + for (Class clazz : simpleTypes) { - if (type == clazz || clazz.isAssignableFrom(type)) { + if (clazz.isAssignableFrom(type)) { return true; } } + return false; } } diff --git a/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtensionSupport.java b/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtensionSupport.java index 24e86773a..25b553a69 100644 --- a/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtensionSupport.java +++ b/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtensionSupport.java @@ -264,7 +264,7 @@ public abstract class RepositoryConfigurationExtensionSupport implements Reposit * @param loader must not be {@literal null}. * @return the repository interface or {@literal null} if it can't be loaded. */ - private static Class loadRepositoryInterface(RepositoryConfiguration configuration, ResourceLoader loader) { + private Class loadRepositoryInterface(RepositoryConfiguration configuration, ResourceLoader loader) { String repositoryInterface = configuration.getRepositoryInterface(); ClassLoader classLoader = loader.getClassLoader(); @@ -272,9 +272,9 @@ public abstract class RepositoryConfigurationExtensionSupport implements Reposit try { return org.springframework.util.ClassUtils.forName(repositoryInterface, classLoader); } catch (ClassNotFoundException e) { - LOGGER.warn(String.format(CLASS_LOADING_ERROR, repositoryInterface, classLoader), e); + LOGGER.warn(String.format(CLASS_LOADING_ERROR, getModuleName(), repositoryInterface, classLoader), e); } catch (LinkageError e) { - LOGGER.warn(String.format(CLASS_LOADING_ERROR, repositoryInterface, classLoader), e); + LOGGER.warn(String.format(CLASS_LOADING_ERROR, getModuleName(), repositoryInterface, classLoader), e); } return null; 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 58b40c288..7d30c4e89 100644 --- a/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationUtils.java +++ b/src/main/java/org/springframework/data/repository/config/RepositoryConfigurationUtils.java @@ -30,6 +30,8 @@ import org.springframework.util.Assert; */ public class RepositoryConfigurationUtils { + private RepositoryConfigurationUtils() {} + /** * Registeres the given {@link RepositoryConfigurationExtension} to indicate the repository configuration for a * particular store (expressed through the extension's concrete type) has appened. Useful for downstream components diff --git a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java index 19a1a5ee5..29299f885 100644 --- a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java +++ b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java @@ -67,9 +67,9 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware { private static final boolean IS_JAVA_8 = org.springframework.util.ClassUtils.isPresent("java.util.Optional", RepositoryFactorySupport.class.getClassLoader()); - private final Map REPOSITORY_INFORMATION_CACHE = new HashMap(); - + private final Map repositoryInformationCache = new HashMap(); private final List postProcessors = new ArrayList(); + private QueryLookupStrategy.Key queryLookupStrategyKey; private List> queryPostProcessors = new ArrayList>(); private NamedQueries namedQueries = PropertiesBasedNamedQueries.EMPTY; @@ -215,7 +215,7 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware { Class customImplementationClass) { RepositoryInformationCacheKey cacheKey = new RepositoryInformationCacheKey(metadata, customImplementationClass); - RepositoryInformation repositoryInformation = REPOSITORY_INFORMATION_CACHE.get(cacheKey); + RepositoryInformation repositoryInformation = repositoryInformationCache.get(cacheKey); if (repositoryInformation != null) { return repositoryInformation; @@ -223,7 +223,7 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware { repositoryInformation = new DefaultRepositoryInformation(metadata, getRepositoryBaseClass(metadata), customImplementationClass); - REPOSITORY_INFORMATION_CACHE.put(cacheKey, repositoryInformation); + repositoryInformationCache.put(cacheKey, repositoryInformation); return repositoryInformation; } diff --git a/src/main/java/org/springframework/data/repository/query/EvaluationContextExtensionInformation.java b/src/main/java/org/springframework/data/repository/query/EvaluationContextExtensionInformation.java index 71d2cf31b..4abf9a38a 100644 --- a/src/main/java/org/springframework/data/repository/query/EvaluationContextExtensionInformation.java +++ b/src/main/java/org/springframework/data/repository/query/EvaluationContextExtensionInformation.java @@ -31,7 +31,6 @@ import org.springframework.beans.BeanUtils; import org.springframework.data.repository.query.EvaluationContextExtensionInformation.ExtensionTypeInformation.PublicMethodAndFieldFilter; import org.springframework.data.repository.query.spi.EvaluationContextExtension; import org.springframework.data.repository.query.spi.Function; -import org.springframework.expression.EvaluationContext; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils.FieldCallback; @@ -46,7 +45,7 @@ import org.springframework.util.ReflectionUtils.MethodFilter; *

* The type basically allows us to cache the type based information within * {@link ExtensionAwareEvaluationContextProvider} to avoid repeated reflection lookups for every creation of an - * {@link EvaluationContext}. + * {@link org.springframework.expression.EvaluationContext}. * * @author Oliver Gierke * @since 1.9 @@ -161,8 +160,8 @@ class EvaluationContextExtensionInformation { static class PublicMethodAndFieldFilter implements MethodFilter, FieldFilter { - public static PublicMethodAndFieldFilter STATIC = new PublicMethodAndFieldFilter(true); - public static PublicMethodAndFieldFilter NON_STATIC = new PublicMethodAndFieldFilter(false); + public static final PublicMethodAndFieldFilter STATIC = new PublicMethodAndFieldFilter(true); + public static final PublicMethodAndFieldFilter NON_STATIC = new PublicMethodAndFieldFilter(false); private final boolean staticOnly; @@ -197,10 +196,6 @@ class EvaluationContextExtensionInformation { @Override public boolean matches(Field field) { - if (field.getDeclaringClass().equals(Object.class)) { - - } - boolean fieldStatic = Modifier.isStatic(field.getModifiers()); boolean staticMatch = staticOnly ? fieldStatic : !fieldStatic; @@ -214,9 +209,9 @@ class EvaluationContextExtensionInformation { * * @author Oliver Gierke */ - public static class RootObjectInformation { + static class RootObjectInformation { - static RootObjectInformation NONE = new RootObjectInformation(Object.class); + private static final RootObjectInformation NONE = new RootObjectInformation(Object.class); private final Map accessors; private final Collection methods; @@ -245,7 +240,7 @@ class EvaluationContextExtensionInformation { ReflectionUtils.doWithMethods(type, new MethodCallback() { @Override - public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { + public void doWith(Method method) { RootObjectInformation.this.methods.add(method); @@ -260,7 +255,7 @@ class EvaluationContextExtensionInformation { ReflectionUtils.doWithFields(type, new FieldCallback() { @Override - public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { + public void doWith(Field field) { RootObjectInformation.this.fields.add(field); } }, PublicMethodAndFieldFilter.NON_STATIC); @@ -321,7 +316,7 @@ class EvaluationContextExtensionInformation { ReflectionUtils.doWithFields(type, new FieldCallback() { @Override - public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { + public void doWith(Field field) throws IllegalAccessException { map.put(field.getName(), field.get(null)); } }, filter); 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 4b21eee09..f0104e236 100644 --- a/src/main/java/org/springframework/data/repository/util/QueryExecutionConverters.java +++ b/src/main/java/org/springframework/data/repository/util/QueryExecutionConverters.java @@ -60,6 +60,8 @@ public class QueryExecutionConverters { } } + private QueryExecutionConverters() {} + /** * Returns whether the given type is a supported wrapper type. * @@ -243,7 +245,7 @@ public class QueryExecutionConverters { */ private static class NullableWrapperToFutureConverter extends AbstractWrapperTypeConverter { - private final AsyncResult NULL_OBJECT = new AsyncResult(null); + private static final AsyncResult NULL_OBJECT = new AsyncResult(null); /** * Creates a new {@link NullableWrapperToFutureConverter} using the given {@link ConversionService}. diff --git a/src/main/java/org/springframework/data/support/CachingIsNewStrategyFactory.java b/src/main/java/org/springframework/data/support/CachingIsNewStrategyFactory.java index cc7db2c96..6ee9949a1 100644 --- a/src/main/java/org/springframework/data/support/CachingIsNewStrategyFactory.java +++ b/src/main/java/org/springframework/data/support/CachingIsNewStrategyFactory.java @@ -28,7 +28,7 @@ import org.springframework.util.Assert; */ public class CachingIsNewStrategyFactory implements IsNewStrategyFactory { - private final Map, IsNewStrategy> CACHE = new ConcurrentHashMap, IsNewStrategy>(); + private final Map, IsNewStrategy> cache = new ConcurrentHashMap, IsNewStrategy>(); private final IsNewStrategyFactory delegate; /** @@ -48,7 +48,7 @@ public class CachingIsNewStrategyFactory implements IsNewStrategyFactory { */ public IsNewStrategy getIsNewStrategy(Class type) { - IsNewStrategy strategy = CACHE.get(type); + IsNewStrategy strategy = cache.get(type); if (strategy != null) { return strategy; @@ -56,7 +56,7 @@ public class CachingIsNewStrategyFactory implements IsNewStrategyFactory { IsNewStrategy isNewStrategy = delegate.getIsNewStrategy(type); - CACHE.put(type, isNewStrategy); + cache.put(type, isNewStrategy); return isNewStrategy; } } diff --git a/src/main/java/org/springframework/data/util/ReflectionUtils.java b/src/main/java/org/springframework/data/util/ReflectionUtils.java index b1028e707..b1255f5eb 100644 --- a/src/main/java/org/springframework/data/util/ReflectionUtils.java +++ b/src/main/java/org/springframework/data/util/ReflectionUtils.java @@ -34,6 +34,8 @@ import org.springframework.util.ReflectionUtils.FieldFilter; */ public class ReflectionUtils { + private ReflectionUtils() {} + /** * Creates an instance of the class with the given fully qualified name or returns the given default instance if the * class cannot be loaded or instantiated. diff --git a/src/main/java/org/springframework/data/web/SpringDataAnnotationUtils.java b/src/main/java/org/springframework/data/web/SpringDataAnnotationUtils.java index 552676b88..1bcbc4552 100644 --- a/src/main/java/org/springframework/data/web/SpringDataAnnotationUtils.java +++ b/src/main/java/org/springframework/data/web/SpringDataAnnotationUtils.java @@ -34,6 +34,8 @@ import org.springframework.util.ObjectUtils; */ class SpringDataAnnotationUtils { + private SpringDataAnnotationUtils() {} + /** * Asserts uniqueness of all {@link Pageable} parameters of the method of the given {@link MethodParameter}. * diff --git a/src/main/java/org/springframework/data/web/config/EnableSpringDataWebSupport.java b/src/main/java/org/springframework/data/web/config/EnableSpringDataWebSupport.java index 0c9e7e28b..0a8e3e27e 100644 --- a/src/main/java/org/springframework/data/web/config/EnableSpringDataWebSupport.java +++ b/src/main/java/org/springframework/data/web/config/EnableSpringDataWebSupport.java @@ -26,38 +26,33 @@ import java.util.List; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.ImportSelector; import org.springframework.core.type.AnnotationMetadata; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.data.repository.support.DomainClassConverter; -import org.springframework.data.web.HateoasPageableHandlerMethodArgumentResolver; -import org.springframework.data.web.HateoasSortHandlerMethodArgumentResolver; import org.springframework.data.web.PageableHandlerMethodArgumentResolver; -import org.springframework.data.web.PagedResourcesAssembler; -import org.springframework.data.web.PagedResourcesAssemblerArgumentResolver; -import org.springframework.data.web.SortHandlerMethodArgumentResolver; import org.springframework.util.ClassUtils; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; /** * Annotation to automatically register the following beans for usage with Spring MVC. Note that using this annotation * will require Spring 3.2. *
    - *
  • {@link DomainClassConverter} - to allow usage of domain types managed by Spring Data repositories as controller - * method arguments bound with {@link PathVariable} or {@link RequestParam}.
  • - *
  • {@link PageableHandlerMethodArgumentResolver} - to allow injection of {@link Pageable} instances into controller - * methods automatically created from request parameters.
  • - *
  • {@link SortHandlerMethodArgumentResolver} - to allow injection of {@link Sort} instances into controller methods - * automatically created from request parameters.
  • + *
  • {@link org.springframework.data.repository.support.DomainClassConverter} - to allow usage of domain types managed + * by Spring Data repositories as controller method arguments bound with + * {@link org.springframework.web.bind.annotation.PathVariable} or + * {@link org.springframework.web.bind.annotation.RequestParam}.
  • + *
  • {@link PageableHandlerMethodArgumentResolver} - to allow injection of + * {@link org.springframework.data.domain.Pageable} instances into controller methods automatically created from request + * parameters.
  • + *
  • {@link org.springframework.data.web.SortHandlerMethodArgumentResolver} - to allow injection of + * {@link org.springframework.data.domain.Sort} instances into controller methods automatically created from request + * parameters.
  • *
* If Spring HATEOAS is present on the classpath we will register the following beans: *
    - *
  • {@link HateoasPageableHandlerMethodArgumentResolver} - instead of {@link PageableHandlerMethodArgumentResolver}
  • - *
  • {@link HateoasSortHandlerMethodArgumentResolver} - instead of {@link SortHandlerMethodArgumentResolver}
  • - *
  • {@link PagedResourcesAssembler} - for injection into web components
  • - *
  • {@link PagedResourcesAssemblerArgumentResolver} - for injection of {@link PagedResourcesAssembler} into - * controller methods
  • + *
  • {@link org.springframework.data.web.HateoasPageableHandlerMethodArgumentResolver} - instead of + * {@link PageableHandlerMethodArgumentResolver}
  • + *
  • {@link org.springframework.data.web.HateoasSortHandlerMethodArgumentResolver} - instead of + * {@link org.springframework.data.web.SortHandlerMethodArgumentResolver}
  • + *
  • {@link org.springframework.data.web.PagedResourcesAssembler} - for injection into web components
  • + *
  • {@link org.springframework.data.web.SortHandlerMethodArgumentResolver} - for injection of + * {@link org.springframework.data.web.PagedResourcesAssembler} into controller methods
  • *
      * * @since 1.6 @@ -74,7 +69,8 @@ public @interface EnableSpringDataWebSupport { /** * Import selector to import the appropriate configuration class depending on whether Spring HATEOAS is present on the * classpath. We need to register the HATEOAS specific class first as apparently only the first class implementing - * {@link WebMvcConfigurationSupport} gets callbacks invoked (see https://jira.springsource.org/browse/SPR-10565). + * {@link org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport} gets callbacks invoked (see + * https://jira.springsource.org/browse/SPR-10565). * * @author Oliver Gierke */