DATACMNS-558 - Some code cleanups according to the Sonar report.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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}).
|
||||
|
||||
@@ -74,7 +74,7 @@ public class SliceImpl<T> extends Chunk<T> {
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -175,10 +175,10 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> 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()) {
|
||||
|
||||
@@ -69,9 +69,9 @@ public class PreferredConstructorDiscoverer<T, P extends PersistentProperty<P>>
|
||||
int numberOfArgConstructors = 0;
|
||||
Class<?> rawOwningType = type.getType();
|
||||
|
||||
for (Constructor<?> constructor : rawOwningType.getDeclaredConstructors()) {
|
||||
for (Constructor<?> candidate : rawOwningType.getDeclaredConstructors()) {
|
||||
|
||||
PreferredConstructor<T, P> preferredConstructor = buildPreferredConstructor(constructor, type, entity);
|
||||
PreferredConstructor<T, P> preferredConstructor = buildPreferredConstructor(candidate, type, entity);
|
||||
|
||||
// Explicitly defined constructor trumps all
|
||||
if (preferredConstructor.isExplicitlyAnnotated()) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<RepositoryInformationCacheKey, RepositoryInformation> REPOSITORY_INFORMATION_CACHE = new HashMap<RepositoryInformationCacheKey, RepositoryInformation>();
|
||||
|
||||
private final Map<RepositoryInformationCacheKey, RepositoryInformation> repositoryInformationCache = new HashMap<RepositoryInformationCacheKey, RepositoryInformation>();
|
||||
private final List<RepositoryProxyPostProcessor> postProcessors = new ArrayList<RepositoryProxyPostProcessor>();
|
||||
|
||||
private QueryLookupStrategy.Key queryLookupStrategyKey;
|
||||
private List<QueryCreationListener<?>> queryPostProcessors = new ArrayList<QueryCreationListener<?>>();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
* <p>
|
||||
* 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<String, Method> accessors;
|
||||
private final Collection<Method> 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);
|
||||
|
||||
@@ -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<Object> NULL_OBJECT = new AsyncResult<Object>(null);
|
||||
private static final AsyncResult<Object> NULL_OBJECT = new AsyncResult<Object>(null);
|
||||
|
||||
/**
|
||||
* Creates a new {@link NullableWrapperToFutureConverter} using the given {@link ConversionService}.
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class CachingIsNewStrategyFactory implements IsNewStrategyFactory {
|
||||
|
||||
private final Map<Class<?>, IsNewStrategy> CACHE = new ConcurrentHashMap<Class<?>, IsNewStrategy>();
|
||||
private final Map<Class<?>, IsNewStrategy> cache = new ConcurrentHashMap<Class<?>, 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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}.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
* <ul>
|
||||
* <li>{@link DomainClassConverter} - to allow usage of domain types managed by Spring Data repositories as controller
|
||||
* method arguments bound with {@link PathVariable} or {@link RequestParam}.</li>
|
||||
* <li>{@link PageableHandlerMethodArgumentResolver} - to allow injection of {@link Pageable} instances into controller
|
||||
* methods automatically created from request parameters.</li>
|
||||
* <li>{@link SortHandlerMethodArgumentResolver} - to allow injection of {@link Sort} instances into controller methods
|
||||
* automatically created from request parameters.</li>
|
||||
* <li>{@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}.</li>
|
||||
* <li>{@link PageableHandlerMethodArgumentResolver} - to allow injection of
|
||||
* {@link org.springframework.data.domain.Pageable} instances into controller methods automatically created from request
|
||||
* parameters.</li>
|
||||
* <li>{@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.</li>
|
||||
* </ul>
|
||||
* If Spring HATEOAS is present on the classpath we will register the following beans:
|
||||
* <ul>
|
||||
* <li>{@link HateoasPageableHandlerMethodArgumentResolver} - instead of {@link PageableHandlerMethodArgumentResolver}</li>
|
||||
* <li>{@link HateoasSortHandlerMethodArgumentResolver} - instead of {@link SortHandlerMethodArgumentResolver}</li>
|
||||
* <li>{@link PagedResourcesAssembler} - for injection into web components</li>
|
||||
* <li>{@link PagedResourcesAssemblerArgumentResolver} - for injection of {@link PagedResourcesAssembler} into
|
||||
* controller methods</li>
|
||||
* <li>{@link org.springframework.data.web.HateoasPageableHandlerMethodArgumentResolver} - instead of
|
||||
* {@link PageableHandlerMethodArgumentResolver}</li>
|
||||
* <li>{@link org.springframework.data.web.HateoasSortHandlerMethodArgumentResolver} - instead of
|
||||
* {@link org.springframework.data.web.SortHandlerMethodArgumentResolver}</li>
|
||||
* <li>{@link org.springframework.data.web.PagedResourcesAssembler} - for injection into web components</li>
|
||||
* <li>{@link org.springframework.data.web.SortHandlerMethodArgumentResolver} - for injection of
|
||||
* {@link org.springframework.data.web.PagedResourcesAssembler} into controller methods</li>
|
||||
* <ul>
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user