diff --git a/src/main/asciidoc/key-value-repositories.adoc b/src/main/asciidoc/key-value-repositories.adoc index 9096052..aa2fa6e 100644 --- a/src/main/asciidoc/key-value-repositories.adoc +++ b/src/main/asciidoc/key-value-repositories.adoc @@ -98,7 +98,7 @@ NOTE: The composed annotation needs to inherit `@Persistent`. @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.TYPE }) static @interface CacheCentricAnnotation { - + @KeySpace String cacheRegion() default ""; } @@ -106,7 +106,7 @@ static @interface CacheCentricAnnotation { class Customer { //... } ----- +---- [[key-value.template-query]] == Querying @@ -133,7 +133,7 @@ When used without further customization sorting is done using a `SpelPropertyCom [source, java] ---- KeyValueQuery query = new KeyValueQuery("lastname == 'baratheon'"); -query.setSort(new Sort(DESC, "age")); +query.setSort(Sort.by(DESC, "age")); List targaryens = template.find(query, Person.class); ---- diff --git a/src/main/java/org/springframework/data/keyvalue/core/AbstractKeyValueAdapter.java b/src/main/java/org/springframework/data/keyvalue/core/AbstractKeyValueAdapter.java index e76164d..dc626fc 100644 --- a/src/main/java/org/springframework/data/keyvalue/core/AbstractKeyValueAdapter.java +++ b/src/main/java/org/springframework/data/keyvalue/core/AbstractKeyValueAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 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. @@ -23,7 +23,7 @@ import org.springframework.data.keyvalue.core.query.KeyValueQuery; /** * Base implementation of {@link KeyValueAdapter} holds {@link QueryEngine} to delegate {@literal find} and * {@literal count} execution to. - * + * * @author Christoph Strobl */ public abstract class AbstractKeyValueAdapter implements KeyValueAdapter { @@ -39,18 +39,18 @@ public abstract class AbstractKeyValueAdapter implements KeyValueAdapter { /** * Creates new {@link AbstractKeyValueAdapter} with using the default query engine. - * + * * @param engine will be defaulted to {@link SpelQueryEngine} if {@literal null}. */ protected AbstractKeyValueAdapter(QueryEngine engine) { - this.engine = engine != null ? engine : new SpelQueryEngine(); + this.engine = engine != null ? engine : new SpelQueryEngine<>(); this.engine.registerAdapter(this); } /** * Get the {@link QueryEngine} used. - * + * * @return */ protected QueryEngine getQueryEngine() { @@ -81,7 +81,7 @@ public abstract class AbstractKeyValueAdapter implements KeyValueAdapter { */ @Override public Iterable find(KeyValueQuery query, Serializable keyspace, Class type) { - return (Iterable) engine.execute(query, keyspace, type); + return engine.execute(query, keyspace, type); } /* diff --git a/src/main/java/org/springframework/data/keyvalue/core/DefaultIdentifierGenerator.java b/src/main/java/org/springframework/data/keyvalue/core/DefaultIdentifierGenerator.java index b5b02cb..26fcfab 100644 --- a/src/main/java/org/springframework/data/keyvalue/core/DefaultIdentifierGenerator.java +++ b/src/main/java/org/springframework/data/keyvalue/core/DefaultIdentifierGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 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. @@ -29,7 +29,7 @@ import org.springframework.util.StringUtils; /** * Default implementation of {@link IdentifierGenerator} to generate identifiers of types {@link UUID}, String, - * + * * @author Christoph Strobl * @author Oliver Gierke */ @@ -37,7 +37,7 @@ enum DefaultIdentifierGenerator implements IdentifierGenerator { INSTANCE; - private final AtomicReference secureRandom = new AtomicReference(null); + private final AtomicReference secureRandom = new AtomicReference<>(null); /* * (non-Javadoc) diff --git a/src/main/java/org/springframework/data/keyvalue/core/IterableConverter.java b/src/main/java/org/springframework/data/keyvalue/core/IterableConverter.java index 8cc093e..cb2ee81 100644 --- a/src/main/java/org/springframework/data/keyvalue/core/IterableConverter.java +++ b/src/main/java/org/springframework/data/keyvalue/core/IterableConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-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. @@ -22,9 +22,8 @@ import java.util.List; /** * Converter capable of transforming a given {@link Iterable} into a collection type. - * + * * @author Christoph Strobl - * @param */ public final class IterableConverter { @@ -32,7 +31,7 @@ public final class IterableConverter { /** * Converts a given {@link Iterable} into a {@link List} - * + * * @param source * @return {@link Collections#emptyList()} when source is {@literal null}. */ @@ -47,10 +46,10 @@ public final class IterableConverter { } if (source instanceof Collection) { - return new ArrayList((Collection) source); + return new ArrayList<>((Collection) source); } - List result = new ArrayList(); + List result = new ArrayList<>(); for (T value : source) { result.add(value); } diff --git a/src/main/java/org/springframework/data/keyvalue/core/KeyValueTemplate.java b/src/main/java/org/springframework/data/keyvalue/core/KeyValueTemplate.java index f9a3204..ae9569c 100644 --- a/src/main/java/org/springframework/data/keyvalue/core/KeyValueTemplate.java +++ b/src/main/java/org/springframework/data/keyvalue/core/KeyValueTemplate.java @@ -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. @@ -42,7 +42,7 @@ import org.springframework.util.ObjectUtils; /** * Basic implementation of {@link KeyValueOperations}. - * + * * @author Christoph Strobl * @author Oliver Gierke * @author Thomas Darimont @@ -64,7 +64,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub /** * Create new {@link KeyValueTemplate} using the given {@link KeyValueAdapter} with a default * {@link KeyValueMappingContext}. - * + * * @param adapter must not be {@literal null}. */ public KeyValueTemplate(KeyValueAdapter adapter) { @@ -73,7 +73,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub /** * Create new {@link KeyValueTemplate} using the given {@link KeyValueAdapter} and {@link MappingContext}. - * + * * @param adapter must not be {@literal null}. * @param mappingContext must not be {@literal null}. */ @@ -90,7 +90,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub /** * Set the {@link PersistenceExceptionTranslator} used for converting {@link RuntimeException}. - * + * * @param exceptionTranslator must not be {@literal null}. */ public void setExceptionTranslator(PersistenceExceptionTranslator exceptionTranslator) { @@ -101,7 +101,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub /** * Define the event types to publish via {@link ApplicationEventPublisher}. - * + * * @param eventTypesToPublish use {@literal null} or {@link Collections#emptySet()} to stop publishing. */ @SuppressWarnings("rawtypes") @@ -247,7 +247,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub return Collections.emptySet(); } - ArrayList filtered = new ArrayList(); + ArrayList filtered = new ArrayList<>(); for (Object candidate : values) { if (typeCheck(type, candidate)) { filtered.add((T) candidate); @@ -407,7 +407,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub return Collections.emptySet(); } - List filtered = new ArrayList(); + List filtered = new ArrayList<>(); for (Object candidate : result) { if (typeCheck(type, candidate)) { diff --git a/src/main/java/org/springframework/data/keyvalue/core/SpelQueryEngine.java b/src/main/java/org/springframework/data/keyvalue/core/SpelQueryEngine.java index 6117ef5..b553054 100644 --- a/src/main/java/org/springframework/data/keyvalue/core/SpelQueryEngine.java +++ b/src/main/java/org/springframework/data/keyvalue/core/SpelQueryEngine.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 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. @@ -30,7 +30,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser; /** * {@link QueryEngine} implementation specific for executing {@link SpelExpression} based {@link KeyValueQuery} against * {@link KeyValueAdapter}. - * + * * @author Christoph Strobl * @author Oliver Gierke * @param @@ -78,7 +78,7 @@ class SpelQueryEngine extends QueryEngine List filterMatchingRange(Iterable source, SpelCriteria criteria, long offset, int rows) { - List result = new ArrayList(); + List result = new ArrayList<>(); boolean compareOffsetAndRows = 0 < offset || 0 <= rows; int remainingRows = rows; diff --git a/src/main/java/org/springframework/data/keyvalue/core/SpelSortAccessor.java b/src/main/java/org/springframework/data/keyvalue/core/SpelSortAccessor.java index d8f5f9b..f96741b 100644 --- a/src/main/java/org/springframework/data/keyvalue/core/SpelSortAccessor.java +++ b/src/main/java/org/springframework/data/keyvalue/core/SpelSortAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 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. @@ -16,21 +16,21 @@ package org.springframework.data.keyvalue.core; import java.util.Comparator; +import java.util.Optional; -import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; import org.springframework.data.domain.Sort.NullHandling; import org.springframework.data.domain.Sort.Order; import org.springframework.data.keyvalue.core.query.KeyValueQuery; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.util.Assert; -import org.springframework.util.comparator.CompoundComparator; /** * {@link SortAccessor} implementation capable of creating {@link SpelPropertyComparator}. - * + * * @author Christoph Strobl * @author Oliver Gierke + * @author Mark Paluch */ class SpelSortAccessor implements SortAccessor> { @@ -53,27 +53,35 @@ class SpelSortAccessor implements SortAccessor> { @Override public Comparator resolve(KeyValueQuery query) { - if (query == null || query.getSort() == null || Sort.unsorted().equals(query.getSort())) { + if (query == null || query.getSort() == null || query.getSort().isUnsorted()) { return null; } - CompoundComparator compoundComperator = new CompoundComparator(); + Optional> comparator = Optional.empty(); for (Order order : query.getSort()) { - SpelPropertyComparator spelSort = new SpelPropertyComparator(order.getProperty(), parser); + SpelPropertyComparator spelSort = new SpelPropertyComparator<>(order.getProperty(), parser); if (Direction.DESC.equals(order.getDirection())) { spelSort.desc(); if (order.getNullHandling() != null && !NullHandling.NATIVE.equals(order.getNullHandling())) { - spelSort = NullHandling.NULLS_FIRST.equals(order.getNullHandling()) ? spelSort.nullsFirst() : spelSort - .nullsLast(); + spelSort = NullHandling.NULLS_FIRST.equals(order.getNullHandling()) ? spelSort.nullsFirst() + : spelSort.nullsLast(); } } - compoundComperator.addComparator(spelSort); + + if (!comparator.isPresent()) { + comparator = Optional.of(spelSort); + } else { + + SpelPropertyComparator spelSortToUse = spelSort; + comparator = comparator.map(it -> it.thenComparing(spelSortToUse)); + } } - return compoundComperator; + return comparator.orElseThrow( + () -> new IllegalStateException("No sort definitions have been added to this CompoundComparator to compare")); } } diff --git a/src/main/java/org/springframework/data/keyvalue/core/event/KeyValueEvent.java b/src/main/java/org/springframework/data/keyvalue/core/event/KeyValueEvent.java index 6587c71..daba6d4 100644 --- a/src/main/java/org/springframework/data/keyvalue/core/event/KeyValueEvent.java +++ b/src/main/java/org/springframework/data/keyvalue/core/event/KeyValueEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-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. @@ -23,7 +23,7 @@ import org.springframework.context.ApplicationEvent; * {@link KeyValueEvent} gets published for operations executed by eg. * {@link org.springframework.data.keyvalue.core.KeyValueTemplate}. Use the {@link #getType()} to determine which event * has been emitted. - * + * * @author Christoph Strobl * @author Thomas Darimont * @param @@ -54,19 +54,19 @@ public class KeyValueEvent extends ApplicationEvent { /** * Create new {@link BeforeGetEvent}. - * + * * @param id * @param keySpace * @param type * @return */ public static BeforeGetEvent beforeGet(Serializable id, String keySpace, Class type) { - return new BeforeGetEvent(id, keySpace, type); + return new BeforeGetEvent<>(id, keySpace, type); } /** * Create new {@link AfterGetEvent}. - * + * * @param id * @param keySpace * @param type @@ -74,12 +74,12 @@ public class KeyValueEvent extends ApplicationEvent { * @return */ public static AfterGetEvent afterGet(Serializable id, String keySpace, Class type, T value) { - return new AfterGetEvent(id, keySpace, type, value); + return new AfterGetEvent<>(id, keySpace, type, value); } /** * Create new {@link BeforeInsertEvent}. - * + * * @param id * @param keySpace * @param type @@ -87,12 +87,12 @@ public class KeyValueEvent extends ApplicationEvent { * @return */ public static BeforeInsertEvent beforeInsert(Serializable id, String keySpace, Class type, T value) { - return new BeforeInsertEvent(id, keySpace, type, value); + return new BeforeInsertEvent<>(id, keySpace, type, value); } /** * Create new {@link AfterInsertEvent}. - * + * * @param id * @param keySpace * @param type @@ -100,12 +100,12 @@ public class KeyValueEvent extends ApplicationEvent { * @return */ public static AfterInsertEvent afterInsert(Serializable id, String keySpace, Class type, T value) { - return new AfterInsertEvent(id, keySpace, type, value); + return new AfterInsertEvent<>(id, keySpace, type, value); } /** * Create new {@link BeforeUpdateEvent}. - * + * * @param id * @param keySpace * @param type @@ -113,12 +113,12 @@ public class KeyValueEvent extends ApplicationEvent { * @return */ public static BeforeUpdateEvent beforeUpdate(Serializable id, String keySpace, Class type, T value) { - return new BeforeUpdateEvent(id, keySpace, type, value); + return new BeforeUpdateEvent<>(id, keySpace, type, value); } /** * Create new {@link AfterUpdateEvent}. - * + * * @param id * @param keySpace * @param type @@ -128,46 +128,46 @@ public class KeyValueEvent extends ApplicationEvent { */ public static AfterUpdateEvent afterUpdate(Serializable id, String keySpace, Class type, T actualValue, Object previousValue) { - return new AfterUpdateEvent(id, keySpace, type, actualValue, previousValue); + return new AfterUpdateEvent<>(id, keySpace, type, actualValue, previousValue); } /** * Create new {@link BeforeDropKeySpaceEvent}. - * + * * @param keySpace * @param type * @return */ public static BeforeDropKeySpaceEvent beforeDropKeySpace(String keySpace, Class type) { - return new BeforeDropKeySpaceEvent(keySpace, type); + return new BeforeDropKeySpaceEvent<>(keySpace, type); } /** * Create new {@link AfterDropKeySpaceEvent}. - * + * * @param keySpace * @param type * @return */ public static AfterDropKeySpaceEvent afterDropKeySpace(String keySpace, Class type) { - return new AfterDropKeySpaceEvent(keySpace, type); + return new AfterDropKeySpaceEvent<>(keySpace, type); } /** * Create new {@link BeforeDeleteEvent}. - * + * * @param id * @param keySpace * @param type * @return */ public static BeforeDeleteEvent beforeDelete(Serializable id, String keySpace, Class type) { - return new BeforeDeleteEvent(id, keySpace, type); + return new BeforeDeleteEvent<>(id, keySpace, type); } /** * Create new {@link AfterDeleteEvent}. - * + * * @param id * @param keySpace * @param type @@ -175,7 +175,7 @@ public class KeyValueEvent extends ApplicationEvent { * @return */ public static AfterDeleteEvent afterDelete(Serializable id, String keySpace, Class type, T value) { - return new AfterDeleteEvent(id, keySpace, type, value); + return new AfterDeleteEvent<>(id, keySpace, type, value); } /** @@ -209,7 +209,7 @@ public class KeyValueEvent extends ApplicationEvent { /** * Get the type of the element the {@link KeyValueEvent} refers to. - * + * * @return */ public Class getType() { @@ -233,7 +233,7 @@ public class KeyValueEvent extends ApplicationEvent { /** * Get the value of the element the {@link KeyValueEvent} refers to. Can be {@literal null}. - * + * * @return */ public T getPayload() { @@ -243,7 +243,7 @@ public class KeyValueEvent extends ApplicationEvent { /** * {@link KeyValueEvent} raised before loading an object by its {@literal key}. - * + * * @author Christoph Strobl * @param */ @@ -258,7 +258,7 @@ public class KeyValueEvent extends ApplicationEvent { /** * {@link KeyValueEvent} after loading an object by its {@literal key}. - * + * * @author Christoph Strobl * @param */ @@ -273,7 +273,7 @@ public class KeyValueEvent extends ApplicationEvent { /** * {@link KeyValueEvent} before inserting an object by with a given {@literal key}. - * + * * @author Christoph Strobl * @param */ @@ -288,7 +288,7 @@ public class KeyValueEvent extends ApplicationEvent { /** * {@link KeyValueEvent} after inserting an object by with a given {@literal key}. - * + * * @author Christoph Strobl * @param */ @@ -302,7 +302,7 @@ public class KeyValueEvent extends ApplicationEvent { /** * {@link KeyValueEvent} before updating an object by with a given {@literal key}. - * + * * @author Christoph Strobl * @param */ @@ -316,7 +316,7 @@ public class KeyValueEvent extends ApplicationEvent { /** * {@link KeyValueEvent} after updating an object by with a given {@literal key}. - * + * * @author Christoph Strobl * @param */ @@ -332,7 +332,7 @@ public class KeyValueEvent extends ApplicationEvent { /** * Get the value before update. Can be {@literal null}. - * + * * @return */ public Object before() { @@ -341,7 +341,7 @@ public class KeyValueEvent extends ApplicationEvent { /** * Get the current value. - * + * * @return */ public T after() { @@ -351,7 +351,7 @@ public class KeyValueEvent extends ApplicationEvent { /** * {@link KeyValueEvent} before removing an object by with a given {@literal key}. - * + * * @author Christoph Strobl * @param */ @@ -365,7 +365,7 @@ public class KeyValueEvent extends ApplicationEvent { /** * {@link KeyValueEvent} after removing an object by with a given {@literal key}. - * + * * @author Christoph Strobl * @param */ @@ -379,7 +379,7 @@ public class KeyValueEvent extends ApplicationEvent { /** * {@link KeyValueEvent} before removing all elements in a given {@literal keySpace}. - * + * * @author Christoph Strobl * @param */ @@ -400,7 +400,7 @@ public class KeyValueEvent extends ApplicationEvent { /** * {@link KeyValueEvent} after removing all elements in a given {@literal keySpace}. - * + * * @author Christoph Strobl * @param */ diff --git a/src/main/java/org/springframework/data/keyvalue/core/mapping/AnnotationBasedKeySpaceResolver.java b/src/main/java/org/springframework/data/keyvalue/core/mapping/AnnotationBasedKeySpaceResolver.java index 7a7ebf3..47c2872 100644 --- a/src/main/java/org/springframework/data/keyvalue/core/mapping/AnnotationBasedKeySpaceResolver.java +++ b/src/main/java/org/springframework/data/keyvalue/core/mapping/AnnotationBasedKeySpaceResolver.java @@ -34,7 +34,7 @@ import org.springframework.util.ObjectUtils; /** * {@link AnnotationBasedKeySpaceResolver} looks up {@link Persistent} and checks for presence of either meta or direct * usage of {@link KeySpace}. If non found it will default the keyspace to {@link Class#getName()}. - * + * * @author Christoph Strobl * @author Oliver Gierke */ @@ -142,7 +142,7 @@ enum AnnotationBasedKeySpaceResolver implements KeySpaceResolver { */ public static AnnotationDescriptor findAnnotationDescriptor(Class clazz, Class annotationType) { - return findAnnotationDescriptor(clazz, new HashSet(), annotationType); + return findAnnotationDescriptor(clazz, new HashSet<>(), annotationType); } /** @@ -165,7 +165,7 @@ enum AnnotationBasedKeySpaceResolver implements KeySpaceResolver { // Declared locally? if (AnnotationUtils.isAnnotationDeclaredLocally(annotationType, clazz)) { - return new AnnotationDescriptor(clazz, clazz.getAnnotation(annotationType)); + return new AnnotationDescriptor<>(clazz, clazz.getAnnotation(annotationType)); } // Declared on a composed annotation (i.e., as a meta-annotation)? @@ -174,7 +174,7 @@ enum AnnotationBasedKeySpaceResolver implements KeySpaceResolver { AnnotationDescriptor descriptor = findAnnotationDescriptor(composedAnnotation.annotationType(), visited, annotationType); if (descriptor != null) { - return new AnnotationDescriptor(clazz, descriptor.getDeclaringClass(), composedAnnotation, + return new AnnotationDescriptor<>(clazz, descriptor.getDeclaringClass(), composedAnnotation, descriptor.getAnnotation()); } } @@ -218,7 +218,7 @@ enum AnnotationBasedKeySpaceResolver implements KeySpaceResolver { */ public static UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(Class clazz, Class... annotationTypes) { - return findAnnotationDescriptorForTypes(clazz, new HashSet(), annotationTypes); + return findAnnotationDescriptorForTypes(clazz, new HashSet<>(), annotationTypes); } /** @@ -301,7 +301,7 @@ enum AnnotationBasedKeySpaceResolver implements KeySpaceResolver { * @Retention(RetentionPolicy.RUNTIME) * public @interface RepositoryTests { * } - * + * * @RepositoryTests * public class UserRepositoryTests {} * diff --git a/src/main/java/org/springframework/data/keyvalue/core/mapping/KeyValuePersistentProperty.java b/src/main/java/org/springframework/data/keyvalue/core/mapping/KeyValuePersistentProperty.java index 0fd45cc..cb34863 100644 --- a/src/main/java/org/springframework/data/keyvalue/core/mapping/KeyValuePersistentProperty.java +++ b/src/main/java/org/springframework/data/keyvalue/core/mapping/KeyValuePersistentProperty.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 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. @@ -24,7 +24,7 @@ import org.springframework.data.mapping.model.SimpleTypeHolder; /** * Most trivial implementation of {@link PersistentProperty}. - * + * * @author Christoph Strobl */ public class KeyValuePersistentProperty

> @@ -41,6 +41,6 @@ public class KeyValuePersistentProperty

> */ @Override protected Association

createAssociation() { - return new Association

((P) this, null); + return new Association<>((P) this, null); } } diff --git a/src/main/java/org/springframework/data/keyvalue/core/query/KeyValueQuery.java b/src/main/java/org/springframework/data/keyvalue/core/query/KeyValueQuery.java index 994d9b5..1a14be6 100644 --- a/src/main/java/org/springframework/data/keyvalue/core/query/KeyValueQuery.java +++ b/src/main/java/org/springframework/data/keyvalue/core/query/KeyValueQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 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. @@ -19,11 +19,12 @@ import org.springframework.data.domain.Sort; /** * @author Christoph Strobl + * @author Mark Paluch * @param Criteria type */ public class KeyValueQuery { - private Sort sort; + private Sort sort = Sort.unsorted(); private long offset = -1; private int rows = -1; private T criteria; @@ -35,7 +36,7 @@ public class KeyValueQuery { /** * Creates new instance of {@link KeyValueQuery} with given criteria. - * + * * @param criteria can be {@literal null}. */ public KeyValueQuery(T criteria) { @@ -44,7 +45,7 @@ public class KeyValueQuery { /** * Creates new instance of {@link KeyValueQuery} with given {@link Sort}. - * + * * @param sort can be {@literal null}. */ public KeyValueQuery(Sort sort) { @@ -53,7 +54,7 @@ public class KeyValueQuery { /** * Get the criteria object. - * + * * @return */ public T getCritieria() { @@ -62,7 +63,7 @@ public class KeyValueQuery { /** * Get {@link Sort}. - * + * * @return */ public Sort getSort() { @@ -71,7 +72,7 @@ public class KeyValueQuery { /** * Number of elements to skip. - * + * * @return negative value if not set. */ public long getOffset() { @@ -80,7 +81,7 @@ public class KeyValueQuery { /** * Number of elements to read. - * + * * @return negative value if not set. */ public int getRows() { @@ -89,7 +90,7 @@ public class KeyValueQuery { /** * Set the number of elements to skip. - * + * * @param offset use negative value for none. */ public void setOffset(long offset) { @@ -98,8 +99,8 @@ public class KeyValueQuery { /** * Set the number of elements to read. - * - * @param offset use negative value for all. + * + * @param rows use negative value for all. */ public void setRows(int rows) { this.rows = rows; @@ -107,7 +108,7 @@ public class KeyValueQuery { /** * Set {@link Sort} to be applied. - * + * * @param sort */ public void setSort(Sort sort) { @@ -116,7 +117,7 @@ public class KeyValueQuery { /** * Add given {@link Sort}. - * + * * @param sort {@literal null} {@link Sort} will be ignored. * @return */ @@ -127,7 +128,7 @@ public class KeyValueQuery { } if (this.sort != null) { - this.sort.and(sort); + this.sort = this.sort.and(sort); } else { this.sort = sort; } @@ -135,7 +136,7 @@ public class KeyValueQuery { } /** - * @see KeyValueQuery#setOffset(int) + * @see KeyValueQuery#setOffset(long) * @param offset * @return */ diff --git a/src/main/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQuery.java b/src/main/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQuery.java index a21ab6c..1b09444 100644 --- a/src/main/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQuery.java +++ b/src/main/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 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. @@ -41,7 +41,7 @@ import org.springframework.util.ClassUtils; /** * {@link RepositoryQuery} implementation deriving queries from {@link PartTree} using a predefined * {@link AbstractQueryCreator}. - * + * * @author Christoph Strobl * @author Oliver Gierke * @author Mark Paluch @@ -56,7 +56,7 @@ public class KeyValuePartTreeQuery implements RepositoryQuery { /** * Creates a new {@link KeyValuePartTreeQuery} for the given {@link QueryMethod}, {@link EvaluationContextProvider}, * {@link KeyValueOperations} and query creator type. - * + * * @param queryMethod must not be {@literal null}. * @param evaluationContextProvider must not be {@literal null}. * @param keyValueOperations must not be {@literal null}. @@ -157,7 +157,7 @@ public class KeyValuePartTreeQuery implements RepositoryQuery { query.setRows(instance.getRows()); } - query.setSort(sort == null || Sort.unsorted().equals(sort) ? instance.getSort() : sort); + query.setSort(sort == null || sort.isUnsorted() ? instance.getSort() : sort); return query; } @@ -179,7 +179,7 @@ public class KeyValuePartTreeQuery implements RepositoryQuery { PartTree tree = new PartTree(getQueryMethod().getName(), getQueryMethod().getEntityInformation().getJavaType()); - Constructor> constructor = (Constructor>) ClassUtils + Constructor> constructor = ClassUtils .getConstructorIfAvailable(queryCreator, PartTree.class, ParameterAccessor.class); KeyValueQuery query = (KeyValueQuery) BeanUtils.instantiateClass(constructor, tree, accessor).createQuery(); diff --git a/src/main/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreator.java b/src/main/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreator.java index a5e27f4..5b0ed81 100644 --- a/src/main/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreator.java +++ b/src/main/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreator.java @@ -32,7 +32,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser; /** * {@link AbstractQueryCreator} to create {@link SpelExpression} based {@link KeyValueQuery}s. - * + * * @author Christoph Strobl * @author Oliver Gierke */ @@ -44,7 +44,7 @@ public class SpelQueryCreator extends AbstractQueryCreator complete(String criteria, Sort sort) { - KeyValueQuery query = new KeyValueQuery(this.expression); + KeyValueQuery query = new KeyValueQuery<>(this.expression); if (sort != null) { query.orderBy(sort); diff --git a/src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtils.java b/src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtils.java index c3dc32e..c6e00a0 100644 --- a/src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtils.java +++ b/src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtils.java @@ -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. @@ -33,7 +33,7 @@ import com.querydsl.core.types.dsl.PathBuilder; /** * Utilities for Querydsl usage. - * + * * @author Christoph Strobl * @author Thomas Darimont * @author Oliver Gierke @@ -46,7 +46,7 @@ abstract class KeyValueQuerydslUtils { /** * Transforms a plain {@link Order} into a QueryDsl specific {@link OrderSpecifier}. - * + * * @param sort * @param builder must not be {@literal null}. * @return empty {@code OrderSpecifier[]} when sort is {@literal null}. @@ -65,7 +65,7 @@ abstract class KeyValueQuerydslUtils { specifiers = ((QSort) sort).getOrderSpecifiers(); } else { - specifiers = new ArrayList>(); + specifiers = new ArrayList<>(); for (Order order : sort) { specifiers.add(toOrderSpecifier(order, builder)); } @@ -83,7 +83,7 @@ abstract class KeyValueQuerydslUtils { /** * Creates an {@link Expression} for the given {@link Order} property. - * + * * @param order must not be {@literal null}. * @param builder must not be {@literal null}. * @return @@ -114,7 +114,7 @@ abstract class KeyValueQuerydslUtils { /** * Converts the given {@link org.springframework.data.domain.Sort.NullHandling} to the appropriate Querydsl * {@link NullHandling}. - * + * * @param nullHandling must not be {@literal null}. * @return */ diff --git a/src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueRepositoryFactory.java b/src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueRepositoryFactory.java index 196cc01..be777f5 100644 --- a/src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueRepositoryFactory.java +++ b/src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueRepositoryFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 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. @@ -15,7 +15,7 @@ */ package org.springframework.data.keyvalue.repository.support; -import static org.springframework.data.querydsl.QuerydslUtils.*; +import static org.springframework.data.querydsl.QuerydslUtils.QUERY_DSL_PRESENT; import java.io.Serializable; import java.lang.reflect.Constructor; @@ -48,7 +48,7 @@ import org.springframework.util.ClassUtils; /** * {@link RepositoryFactorySupport} specific of handing * {@link org.springframework.data.keyvalue.repository.KeyValueRepository}. - * + * * @author Christoph Strobl * @author Oliver Gierke */ @@ -63,7 +63,7 @@ public class KeyValueRepositoryFactory extends RepositoryFactorySupport { /** * Creates a new {@link KeyValueRepositoryFactory} for the given {@link KeyValueOperations}. - * + * * @param keyValueOperations must not be {@literal null}. */ public KeyValueRepositoryFactory(KeyValueOperations keyValueOperations) { @@ -73,7 +73,7 @@ public class KeyValueRepositoryFactory extends RepositoryFactorySupport { /** * Creates a new {@link KeyValueRepositoryFactory} for the given {@link KeyValueOperations} and * {@link AbstractQueryCreator}-type. - * + * * @param keyValueOperations must not be {@literal null}. * @param queryCreator defaulted to {@link #DEFAULT_QUERY_CREATOR} if {@literal null}. */ @@ -86,7 +86,7 @@ public class KeyValueRepositoryFactory extends RepositoryFactorySupport { /** * Creates a new {@link KeyValueRepositoryFactory} for the given {@link KeyValueOperations} and * {@link AbstractQueryCreator}-type. - * + * * @param keyValueOperations must not be {@literal null}. * @param queryCreator must not be {@literal null}. * @param repositoryQueryType must not be {@literal null}. @@ -114,7 +114,7 @@ public class KeyValueRepositoryFactory extends RepositoryFactorySupport { public EntityInformation getEntityInformation(Class domainClass) { PersistentEntity entity = (PersistentEntity) context.getPersistentEntity(domainClass).get(); - PersistentEntityInformation entityInformation = new PersistentEntityInformation(entity); + PersistentEntityInformation entityInformation = new PersistentEntityInformation<>(entity); return entityInformation; } @@ -142,7 +142,7 @@ public class KeyValueRepositoryFactory extends RepositoryFactorySupport { /** * Returns whether the given repository interface requires a QueryDsl specific implementation to be chosen. - * + * * @param repositoryInterface must not be {@literal null}. * @return */ @@ -177,7 +177,7 @@ public class KeyValueRepositoryFactory extends RepositoryFactorySupport { * {@link KeyValueOperations} and query creator type. *

* TODO: Key is not considered. Should it? - * + * * @param key * @param evaluationContextProvider must not be {@literal null}. * @param keyValueOperations must not be {@literal null}. @@ -210,7 +210,7 @@ public class KeyValueRepositoryFactory extends RepositoryFactorySupport { this.repositoryQueryType = repositoryQueryType; } - /* + /* * (non-Javadoc) * @see org.springframework.data.repository.query.QueryLookupStrategy#resolveQuery(java.lang.reflect.Method, org.springframework.data.repository.core.RepositoryMetadata, org.springframework.data.projection.ProjectionFactory, org.springframework.data.repository.core.NamedQueries) */ diff --git a/src/main/java/org/springframework/data/keyvalue/repository/support/QuerydslKeyValueRepository.java b/src/main/java/org/springframework/data/keyvalue/repository/support/QuerydslKeyValueRepository.java index 0fd9df6..35c2ed8 100644 --- a/src/main/java/org/springframework/data/keyvalue/repository/support/QuerydslKeyValueRepository.java +++ b/src/main/java/org/springframework/data/keyvalue/repository/support/QuerydslKeyValueRepository.java @@ -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. @@ -15,7 +15,7 @@ */ package org.springframework.data.keyvalue.repository.support; -import static org.springframework.data.keyvalue.repository.support.KeyValueQuerydslUtils.*; +import static org.springframework.data.keyvalue.repository.support.KeyValueQuerydslUtils.toOrderSpecifier; import java.io.Serializable; @@ -41,7 +41,7 @@ import com.querydsl.core.types.dsl.PathBuilder; /** * {@link KeyValueRepository} implementation capable of executing {@link Predicate}s using {@link CollQuery}. - * + * * @author Christoph Strobl * @author Oliver Gierke * @author Thomas Darimont @@ -59,7 +59,7 @@ public class QuerydslKeyValueRepository extends Simp /** * Creates a new {@link QuerydslKeyValueRepository} for the given {@link EntityInformation} and * {@link KeyValueOperations}. - * + * * @param entityInformation must not be {@literal null}. * @param operations must not be {@literal null}. */ @@ -70,7 +70,7 @@ public class QuerydslKeyValueRepository extends Simp /** * Creates a new {@link QuerydslKeyValueRepository} for the given {@link EntityInformation}, * {@link KeyValueOperations} and {@link EntityPathResolver}. - * + * * @param entityInformation must not be {@literal null}. * @param operations must not be {@literal null}. * @param resolver must not be {@literal null}. @@ -83,7 +83,7 @@ public class QuerydslKeyValueRepository extends Simp Assert.notNull(resolver, "EntityPathResolver must not be null!"); this.path = resolver.createPath(entityInformation.getJavaType()); - this.builder = new PathBuilder(path.getType(), path.getMetadata()); + this.builder = new PathBuilder<>(path.getType(), path.getMetadata()); } /* @@ -117,7 +117,7 @@ public class QuerydslKeyValueRepository extends Simp return query.fetchResults().getResults(); } - /* + /* * (non-Javadoc) * @see org.springframework.data.querydsl.QueryDslPredicateExecutor#findAll(com.mysema.query.types.Predicate, org.springframework.data.domain.Sort) */ @@ -145,7 +145,7 @@ public class QuerydslKeyValueRepository extends Simp } } - return new PageImpl(query.fetchResults().getResults(), pageable, count(predicate)); + return new PageImpl<>(query.fetchResults().getResults(), pageable, count(predicate)); } /* @@ -174,7 +174,7 @@ public class QuerydslKeyValueRepository extends Simp return prepareQuery(predicate).fetchCount(); } - /* + /* * (non-Javadoc) * @see org.springframework.data.querydsl.QueryDslPredicateExecutor#exists(com.mysema.query.types.Predicate) */ @@ -185,13 +185,13 @@ public class QuerydslKeyValueRepository extends Simp /** * Creates executable query for given {@link Predicate}. - * + * * @param predicate * @return */ protected AbstractCollQuery prepareQuery(Predicate predicate) { - CollQuery query = new CollQuery(); + CollQuery query = new CollQuery<>(); query.from(builder, findAll()); return predicate != null ? query.where(predicate) : query; diff --git a/src/main/java/org/springframework/data/keyvalue/repository/support/SimpleKeyValueRepository.java b/src/main/java/org/springframework/data/keyvalue/repository/support/SimpleKeyValueRepository.java index 0691a12..80c7abc 100644 --- a/src/main/java/org/springframework/data/keyvalue/repository/support/SimpleKeyValueRepository.java +++ b/src/main/java/org/springframework/data/keyvalue/repository/support/SimpleKeyValueRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 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. @@ -44,7 +44,7 @@ public class SimpleKeyValueRepository implements Key /** * Creates a new {@link SimpleKeyValueRepository} for the given {@link EntityInformation} and * {@link KeyValueOperations}. - * + * * @param metadata must not be {@literal null}. * @param operations must not be {@literal null}. */ @@ -75,13 +75,13 @@ public class SimpleKeyValueRepository implements Key if (pageable == null) { List result = findAll(); - return new PageImpl(result, Pageable.unpaged(), result.size()); + return new PageImpl<>(result, Pageable.unpaged(), result.size()); } Iterable content = operations.findInRange(pageable.getOffset(), pageable.getPageSize(), pageable.getSort(), entityInformation.getJavaType()); - return new PageImpl(IterableConverter.toList(content), pageable, + return new PageImpl<>(IterableConverter.toList(content), pageable, this.operations.count(entityInformation.getJavaType())); } @@ -150,7 +150,7 @@ public class SimpleKeyValueRepository implements Key @Override public Iterable findAll(Iterable ids) { - List result = new ArrayList(); + List result = new ArrayList<>(); for (ID id : ids) { diff --git a/src/main/java/org/springframework/data/map/MapKeyValueAdapter.java b/src/main/java/org/springframework/data/map/MapKeyValueAdapter.java index f5bb75a..b2628e3 100644 --- a/src/main/java/org/springframework/data/map/MapKeyValueAdapter.java +++ b/src/main/java/org/springframework/data/map/MapKeyValueAdapter.java @@ -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. @@ -31,7 +31,7 @@ import org.springframework.util.ClassUtils; /** * {@link KeyValueAdapter} implementation for {@link Map}. - * + * * @author Christoph Strobl */ public class MapKeyValueAdapter extends AbstractKeyValueAdapter { @@ -49,7 +49,7 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter { /** * Creates a new {@link MapKeyValueAdapter} using the given {@link Map} as backing store. - * + * * @param mapType must not be {@literal null}. */ @SuppressWarnings("rawtypes") @@ -59,7 +59,7 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter { /** * Create new instance of {@link MapKeyValueAdapter} using given dataStore for persistence. - * + * * @param store must not be {@literal null}. */ @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -69,7 +69,7 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter { /** * Creates a new {@link MapKeyValueAdapter} with the given store and type to be used when creating key spaces. - * + * * @param store must not be {@literal null}. * @param keySpaceMapType must not be {@literal null}. */ @@ -150,7 +150,7 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter { */ @Override public CloseableIterator> entries(Serializable keyspace) { - return new ForwardingCloseableIterator>(getKeySpaceMap(keyspace).entrySet().iterator()); + return new ForwardingCloseableIterator<>(getKeySpaceMap(keyspace).entrySet().iterator()); } /* @@ -182,7 +182,7 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter { /** * Get map associated with given key space. - * + * * @param keyspace must not be {@literal null}. * @return */ diff --git a/src/test/java/org/springframework/data/keyvalue/core/ForwardingCloseableIteratorUnitTests.java b/src/test/java/org/springframework/data/keyvalue/core/ForwardingCloseableIteratorUnitTests.java index 115f4fa..0d389c4 100644 --- a/src/test/java/org/springframework/data/keyvalue/core/ForwardingCloseableIteratorUnitTests.java +++ b/src/test/java/org/springframework/data/keyvalue/core/ForwardingCloseableIteratorUnitTests.java @@ -15,8 +15,7 @@ */ package org.springframework.data.keyvalue.core; -import static org.hamcrest.core.Is.*; -import static org.hamcrest.core.IsNull.*; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -47,7 +46,7 @@ public class ForwardingCloseableIteratorUnitTests { when(iteratorMock.hasNext()).thenReturn(true); - CloseableIterator> iterator = new ForwardingCloseableIterator>(iteratorMock); + CloseableIterator> iterator = new ForwardingCloseableIterator<>(iteratorMock); try { assertThat(iterator.hasNext(), is(true)); @@ -63,7 +62,7 @@ public class ForwardingCloseableIteratorUnitTests { when(iteratorMock.next()).thenReturn((Entry) mock(Map.Entry.class)); - CloseableIterator> iterator = new ForwardingCloseableIterator>(iteratorMock); + CloseableIterator> iterator = new ForwardingCloseableIterator<>(iteratorMock); try { assertThat(iterator.next(), notNullValue()); @@ -78,7 +77,7 @@ public class ForwardingCloseableIteratorUnitTests { when(iteratorMock.next()).thenThrow(new NoSuchElementException()); - CloseableIterator> iterator = new ForwardingCloseableIterator>(iteratorMock); + CloseableIterator> iterator = new ForwardingCloseableIterator<>(iteratorMock); try { iterator.next(); @@ -90,7 +89,7 @@ public class ForwardingCloseableIteratorUnitTests { @Test // DATAKV-99 public void closeShouldDoNothingByDefault() { - new ForwardingCloseableIterator>(iteratorMock).close(); + new ForwardingCloseableIterator<>(iteratorMock).close(); verifyZeroInteractions(iteratorMock); } @@ -98,7 +97,7 @@ public class ForwardingCloseableIteratorUnitTests { @Test // DATAKV-99 public void closeShouldInvokeConfiguredCloseAction() { - new ForwardingCloseableIterator>(iteratorMock, closeActionMock).close(); + new ForwardingCloseableIterator<>(iteratorMock, closeActionMock).close(); verify(closeActionMock, times(1)).run(); } diff --git a/src/test/java/org/springframework/data/keyvalue/core/IterableConverterUnitTests.java b/src/test/java/org/springframework/data/keyvalue/core/IterableConverterUnitTests.java index 8e7794d..2f9ebd7 100644 --- a/src/test/java/org/springframework/data/keyvalue/core/IterableConverterUnitTests.java +++ b/src/test/java/org/springframework/data/keyvalue/core/IterableConverterUnitTests.java @@ -15,11 +15,7 @@ */ package org.springframework.data.keyvalue.core; -import static org.hamcrest.collection.IsEmptyCollection.*; -import static org.hamcrest.collection.IsIterableContainingInOrder.*; -import static org.hamcrest.core.IsInstanceOf.*; -import static org.hamcrest.core.IsNull.*; -import static org.hamcrest.core.IsSame.*; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; import static org.springframework.data.keyvalue.core.IterableConverter.*; @@ -50,7 +46,7 @@ public class IterableConverterUnitTests { @Test // DATAKV-101 public void toListShouldReturnSameObjectWhenSourceIsAlreadyListType() { - List source = new ArrayList(); + List source = new ArrayList<>(); assertThat(toList(source), sameInstance(source)); } @@ -58,7 +54,7 @@ public class IterableConverterUnitTests { @Test // DATAKV-101 public void toListShouldReturnListWhenSourceIsNonListType() { - Set source = new HashSet(); + Set source = new HashSet<>(); source.add("tyrion"); assertThat(toList(source), instanceOf(List.class)); @@ -67,7 +63,7 @@ public class IterableConverterUnitTests { @Test // DATAKV-101 public void toListShouldHoldValuesInOrderOfSource() { - Set source = new LinkedHashSet(); + Set source = new LinkedHashSet<>(); source.add("tyrion"); source.add("jaime"); diff --git a/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateTests.java b/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateTests.java index f2b7c27..b02c355 100644 --- a/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateTests.java +++ b/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateTests.java @@ -15,12 +15,7 @@ */ package org.springframework.data.keyvalue.core; -import static org.hamcrest.collection.IsCollectionWithSize.*; -import static org.hamcrest.collection.IsEmptyIterable.*; -import static org.hamcrest.collection.IsIterableContainingInAnyOrder.*; -import static org.hamcrest.core.Is.*; -import static org.hamcrest.core.IsNull.*; -import static org.hamcrest.core.IsSame.*; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; import java.io.Serializable; @@ -54,7 +49,7 @@ public class KeyValueTemplateTests { static final Bar BAR_ONE = new Bar("one"); static final ClassWithTypeAlias ALIASED = new ClassWithTypeAlias("super"); static final SubclassOfAliasedType SUBCLASS_OF_ALIASED = new SubclassOfAliasedType("sub"); - static final KeyValueQuery STRING_QUERY = new KeyValueQuery("foo == 'two'"); + static final KeyValueQuery STRING_QUERY = new KeyValueQuery<>("foo == 'two'"); KeyValueTemplate operations; diff --git a/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java b/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java index b0b90bd..ba028ec 100644 --- a/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java +++ b/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java @@ -15,8 +15,7 @@ */ package org.springframework.data.keyvalue.core; -import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.collection.IsIterableContainingInAnyOrder.*; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -75,7 +74,7 @@ public class KeyValueTemplateUnitTests { "super"); private static final SubclassOfTypeWithCustomComposedKeySpaceAnnotation SUBCLASS_OF_ALIASED = new SubclassOfTypeWithCustomComposedKeySpaceAnnotation( "sub"); - private static final KeyValueQuery STRING_QUERY = new KeyValueQuery("foo == 'two'"); + private static final KeyValueQuery STRING_QUERY = new KeyValueQuery<>("foo == 'two'"); private @Mock KeyValueAdapter adapterMock; private KeyValueTemplate template; @@ -557,7 +556,7 @@ public class KeyValueTemplateUnitTests { @SuppressWarnings("rawtypes") private void setEventsToPublish(Class... events) { - template.setEventTypesToPublish(new HashSet>(Arrays.asList(events))); + template.setEventTypesToPublish(new HashSet<>(Arrays.asList(events))); } static class Foo { diff --git a/src/test/java/org/springframework/data/keyvalue/core/SpelPropertyComperatorUnitTests.java b/src/test/java/org/springframework/data/keyvalue/core/SpelPropertyComperatorUnitTests.java index 1784b36..6e1be47 100644 --- a/src/test/java/org/springframework/data/keyvalue/core/SpelPropertyComperatorUnitTests.java +++ b/src/test/java/org/springframework/data/keyvalue/core/SpelPropertyComperatorUnitTests.java @@ -27,7 +27,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser; /** * Unit tests for {@link SpelPropertyComparator}. - * + * * @author Christoph Strobl * @author Oliver Gierke */ @@ -43,7 +43,7 @@ public class SpelPropertyComperatorUnitTests { @Test // DATACMNS-525 public void shouldCompareStringAscCorrectly() { - Comparator comparator = new SpelPropertyComparator("stringProperty", PARSER); + Comparator comparator = new SpelPropertyComparator<>("stringProperty", PARSER); assertThat(comparator.compare(ONE, TWO), is(ONE.getStringProperty().compareTo(TWO.getStringProperty()))); } @@ -57,7 +57,7 @@ public class SpelPropertyComperatorUnitTests { @Test // DATACMNS-525 public void shouldCompareIntegerAscCorrectly() { - Comparator comparator = new SpelPropertyComparator("integerProperty", PARSER); + Comparator comparator = new SpelPropertyComparator<>("integerProperty", PARSER); assertThat(comparator.compare(ONE, TWO), is(ONE.getIntegerProperty().compareTo(TWO.getIntegerProperty()))); } @@ -71,7 +71,7 @@ public class SpelPropertyComperatorUnitTests { @Test // DATACMNS-525 public void shouldComparePrimitiveIntegerAscCorrectly() { - Comparator comparator = new SpelPropertyComparator("primitiveProperty", PARSER); + Comparator comparator = new SpelPropertyComparator<>("primitiveProperty", PARSER); assertThat(comparator.compare(ONE, TWO), is(valueOf(ONE.getPrimitiveProperty()).compareTo(valueOf(TWO.getPrimitiveProperty())))); } @@ -79,7 +79,7 @@ public class SpelPropertyComperatorUnitTests { @Test // DATACMNS-525 public void shouldNotFailOnNullValues() { - Comparator comparator = new SpelPropertyComparator("stringProperty", PARSER); + Comparator comparator = new SpelPropertyComparator<>("stringProperty", PARSER); assertThat(comparator.compare(ONE, new SomeType(null, null, 2)), is(1)); } @@ -107,16 +107,15 @@ public class SpelPropertyComperatorUnitTests { @Test // DATACMNS-525 public void shouldCompareNestedTypesCorrectly() { - Comparator comparator = new SpelPropertyComparator("nestedType.stringProperty", PARSER); - assertThat(comparator.compare(WRAPPER_ONE, WRAPPER_TWO), is(WRAPPER_ONE.getNestedType().getStringProperty() - .compareTo(WRAPPER_TWO.getNestedType().getStringProperty()))); + Comparator comparator = new SpelPropertyComparator<>("nestedType.stringProperty", PARSER); + assertThat(comparator.compare(WRAPPER_ONE, WRAPPER_TWO), + is(WRAPPER_ONE.getNestedType().getStringProperty().compareTo(WRAPPER_TWO.getNestedType().getStringProperty()))); } @Test // DATACMNS-525 public void shouldCompareNestedTypesCorrectlyWhenOneOfThemHasNullValue() { - SpelPropertyComparator comparator = new SpelPropertyComparator( - "nestedType.stringProperty", PARSER); + SpelPropertyComparator comparator = new SpelPropertyComparator<>("nestedType.stringProperty", PARSER); assertThat(comparator.compare(WRAPPER_ONE, new WrapperType("two", null)), is(greaterThanOrEqualTo(1))); } diff --git a/src/test/java/org/springframework/data/keyvalue/core/SpelQueryEngineUnitTests.java b/src/test/java/org/springframework/data/keyvalue/core/SpelQueryEngineUnitTests.java index 207da6c..316694a 100644 --- a/src/test/java/org/springframework/data/keyvalue/core/SpelQueryEngineUnitTests.java +++ b/src/test/java/org/springframework/data/keyvalue/core/SpelQueryEngineUnitTests.java @@ -18,13 +18,12 @@ package org.springframework.data.keyvalue.core; import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.contains; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.List; import org.junit.Before; @@ -43,7 +42,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext; /** * Unit tests for {@link SpelQueryEngine}. - * + * * @author Martin Macko * @author Oliver Gierke */ @@ -62,7 +61,7 @@ public class SpelQueryEngineUnitTests { @Before public void setUp() { - engine = new SpelQueryEngine(); + engine = new SpelQueryEngine<>(); engine.registerAdapter(adapter); } @@ -72,8 +71,8 @@ public class SpelQueryEngineUnitTests { doReturn(people).when(adapter).getAllOf(anyString()); - assertThat((Collection) engine.execute(createQueryForMethodWithArgs("findByFirstname", "bob"), null, -1, - -1, anyString()), contains(BOB_WITH_FIRSTNAME)); + assertThat(engine.execute(createQueryForMethodWithArgs("findByFirstname", "bob"), null, -1, -1, anyString()), + contains(BOB_WITH_FIRSTNAME)); } @Test // DATAKV-114 @@ -86,7 +85,7 @@ public class SpelQueryEngineUnitTests { private static SpelCriteria createQueryForMethodWithArgs(String methodName, Object... args) throws Exception { - List> types = new ArrayList>(args.length); + List> types = new ArrayList<>(args.length); for (Object arg : args) { types.add(arg.getClass()); @@ -97,8 +96,8 @@ public class SpelQueryEngineUnitTests { doReturn(method.getReturnType()).when(metadata).getReturnedDomainClass(method); PartTree partTree = new PartTree(method.getName(), method.getReturnType()); - SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(new QueryMethod(method, - metadata, new SpelAwareProxyProjectionFactory()).getParameters(), args)); + SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor( + new QueryMethod(method, metadata, new SpelAwareProxyProjectionFactory()).getParameters(), args)); return new SpelCriteria(creator.createQuery().getCritieria(), new StandardEvaluationContext(args)); } diff --git a/src/test/java/org/springframework/data/keyvalue/repository/SimpleKeyValueRepositoryUnitTests.java b/src/test/java/org/springframework/data/keyvalue/repository/SimpleKeyValueRepositoryUnitTests.java index d34f72b..5751ddf 100644 --- a/src/test/java/org/springframework/data/keyvalue/repository/SimpleKeyValueRepositoryUnitTests.java +++ b/src/test/java/org/springframework/data/keyvalue/repository/SimpleKeyValueRepositoryUnitTests.java @@ -48,17 +48,15 @@ public class SimpleKeyValueRepositoryUnitTests { @Before public void setUp() { - ReflectionEntityInformation ei = new ReflectionEntityInformation(Foo.class); - repo = new SimpleKeyValueRepository(ei, opsMock); + ReflectionEntityInformation ei = new ReflectionEntityInformation<>(Foo.class); + repo = new SimpleKeyValueRepository<>(ei, opsMock); } @Test // DATACMNS-525 public void saveNewWithNumericId() { - ReflectionEntityInformation ei = new ReflectionEntityInformation( - WithNumericId.class); - SimpleKeyValueRepository temp = new SimpleKeyValueRepository(ei, - opsMock); + ReflectionEntityInformation ei = new ReflectionEntityInformation<>(WithNumericId.class); + SimpleKeyValueRepository temp = new SimpleKeyValueRepository<>(ei, opsMock); WithNumericId withNumericId = new WithNumericId(); temp.save(withNumericId); @@ -129,7 +127,7 @@ public class SimpleKeyValueRepositoryUnitTests { @Test // DATACMNS-525 public void findAllWithPageableShouldDelegateToOperationsCorrectlyWhenPageableDoesNotContainSort() { - repo.findAll(new PageRequest(10, 15)); + repo.findAll(PageRequest.of(10, 15)); verify(opsMock, times(1)).findInRange(eq(150L), eq(15), eq(Sort.unsorted()), eq(Foo.class)); } @@ -137,8 +135,8 @@ public class SimpleKeyValueRepositoryUnitTests { @Test // DATACMNS-525 public void findAllWithPageableShouldDelegateToOperationsCorrectlyWhenPageableContainsSort() { - Sort sort = new Sort("for", "bar"); - repo.findAll(new PageRequest(10, 15, sort)); + Sort sort = Sort.by("for", "bar"); + repo.findAll(PageRequest.of(10, 15, sort)); verify(opsMock, times(1)).findInRange(eq(150L), eq(15), eq(sort), eq(Foo.class)); } diff --git a/src/test/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQueryUnitTests.java b/src/test/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQueryUnitTests.java index 5bad755..928dfc1 100644 --- a/src/test/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQueryUnitTests.java +++ b/src/test/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQueryUnitTests.java @@ -15,12 +15,9 @@ */ package org.springframework.data.keyvalue.repository.query; -import static org.hamcrest.core.Is.*; -import static org.hamcrest.core.IsNot.*; -import static org.hamcrest.core.IsNull.*; -import static org.hamcrest.core.IsSame.*; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.lang.reflect.Method; @@ -86,7 +83,7 @@ public class KeyValuePartTreeQueryUnitTests { KeyValuePartTreeQuery partTreeQuery = new KeyValuePartTreeQuery(qm, DefaultEvaluationContextProvider.INSTANCE, kvOpsMock, SpelQueryCreator.class); - KeyValueQuery query = partTreeQuery.prepareQuery(new Object[] { new PageRequest(2, 3) }); + KeyValueQuery query = partTreeQuery.prepareQuery(new Object[] { PageRequest.of(2, 3) }); assertThat(query.getOffset(), is(6L)); assertThat(query.getRows(), is(3)); diff --git a/src/test/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreatorUnitTests.java b/src/test/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreatorUnitTests.java index f6f50ce..e21fa92 100644 --- a/src/test/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreatorUnitTests.java +++ b/src/test/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreatorUnitTests.java @@ -72,32 +72,32 @@ public class SpelQueryCreatorUnitTests { } @Test // DATACMNS-525 - public void isTrueAssertedPropertlyWhenTrue() throws Exception { + public void isTrueAssertedProperlyWhenTrue() throws Exception { assertThat(evaluate("findBySkinChangerIsTrue").against(BRAN), is(true)); } @Test // DATACMNS-525 - public void isTrueAssertedPropertlyWhenFalse() throws Exception { + public void isTrueAssertedProperlyWhenFalse() throws Exception { assertThat(evaluate("findBySkinChangerIsTrue").against(RICKON), is(false)); } @Test // DATACMNS-525 - public void isFalseAssertedPropertlyWhenTrue() throws Exception { + public void isFalseAssertedProperlyWhenTrue() throws Exception { assertThat(evaluate("findBySkinChangerIsFalse").against(BRAN), is(false)); } @Test // DATACMNS-525 - public void isFalseAssertedPropertlyWhenFalse() throws Exception { + public void isFalseAssertedProperlyWhenFalse() throws Exception { assertThat(evaluate("findBySkinChangerIsFalse").against(RICKON), is(true)); } @Test // DATACMNS-525 - public void isNullAssertedPropertlyWhenAttributeIsNull() throws Exception { + public void isNullAssertedProperlyWhenAttributeIsNull() throws Exception { assertThat(evaluate("findByLastnameIsNull").against(BRAN), is(true)); } @Test // DATACMNS-525 - public void isNullAssertedPropertlyWhenAttributeIsNotNull() throws Exception { + public void isNullAssertedProperlyWhenAttributeIsNotNull() throws Exception { assertThat(evaluate("findByLastnameIsNull").against(ROBB), is(false)); } @@ -400,8 +400,8 @@ public class SpelQueryCreatorUnitTests { SpelExpression expression; Object candidate; - public Evaluation(SpelExpression expresison) { - this.expression = expresison; + public Evaluation(SpelExpression expression) { + this.expression = expression; } public Boolean against(Object candidate) { diff --git a/src/test/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtilsUnitTests.java b/src/test/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtilsUnitTests.java index ba117d6..c942e8c 100644 --- a/src/test/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtilsUnitTests.java +++ b/src/test/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtilsUnitTests.java @@ -35,7 +35,7 @@ import com.querydsl.core.types.dsl.PathBuilder; /** * Unit tests for {@link KeyValueQuerydslUtils}. - * + * * @author Christoph Strobl * @author Thomas Darimont * @author Oliver Gierke @@ -49,12 +49,12 @@ public class KeyValueQuerydslUtilsUnitTests { public void setUp() { this.path = SimpleEntityPathResolver.INSTANCE.createPath(Person.class); - this.builder = new PathBuilder(path.getType(), path.getMetadata()); + this.builder = new PathBuilder<>(path.getType(), path.getMetadata()); } @Test(expected = IllegalArgumentException.class) // DATACMNS-525 public void toOrderSpecifierThrowsExceptioOnNullPathBuilder() { - toOrderSpecifier(new Sort("firstname"), null); + toOrderSpecifier(Sort.by("firstname"), null); } @Test // DATACMNS-525 @@ -65,7 +65,7 @@ public class KeyValueQuerydslUtilsUnitTests { @Test // DATACMNS-525 public void toOrderSpecifierConvertsSimpleAscSortCorrectly() { - Sort sort = new Sort(Direction.ASC, "firstname"); + Sort sort = Sort.by(Direction.ASC, "firstname"); OrderSpecifier[] specifiers = toOrderSpecifier(sort, builder); @@ -76,7 +76,7 @@ public class KeyValueQuerydslUtilsUnitTests { @Test // DATACMNS-525 public void toOrderSpecifierConvertsSimpleDescSortCorrectly() { - Sort sort = new Sort(Direction.DESC, "firstname"); + Sort sort = Sort.by(Direction.DESC, "firstname"); OrderSpecifier[] specifiers = toOrderSpecifier(sort, builder); @@ -87,7 +87,7 @@ public class KeyValueQuerydslUtilsUnitTests { @Test // DATACMNS-525 public void toOrderSpecifierConvertsSortCorrectlyAndRetainsArgumentOrder() { - Sort sort = new Sort(Direction.DESC, "firstname").and(new Sort(Direction.ASC, "age")); + Sort sort = Sort.by(Direction.DESC, "firstname").and(Sort.by(Direction.ASC, "age")); OrderSpecifier[] specifiers = toOrderSpecifier(sort, builder); @@ -98,7 +98,7 @@ public class KeyValueQuerydslUtilsUnitTests { @Test // DATACMNS-525 public void toOrderSpecifierConvertsSortWithNullHandlingCorrectly() { - Sort sort = new Sort(new Sort.Order(Direction.DESC, "firstname", NullHandling.NULLS_LAST)); + Sort sort = Sort.by(new Sort.Order(Direction.DESC, "firstname", NullHandling.NULLS_LAST)); OrderSpecifier[] specifiers = toOrderSpecifier(sort, builder); diff --git a/src/test/java/org/springframework/data/map/AbstractRepositoryUnitTests.java b/src/test/java/org/springframework/data/map/AbstractRepositoryUnitTests.java index d2200ea..bb3d8cf 100644 --- a/src/test/java/org/springframework/data/map/AbstractRepositoryUnitTests.java +++ b/src/test/java/org/springframework/data/map/AbstractRepositoryUnitTests.java @@ -39,7 +39,7 @@ import org.springframework.data.repository.CrudRepository; /** * Base class for test cases for repository implementations. - * + * * @author Christoph Strobl * @author Oliver Gierke * @author Thomas Darimont @@ -98,7 +98,7 @@ public abstract class AbstractRepositoryUnitTests page = repository.findByAge(19, new PageRequest(0, 1)); + Page page = repository.findByAge(19, PageRequest.of(0, 1)); assertThat(page.hasNext(), is(true)); assertThat(page.getTotalElements(), is(2L)); assertThat(page.getContent(), IsCollectionWithSize.hasSize(1)); @@ -132,7 +132,7 @@ public abstract class AbstractRepositoryUnitTests result = repository.findByAgeGreaterThan(0, new Sort("firstname")); + List result = repository.findByAgeGreaterThan(0, Sort.by("firstname")); assertThat(result, hasSize(3)); assertThat(result.get(0).getFirstname(), is(CERSEI.getFirstname())); @@ -162,7 +162,7 @@ public abstract class AbstractRepositoryUnitTests result = repository.findByAgeGreaterThan(0, new Sort("firstname"), PersonSummary.class); + List result = repository.findByAgeGreaterThan(0, Sort.by("firstname"), PersonSummary.class); assertThat(result, hasSize(3)); assertThat(result.get(0).getFirstname(), is(CERSEI.getFirstname())); diff --git a/src/test/java/org/springframework/data/map/QuerydslKeyValueRepositoryUnitTests.java b/src/test/java/org/springframework/data/map/QuerydslKeyValueRepositoryUnitTests.java index 2133024..024ad1f 100644 --- a/src/test/java/org/springframework/data/map/QuerydslKeyValueRepositoryUnitTests.java +++ b/src/test/java/org/springframework/data/map/QuerydslKeyValueRepositoryUnitTests.java @@ -37,7 +37,7 @@ import com.google.common.collect.Lists; /** * Unit tests for {@link QuerydslKeyValueRepository}. - * + * * @author Christoph Strobl * @author Oliver Gierke * @author Thomas Darimont @@ -66,7 +66,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT public void findWithPaginationWorksCorrectly() { repository.save(LENNISTERS); - Page page1 = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()), new PageRequest(0, 1)); + Page page1 = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()), PageRequest.of(0, 1)); assertThat(page1.getTotalElements(), is(2L)); assertThat(page1.getContent(), hasSize(1)); @@ -96,8 +96,8 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT repository.save(LENNISTERS); - Iterable result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()), new PageRequest(0, 10, - Direction.DESC, "firstname")); + Iterable result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()), + PageRequest.of(0, 10, Direction.DESC, "firstname")); assertThat(result, contains(JAIME, CERSEI)); } @@ -107,8 +107,8 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT repository.save(LENNISTERS); - Iterable result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()), new PageRequest(0, 10, - new QSort(QPerson.person.firstname.desc()))); + Iterable result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()), + PageRequest.of(0, 10, new QSort(QPerson.person.firstname.desc()))); assertThat(result, contains(JAIME, CERSEI)); } @@ -146,7 +146,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT repository.save(LENNISTERS); - List users = Lists.newArrayList(repository.findAll(person.age.gt(0), new Sort(Direction.ASC, "firstname"))); + List users = Lists.newArrayList(repository.findAll(person.age.gt(0), Sort.by(Direction.ASC, "firstname"))); assertThat(users, hasSize(3)); assertThat(users.get(0).getFirstname(), is(CERSEI.getFirstname())); @@ -154,7 +154,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT assertThat(users, hasItems(CERSEI, JAIME, TYRION)); } - /* + /* * (non-Javadoc) * @see org.springframework.data.map.SimpleKeyValueRepositoryUnitTests#getRepository(org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactory) */