Browse Source

DATACMNS-558 - Some code cleanups according to the Sonar report.

1.8.x
Oliver Gierke 12 years ago
parent
commit
e62391f825
  1. 2
      src/main/java/org/springframework/data/auditing/AuditableBeanWrapperFactory.java
  2. 2
      src/main/java/org/springframework/data/convert/CollectionFactory.java
  3. 2
      src/main/java/org/springframework/data/domain/SliceImpl.java
  4. 6
      src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java
  5. 6
      src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java
  6. 6
      src/main/java/org/springframework/data/mapping/model/SimpleTypeHolder.java
  7. 8
      src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java
  8. 4
      src/main/java/org/springframework/data/repository/util/QueryExecutionConverters.java
  9. 6
      src/main/java/org/springframework/data/support/CachingIsNewStrategyFactory.java
  10. 2
      src/main/java/org/springframework/data/util/ReflectionUtils.java
  11. 2
      src/main/java/org/springframework/data/web/SpringDataAnnotationUtils.java
  12. 42
      src/main/java/org/springframework/data/web/config/EnableSpringDataWebSupport.java

2
src/main/java/org/springframework/data/auditing/AuditableBeanWrapperFactory.java

@ -117,7 +117,7 @@ class AuditableBeanWrapperFactory { @@ -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;

2
src/main/java/org/springframework/data/convert/CollectionFactory.java

@ -30,6 +30,8 @@ import org.springframework.util.Assert; @@ -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}).

2
src/main/java/org/springframework/data/domain/SliceImpl.java

@ -74,7 +74,7 @@ public class SliceImpl<T> extends Chunk<T> { @@ -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);
}
/*

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

@ -175,10 +175,10 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement @@ -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()) {

6
src/main/java/org/springframework/data/mapping/model/PreferredConstructorDiscoverer.java

@ -73,9 +73,9 @@ public class PreferredConstructorDiscoverer<T, P extends PersistentProperty<P>> @@ -73,9 +73,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()) {
@ -135,4 +135,4 @@ public class PreferredConstructorDiscoverer<T, P extends PersistentProperty<P>> @@ -135,4 +135,4 @@ public class PreferredConstructorDiscoverer<T, P extends PersistentProperty<P>>
public PreferredConstructor<T, P> getConstructor() {
return constructor;
}
}
}

6
src/main/java/org/springframework/data/mapping/model/SimpleTypeHolder.java

@ -115,15 +115,19 @@ public class SimpleTypeHolder { @@ -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;
}
}

8
src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java

@ -60,9 +60,9 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware { @@ -60,9 +60,9 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware {
private static final TypeDescriptor WRAPPER_TYPE = TypeDescriptor.valueOf(NullableWrapper.class);
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;
@ -193,7 +193,7 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware { @@ -193,7 +193,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;
@ -201,7 +201,7 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware { @@ -201,7 +201,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;
}

4
src/main/java/org/springframework/data/repository/util/QueryExecutionConverters.java

@ -60,6 +60,8 @@ public class QueryExecutionConverters { @@ -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 { @@ -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}.

6
src/main/java/org/springframework/data/support/CachingIsNewStrategyFactory.java

@ -28,7 +28,7 @@ import org.springframework.util.Assert; @@ -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 { @@ -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 { @@ -56,7 +56,7 @@ public class CachingIsNewStrategyFactory implements IsNewStrategyFactory {
IsNewStrategy isNewStrategy = delegate.getIsNewStrategy(type);
CACHE.put(type, isNewStrategy);
cache.put(type, isNewStrategy);
return isNewStrategy;
}
}

2
src/main/java/org/springframework/data/util/ReflectionUtils.java

@ -32,6 +32,8 @@ import org.springframework.util.ReflectionUtils.FieldFilter; @@ -32,6 +32,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.

2
src/main/java/org/springframework/data/web/SpringDataAnnotationUtils.java

@ -34,6 +34,8 @@ import org.springframework.util.ObjectUtils; @@ -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}.
*

42
src/main/java/org/springframework/data/web/config/EnableSpringDataWebSupport.java

@ -26,38 +26,33 @@ import java.util.List; @@ -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 { @@ -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
*/

Loading…
Cancel
Save