DATAKV-251 - Removed off deprecations in Spring Data Commons.

Some additional polishing.

Related ticket: DATACMNS-1496.
This commit is contained in:
Oliver Drotbohm
2019-03-13 16:53:19 +01:00
parent 269ea76f10
commit 9b44b2dccb
9 changed files with 37 additions and 39 deletions

View File

@@ -30,7 +30,7 @@ import org.springframework.util.Assert;
*/
class GeneratingIdAccessor implements IdentifierAccessor {
private final PersistentPropertyAccessor accessor;
private final PersistentPropertyAccessor<?> accessor;
private final PersistentProperty<?> identifierProperty;
private final IdentifierGenerator generator;
@@ -42,7 +42,7 @@ class GeneratingIdAccessor implements IdentifierAccessor {
* @param identifierProperty must not be {@literal null}.
* @param generator must not be {@literal null}.
*/
GeneratingIdAccessor(PersistentPropertyAccessor accessor, PersistentProperty<?> identifierProperty,
GeneratingIdAccessor(PersistentPropertyAccessor<?> accessor, PersistentProperty<?> identifierProperty,
IdentifierGenerator generator) {
Assert.notNull(accessor, "PersistentPropertyAccessor must not be null!");

View File

@@ -174,7 +174,6 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
* (non-Javadoc)
* @see org.springframework.data.keyvalue.core.KeyValueOperations#update(java.lang.Object)
*/
@SuppressWarnings("rawtypes")
@Override
public <T> T update(T objectToUpdate) {
@@ -290,7 +289,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
* (non-Javadoc)
* @see org.springframework.data.keyvalue.core.KeyValueOperations#delete(java.lang.Object)
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings("unchecked")
@Override
public <T> T delete(T objectToDelete) {
@@ -447,12 +446,10 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
this.adapter.clear();
}
@SuppressWarnings("unchecked")
private KeyValuePersistentEntity<?, ?> getKeyValuePersistentEntity(Object objectToInsert) {
return this.mappingContext.getRequiredPersistentEntity(ClassUtils.getUserClass(objectToInsert));
}
@SuppressWarnings("unchecked")
private String resolveKeySpace(Class<?> type) {
return this.mappingContext.getRequiredPersistentEntity(type).getKeySpace();
}

View File

@@ -126,7 +126,6 @@ public class SpelPropertyComparator<T> implements Comparator<T> {
* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
@SuppressWarnings("ConstantConditions")
@Override
public int compare(T arg1, T arg2) {

View File

@@ -52,7 +52,8 @@ class SpelQueryEngine extends QueryEngine<KeyValueAdapter, SpelCriteria, Compara
* @see org.springframework.data.keyvalue.core.QueryEngine#execute(java.lang.Object, java.lang.Object, int, int, java.lang.String)
*/
@Override
public Collection<?> execute(@Nullable SpelCriteria criteria, @Nullable Comparator<?> sort, long offset, int rows, String keyspace) {
public Collection<?> execute(@Nullable SpelCriteria criteria, @Nullable Comparator<?> sort, long offset, int rows,
String keyspace) {
return sortAndFilterMatchingRange(getRequiredAdapter().getAllOf(keyspace), criteria, sort, offset, rows);
}
@@ -66,9 +67,9 @@ class SpelQueryEngine extends QueryEngine<KeyValueAdapter, SpelCriteria, Compara
.size();
}
@SuppressWarnings("unchecked")
private List<?> sortAndFilterMatchingRange(Iterable<?> source, @Nullable SpelCriteria criteria, @Nullable Comparator sort,
long offset, int rows) {
@SuppressWarnings({ "unchecked", "rawtypes" })
private List<?> sortAndFilterMatchingRange(Iterable<?> source, @Nullable SpelCriteria criteria,
@Nullable Comparator sort, long offset, int rows) {
List<?> tmp = IterableConverter.toList(source);
if (sort != null) {
@@ -96,7 +97,6 @@ class SpelQueryEngine extends QueryEngine<KeyValueAdapter, SpelCriteria, Compara
return stream.collect(Collectors.toList());
}
@SuppressWarnings("ConstantConditions")
private static boolean evaluateExpression(SpelCriteria criteria, Object candidate) {
try {

View File

@@ -51,7 +51,6 @@ public class SpelSortAccessor implements SortAccessor<Comparator<?>> {
* (non-Javadoc)
* @see org.springframework.data.keyvalue.core.SortAccessor#resolve(org.springframework.data.keyvalue.core.query.KeyValueQuery)
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Comparator<?> resolve(KeyValueQuery<?> query) {

View File

@@ -57,6 +57,6 @@ public class KeyValueMappingContext<E extends KeyValuePersistentEntity<?, P>, P
@Override
@SuppressWarnings("unchecked")
protected P createPersistentProperty(Property property, E owner, SimpleTypeHolder simpleTypeHolder) {
return (P) new KeyValuePersistentProperty(property, owner, simpleTypeHolder);
return (P) new KeyValuePersistentProperty<>(property, owner, simpleTypeHolder);
}
}

View File

@@ -154,10 +154,14 @@ public abstract class KeyValueRepositoryConfigurationExtension extends Repositor
super.registerBeansForRoot(registry, configurationSource);
RootBeanDefinition mappingContextDefinition = new RootBeanDefinition(KeyValueMappingContext.class);
mappingContextDefinition.setSource(configurationSource.getSource());
registerIfNotAlreadyRegistered(() -> {
registerIfNotAlreadyRegistered(mappingContextDefinition, registry, getMappingContextBeanRef(), configurationSource);
RootBeanDefinition definitionefinition = new RootBeanDefinition(KeyValueMappingContext.class);
definitionefinition.setSource(configurationSource.getSource());
return definitionefinition;
}, registry, getMappingContextBeanRef(), configurationSource);
Optional<String> keyValueTemplateName = configurationSource.getAttribute(KEY_VALUE_TEMPLATE_BEAN_REF_ATTRIBUTE);
@@ -168,7 +172,7 @@ public abstract class KeyValueRepositoryConfigurationExtension extends Repositor
AbstractBeanDefinition beanDefinition = getDefaultKeyValueTemplateBeanDefinition(configurationSource);
if (beanDefinition != null) {
registerIfNotAlreadyRegistered(beanDefinition, registry, keyValueTemplateName.get(),
registerIfNotAlreadyRegistered(() -> beanDefinition, registry, keyValueTemplateName.get(),
configurationSource.getSource());
}
}

View File

@@ -41,7 +41,6 @@ import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.data.repository.query.parser.AbstractQueryCreator;
import org.springframework.data.spel.EvaluationContextProvider;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -174,22 +173,6 @@ public class KeyValueRepositoryFactory extends RepositoryFactorySupport {
private Class<? extends AbstractQueryCreator<?, ?>> queryCreator;
private Class<? extends RepositoryQuery> repositoryQueryType;
/**
* Creates a new {@link KeyValueQueryLookupStrategy} for the given {@link Key}, {@link EvaluationContextProvider},
* {@link KeyValueOperations} and query creator type.
* <p>
* TODO: Key is not considered. Should it?
*
* @param key
* @param evaluationContextProvider must not be {@literal null}.
* @param keyValueOperations must not be {@literal null}.
* @param queryCreator must not be {@literal null}.
*/
public KeyValueQueryLookupStrategy(Key key, QueryMethodEvaluationContextProvider evaluationContextProvider,
KeyValueOperations keyValueOperations, Class<? extends AbstractQueryCreator<?, ?>> queryCreator) {
this(key, evaluationContextProvider, keyValueOperations, queryCreator, KeyValuePartTreeQuery.class);
}
/**
* @param key
* @param evaluationContextProvider

View File

@@ -17,6 +17,7 @@ package org.springframework.data.keyvalue.repository;
import static org.hamcrest.core.Is.*;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import lombok.Data;
@@ -36,8 +37,11 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.keyvalue.core.KeyValueOperations;
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
import org.springframework.data.keyvalue.repository.support.SimpleKeyValueRepository;
import org.springframework.data.repository.core.support.ReflectionEntityInformation;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.repository.core.EntityInformation;
import org.springframework.data.repository.core.support.PersistentEntityInformation;
/**
* @author Christoph Strobl
@@ -48,19 +52,22 @@ public class SimpleKeyValueRepositoryUnitTests {
private SimpleKeyValueRepository<Foo, String> repo;
private @Mock KeyValueOperations opsMock;
KeyValueMappingContext<?, ?> context;
@Before
public void setUp() {
ReflectionEntityInformation<Foo, String> ei = new ReflectionEntityInformation<>(Foo.class);
this.context = new KeyValueMappingContext<>();
EntityInformation<Foo, String> ei = getEntityInformationFor(Foo.class);
repo = new SimpleKeyValueRepository<>(ei, opsMock);
}
@Test // DATACMNS-525
public void saveNewWithNumericId() {
ReflectionEntityInformation<WithNumericId, Integer> ei = new ReflectionEntityInformation<>(WithNumericId.class);
SimpleKeyValueRepository<WithNumericId, Integer> temp = new SimpleKeyValueRepository<>(ei, opsMock);
EntityInformation<WithNumericId, ?> ei = getEntityInformationFor(WithNumericId.class);
SimpleKeyValueRepository<WithNumericId, ?> temp = new SimpleKeyValueRepository<>(ei, opsMock);
WithNumericId withNumericId = new WithNumericId();
temp.save(withNumericId);
@@ -170,6 +177,15 @@ public class SimpleKeyValueRepositoryUnitTests {
verify(opsMock, times(1)).findAll(eq(Foo.class));
}
@SuppressWarnings("unchecked")
private <T, S> EntityInformation<T, S> getEntityInformationFor(Class<T> type) {
PersistentEntity<T, ?> requiredPersistentEntity = (PersistentEntity<T, ?>) context
.getRequiredPersistentEntity(type);
return new PersistentEntityInformation<>(requiredPersistentEntity);
}
@Data
@NoArgsConstructor
static class Foo {