DATAKV-192 - Polishing.
Reduce member visibility according type visibility. Adapt to required argument in KeyValueRepository.findAll(Pageable). Replace cast with type to Class.cast(…). Use lombok for for getters/setters in test code. Suppress warnings, formatting. Original pull request: #26.
This commit is contained in:
@@ -31,8 +31,8 @@ public interface CriteriaAccessor<T> {
|
||||
*
|
||||
* @param query can be {@literal null}.
|
||||
* @return the criteria extracted from the query.
|
||||
* @throws IllegalArgumentException in case the criteria is not valid for usage with specific {@link CriteriaAccessor}
|
||||
* .
|
||||
* @throws IllegalArgumentException in case the criteria is not valid for usage with specific
|
||||
* {@link CriteriaAccessor}.
|
||||
*/
|
||||
T resolve(KeyValueQuery<?> query);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class GeneratingIdAccessor implements IdentifierAccessor {
|
||||
* @param identifierProperty must not be {@literal null}.
|
||||
* @param generator must not be {@literal null}.
|
||||
*/
|
||||
public GeneratingIdAccessor(PersistentPropertyAccessor accessor, PersistentProperty<?> identifierProperty,
|
||||
GeneratingIdAccessor(PersistentPropertyAccessor accessor, PersistentProperty<?> identifierProperty,
|
||||
IdentifierGenerator generator) {
|
||||
|
||||
Assert.notNull(accessor, "PersistentPropertyAccessor must not be null!");
|
||||
@@ -69,7 +69,7 @@ class GeneratingIdAccessor implements IdentifierAccessor {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Object getOrGenerateIdentifier() {
|
||||
Object getOrGenerateIdentifier() {
|
||||
|
||||
Object existingIdentifier = getIdentifier();
|
||||
|
||||
|
||||
@@ -140,10 +140,6 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
|
||||
return objectToInsert;
|
||||
}
|
||||
|
||||
private KeyValuePersistentEntity<?, ?> getKeyValuePersistentEntity(Object objectToInsert) {
|
||||
return this.mappingContext.getRequiredPersistentEntity(ClassUtils.getUserClass(objectToInsert));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueOperations#insert(java.lang.Object, java.lang.Object)
|
||||
@@ -230,7 +226,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
|
||||
ArrayList<T> filtered = new ArrayList<>();
|
||||
for (Object candidate : values) {
|
||||
if (typeCheck(type, candidate)) {
|
||||
filtered.add((T) candidate);
|
||||
filtered.add(type.cast(candidate));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -436,6 +432,12 @@ 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();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.springframework.data.keyvalue.core.query.KeyValueQuery;
|
||||
|
||||
/**
|
||||
* Base implementation for accessing and executing {@link KeyValueQuery} against a {@link KeyValueAdapter}.
|
||||
*
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @param <ADAPTER>
|
||||
* @param <CRITERIA>
|
||||
@@ -42,7 +42,7 @@ public abstract class QueryEngine<ADAPTER extends KeyValueAdapter, CRITERIA, SOR
|
||||
|
||||
/**
|
||||
* Extract query attributes and delegate to concrete execution.
|
||||
*
|
||||
*
|
||||
* @param query
|
||||
* @param keyspace
|
||||
* @return
|
||||
@@ -57,7 +57,7 @@ public abstract class QueryEngine<ADAPTER extends KeyValueAdapter, CRITERIA, SOR
|
||||
|
||||
/**
|
||||
* Extract query attributes and delegate to concrete execution.
|
||||
*
|
||||
*
|
||||
* @param query
|
||||
* @param keyspace
|
||||
* @return
|
||||
@@ -72,7 +72,7 @@ public abstract class QueryEngine<ADAPTER extends KeyValueAdapter, CRITERIA, SOR
|
||||
|
||||
/**
|
||||
* Extract query attributes and delegate to concrete execution.
|
||||
*
|
||||
*
|
||||
* @param query
|
||||
* @param keyspace
|
||||
* @return
|
||||
@@ -103,6 +103,7 @@ public abstract class QueryEngine<ADAPTER extends KeyValueAdapter, CRITERIA, SOR
|
||||
* @return
|
||||
* @since 1.1
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Collection<T> execute(CRITERIA criteria, SORT sort, long offset, int rows, String keyspace,
|
||||
Class<T> type) {
|
||||
return (Collection<T>) execute(criteria, sort, offset, rows, keyspace);
|
||||
@@ -117,7 +118,7 @@ public abstract class QueryEngine<ADAPTER extends KeyValueAdapter, CRITERIA, SOR
|
||||
|
||||
/**
|
||||
* Get the {@link KeyValueAdapter} used.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected ADAPTER getAdapter() {
|
||||
|
||||
@@ -93,18 +93,14 @@ class SpelQueryEngine extends QueryEngine<KeyValueAdapter, SpelCriteria, Compara
|
||||
return stream.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
static boolean evaluateExpression(SpelCriteria criteria, Object candidate) {
|
||||
|
||||
boolean matches = false;
|
||||
private static boolean evaluateExpression(SpelCriteria criteria, Object candidate) {
|
||||
|
||||
try {
|
||||
matches = criteria.getExpression().getValue(criteria.getContext(), candidate, Boolean.class);
|
||||
return criteria.getExpression().getValue(criteria.getContext(), candidate, Boolean.class);
|
||||
} catch (SpelEvaluationException e) {
|
||||
criteria.getContext().setVariable("it", candidate);
|
||||
matches = criteria.getExpression().getValue(criteria.getContext()) == null ? false
|
||||
return criteria.getExpression().getValue(criteria.getContext()) == null ? false
|
||||
: criteria.getExpression().getValue(criteria.getContext(), Boolean.class);
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class SpelSortAccessor implements SortAccessor<Comparator<?>> {
|
||||
/**
|
||||
* @param parser must not be {@literal null}.
|
||||
*/
|
||||
public SpelSortAccessor(SpelExpressionParser parser) {
|
||||
SpelSortAccessor(SpelExpressionParser parser) {
|
||||
|
||||
Assert.notNull(parser, "SpelExpressionParser must not be null!");
|
||||
this.parser = parser;
|
||||
@@ -66,7 +66,7 @@ class SpelSortAccessor implements SortAccessor<Comparator<?>> {
|
||||
|
||||
spelSort.desc();
|
||||
|
||||
if (order.getNullHandling() != null && !NullHandling.NATIVE.equals(order.getNullHandling())) {
|
||||
if (!NullHandling.NATIVE.equals(order.getNullHandling())) {
|
||||
spelSort = NullHandling.NULLS_FIRST.equals(order.getNullHandling()) ? spelSort.nullsFirst()
|
||||
: spelSort.nullsLast();
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
private Object key;
|
||||
private Class<? extends T> type;
|
||||
|
||||
protected KeyBasedEvent(Object key, String keyspace, Class<? extends T> type) {
|
||||
KeyBasedEvent(Object key, String keyspace, Class<? extends T> type) {
|
||||
|
||||
super(type, keyspace);
|
||||
this.key = key;
|
||||
@@ -225,7 +225,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
|
||||
private final T payload;
|
||||
|
||||
public KeyBasedEventWithPayload(Object key, String keyspace, Class<? extends T> type, T payload) {
|
||||
KeyBasedEventWithPayload(Object key, String keyspace, Class<? extends T> type, T payload) {
|
||||
super(key, keyspace, type);
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
* Most trivial implementation of {@link PersistentProperty}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class KeyValuePersistentProperty<P extends KeyValuePersistentProperty<P>>
|
||||
extends AnnotationBasedPersistentProperty<P> {
|
||||
@@ -40,6 +41,7 @@ public class KeyValuePersistentProperty<P extends KeyValuePersistentProperty<P>>
|
||||
* @see org.springframework.data.mapping.model.AbstractPersistentProperty#createAssociation()
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Association<P> createAssociation() {
|
||||
return new Association<>((P) this, null);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2015 the original author or authors.
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,9 +28,10 @@ import org.springframework.data.util.TypeInformation;
|
||||
/**
|
||||
* Default implementation of a {@link MappingContext} using {@link KeyValuePersistentEntity} and
|
||||
* {@link KeyValuePersistentProperty} as primary abstractions.
|
||||
*
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class KeyValueMappingContext<E extends KeyValuePersistentEntity<?, P>, P extends KeyValuePersistentProperty<P>>
|
||||
extends AbstractMappingContext<E, P> {
|
||||
@@ -39,7 +40,7 @@ public class KeyValueMappingContext<E extends KeyValuePersistentEntity<?, P>, P
|
||||
|
||||
/**
|
||||
* Configures the {@link KeySpaceResolver} to be used if not explicit key space is annotated to the domain type.
|
||||
*
|
||||
*
|
||||
* @param fallbackKeySpaceResolver can be {@literal null}.
|
||||
*/
|
||||
public void setFallbackKeySpaceResolver(KeySpaceResolver fallbackKeySpaceResolver) {
|
||||
@@ -47,11 +48,13 @@ public class KeyValueMappingContext<E extends KeyValuePersistentEntity<?, P>, P
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <T> E createPersistentEntity(TypeInformation<T> typeInformation) {
|
||||
return (E) new BasicKeyValuePersistentEntity<T, P>(typeInformation, fallbackKeySpaceResolver);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected P createPersistentProperty(Property property, E owner, SimpleTypeHolder simpleTypeHolder) {
|
||||
return (P) new KeyValuePersistentProperty(property, owner, simpleTypeHolder);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ abstract class KeyValueQuerydslUtils {
|
||||
* @param builder must not be {@literal null}.
|
||||
* @return empty {@code OrderSpecifier<?>[]} when sort is {@literal null}.
|
||||
*/
|
||||
public static OrderSpecifier<?>[] toOrderSpecifier(Sort sort, PathBuilder<?> builder) {
|
||||
static OrderSpecifier<?>[] toOrderSpecifier(Sort sort, PathBuilder<?> builder) {
|
||||
|
||||
Assert.notNull(builder, "Builder must not be 'null'.");
|
||||
|
||||
|
||||
@@ -74,7 +74,9 @@ public class SimpleKeyValueRepository<T, ID> implements KeyValueRepository<T, ID
|
||||
@Override
|
||||
public Page<T> findAll(Pageable pageable) {
|
||||
|
||||
if (pageable == null) {
|
||||
Assert.notNull(pageable, "Pageable must not be null!");
|
||||
|
||||
if (pageable.isUnpaged()) {
|
||||
List<T> result = findAll();
|
||||
return new PageImpl<>(result, Pageable.unpaged(), result.size());
|
||||
}
|
||||
@@ -110,9 +112,7 @@ public class SimpleKeyValueRepository<T, ID> implements KeyValueRepository<T, ID
|
||||
@Override
|
||||
public <S extends T> Iterable<S> saveAll(Iterable<S> entities) {
|
||||
|
||||
for (S entity : entities) {
|
||||
save(entity);
|
||||
}
|
||||
entities.forEach(this::save);
|
||||
|
||||
return entities;
|
||||
}
|
||||
@@ -153,9 +153,7 @@ public class SimpleKeyValueRepository<T, ID> implements KeyValueRepository<T, ID
|
||||
|
||||
List<T> result = new ArrayList<>();
|
||||
|
||||
for (ID id : ids) {
|
||||
findById(id).ifPresent(result::add);
|
||||
}
|
||||
ids.forEach(id -> findById(id).ifPresent(result::add));
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -193,10 +191,7 @@ public class SimpleKeyValueRepository<T, ID> implements KeyValueRepository<T, ID
|
||||
*/
|
||||
@Override
|
||||
public void deleteAll(Iterable<? extends T> entities) {
|
||||
|
||||
for (T entity : entities) {
|
||||
delete(entity);
|
||||
}
|
||||
entities.forEach(this::delete);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user