DATAKV-192 - Move codebase to Java8 API.
Make use of stream lambdas in query execution. Remove copy of MetaAnnotationUtils in favor of @AliasFor usage. Original pull request: #26.
This commit is contained in:
committed by
Mark Paluch
parent
871130b9dc
commit
0025c03e5a
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
import org.springframework.data.keyvalue.annotation.KeySpace;
|
||||
|
||||
/**
|
||||
* Custom composed {@link Persistent} annotation using {@link KeySpace} on name attribute.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@Persistent
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE })
|
||||
public @interface CustomKeySpaceAnnotation {
|
||||
|
||||
@KeySpace
|
||||
String name() default "";
|
||||
}
|
||||
@@ -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.
|
||||
@@ -18,10 +18,13 @@ package org.springframework.data.keyvalue;
|
||||
import org.springframework.data.keyvalue.annotation.KeySpace;
|
||||
|
||||
/**
|
||||
* Class that inherits its {@link KeySpace} from a super class annotated with a custom {@link CustomKeySpaceAnnotation} annotation.
|
||||
* Class that inherits its {@link KeySpace} from a super class annotated with a custom {@link CustomKeySpaceAnnotation}
|
||||
* annotation.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class SubclassOfTypeWithCustomComposedKeySpaceAnnotation extends TypeWithCustomComposedKeySpaceAnnotation {
|
||||
public class SubclassOfTypeWithCustomComposedKeySpaceAnnotation
|
||||
extends TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor {
|
||||
|
||||
public SubclassOfTypeWithCustomComposedKeySpaceAnnotation(String name) {
|
||||
super(name);
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* A {@link Persistent} type with {@link CustomKeySpaceAnnotation}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@CustomKeySpaceAnnotation(name = "aliased")
|
||||
public class TypeWithCustomComposedKeySpaceAnnotation {
|
||||
|
||||
@Id String id;
|
||||
String name;
|
||||
|
||||
public TypeWithCustomComposedKeySpaceAnnotation(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ObjectUtils.nullSafeHashCode(this.id);
|
||||
result = prime * result + ObjectUtils.nullSafeHashCode(this.name);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof TypeWithCustomComposedKeySpaceAnnotation)) {
|
||||
return false;
|
||||
}
|
||||
TypeWithCustomComposedKeySpaceAnnotation other = (TypeWithCustomComposedKeySpaceAnnotation) obj;
|
||||
if (!ObjectUtils.nullSafeEquals(this.id, other.id)) {
|
||||
return false;
|
||||
}
|
||||
if (!ObjectUtils.nullSafeEquals(this.name, other.name)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public class KeyValuePersistenceExceptionTranslatorUnitTests {
|
||||
instanceOf(DataRetrievalFailureException.class));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525, DATAKV-192
|
||||
public void translateExeptionShouldReturnNullWhenGivenNull() {
|
||||
assertThat(translator.translateExceptionIfPossible(null), nullValue());
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.Optional;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
@@ -261,12 +262,13 @@ public class KeyValueTemplateTests {
|
||||
|
||||
}
|
||||
|
||||
@KeySpace
|
||||
@Persistent
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE })
|
||||
static @interface ExplicitKeySpace {
|
||||
@interface ExplicitKeySpace {
|
||||
|
||||
@KeySpace
|
||||
@AliasFor(annotation = KeySpace.class, value = "value")
|
||||
String name() default "";
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.springframework.data.keyvalue.core;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -35,7 +34,6 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
@@ -43,7 +41,6 @@ import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.keyvalue.SubclassOfTypeWithCustomComposedKeySpaceAnnotation;
|
||||
import org.springframework.data.keyvalue.TypeWithCustomComposedKeySpaceAnnotation;
|
||||
import org.springframework.data.keyvalue.TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor;
|
||||
import org.springframework.data.keyvalue.core.event.KeyValueEvent;
|
||||
import org.springframework.data.keyvalue.core.event.KeyValueEvent.AfterDeleteEvent;
|
||||
@@ -70,11 +67,9 @@ public class KeyValueTemplateUnitTests {
|
||||
|
||||
private static final Foo FOO_ONE = new Foo("one");
|
||||
private static final Foo FOO_TWO = new Foo("two");
|
||||
private static final TypeWithCustomComposedKeySpaceAnnotation ALIASED = new TypeWithCustomComposedKeySpaceAnnotation(
|
||||
"super");
|
||||
private static final TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor ALIASED_USING_ALIAS_FOR = new TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor(
|
||||
"super");
|
||||
private static final SubclassOfTypeWithCustomComposedKeySpaceAnnotation SUBCLASS_OF_ALIASED = new SubclassOfTypeWithCustomComposedKeySpaceAnnotation(
|
||||
private static final SubclassOfTypeWithCustomComposedKeySpaceAnnotation SUBCLASS_OF_ALIASED_USING_ALIAS_FOR = new SubclassOfTypeWithCustomComposedKeySpaceAnnotation(
|
||||
"sub");
|
||||
private static final KeyValueQuery<String> STRING_QUERY = new KeyValueQuery<>("foo == 'two'");
|
||||
|
||||
@@ -300,34 +295,35 @@ public class KeyValueTemplateUnitTests {
|
||||
@Test // DATACMNS-525
|
||||
public void insertShouldRespectTypeAlias() {
|
||||
|
||||
template.insert("1", ALIASED);
|
||||
template.insert("1", ALIASED_USING_ALIAS_FOR);
|
||||
|
||||
verify(adapterMock, times(1)).put("1", ALIASED, "aliased");
|
||||
verify(adapterMock, times(1)).put("1", ALIASED_USING_ALIAS_FOR, "aliased");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void insertShouldRespectTypeAliasOnSubClass() {
|
||||
|
||||
template.insert("1", SUBCLASS_OF_ALIASED);
|
||||
template.insert("1", SUBCLASS_OF_ALIASED_USING_ALIAS_FOR);
|
||||
|
||||
verify(adapterMock, times(1)).put("1", SUBCLASS_OF_ALIASED, "aliased");
|
||||
verify(adapterMock, times(1)).put("1", SUBCLASS_OF_ALIASED_USING_ALIAS_FOR, "aliased");
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test // DATACMNS-525
|
||||
public void findAllOfShouldRespectTypeAliasAndFilterNonMatchingTypes() {
|
||||
|
||||
Collection foo = Arrays.asList(ALIASED, SUBCLASS_OF_ALIASED);
|
||||
Collection foo = Arrays.asList(ALIASED_USING_ALIAS_FOR, SUBCLASS_OF_ALIASED_USING_ALIAS_FOR);
|
||||
when(adapterMock.getAllOf("aliased")).thenReturn(foo);
|
||||
|
||||
assertThat(template.findAll(SUBCLASS_OF_ALIASED.getClass()), containsInAnyOrder(SUBCLASS_OF_ALIASED));
|
||||
assertThat(template.findAll(SUBCLASS_OF_ALIASED_USING_ALIAS_FOR.getClass()),
|
||||
containsInAnyOrder(SUBCLASS_OF_ALIASED_USING_ALIAS_FOR));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void insertSouldRespectTypeAliasAndFilterNonMatching() {
|
||||
|
||||
template.insert("1", ALIASED);
|
||||
assertThat(template.findById("1", SUBCLASS_OF_ALIASED.getClass()), is(Optional.empty()));
|
||||
template.insert("1", ALIASED_USING_ALIAS_FOR);
|
||||
assertThat(template.findById("1", SUBCLASS_OF_ALIASED_USING_ALIAS_FOR.getClass()), is(Optional.empty()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@@ -359,7 +355,7 @@ public class KeyValueTemplateUnitTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void shouldNotPublishEventsWhenEventsToPublishIsSetToEmptyList() {
|
||||
|
||||
template.setEventTypesToPublish(Collections.<Class<? extends KeyValueEvent>> emptySet());
|
||||
template.setEventTypesToPublish(Collections.emptySet());
|
||||
|
||||
template.insert("1", FOO_ONE);
|
||||
|
||||
@@ -371,7 +367,7 @@ public class KeyValueTemplateUnitTests {
|
||||
|
||||
template.insert("1", FOO_ONE);
|
||||
|
||||
verify(publisherMock, atLeastOnce()).publishEvent(Matchers.any(KeyValueEvent.class));
|
||||
verify(publisherMock, atLeastOnce()).publishEvent(any());
|
||||
}
|
||||
|
||||
@Test // DATAKV-91, DATAKV-104
|
||||
@@ -400,7 +396,7 @@ public class KeyValueTemplateUnitTests {
|
||||
|
||||
assertThat(captor.getValue().getKey(), is("1"));
|
||||
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
|
||||
assertThat(captor.getValue().getPayload(), is((Object) FOO_ONE));
|
||||
assertThat(captor.getValue().getPayload(), is(FOO_ONE));
|
||||
}
|
||||
|
||||
@Test // DATAKV-91, DATAKV-104, DATAKV-187
|
||||
|
||||
@@ -35,8 +35,8 @@ public class SpelPropertyComperatorUnitTests {
|
||||
|
||||
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
|
||||
|
||||
private static final SomeType ONE = new SomeType("one", Integer.valueOf(1), 1);
|
||||
private static final SomeType TWO = new SomeType("two", Integer.valueOf(2), 2);
|
||||
private static final SomeType ONE = new SomeType("one", 1, 1);
|
||||
private static final SomeType TWO = new SomeType("two", 2, 2);
|
||||
private static final WrapperType WRAPPER_ONE = new WrapperType("w-one", ONE);
|
||||
private static final WrapperType WRAPPER_TWO = new WrapperType("w-two", TWO);
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ 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.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -52,11 +52,6 @@ public class AnnotationBasedKeySpaceResolverUnitTests {
|
||||
assertThat(resolver.resolveKeySpace(EntityWithDefaultKeySpace.class), is("daenerys"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void shouldResolveKeySpaceCorrectly() {
|
||||
assertThat(resolver.resolveKeySpace(EntityWithSetKeySpace.class), is("viserys"));
|
||||
}
|
||||
|
||||
@Test // DATAKV-105
|
||||
public void shouldReturnNullWhenNoKeySpaceFoundOnComposedPersistentAnnotation() {
|
||||
assertThat(resolver.resolveKeySpace(TypeWithInhteritedPersistentAnnotationNotHavingKeySpace.class), nullValue());
|
||||
@@ -92,40 +87,24 @@ public class AnnotationBasedKeySpaceResolverUnitTests {
|
||||
assertThat(resolver.resolveKeySpace(EntityWithInheritedKeySpaceUsingAliasFor.class), is("viserys"));
|
||||
}
|
||||
|
||||
@PersistentAnnotationWithExplicitKeySpace
|
||||
@PersistentAnnotationWithExplicitKeySpaceUsingAliasFor
|
||||
static class EntityWithDefaultKeySpace {
|
||||
|
||||
}
|
||||
|
||||
@PersistentAnnotationWithExplicitKeySpace(firstname = "viserys")
|
||||
static class EntityWithSetKeySpace {
|
||||
|
||||
}
|
||||
|
||||
static class EntityWithInheritedKeySpace extends EntityWithSetKeySpace {
|
||||
|
||||
}
|
||||
|
||||
@PersistentAnnotationWithExplicitKeySpace(firstname = "viserys")
|
||||
@PersistentAnnotationWithExplicitKeySpaceUsingAliasFor(firstname = "viserys")
|
||||
static class EntityWithSetKeySpaceUsingAliasFor {
|
||||
|
||||
}
|
||||
|
||||
static class EntityWithInheritedKeySpace extends EntityWithSetKeySpaceUsingAliasFor {
|
||||
|
||||
}
|
||||
|
||||
static class EntityWithInheritedKeySpaceUsingAliasFor extends EntityWithSetKeySpaceUsingAliasFor {
|
||||
|
||||
}
|
||||
|
||||
@Persistent
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE })
|
||||
static @interface PersistentAnnotationWithExplicitKeySpace {
|
||||
|
||||
@KeySpace
|
||||
String firstname() default "daenerys";
|
||||
|
||||
String lastnamne() default "targaryen";
|
||||
}
|
||||
|
||||
@Persistent
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE })
|
||||
|
||||
@@ -17,9 +17,6 @@ package org.springframework.data.keyvalue.repository;
|
||||
|
||||
import static org.hamcrest.core.Is.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.data.keyvalue.repository.query;
|
||||
import static org.hamcrest.core.IsNot.*;
|
||||
import static org.hamcrest.core.IsSame.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -314,7 +314,7 @@ public class SpelQueryCreatorUnitTests {
|
||||
}
|
||||
|
||||
private Evaluation evaluate(String methodName, Object... args) throws Exception {
|
||||
return new Evaluation((SpelExpression) createQueryForMethodWithArgs(methodName, args).getCriteria());
|
||||
return new Evaluation(createQueryForMethodWithArgs(methodName, args).getCriteria());
|
||||
}
|
||||
|
||||
private KeyValueQuery<SpelExpression> createQueryForMethodWithArgs(String methodName, Object... args)
|
||||
|
||||
@@ -70,7 +70,7 @@ public class KeyValueQuerydslUtilsUnitTests {
|
||||
OrderSpecifier<?>[] specifiers = toOrderSpecifier(sort, builder);
|
||||
|
||||
assertThat(specifiers,
|
||||
IsArrayContainingInOrder.<OrderSpecifier<?>> arrayContaining(QPerson.person.firstname.asc()));
|
||||
IsArrayContainingInOrder.arrayContaining(QPerson.person.firstname.asc()));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -81,7 +81,7 @@ public class KeyValueQuerydslUtilsUnitTests {
|
||||
OrderSpecifier<?>[] specifiers = toOrderSpecifier(sort, builder);
|
||||
|
||||
assertThat(specifiers,
|
||||
IsArrayContainingInOrder.<OrderSpecifier<?>> arrayContaining(QPerson.person.firstname.desc()));
|
||||
IsArrayContainingInOrder.arrayContaining(QPerson.person.firstname.desc()));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -91,7 +91,7 @@ public class KeyValueQuerydslUtilsUnitTests {
|
||||
|
||||
OrderSpecifier<?>[] specifiers = toOrderSpecifier(sort, builder);
|
||||
|
||||
assertThat(specifiers, IsArrayContainingInOrder.<OrderSpecifier<?>> arrayContaining(QPerson.person.firstname.desc(),
|
||||
assertThat(specifiers, IsArrayContainingInOrder.arrayContaining(QPerson.person.firstname.desc(),
|
||||
QPerson.person.age.asc()));
|
||||
}
|
||||
|
||||
@@ -103,6 +103,6 @@ public class KeyValueQuerydslUtilsUnitTests {
|
||||
OrderSpecifier<?>[] specifiers = toOrderSpecifier(sort, builder);
|
||||
|
||||
assertThat(specifiers,
|
||||
IsArrayContainingInOrder.<OrderSpecifier<?>> arrayContaining(QPerson.person.firstname.desc().nullsLast()));
|
||||
IsArrayContainingInOrder.arrayContaining(QPerson.person.firstname.desc().nullsLast()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
assertThat(page1.getContent(), hasSize(1));
|
||||
assertThat(page1.hasNext(), is(true));
|
||||
|
||||
Page<Person> page2 = ((QPersonRepository) repository).findAll(QPerson.person.age.eq(CERSEI.getAge()),
|
||||
Page<Person> page2 = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()),
|
||||
page1.nextPageable());
|
||||
|
||||
assertThat(page2.getTotalElements(), is(2L));
|
||||
|
||||
Reference in New Issue
Block a user