DATAKV-187 - Polishing.

Remove Serializable ID constraints from factory beans. Replace casts with type.cast(…). Convert anonymous inner classes to lambdas. Remove unused code and casts. Simplify test entities by removing Serializable and using lombok. Letter casing, formatting, Javadoc.

Original pull request: #25.
This commit is contained in:
Mark Paluch
2017-07-21 14:18:33 +02:00
parent d6ee87ace5
commit 14da42ff15
16 changed files with 200 additions and 492 deletions

View File

@@ -20,7 +20,7 @@ interface KeyValueOperations {
void delete(Class<?> type); <3>
<T> T findById(Serializable id, Class<T> type); <4>
<T> T findById(Object id, Class<T> type); <4>
<T> Iterable<T> findAllOf(Class<T> type); <5>

View File

@@ -24,6 +24,7 @@ import org.springframework.data.keyvalue.core.query.KeyValueQuery;
* {@literal count} execution to.
*
* @author Christoph Strobl
* @author Mark Paluch
*/
public abstract class AbstractKeyValueAdapter implements KeyValueAdapter {
@@ -43,7 +44,7 @@ public abstract class AbstractKeyValueAdapter implements KeyValueAdapter {
*/
protected AbstractKeyValueAdapter(QueryEngine<? extends KeyValueAdapter, ?, ?> engine) {
this.engine = engine != null ? engine : new SpelQueryEngine<>();
this.engine = engine != null ? engine : new SpelQueryEngine();
this.engine.registerAdapter(this);
}
@@ -62,7 +63,7 @@ public abstract class AbstractKeyValueAdapter implements KeyValueAdapter {
*/
@Override
public <T> T get(Object id, String keyspace, Class<T> type) {
return (T) get(id, keyspace);
return type.cast(get(id, keyspace));
}
/*
@@ -71,7 +72,7 @@ public abstract class AbstractKeyValueAdapter implements KeyValueAdapter {
*/
@Override
public <T> T delete(Object id, String keyspace, Class<T> type) {
return (T) delete(id, keyspace);
return type.cast(delete(id, keyspace));
}
/*

View File

@@ -25,14 +25,14 @@ import org.springframework.data.mapping.context.MappingContext;
/**
* Interface that specifies a basic set of key/value operations. Implemented by {@link KeyValueTemplate}.
*
*
* @author Christoph Strobl
*/
public interface KeyValueOperations extends DisposableBean {
/**
* Add given object. Object needs to have id property to which a generated value will be assigned.
*
*
* @param objectToInsert
* @return
*/
@@ -40,7 +40,7 @@ public interface KeyValueOperations extends DisposableBean {
/**
* Add object with given id.
*
*
* @param id must not be {@literal null}.
* @param objectToInsert must not be {@literal null}.
*/
@@ -49,7 +49,7 @@ public interface KeyValueOperations extends DisposableBean {
/**
* Get all elements of given type. Respects {@link KeySpace} if present and therefore returns all elements that can be
* assigned to requested type.
*
*
* @param type must not be {@literal null}.
* @return empty iterable if no elements found.
*/
@@ -58,7 +58,7 @@ public interface KeyValueOperations extends DisposableBean {
/**
* Get all elements ordered by sort. Respects {@link KeySpace} if present and therefore returns all elements that can
* be assigned to requested type.
*
*
* @param sort must not be {@literal null}.
* @param type must not be {@literal null}.
* @return
@@ -68,16 +68,16 @@ public interface KeyValueOperations extends DisposableBean {
/**
* Get element of given type with given id. Respects {@link KeySpace} if present and therefore returns all elements
* that can be assigned to requested type.
*
*
* @param id must not be {@literal null}.
* @param type must not be {@literal null}.
* @return null if not found.
* @return {@link Optional#empty()} if not found.
*/
<T> Optional<T> findById(Object id, Class<T> type);
/**
* Execute operation against underlying store.
*
*
* @param action must not be {@literal null}.
* @return
*/
@@ -86,7 +86,7 @@ public interface KeyValueOperations extends DisposableBean {
/**
* Get all elements matching the given query. <br />
* Respects {@link KeySpace} if present and therefore returns all elements that can be assigned to requested type..
*
*
* @param query must not be {@literal null}.
* @param type must not be {@literal null}.
* @return empty iterable if no match found.
@@ -96,7 +96,7 @@ public interface KeyValueOperations extends DisposableBean {
/**
* Get all elements in given range. Respects {@link KeySpace} if present and therefore returns all elements that can
* be assigned to requested type.
*
*
* @param offset
* @param rows
* @param type must not be {@literal null}.
@@ -107,7 +107,7 @@ public interface KeyValueOperations extends DisposableBean {
/**
* Get all elements in given range ordered by sort. Respects {@link KeySpace} if present and therefore returns all
* elements that can be assigned to requested type.
*
*
* @param offset
* @param rows
* @param sort
@@ -130,7 +130,7 @@ public interface KeyValueOperations extends DisposableBean {
/**
* Remove all elements of type. Respects {@link KeySpace} if present and therefore removes all elements that can be
* assigned to requested type.
*
*
* @param type must not be {@literal null}.
*/
void delete(Class<?> type);
@@ -143,7 +143,7 @@ public interface KeyValueOperations extends DisposableBean {
/**
* Delete item of type with given id.
*
*
* @param id must not be {@literal null}.
* @param type must not be {@literal null}.
* @return the deleted item or {@literal null} if no match found.
@@ -153,7 +153,7 @@ public interface KeyValueOperations extends DisposableBean {
/**
* Total number of elements with given type available. Respects {@link KeySpace} if present and therefore counts all
* elements that can be assigned to requested type.
*
*
* @param type must not be {@literal null}.
* @return
*/
@@ -162,7 +162,7 @@ public interface KeyValueOperations extends DisposableBean {
/**
* Total number of elements matching given query. Respects {@link KeySpace} if present and therefore counts all
* elements that can be assigned to requested type.
*
*
* @param query
* @param type
* @return

View File

@@ -67,7 +67,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
* @param adapter must not be {@literal null}.
*/
public KeyValueTemplate(KeyValueAdapter adapter) {
this(adapter, new KeyValueMappingContext());
this(adapter, new KeyValueMappingContext<>());
}
/**
@@ -149,28 +149,24 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
* @see org.springframework.data.keyvalue.core.KeyValueOperations#insert(java.lang.Object, java.lang.Object)
*/
@Override
public void insert(final Object id, final Object objectToInsert) {
public void insert(Object id, Object objectToInsert) {
Assert.notNull(id, "Id for object to be inserted must not be null!");
Assert.notNull(objectToInsert, "Object to be inserted must not be null!");
final String keyspace = resolveKeySpace(objectToInsert.getClass());
String keyspace = resolveKeySpace(objectToInsert.getClass());
potentiallyPublishEvent(KeyValueEvent.beforeInsert(id, keyspace, objectToInsert.getClass(), objectToInsert));
execute(new KeyValueCallback<Void>() {
execute((KeyValueCallback<Void>) adapter -> {
@Override
public Void doInKeyValue(KeyValueAdapter adapter) {
if (adapter.contains(id, keyspace)) {
throw new DuplicateKeyException(
String.format("Cannot insert existing object with id %s!. Please use update.", id));
}
adapter.put(id, objectToInsert, keyspace);
return null;
if (adapter.contains(id, keyspace)) {
throw new DuplicateKeyException(
String.format("Cannot insert existing object with id %s!. Please use update.", id));
}
adapter.put(id, objectToInsert, keyspace);
return null;
});
potentiallyPublishEvent(KeyValueEvent.afterInsert(id, keyspace, objectToInsert.getClass(), objectToInsert));
@@ -199,22 +195,16 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
* @see org.springframework.data.keyvalue.core.KeyValueOperations#update(java.lang.Object, java.lang.Object)
*/
@Override
public void update(final Object id, final Object objectToUpdate) {
public void update(Object id, Object objectToUpdate) {
Assert.notNull(id, "Id for object to be inserted must not be null!");
Assert.notNull(objectToUpdate, "Object to be updated must not be null!");
final String keyspace = resolveKeySpace(objectToUpdate.getClass());
String keyspace = resolveKeySpace(objectToUpdate.getClass());
potentiallyPublishEvent(KeyValueEvent.beforeUpdate(id, keyspace, objectToUpdate.getClass(), objectToUpdate));
Object existing = execute(new KeyValueCallback<Object>() {
@Override
public Object doInKeyValue(KeyValueAdapter adapter) {
return adapter.put(id, objectToUpdate, keyspace);
}
});
Object existing = execute(adapter -> adapter.put(id, objectToUpdate, keyspace));
potentiallyPublishEvent(
KeyValueEvent.afterUpdate(id, keyspace, objectToUpdate.getClass(), objectToUpdate, existing));
@@ -225,7 +215,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
* @see org.springframework.data.keyvalue.core.KeyValueOperations#findAllOf(java.lang.Class)
*/
@Override
public <T> Iterable<T> findAll(final Class<T> type) {
public <T> Iterable<T> findAll(Class<T> type) {
Assert.notNull(type, "Type to fetch must not be null!");
@@ -258,29 +248,24 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
* @see org.springframework.data.keyvalue.core.KeyValueOperations#findById(java.lang.Object, java.lang.Class)
*/
@Override
public <T> Optional<T> findById(final Object id, final Class<T> type) {
public <T> Optional<T> findById(Object id, Class<T> type) {
Assert.notNull(id, "Id for object to be inserted must not be null!");
Assert.notNull(type, "Type to fetch must not be null!");
final String keyspace = resolveKeySpace(type);
String keyspace = resolveKeySpace(type);
potentiallyPublishEvent(KeyValueEvent.beforeGet(id, keyspace, type));
T result = execute(new KeyValueCallback<T>() {
T result = execute(adapter -> {
@SuppressWarnings("unchecked")
@Override
public T doInKeyValue(KeyValueAdapter adapter) {
Object value = adapter.get(id, keyspace, type);
Object result = adapter.get(id, keyspace, type);
if (result == null || typeCheck(type, result)) {
return (T) result;
}
return null;
if (value == null || typeCheck(type, value)) {
return type.cast(value);
}
return null;
});
potentiallyPublishEvent(KeyValueEvent.afterGet(id, keyspace, type, result));
@@ -293,22 +278,18 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
* @see org.springframework.data.keyvalue.core.KeyValueOperations#delete(java.lang.Class)
*/
@Override
public void delete(final Class<?> type) {
public void delete(Class<?> type) {
Assert.notNull(type, "Type to delete must not be null!");
final String keyspace = resolveKeySpace(type);
String keyspace = resolveKeySpace(type);
potentiallyPublishEvent(KeyValueEvent.beforeDropKeySpace(keyspace, type));
execute(new KeyValueCallback<Void>() {
execute((KeyValueCallback<Void>) adapter -> {
@Override
public Void doInKeyValue(KeyValueAdapter adapter) {
adapter.deleteAllOf(keyspace);
return null;
}
adapter.deleteAllOf(keyspace);
return null;
});
potentiallyPublishEvent(KeyValueEvent.afterDropKeySpace(keyspace, type));
@@ -333,22 +314,16 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
* @see org.springframework.data.keyvalue.core.KeyValueOperations#delete(java.lang.Object, java.lang.Class)
*/
@Override
public <T> T delete(final Object id, final Class<T> type) {
public <T> T delete(Object id, Class<T> type) {
Assert.notNull(id, "Id for object to be deleted must not be null!");
Assert.notNull(type, "Type to delete must not be null!");
final String keyspace = resolveKeySpace(type);
String keyspace = resolveKeySpace(type);
potentiallyPublishEvent(KeyValueEvent.beforeDelete(id, keyspace, type));
T result = execute(new KeyValueCallback<T>() {
@Override
public T doInKeyValue(KeyValueAdapter adapter) {
return (T) adapter.delete(id, keyspace, type);
}
});
T result = execute(adapter -> (T) adapter.delete(id, keyspace, type));
potentiallyPublishEvent(KeyValueEvent.afterDelete(id, keyspace, type, result));
@@ -387,29 +362,24 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
* @see org.springframework.data.keyvalue.core.KeyValueOperations#find(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.lang.Class)
*/
@Override
public <T> Iterable<T> find(final KeyValueQuery<?> query, final Class<T> type) {
public <T> Iterable<T> find(KeyValueQuery<?> query, Class<T> type) {
return execute(new KeyValueCallback<Iterable<T>>() {
return execute((KeyValueCallback<Iterable<T>>) adapter -> {
@SuppressWarnings("unchecked")
@Override
public Iterable<T> doInKeyValue(KeyValueAdapter adapter) {
Iterable<?> result = adapter.find(query, resolveKeySpace(type), type);
if (result == null) {
return Collections.emptySet();
}
List<T> filtered = new ArrayList<>();
for (Object candidate : result) {
if (typeCheck(type, candidate)) {
filtered.add((T) candidate);
}
}
return filtered;
Iterable<?> result = adapter.find(query, resolveKeySpace(type), type);
if (result == null) {
return Collections.emptySet();
}
List<T> filtered = new ArrayList<>();
for (Object candidate : result) {
if (typeCheck(type, candidate)) {
filtered.add(type.cast(candidate));
}
}
return filtered;
});
}
@@ -448,15 +418,9 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
* @see org.springframework.data.keyvalue.core.KeyValueOperations#count(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.lang.Class)
*/
@Override
public long count(final KeyValueQuery<?> query, final Class<?> type) {
public long count(KeyValueQuery<?> query, Class<?> type) {
return execute(new KeyValueCallback<Long>() {
@Override
public Long doInKeyValue(KeyValueAdapter adapter) {
return adapter.count(query, resolveKeySpace(type));
}
});
return execute(adapter -> adapter.count(query, resolveKeySpace(type)));
}
/*
@@ -500,6 +464,6 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
}
private static boolean typeCheck(Class<?> requiredType, Object candidate) {
return candidate == null ? true : ClassUtils.isAssignable(requiredType, candidate.getClass());
return candidate == null || ClassUtils.isAssignable(requiredType, candidate.getClass());
}
}

View File

@@ -17,7 +17,6 @@ package org.springframework.data.keyvalue.core;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -32,9 +31,10 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
*
* @author Christoph Strobl
* @author Oliver Gierke
* @author Mark Paluch
* @param <T>
*/
class SpelQueryEngine<T extends KeyValueAdapter> extends QueryEngine<KeyValueAdapter, SpelCriteria, Comparator<?>> {
class SpelQueryEngine extends QueryEngine<KeyValueAdapter, SpelCriteria, Comparator<?>> {
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
@@ -63,13 +63,13 @@ class SpelQueryEngine<T extends KeyValueAdapter> extends QueryEngine<KeyValueAda
return filterMatchingRange(getAdapter().getAllOf(keyspace), criteria, -1, -1).size();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings("unchecked")
private List<?> sortAndFilterMatchingRange(Iterable<?> source, SpelCriteria criteria, Comparator sort, long offset,
int rows) {
List<?> tmp = IterableConverter.toList(source);
if (sort != null) {
Collections.sort(tmp, sort);
tmp.sort(sort);
}
return filterMatchingRange(tmp, criteria, offset, rows);

View File

@@ -54,126 +54,126 @@ public class KeyValueEvent<T> extends ApplicationEvent {
* Create new {@link BeforeGetEvent}.
*
* @param id
* @param keySpace
* @param keyspace
* @param type
* @return
*/
public static <T> BeforeGetEvent<T> beforeGet(Object id, String keySpace, Class<T> type) {
return new BeforeGetEvent<>(id, keySpace, type);
public static <T> BeforeGetEvent<T> beforeGet(Object id, String keyspace, Class<T> type) {
return new BeforeGetEvent<>(id, keyspace, type);
}
/**
* Create new {@link AfterGetEvent}.
*
* @param id
* @param keySpace
* @param keyspace
* @param type
* @param value
* @return
*/
public static <T> AfterGetEvent<T> afterGet(Object id, String keySpace, Class<T> type, T value) {
return new AfterGetEvent<>(id, keySpace, type, value);
public static <T> AfterGetEvent<T> afterGet(Object id, String keyspace, Class<T> type, T value) {
return new AfterGetEvent<>(id, keyspace, type, value);
}
/**
* Create new {@link BeforeInsertEvent}.
*
* @param id
* @param keySpace
* @param keyspace
* @param type
* @param value
* @return
*/
public static <T> BeforeInsertEvent<T> beforeInsert(Object id, String keySpace, Class<? extends T> type, T value) {
return new BeforeInsertEvent<>(id, keySpace, type, value);
public static <T> BeforeInsertEvent<T> beforeInsert(Object id, String keyspace, Class<? extends T> type, T value) {
return new BeforeInsertEvent<>(id, keyspace, type, value);
}
/**
* Create new {@link AfterInsertEvent}.
*
* @param id
* @param keySpace
* @param keyspace
* @param type
* @param value
* @return
*/
public static <T> AfterInsertEvent<T> afterInsert(Object id, String keySpace, Class<? extends T> type, T value) {
return new AfterInsertEvent<>(id, keySpace, type, value);
public static <T> AfterInsertEvent<T> afterInsert(Object id, String keyspace, Class<? extends T> type, T value) {
return new AfterInsertEvent<>(id, keyspace, type, value);
}
/**
* Create new {@link BeforeUpdateEvent}.
*
* @param id
* @param keySpace
* @param keyspace
* @param type
* @param value
* @return
*/
public static <T> BeforeUpdateEvent<T> beforeUpdate(Object id, String keySpace, Class<? extends T> type, T value) {
return new BeforeUpdateEvent<>(id, keySpace, type, value);
public static <T> BeforeUpdateEvent<T> beforeUpdate(Object id, String keyspace, Class<? extends T> type, T value) {
return new BeforeUpdateEvent<>(id, keyspace, type, value);
}
/**
* Create new {@link AfterUpdateEvent}.
*
* @param id
* @param keySpace
* @param keyspace
* @param type
* @param actualValue
* @param previousValue
* @return
*/
public static <T> AfterUpdateEvent<T> afterUpdate(Object id, String keySpace, Class<? extends T> type, T actualValue,
public static <T> AfterUpdateEvent<T> afterUpdate(Object id, String keyspace, Class<? extends T> 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 keyspace
* @param type
* @return
*/
public static <T> BeforeDropKeySpaceEvent<T> beforeDropKeySpace(String keySpace, Class<? extends T> type) {
return new BeforeDropKeySpaceEvent<>(keySpace, type);
public static <T> BeforeDropKeySpaceEvent<T> beforeDropKeySpace(String keyspace, Class<? extends T> type) {
return new BeforeDropKeySpaceEvent<>(keyspace, type);
}
/**
* Create new {@link AfterDropKeySpaceEvent}.
*
* @param keySpace
* @param keyspace
* @param type
* @return
*/
public static <T> AfterDropKeySpaceEvent<T> afterDropKeySpace(String keySpace, Class<? extends T> type) {
return new AfterDropKeySpaceEvent<>(keySpace, type);
public static <T> AfterDropKeySpaceEvent<T> afterDropKeySpace(String keyspace, Class<? extends T> type) {
return new AfterDropKeySpaceEvent<>(keyspace, type);
}
/**
* Create new {@link BeforeDeleteEvent}.
*
* @param id
* @param keySpace
* @param keyspace
* @param type
* @return
*/
public static <T> BeforeDeleteEvent<T> beforeDelete(Object id, String keySpace, Class<? extends T> type) {
return new BeforeDeleteEvent<>(id, keySpace, type);
public static <T> BeforeDeleteEvent<T> beforeDelete(Object id, String keyspace, Class<? extends T> type) {
return new BeforeDeleteEvent<>(id, keyspace, type);
}
/**
* Create new {@link AfterDeleteEvent}.
*
* @param id
* @param keySpace
* @param keyspace
* @param type
* @param value
* @return
*/
public static <T> AfterDeleteEvent<T> afterDelete(Object id, String keySpace, Class<? extends T> type, T value) {
return new AfterDeleteEvent<>(id, keySpace, type, value);
public static <T> AfterDeleteEvent<T> afterDelete(Object id, String keyspace, Class<? extends T> type, T value) {
return new AfterDeleteEvent<>(id, keyspace, type, value);
}
/**
@@ -186,9 +186,9 @@ public class KeyValueEvent<T> extends ApplicationEvent {
private Object key;
private Class<? extends T> type;
protected KeyBasedEvent(Object key, String keySpace, Class<? extends T> type) {
protected KeyBasedEvent(Object key, String keyspace, Class<? extends T> type) {
super(type, keySpace);
super(type, keyspace);
this.key = key;
this.type = type;
}
@@ -225,8 +225,8 @@ public class KeyValueEvent<T> extends ApplicationEvent {
private final T payload;
public KeyBasedEventWithPayload(Object key, String keySpace, Class<? extends T> type, T payload) {
super(key, keySpace, type);
public KeyBasedEventWithPayload(Object key, String keyspace, Class<? extends T> type, T payload) {
super(key, keyspace, type);
this.payload = payload;
}
@@ -249,8 +249,8 @@ public class KeyValueEvent<T> extends ApplicationEvent {
@SuppressWarnings("serial")
public static class BeforeGetEvent<T> extends KeyBasedEvent<T> {
protected BeforeGetEvent(Object key, String keySpace, Class<T> type) {
super(key, keySpace, type);
protected BeforeGetEvent(Object key, String keyspace, Class<T> type) {
super(key, keyspace, type);
}
}
@@ -279,8 +279,8 @@ public class KeyValueEvent<T> extends ApplicationEvent {
@SuppressWarnings("serial")
public static class BeforeInsertEvent<T> extends KeyBasedEventWithPayload<T> {
public BeforeInsertEvent(Object key, String keySpace, Class<? extends T> type, T payload) {
super(key, keySpace, type, payload);
public BeforeInsertEvent(Object key, String keyspace, Class<? extends T> type, T payload) {
super(key, keyspace, type, payload);
}
}
@@ -294,8 +294,8 @@ public class KeyValueEvent<T> extends ApplicationEvent {
@SuppressWarnings("serial")
public static class AfterInsertEvent<T> extends KeyBasedEventWithPayload<T> {
public AfterInsertEvent(Object key, String keySpace, Class<? extends T> type, T payload) {
super(key, keySpace, type, payload);
public AfterInsertEvent(Object key, String keyspace, Class<? extends T> type, T payload) {
super(key, keyspace, type, payload);
}
}
@@ -308,8 +308,8 @@ public class KeyValueEvent<T> extends ApplicationEvent {
@SuppressWarnings("serial")
public static class BeforeUpdateEvent<T> extends KeyBasedEventWithPayload<T> {
public BeforeUpdateEvent(Object key, String keySpace, Class<? extends T> type, T payload) {
super(key, keySpace, type, payload);
public BeforeUpdateEvent(Object key, String keyspace, Class<? extends T> type, T payload) {
super(key, keyspace, type, payload);
}
}
@@ -324,8 +324,8 @@ public class KeyValueEvent<T> extends ApplicationEvent {
private final Object existing;
public AfterUpdateEvent(Object key, String keySpace, Class<? extends T> type, T payload, Object existing) {
super(key, keySpace, type, payload);
public AfterUpdateEvent(Object key, String keyspace, Class<? extends T> type, T payload, Object existing) {
super(key, keyspace, type, payload);
this.existing = existing;
}
@@ -357,8 +357,8 @@ public class KeyValueEvent<T> extends ApplicationEvent {
@SuppressWarnings("serial")
public static class BeforeDeleteEvent<T> extends KeyBasedEvent<T> {
public BeforeDeleteEvent(Object key, String keySpace, Class<? extends T> type) {
super(key, keySpace, type);
public BeforeDeleteEvent(Object key, String keyspace, Class<? extends T> type) {
super(key, keyspace, type);
}
}
@@ -371,13 +371,13 @@ public class KeyValueEvent<T> extends ApplicationEvent {
@SuppressWarnings("serial")
public static class AfterDeleteEvent<T> extends KeyBasedEventWithPayload<T> {
public AfterDeleteEvent(Object key, String keySpace, Class<? extends T> type, T payload) {
super(key, keySpace, type, payload);
public AfterDeleteEvent(Object key, String keyspace, Class<? extends T> type, T payload) {
super(key, keyspace, type, payload);
}
}
/**
* {@link KeyValueEvent} before removing all elements in a given {@literal keySpace}.
* {@link KeyValueEvent} before removing all elements in a given {@literal keyspace}.
*
* @author Christoph Strobl
* @param <T>
@@ -385,8 +385,8 @@ public class KeyValueEvent<T> extends ApplicationEvent {
@SuppressWarnings("serial")
public static class BeforeDropKeySpaceEvent<T> extends KeyValueEvent<T> {
public BeforeDropKeySpaceEvent(String keySpace, Class<? extends T> type) {
super(type, keySpace);
public BeforeDropKeySpaceEvent(String keyspace, Class<? extends T> type) {
super(type, keyspace);
}
@Override
@@ -398,7 +398,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
}
/**
* {@link KeyValueEvent} after removing all elements in a given {@literal keySpace}.
* {@link KeyValueEvent} after removing all elements in a given {@literal keyspace}.
*
* @author Christoph Strobl
* @param <T>
@@ -406,8 +406,8 @@ public class KeyValueEvent<T> extends ApplicationEvent {
@SuppressWarnings("serial")
public static class AfterDropKeySpaceEvent<T> extends KeyValueEvent<T> {
public AfterDropKeySpaceEvent(String keySpace, Class<? extends T> type) {
super(type, keySpace);
public AfterDropKeySpaceEvent(String keyspace, Class<? extends T> type) {
super(type, keyspace);
}
@Override

View File

@@ -17,7 +17,6 @@ package org.springframework.data.keyvalue.repository.support;
import static org.springframework.data.querydsl.QuerydslUtils.QUERY_DSL_PRESENT;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Optional;
@@ -126,7 +125,7 @@ public class KeyValueRepositoryFactory extends RepositoryFactorySupport {
@Override
protected Object getTargetRepository(RepositoryInformation repositoryInformation) {
EntityInformation<?, Serializable> entityInformation = getEntityInformation(repositoryInformation.getDomainType());
EntityInformation<?, ?> entityInformation = getEntityInformation(repositoryInformation.getDomainType());
return super.getTargetRepositoryViaReflection(repositoryInformation, entityInformation, keyValueOperations);
}

View File

@@ -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,8 +15,6 @@
*/
package org.springframework.data.keyvalue.repository.support;
import java.io.Serializable;
import org.springframework.data.keyvalue.core.KeyValueOperations;
import org.springframework.data.keyvalue.repository.KeyValueRepository;
import org.springframework.data.keyvalue.repository.config.QueryCreatorType;
@@ -30,11 +28,12 @@ import org.springframework.util.Assert;
/**
* {@link org.springframework.beans.factory.FactoryBean} to create {@link KeyValueRepository}.
*
*
* @author Christoph Strobl
* @author Oliver Gierke
* @author Mark Paluch
*/
public class KeyValueRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable>
public class KeyValueRepositoryFactoryBean<T extends Repository<S, ID>, S, ID>
extends RepositoryFactoryBeanSupport<T, S, ID> {
private KeyValueOperations operations;
@@ -43,7 +42,7 @@ public class KeyValueRepositoryFactoryBean<T extends Repository<S, ID>, S, ID ex
/**
* Creates a new {@link KeyValueRepositoryFactoryBean} for the given repository interface.
*
*
* @param repositoryInterface must not be {@literal null}.
*/
public KeyValueRepositoryFactoryBean(Class<? extends T> repositoryInterface) {
@@ -52,7 +51,7 @@ public class KeyValueRepositoryFactoryBean<T extends Repository<S, ID>, S, ID ex
/**
* Configures the {@link KeyValueOperations} to be used for the repositories.
*
*
* @param operations must not be {@literal null}.
*/
public void setKeyValueOperations(KeyValueOperations operations) {
@@ -73,7 +72,7 @@ public class KeyValueRepositoryFactoryBean<T extends Repository<S, ID>, S, ID ex
/**
* Configures the {@link QueryCreatorType} to be used.
*
*
* @param queryCreator must not be {@literal null}.
*/
public void setQueryCreator(Class<? extends AbstractQueryCreator<?, ?>> queryCreator) {

View File

@@ -17,7 +17,6 @@ package org.springframework.data.keyvalue.repository.support;
import static org.springframework.data.keyvalue.repository.support.KeyValueQuerydslUtils.*;
import java.io.Serializable;
import java.util.Optional;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
@@ -51,7 +50,7 @@ import com.querydsl.core.types.dsl.PathBuilder;
* @param <T> the domain type to manage
* @param <ID> the identifier type of the domain type
*/
public class QuerydslKeyValueRepository<T, ID extends Serializable> extends SimpleKeyValueRepository<T, ID>
public class QuerydslKeyValueRepository<T, ID> extends SimpleKeyValueRepository<T, ID>
implements QuerydslPredicateExecutor<T> {
private static final EntityPathResolver DEFAULT_ENTITY_PATH_RESOLVER = SimpleEntityPathResolver.INSTANCE;

View File

@@ -119,7 +119,7 @@ public class SimpleKeyValueRepository<T, ID> implements KeyValueRepository<T, ID
/*
* (non-Javadoc)
* @see org.springframework.data.repository.CrudRepository#findOne(java.io.Serializable)
* @see org.springframework.data.repository.CrudRepository#findOne(java.lang.Object)
*/
@Override
public Optional<T> findById(ID id) {
@@ -128,7 +128,7 @@ public class SimpleKeyValueRepository<T, ID> implements KeyValueRepository<T, ID
/*
* (non-Javadoc)
* @see org.springframework.data.repository.CrudRepository#exists(java.io.Serializable)
* @see org.springframework.data.repository.CrudRepository#exists(java.lang.Object)
*/
@Override
public boolean existsById(ID id) {
@@ -176,7 +176,7 @@ public class SimpleKeyValueRepository<T, ID> implements KeyValueRepository<T, ID
/*
* (non-Javadoc)
* @see org.springframework.data.repository.CrudRepository#delete(java.io.Serializable)
* @see org.springframework.data.repository.CrudRepository#delete(java.lang.Object)
*/
@Override
public void deleteById(ID id) {

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.keyvalue;
import java.io.Serializable;
import org.springframework.data.annotation.Id;
import org.springframework.util.ObjectUtils;
@@ -26,9 +24,7 @@ import com.querydsl.core.annotations.QueryEntity;
* @author Christoph Strobl
*/
@QueryEntity
public class Person implements Serializable {
private static final long serialVersionUID = 4212763002445358314L;
public class Person {
private @Id String id;
private String firstname;

View File

@@ -18,6 +18,9 @@ package org.springframework.data.keyvalue.core;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.io.Serializable;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -35,11 +38,11 @@ import org.springframework.data.annotation.Persistent;
import org.springframework.data.keyvalue.annotation.KeySpace;
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
import org.springframework.data.map.MapKeyValueAdapter;
import org.springframework.util.ObjectUtils;
/**
* @author Christoph Strobl
* @author Oliver Gierke
* @author Mark Paluch
*/
public class KeyValueTemplateTests {
@@ -212,116 +215,31 @@ public class KeyValueTemplateTests {
assertThat(operations.findAll(ALIASED.getClass()), containsInAnyOrder(ALIASED, SUBCLASS_OF_ALIASED));
}
static class Foo implements Serializable {
private static final long serialVersionUID = -8912754229220128922L;
@Data
@AllArgsConstructor
static class Foo {
String foo;
public Foo(String foo) {
this.foo = foo;
}
public String getFoo() {
return foo;
}
@Override
public int hashCode() {
return ObjectUtils.nullSafeHashCode(this.foo);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Foo)) {
return false;
}
Foo other = (Foo) obj;
return ObjectUtils.nullSafeEquals(this.foo, other.foo);
}
}
static class Bar implements Serializable {
@Data
@AllArgsConstructor
static class Bar {
private static final long serialVersionUID = 196011921826060210L;
String bar;
public Bar(String bar) {
this.bar = bar;
}
public String getBar() {
return bar;
}
@Override
public int hashCode() {
return ObjectUtils.nullSafeHashCode(this.bar);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Bar)) {
return false;
}
Bar other = (Bar) obj;
return ObjectUtils.nullSafeEquals(this.bar, other.bar);
}
}
@Data
static class ClassWithStringId implements Serializable {
private static final long serialVersionUID = -7481030649267602830L;
@Id String id;
String value;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ObjectUtils.nullSafeHashCode(this.id);
result = prime * result + ObjectUtils.nullSafeHashCode(this.value);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof ClassWithStringId)) {
return false;
}
ClassWithStringId other = (ClassWithStringId) obj;
if (!ObjectUtils.nullSafeEquals(this.id, other.id)) {
return false;
}
if (!ObjectUtils.nullSafeEquals(this.value, other.value)) {
return false;
}
return true;
}
}
@ExplicitKeySpace(name = "aliased")
@Data
static class ClassWithTypeAlias implements Serializable {
private static final long serialVersionUID = -5921943364908784571L;
@@ -331,53 +249,6 @@ public class KeyValueTemplateTests {
public ClassWithTypeAlias(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 ClassWithTypeAlias)) {
return false;
}
ClassWithTypeAlias other = (ClassWithTypeAlias) obj;
if (!ObjectUtils.nullSafeEquals(this.id, other.id)) {
return false;
}
if (!ObjectUtils.nullSafeEquals(this.name, other.name)) {
return false;
}
return true;
}
}
static class SubclassOfAliasedType extends ClassWithTypeAlias {

View File

@@ -20,7 +20,9 @@ import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -54,12 +56,12 @@ import org.springframework.data.keyvalue.core.event.KeyValueEvent.BeforeGetEvent
import org.springframework.data.keyvalue.core.event.KeyValueEvent.BeforeInsertEvent;
import org.springframework.data.keyvalue.core.event.KeyValueEvent.BeforeUpdateEvent;
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
import org.springframework.util.ObjectUtils;
/**
* @author Christoph Strobl
* @author Thomas Darimont
* @author Oliver Gierke
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.Silent.class)
public class KeyValueTemplateUnitTests {
@@ -179,9 +181,9 @@ public class KeyValueTemplateUnitTests {
verify(adapterMock, times(1)).get("1", Foo.class.getName(), Foo.class);
}
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
@Test(expected = IllegalArgumentException.class) // DATACMNS-525, DATAKV-187
public void findByIdShouldThrowExceptionWhenGivenNullId() {
template.findById((Serializable) null, Foo.class);
template.findById(null, Foo.class);
}
@Test // DATACMNS-525
@@ -383,7 +385,7 @@ public class KeyValueTemplateUnitTests {
verifyZeroInteractions(publisherMock);
}
@Test // DATAKV-91, DATAKV-104
@Test // DATAKV-91, DATAKV-104, DATAKV-187
@SuppressWarnings({ "unchecked", "rawtypes" })
public void shouldPublishBeforeInsertEventCorrectly() {
@@ -396,12 +398,12 @@ public class KeyValueTemplateUnitTests {
verify(publisherMock, times(1)).publishEvent(captor.capture());
verifyNoMoreInteractions(publisherMock);
assertThat(captor.getValue().getKey(), is((Serializable) "1"));
assertThat(captor.getValue().getKey(), is("1"));
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
assertThat(captor.getValue().getPayload(), is((Object) FOO_ONE));
}
@Test // DATAKV-91, DATAKV-104
@Test // DATAKV-91, DATAKV-104, DATAKV-187
@SuppressWarnings({ "unchecked", "rawtypes" })
public void shouldPublishAfterInsertEventCorrectly() {
@@ -414,12 +416,12 @@ public class KeyValueTemplateUnitTests {
verify(publisherMock, times(1)).publishEvent(captor.capture());
verifyNoMoreInteractions(publisherMock);
assertThat(captor.getValue().getKey(), is((Serializable) "1"));
assertThat(captor.getValue().getKey(), is("1"));
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
assertThat(captor.getValue().getPayload(), is((Object) FOO_ONE));
}
@Test // DATAKV-91, DATAKV-104
@Test // DATAKV-91, DATAKV-104, DATAKV-187
@SuppressWarnings({ "unchecked", "rawtypes" })
public void shouldPublishBeforeUpdateEventCorrectly() {
@@ -432,12 +434,12 @@ public class KeyValueTemplateUnitTests {
verify(publisherMock, times(1)).publishEvent(captor.capture());
verifyNoMoreInteractions(publisherMock);
assertThat(captor.getValue().getKey(), is((Serializable) "1"));
assertThat(captor.getValue().getKey(), is("1"));
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
assertThat(captor.getValue().getPayload(), is((Object) FOO_ONE));
}
@Test // DATAKV-91, DATAKV-104
@Test // DATAKV-91, DATAKV-104, DATAKV-187
@SuppressWarnings({ "unchecked", "rawtypes" })
public void shouldPublishAfterUpdateEventCorrectly() {
@@ -450,12 +452,12 @@ public class KeyValueTemplateUnitTests {
verify(publisherMock, times(1)).publishEvent(captor.capture());
verifyNoMoreInteractions(publisherMock);
assertThat(captor.getValue().getKey(), is((Serializable) "1"));
assertThat(captor.getValue().getKey(), is("1"));
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
assertThat(captor.getValue().getPayload(), is((Object) FOO_ONE));
}
@Test // DATAKV-91, DATAKV-104
@Test // DATAKV-91, DATAKV-104, DATAKV-187
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldPublishBeforeDeleteEventCorrectly() {
@@ -468,11 +470,11 @@ public class KeyValueTemplateUnitTests {
verify(publisherMock, times(1)).publishEvent(captor.capture());
verifyNoMoreInteractions(publisherMock);
assertThat(captor.getValue().getKey(), is((Serializable) "1"));
assertThat(captor.getValue().getKey(), is("1"));
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
}
@Test // DATAKV-91, DATAKV-104
@Test // DATAKV-91, DATAKV-104, DATAKV-187
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldPublishAfterDeleteEventCorrectly() {
@@ -486,12 +488,12 @@ public class KeyValueTemplateUnitTests {
verify(publisherMock, times(1)).publishEvent(captor.capture());
verifyNoMoreInteractions(publisherMock);
assertThat(captor.getValue().getKey(), is((Serializable) "1"));
assertThat(captor.getValue().getKey(), is("1"));
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
assertThat(captor.getValue().getPayload(), is((Object) FOO_ONE));
}
@Test // DATAKV-91, DATAKV-104
@Test // DATAKV-91, DATAKV-104, DATAKV-187
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldPublishBeforeGetEventCorrectly() {
@@ -506,7 +508,7 @@ public class KeyValueTemplateUnitTests {
verify(publisherMock, times(1)).publishEvent(captor.capture());
verifyNoMoreInteractions(publisherMock);
assertThat(captor.getValue().getKey(), is((Serializable) "1"));
assertThat(captor.getValue().getKey(), is("1"));
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
}
@@ -525,12 +527,12 @@ public class KeyValueTemplateUnitTests {
verify(publisherMock, times(1)).publishEvent(captor.capture());
verifyNoMoreInteractions(publisherMock);
assertThat(captor.getValue().getKey(), is((Serializable) "1"));
assertThat(captor.getValue().getKey(), is("1"));
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
assertThat(captor.getValue().getPayload(), is((Object) FOO_ONE));
}
@Test // DATAKV-91, DATAKV-104
@Test // DATAKV-91, DATAKV-104, DATAKV-187
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldPublishDropKeyspaceEventCorrectly() {
@@ -559,108 +561,24 @@ public class KeyValueTemplateUnitTests {
template.setEventTypesToPublish(new HashSet<>(Arrays.asList(events)));
}
@Data
@AllArgsConstructor
static class Foo {
String foo;
public Foo(String foo) {
this.foo = foo;
}
public String getFoo() {
return foo;
}
@Override
public int hashCode() {
return ObjectUtils.nullSafeHashCode(this.foo);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Foo)) {
return false;
}
Foo other = (Foo) obj;
return ObjectUtils.nullSafeEquals(this.foo, other.foo);
}
}
@Data
@AllArgsConstructor
class Bar {
String bar;
public Bar(String bar) {
this.bar = bar;
}
public String getBar() {
return bar;
}
@Override
public int hashCode() {
return ObjectUtils.nullSafeHashCode(this.bar);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Bar)) {
return false;
}
Bar other = (Bar) obj;
return ObjectUtils.nullSafeEquals(this.bar, other.bar);
}
}
@Data
static class ClassWithStringId {
@Id String id;
String value;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ObjectUtils.nullSafeHashCode(this.id);
result = prime * result + ObjectUtils.nullSafeHashCode(this.value);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof ClassWithStringId)) {
return false;
}
ClassWithStringId other = (ClassWithStringId) obj;
if (!ObjectUtils.nullSafeEquals(this.id, other.id)) {
return false;
}
if (!ObjectUtils.nullSafeEquals(this.value, other.value)) {
return false;
}
return true;
}
}
}

View File

@@ -45,6 +45,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
*
* @author Martin Macko
* @author Oliver Gierke
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
public class SpelQueryEngineUnitTests {
@@ -54,14 +55,14 @@ public class SpelQueryEngineUnitTests {
@Mock KeyValueAdapter adapter;
SpelQueryEngine<KeyValueAdapter> engine;
SpelQueryEngine engine;
Iterable<Person> people = Arrays.asList(BOB_WITH_FIRSTNAME, MIKE_WITHOUT_FIRSTNAME);
@Before
public void setUp() {
engine = new SpelQueryEngine<>();
engine = new SpelQueryEngine();
engine.registerAdapter(adapter);
}
@@ -102,7 +103,7 @@ public class SpelQueryEngineUnitTests {
return new SpelCriteria(creator.createQuery().getCriteria(), new StandardEvaluationContext(args));
}
static interface PersonRepository {
interface PersonRepository {
Person findByFirstname(String firstname);
}

View File

@@ -22,7 +22,9 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
import java.io.Serializable;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Arrays;
import java.util.Optional;
@@ -86,7 +88,7 @@ public class SimpleKeyValueRepositoryUnitTests {
public void multipleSave() {
Foo one = new Foo("one");
Foo two = new Foo("one");
Foo two = new Foo("two");
repo.saveAll(Arrays.asList(one, two));
verify(opsMock, times(1)).insert(eq(one));
@@ -121,25 +123,28 @@ public class SimpleKeyValueRepositoryUnitTests {
}
@Test // DATACMNS-525
@SuppressWarnings("unchecked")
public void findAllIds() {
when(opsMock.findById(any(Serializable.class), any(Class.class))).thenReturn(Optional.empty());
when(opsMock.findById(any(), any(Class.class))).thenReturn(Optional.empty());
repo.findAllById(Arrays.asList("one", "two", "three"));
verify(opsMock, times(3)).findById(anyString(), eq(Foo.class));
}
@Test // DATAKV-186
@SuppressWarnings("unchecked")
public void existsByIdReturnsFalseForEmptyOptional() {
when(opsMock.findById(any(Serializable.class), any(Class.class))).thenReturn(Optional.empty());
when(opsMock.findById(any(), any(Class.class))).thenReturn(Optional.empty());
assertThat(repo.existsById("one"), is(false));
}
@Test // DATAKV-186
@SuppressWarnings("unchecked")
public void existsByIdReturnsTrueWhenOptionalValuePresent() {
when(opsMock.findById(any(Serializable.class), any(Class.class))).thenReturn(Optional.of(new Foo()));
when(opsMock.findById(any(), any(Class.class))).thenReturn(Optional.of(new Foo()));
assertTrue(repo.existsById("one"));
}
@@ -168,6 +173,8 @@ public class SimpleKeyValueRepositoryUnitTests {
verify(opsMock, times(1)).findAll(eq(Foo.class));
}
@Data
@NoArgsConstructor
static class Foo {
private @Id String id;
@@ -175,65 +182,20 @@ public class SimpleKeyValueRepositoryUnitTests {
private String name;
private Bar bar;
public Foo() {
}
public Foo(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Long getLongValue() {
return longValue;
}
public void setLongValue(Long longValue) {
this.longValue = longValue;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Bar getBar() {
return bar;
}
public void setBar(Bar bar) {
this.bar = bar;
}
}
@Data
static class Bar {
private String bar;
public String getBar() {
return bar;
}
public void setBar(String bar) {
this.bar = bar;
}
}
@Persistent
static class WithNumericId {
@Id Integer id;
}
}

View File

@@ -19,8 +19,6 @@ import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.io.Serializable;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -33,8 +31,9 @@ import org.springframework.data.repository.query.parser.AbstractQueryCreator;
/**
* Unit tests for {@link KeyValueRepositoryFactoryBean}.
*
*
* @author Oliver Gierke
* @author Mark Paluch
*/
public class KeyValueRepositoryFactoryBeanUnitTests {
@@ -44,7 +43,7 @@ public class KeyValueRepositoryFactoryBeanUnitTests {
@Before
public void setUp() {
this.factoryBean = new KeyValueRepositoryFactoryBean<Repository<Object, Serializable>, Object, Serializable>(
this.factoryBean = new KeyValueRepositoryFactoryBean<Repository<Object, Object>, Object, Object>(
SampleRepository.class);
}
@@ -87,8 +86,7 @@ public class KeyValueRepositoryFactoryBeanUnitTests {
Class<? extends AbstractQueryCreator<?, ?>> creatorType = (Class<? extends AbstractQueryCreator<?, ?>>) mock(
AbstractQueryCreator.class).getClass();
Class<? extends RepositoryQuery> queryType = (Class<? extends RepositoryQuery>) mock(KeyValuePartTreeQuery.class)
.getClass();
Class<? extends RepositoryQuery> queryType = mock(KeyValuePartTreeQuery.class).getClass();
factoryBean.setQueryCreator(creatorType);
factoryBean.setKeyValueOperations(mock(KeyValueOperations.class));
@@ -102,5 +100,5 @@ public class KeyValueRepositoryFactoryBeanUnitTests {
factoryBean.setQueryType(null);
}
interface SampleRepository extends Repository<Object, Serializable> {}
interface SampleRepository extends Repository<Object, Object> {}
}