DATACMNS-601 - Fixes for most of the SonarQube warnings.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<TypeInformation<?>, EntityInstantiator> entityInstantiators = new HashMap<TypeInformation<?>, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class CollectionFactory {
|
||||
public abstract class CollectionFactory {
|
||||
|
||||
private CollectionFactory() {}
|
||||
|
||||
|
||||
@@ -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<String, ClassTypeInformation<?>> cache = new ConcurrentHashMap<String, ClassTypeInformation<?>>();
|
||||
private static final Map<String, ClassTypeInformation<?>> CACHE = new ConcurrentHashMap<String, ClassTypeInformation<?>>();
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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<T> extends PageImpl<GeoResult<T>> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -69,15 +69,15 @@ public class PropertyPath implements Iterable<PropertyPath> {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ class DefaultPersistentPropertyPath<T extends PersistentProperty<T>> implements
|
||||
return this;
|
||||
}
|
||||
|
||||
List<T> properties = new ArrayList<T>();
|
||||
List<T> result = new ArrayList<T>();
|
||||
Iterator<T> iterator = iterator();
|
||||
|
||||
for (int i = 0; i < base.getLength(); i++) {
|
||||
@@ -166,10 +166,10 @@ class DefaultPersistentPropertyPath<T extends PersistentProperty<T>> implements
|
||||
}
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
properties.add(iterator.next());
|
||||
result.add(iterator.next());
|
||||
}
|
||||
|
||||
return new DefaultPersistentPropertyPath<T>(properties);
|
||||
return new DefaultPersistentPropertyPath<T>(result);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -158,9 +158,10 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
|
||||
@Override
|
||||
public boolean isTransient() {
|
||||
|
||||
if (isTransient == null) {
|
||||
boolean isTransient = super.isTransient() || isAnnotationPresent(Transient.class);
|
||||
this.isTransient = isTransient || isAnnotationPresent(Value.class) || isAnnotationPresent(Autowired.class);
|
||||
if (this.isTransient == null) {
|
||||
boolean potentiallyTransient = super.isTransient() || isAnnotationPresent(Transient.class);
|
||||
this.isTransient = potentiallyTransient || isAnnotationPresent(Value.class)
|
||||
|| isAnnotationPresent(Autowired.class);
|
||||
}
|
||||
|
||||
return this.isTransient;
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -40,7 +39,8 @@ public class BeanWrapper<T> 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 <T> BeanWrapper<T> create(T bean, ConversionService conversionService) {
|
||||
|
||||
@@ -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<T> {
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class RepositoryConfigurationUtils {
|
||||
public abstract class RepositoryConfigurationUtils {
|
||||
|
||||
private RepositoryConfigurationUtils() {}
|
||||
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -253,7 +253,7 @@ public abstract class Parameters<S extends Parameters<S, T>, T extends Parameter
|
||||
*
|
||||
* @param method
|
||||
*/
|
||||
private void assertEitherAllParamAnnotatedOrNone() {
|
||||
private final void assertEitherAllParamAnnotatedOrNone() {
|
||||
|
||||
boolean nameFound = false;
|
||||
int index = 0;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Object, Serializable> 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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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}.
|
||||
|
||||
@@ -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}.
|
||||
|
||||
@@ -43,7 +43,9 @@ import org.springframework.util.ClassUtils;
|
||||
public class Repositories implements Iterable<Class<?>> {
|
||||
|
||||
static final Repositories NONE = new Repositories();
|
||||
|
||||
private static final RepositoryFactoryInformation<Object, Serializable> 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<Class<?>, String> repositoryBeanNames;
|
||||
@@ -100,7 +102,7 @@ public class Repositories implements Iterable<Class<?>> {
|
||||
*/
|
||||
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<Class<?>> {
|
||||
*/
|
||||
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<Class<?>> {
|
||||
*/
|
||||
private RepositoryFactoryInformation<Object, Serializable> getRepositoryFactoryInfoFor(Class<?> domainClass) {
|
||||
|
||||
Assert.notNull(domainClass, "Domain class must not be null!");
|
||||
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
|
||||
|
||||
RepositoryFactoryInformation<Object, Serializable> repositoryInfo = repositoryFactoryInfos.get(ClassUtils
|
||||
.getUserClass(domainClass));
|
||||
@@ -145,7 +147,7 @@ public class Repositories implements Iterable<Class<?>> {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T, S extends Serializable> EntityInformation<T, S> getEntityInformationFor(Class<?> domainClass) {
|
||||
|
||||
Assert.notNull(domainClass, "Domain class must not be null!");
|
||||
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
|
||||
|
||||
return (EntityInformation<T, S>) getRepositoryFactoryInfoFor(domainClass).getEntityInformation();
|
||||
}
|
||||
@@ -159,7 +161,7 @@ public class Repositories implements Iterable<Class<?>> {
|
||||
*/
|
||||
public RepositoryInformation getRepositoryInformationFor(Class<?> domainClass) {
|
||||
|
||||
Assert.notNull(domainClass, "Domain class must not be null!");
|
||||
Assert.notNull(domainClass, DOMAIN_TYPE_MUST_NOT_BE_NULL);
|
||||
|
||||
RepositoryFactoryInformation<Object, Serializable> information = getRepositoryFactoryInfoFor(domainClass);
|
||||
return information == EMPTY_REPOSITORY_FACTORY_INFO ? null : information.getRepositoryInformation();
|
||||
@@ -175,7 +177,7 @@ public class Repositories implements Iterable<Class<?>> {
|
||||
*/
|
||||
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<Class<?>> {
|
||||
*/
|
||||
public List<QueryMethod> 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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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> 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<Object> 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.
|
||||
|
||||
@@ -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<Class<?>> WRAPPER_TYPES = new HashSet<Class<?>>();
|
||||
private static final Set<Class<?>> WRAPPER_TYPES = new HashSet<Class<?>>();
|
||||
|
||||
static {
|
||||
|
||||
|
||||
@@ -94,16 +94,16 @@ public class AnnotationDetectionMethodCallback<A extends Annotation> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -200,15 +200,15 @@ class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T>
|
||||
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()) {
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
|
||||
@@ -159,8 +159,8 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
Assert.notNull(constructor);
|
||||
List<TypeInformation<?>> result = new ArrayList<TypeInformation<?>>();
|
||||
|
||||
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<S> implements TypeInformation<S> {
|
||||
*/
|
||||
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<S> implements TypeInformation<S> {
|
||||
Type[] parameterTypes = method.getGenericParameterTypes();
|
||||
List<TypeInformation<?>> result = new ArrayList<TypeInformation<?>>(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<S> implements TypeInformation<S> {
|
||||
*/
|
||||
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<S> implements TypeInformation<S> {
|
||||
|
||||
List<Type> candidates = new ArrayList<Type>();
|
||||
|
||||
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) {
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.util.ObjectUtils;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
class SpringDataAnnotationUtils {
|
||||
abstract class SpringDataAnnotationUtils {
|
||||
|
||||
private SpringDataAnnotationUtils() {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user