DATAKV-187 - Remove restriction of ID type to be Serializable.
Original pull request: #25.
This commit is contained in:
committed by
Mark Paluch
parent
8f5fa59386
commit
d6ee87ace5
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
|
||||
@@ -59,46 +58,46 @@ public abstract class AbstractKeyValueAdapter implements KeyValueAdapter {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.io.Serializable, java.io.Serializable, java.lang.Class)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.lang.Object, java.lang.String, java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public <T> T get(Serializable id, Serializable keyspace, Class<T> type) {
|
||||
public <T> T get(Object id, String keyspace, Class<T> type) {
|
||||
return (T) get(id, keyspace);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.io.Serializable, java.io.Serializable, java.lang.Class)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#delete(java.lang.Object, java.lang.String, java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public <T> T delete(Serializable id, Serializable keyspace, Class<T> type) {
|
||||
public <T> T delete(Object id, String keyspace, Class<T> type) {
|
||||
return (T) delete(id, keyspace);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.io.Serializable, java.io.Serializable, java.lang.Class)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#find(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.lang.String, java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public <T> Iterable<T> find(KeyValueQuery<?> query, Serializable keyspace, Class<T> type) {
|
||||
public <T> Iterable<T> find(KeyValueQuery<?> query, String keyspace, Class<T> type) {
|
||||
return engine.execute(query, keyspace, type);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#find(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.io.Serializable)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#find(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Collection<?> find(KeyValueQuery<?> query, Serializable keyspace) {
|
||||
public Collection<?> find(KeyValueQuery<?> query, String keyspace) {
|
||||
return engine.execute(query, keyspace);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#count(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.io.Serializable)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#count(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public long count(KeyValueQuery<?> query, Serializable keyspace) {
|
||||
public long count(KeyValueQuery<?> query, String keyspace) {
|
||||
return engine.count(query, keyspace);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,6 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -38,7 +37,7 @@ public interface KeyValueAdapter extends DisposableBean {
|
||||
* @param keyspace must not be {@literal null}.
|
||||
* @return the item previously associated with the id.
|
||||
*/
|
||||
Object put(Serializable id, Object item, Serializable keyspace);
|
||||
Object put(Object id, Object item, String keyspace);
|
||||
|
||||
/**
|
||||
* Check if a object with given id exists in keyspace.
|
||||
@@ -47,7 +46,7 @@ public interface KeyValueAdapter extends DisposableBean {
|
||||
* @param keyspace must not be {@literal null}.
|
||||
* @return true if item of type with id exists.
|
||||
*/
|
||||
boolean contains(Serializable id, Serializable keyspace);
|
||||
boolean contains(Object id, String keyspace);
|
||||
|
||||
/**
|
||||
* Get the object with given id from keyspace.
|
||||
@@ -56,7 +55,7 @@ public interface KeyValueAdapter extends DisposableBean {
|
||||
* @param keyspace must not be {@literal null}.
|
||||
* @return {@literal null} in case no matching item exists.
|
||||
*/
|
||||
Object get(Serializable id, Serializable keyspace);
|
||||
Object get(Object id, String keyspace);
|
||||
|
||||
/**
|
||||
* @param id
|
||||
@@ -65,7 +64,7 @@ public interface KeyValueAdapter extends DisposableBean {
|
||||
* @return
|
||||
* @since 1.1
|
||||
*/
|
||||
<T> T get(Serializable id, Serializable keyspace, Class<T> type);
|
||||
<T> T get(Object id, String keyspace, Class<T> type);
|
||||
|
||||
/**
|
||||
* Delete and return the obect with given type and id.
|
||||
@@ -74,7 +73,7 @@ public interface KeyValueAdapter extends DisposableBean {
|
||||
* @param keyspace must not be {@literal null}.
|
||||
* @return {@literal null} if object could not be found
|
||||
*/
|
||||
Object delete(Serializable id, Serializable keyspace);
|
||||
Object delete(Object id, String keyspace);
|
||||
|
||||
/**
|
||||
* @param id
|
||||
@@ -83,7 +82,7 @@ public interface KeyValueAdapter extends DisposableBean {
|
||||
* @return
|
||||
* @since 1.1
|
||||
*/
|
||||
<T> T delete(Serializable id, Serializable keyspace, Class<T> type);
|
||||
<T> T delete(Object id, String keyspace, Class<T> type);
|
||||
|
||||
/**
|
||||
* Get all elements for given keyspace.
|
||||
@@ -91,7 +90,7 @@ public interface KeyValueAdapter extends DisposableBean {
|
||||
* @param keyspace must not be {@literal null}.
|
||||
* @return empty {@link Collection} if nothing found.
|
||||
*/
|
||||
Iterable<?> getAllOf(Serializable keyspace);
|
||||
Iterable<?> getAllOf(String keyspace);
|
||||
|
||||
/**
|
||||
* Returns a {@link CloseableIterator} that iterates over all entries.
|
||||
@@ -99,14 +98,14 @@ public interface KeyValueAdapter extends DisposableBean {
|
||||
* @param keyspace
|
||||
* @return
|
||||
*/
|
||||
CloseableIterator<Map.Entry<Serializable, Object>> entries(Serializable keyspace);
|
||||
CloseableIterator<Map.Entry<Object, Object>> entries(String keyspace);
|
||||
|
||||
/**
|
||||
* Remove all objects of given type.
|
||||
*
|
||||
* @param keyspace must not be {@literal null}.
|
||||
*/
|
||||
void deleteAllOf(Serializable keyspace);
|
||||
void deleteAllOf(String keyspace);
|
||||
|
||||
/**
|
||||
* Removes all objects.
|
||||
@@ -120,7 +119,7 @@ public interface KeyValueAdapter extends DisposableBean {
|
||||
* @param keyspace must not be {@literal null}.
|
||||
* @return empty {@link Collection} if no match found.
|
||||
*/
|
||||
Iterable<?> find(KeyValueQuery<?> query, Serializable keyspace);
|
||||
Iterable<?> find(KeyValueQuery<?> query, String keyspace);
|
||||
|
||||
/**
|
||||
* @param query
|
||||
@@ -129,14 +128,14 @@ public interface KeyValueAdapter extends DisposableBean {
|
||||
* @return
|
||||
* @since 1.1
|
||||
*/
|
||||
<T> Iterable<T> find(KeyValueQuery<?> query, Serializable keyspace, Class<T> type);
|
||||
<T> Iterable<T> find(KeyValueQuery<?> query, String keyspace, Class<T> type);
|
||||
|
||||
/**
|
||||
* Count number of objects within {@literal keyspace}.
|
||||
*
|
||||
* @param keyspace must not be {@literal null}.
|
||||
*/
|
||||
long count(Serializable keyspace);
|
||||
long count(String keyspace);
|
||||
|
||||
/**
|
||||
* Count all matching objects within {@literal keyspace}.
|
||||
@@ -145,5 +144,5 @@ public interface KeyValueAdapter extends DisposableBean {
|
||||
* @param keyspace must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
long count(KeyValueQuery<?> query, Serializable keyspace);
|
||||
long count(KeyValueQuery<?> query, String keyspace);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
@@ -45,7 +44,7 @@ public interface KeyValueOperations extends DisposableBean {
|
||||
* @param id must not be {@literal null}.
|
||||
* @param objectToInsert must not be {@literal null}.
|
||||
*/
|
||||
void insert(Serializable id, Object objectToInsert);
|
||||
void insert(Object id, Object objectToInsert);
|
||||
|
||||
/**
|
||||
* Get all elements of given type. Respects {@link KeySpace} if present and therefore returns all elements that can be
|
||||
@@ -74,7 +73,7 @@ public interface KeyValueOperations extends DisposableBean {
|
||||
* @param type must not be {@literal null}.
|
||||
* @return null if not found.
|
||||
*/
|
||||
<T> Optional<T> findById(Serializable id, Class<T> type);
|
||||
<T> Optional<T> findById(Object id, Class<T> type);
|
||||
|
||||
/**
|
||||
* Execute operation against underlying store.
|
||||
@@ -126,7 +125,7 @@ public interface KeyValueOperations extends DisposableBean {
|
||||
* @param id must not be {@literal null}.
|
||||
* @param objectToUpdate must not be {@literal null}.
|
||||
*/
|
||||
void update(Serializable id, Object objectToUpdate);
|
||||
void update(Object id, Object objectToUpdate);
|
||||
|
||||
/**
|
||||
* Remove all elements of type. Respects {@link KeySpace} if present and therefore removes all elements that can be
|
||||
@@ -149,7 +148,7 @@ public interface KeyValueOperations extends DisposableBean {
|
||||
* @param type must not be {@literal null}.
|
||||
* @return the deleted item or {@literal null} if no match found.
|
||||
*/
|
||||
<T> T delete(Serializable id, Class<T> type);
|
||||
<T> T delete(Object id, Class<T> type);
|
||||
|
||||
/**
|
||||
* Total number of elements with given type available. Respects {@link KeySpace} if present and therefore counts all
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -38,7 +37,6 @@ import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Basic implementation of {@link KeyValueOperations}.
|
||||
@@ -135,11 +133,10 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
|
||||
KeyValuePersistentEntity<?, ?> entity = getKeyValuePersistentEntity(objectToInsert);
|
||||
|
||||
GeneratingIdAccessor generatingIdAccessor = new GeneratingIdAccessor(entity.getPropertyAccessor(objectToInsert),
|
||||
entity.getIdProperty(),
|
||||
identifierGenerator);
|
||||
entity.getIdProperty(), identifierGenerator);
|
||||
Object id = generatingIdAccessor.getOrGenerateIdentifier();
|
||||
|
||||
insert((Serializable) id, objectToInsert);
|
||||
insert(id, objectToInsert);
|
||||
return objectToInsert;
|
||||
}
|
||||
|
||||
@@ -149,10 +146,10 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueOperations#insert(java.io.Serializable, java.lang.Object)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueOperations#insert(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public void insert(final Serializable id, final Object objectToInsert) {
|
||||
public void insert(final Object id, final 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!");
|
||||
@@ -194,15 +191,15 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
|
||||
String.format("Cannot determine id for type %s", ClassUtils.getUserClass(objectToUpdate)));
|
||||
}
|
||||
|
||||
update((Serializable) entity.getIdentifierAccessor(objectToUpdate).getRequiredIdentifier(), objectToUpdate);
|
||||
update(entity.getIdentifierAccessor(objectToUpdate).getRequiredIdentifier(), objectToUpdate);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueOperations#update(java.io.Serializable, java.lang.Object)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueOperations#update(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public void update(final Serializable id, final Object objectToUpdate) {
|
||||
public void update(final Object id, final 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!");
|
||||
@@ -258,10 +255,10 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueOperations#findById(java.io.Serializable, java.lang.Class)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueOperations#findById(java.lang.Object, java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public <T> Optional<T> findById(final Serializable id, final Class<T> type) {
|
||||
public <T> Optional<T> findById(final Object id, final 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!");
|
||||
@@ -328,15 +325,15 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
|
||||
Class<T> type = (Class<T>) ClassUtils.getUserClass(objectToDelete);
|
||||
KeyValuePersistentEntity<?, ?> entity = getKeyValuePersistentEntity(objectToDelete);
|
||||
|
||||
return delete((Serializable) entity.getIdentifierAccessor(objectToDelete).getIdentifier(), type);
|
||||
return delete(entity.getIdentifierAccessor(objectToDelete).getIdentifier(), type);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueOperations#delete(java.io.Serializable, java.lang.Class)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueOperations#delete(java.lang.Object, java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public <T> T delete(final Serializable id, final Class<T> type) {
|
||||
public <T> T delete(final Object id, final 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!");
|
||||
|
||||
@@ -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,6 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
|
||||
@@ -48,7 +47,7 @@ public abstract class QueryEngine<ADAPTER extends KeyValueAdapter, CRITERIA, SOR
|
||||
* @param keyspace
|
||||
* @return
|
||||
*/
|
||||
public Collection<?> execute(KeyValueQuery<?> query, Serializable keyspace) {
|
||||
public Collection<?> execute(KeyValueQuery<?> query, String keyspace) {
|
||||
|
||||
CRITERIA criteria = this.criteriaAccessor != null ? this.criteriaAccessor.resolve(query) : null;
|
||||
SORT sort = this.sortAccessor != null ? this.sortAccessor.resolve(query) : null;
|
||||
@@ -63,7 +62,7 @@ public abstract class QueryEngine<ADAPTER extends KeyValueAdapter, CRITERIA, SOR
|
||||
* @param keyspace
|
||||
* @return
|
||||
*/
|
||||
public <T> Collection<T> execute(KeyValueQuery<?> query, Serializable keyspace, Class<T> type) {
|
||||
public <T> Collection<T> execute(KeyValueQuery<?> query, String keyspace, Class<T> type) {
|
||||
|
||||
CRITERIA criteria = this.criteriaAccessor != null ? this.criteriaAccessor.resolve(query) : null;
|
||||
SORT sort = this.sortAccessor != null ? this.sortAccessor.resolve(query) : null;
|
||||
@@ -78,7 +77,7 @@ public abstract class QueryEngine<ADAPTER extends KeyValueAdapter, CRITERIA, SOR
|
||||
* @param keyspace
|
||||
* @return
|
||||
*/
|
||||
public long count(KeyValueQuery<?> query, Serializable keyspace) {
|
||||
public long count(KeyValueQuery<?> query, String keyspace) {
|
||||
|
||||
CRITERIA criteria = this.criteriaAccessor != null ? this.criteriaAccessor.resolve(query) : null;
|
||||
return count(criteria, keyspace);
|
||||
@@ -92,7 +91,7 @@ public abstract class QueryEngine<ADAPTER extends KeyValueAdapter, CRITERIA, SOR
|
||||
* @param keyspace
|
||||
* @return
|
||||
*/
|
||||
public abstract Collection<?> execute(CRITERIA criteria, SORT sort, long offset, int rows, Serializable keyspace);
|
||||
public abstract Collection<?> execute(CRITERIA criteria, SORT sort, long offset, int rows, String keyspace);
|
||||
|
||||
/**
|
||||
* @param criteria
|
||||
@@ -104,7 +103,7 @@ public abstract class QueryEngine<ADAPTER extends KeyValueAdapter, CRITERIA, SOR
|
||||
* @return
|
||||
* @since 1.1
|
||||
*/
|
||||
public <T> Collection<T> execute(CRITERIA criteria, SORT sort, long offset, int rows, Serializable keyspace,
|
||||
public <T> Collection<T> execute(CRITERIA criteria, SORT sort, long offset, int rows, String keyspace,
|
||||
Class<T> type) {
|
||||
return (Collection<T>) execute(criteria, sort, offset, rows, keyspace);
|
||||
}
|
||||
@@ -114,7 +113,7 @@ public abstract class QueryEngine<ADAPTER extends KeyValueAdapter, CRITERIA, SOR
|
||||
* @param keyspace
|
||||
* @return
|
||||
*/
|
||||
public abstract long count(CRITERIA criteria, Serializable keyspace);
|
||||
public abstract long count(CRITERIA criteria, String keyspace);
|
||||
|
||||
/**
|
||||
* Get the {@link KeyValueAdapter} used.
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -48,19 +47,19 @@ class SpelQueryEngine<T extends KeyValueAdapter> extends QueryEngine<KeyValueAda
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.QueryEngine#execute(java.lang.Object, java.lang.Object, int, int, java.io.Serializable)
|
||||
* @see org.springframework.data.keyvalue.core.QueryEngine#execute(java.lang.Object, java.lang.Object, int, int, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Collection<?> execute(SpelCriteria criteria, Comparator<?> sort, long offset, int rows, Serializable keyspace) {
|
||||
public Collection<?> execute(SpelCriteria criteria, Comparator<?> sort, long offset, int rows, String keyspace) {
|
||||
return sortAndFilterMatchingRange(getAdapter().getAllOf(keyspace), criteria, sort, offset, rows);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.QueryEngine#count(java.lang.Object, java.io.Serializable)
|
||||
* @see org.springframework.data.keyvalue.core.QueryEngine#count(java.lang.Object, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public long count(SpelCriteria criteria, Serializable keyspace) {
|
||||
public long count(SpelCriteria criteria, String keyspace) {
|
||||
return filterMatchingRange(getAdapter().getAllOf(keyspace), criteria, -1, -1).size();
|
||||
}
|
||||
|
||||
@@ -93,8 +92,8 @@ class SpelQueryEngine<T extends KeyValueAdapter> extends QueryEngine<KeyValueAda
|
||||
matches = criteria.getExpression().getValue(criteria.getContext(), candidate, Boolean.class);
|
||||
} catch (SpelEvaluationException e) {
|
||||
criteria.getContext().setVariable("it", candidate);
|
||||
matches = criteria.getExpression().getValue(criteria.getContext()) == null ? false : criteria.getExpression()
|
||||
.getValue(criteria.getContext(), Boolean.class);
|
||||
matches = criteria.getExpression().getValue(criteria.getContext()) == null ? false
|
||||
: criteria.getExpression().getValue(criteria.getContext(), Boolean.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core.event;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
@@ -60,7 +58,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public static <T> BeforeGetEvent<T> beforeGet(Serializable id, String keySpace, Class<T> type) {
|
||||
public static <T> BeforeGetEvent<T> beforeGet(Object id, String keySpace, Class<T> type) {
|
||||
return new BeforeGetEvent<>(id, keySpace, type);
|
||||
}
|
||||
|
||||
@@ -73,7 +71,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static <T> AfterGetEvent<T> afterGet(Serializable id, String keySpace, Class<T> type, T value) {
|
||||
public static <T> AfterGetEvent<T> afterGet(Object id, String keySpace, Class<T> type, T value) {
|
||||
return new AfterGetEvent<>(id, keySpace, type, value);
|
||||
}
|
||||
|
||||
@@ -86,7 +84,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static <T> BeforeInsertEvent<T> beforeInsert(Serializable id, String keySpace, Class<? extends T> type, T value) {
|
||||
public static <T> BeforeInsertEvent<T> beforeInsert(Object id, String keySpace, Class<? extends T> type, T value) {
|
||||
return new BeforeInsertEvent<>(id, keySpace, type, value);
|
||||
}
|
||||
|
||||
@@ -99,7 +97,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static <T> AfterInsertEvent<T> afterInsert(Serializable id, String keySpace, Class<? extends T> type, T value) {
|
||||
public static <T> AfterInsertEvent<T> afterInsert(Object id, String keySpace, Class<? extends T> type, T value) {
|
||||
return new AfterInsertEvent<>(id, keySpace, type, value);
|
||||
}
|
||||
|
||||
@@ -112,7 +110,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static <T> BeforeUpdateEvent<T> beforeUpdate(Serializable id, String keySpace, Class<? extends T> type, T value) {
|
||||
public static <T> BeforeUpdateEvent<T> beforeUpdate(Object id, String keySpace, Class<? extends T> type, T value) {
|
||||
return new BeforeUpdateEvent<>(id, keySpace, type, value);
|
||||
}
|
||||
|
||||
@@ -126,8 +124,8 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
* @param previousValue
|
||||
* @return
|
||||
*/
|
||||
public static <T> AfterUpdateEvent<T> afterUpdate(Serializable id, String keySpace, Class<? extends T> type,
|
||||
T actualValue, Object previousValue) {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -161,7 +159,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public static <T> BeforeDeleteEvent<T> beforeDelete(Serializable id, String keySpace, Class<? extends T> type) {
|
||||
public static <T> BeforeDeleteEvent<T> beforeDelete(Object id, String keySpace, Class<? extends T> type) {
|
||||
return new BeforeDeleteEvent<>(id, keySpace, type);
|
||||
}
|
||||
|
||||
@@ -174,7 +172,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static <T> AfterDeleteEvent<T> afterDelete(Serializable id, String keySpace, Class<? extends T> type, T value) {
|
||||
public static <T> AfterDeleteEvent<T> afterDelete(Object id, String keySpace, Class<? extends T> type, T value) {
|
||||
return new AfterDeleteEvent<>(id, keySpace, type, value);
|
||||
}
|
||||
|
||||
@@ -185,16 +183,17 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
@SuppressWarnings("serial")
|
||||
abstract static class KeyBasedEvent<T> extends KeyValueEvent<T> {
|
||||
|
||||
private Serializable key;
|
||||
private Object key;
|
||||
private Class<? extends T> type;
|
||||
|
||||
protected KeyBasedEvent(Serializable key, String keySpace, Class<? extends T> type) {
|
||||
protected KeyBasedEvent(Object key, String keySpace, Class<? extends T> type) {
|
||||
|
||||
super(type, keySpace);
|
||||
this.key = key;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Serializable getKey() {
|
||||
public Object getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@@ -203,7 +202,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
* @see java.util.EventObject#getSource()
|
||||
*/
|
||||
@Override
|
||||
public Serializable getSource() {
|
||||
public Object getSource() {
|
||||
return getKey();
|
||||
}
|
||||
|
||||
@@ -226,7 +225,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
|
||||
private final T payload;
|
||||
|
||||
public KeyBasedEventWithPayload(Serializable key, String keySpace, Class<? extends T> type, T payload) {
|
||||
public KeyBasedEventWithPayload(Object key, String keySpace, Class<? extends T> type, T payload) {
|
||||
super(key, keySpace, type);
|
||||
this.payload = payload;
|
||||
}
|
||||
@@ -250,7 +249,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
@SuppressWarnings("serial")
|
||||
public static class BeforeGetEvent<T> extends KeyBasedEvent<T> {
|
||||
|
||||
protected BeforeGetEvent(Serializable key, String keySpace, Class<T> type) {
|
||||
protected BeforeGetEvent(Object key, String keySpace, Class<T> type) {
|
||||
super(key, keySpace, type);
|
||||
}
|
||||
|
||||
@@ -265,7 +264,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
@SuppressWarnings("serial")
|
||||
public static class AfterGetEvent<T> extends KeyBasedEventWithPayload<T> {
|
||||
|
||||
protected AfterGetEvent(Serializable key, String keyspace, Class<T> type, T payload) {
|
||||
protected AfterGetEvent(Object key, String keyspace, Class<T> type, T payload) {
|
||||
super(key, keyspace, type, payload);
|
||||
}
|
||||
|
||||
@@ -280,7 +279,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
@SuppressWarnings("serial")
|
||||
public static class BeforeInsertEvent<T> extends KeyBasedEventWithPayload<T> {
|
||||
|
||||
public BeforeInsertEvent(Serializable key, String keySpace, Class<? extends T> type, T payload) {
|
||||
public BeforeInsertEvent(Object key, String keySpace, Class<? extends T> type, T payload) {
|
||||
super(key, keySpace, type, payload);
|
||||
|
||||
}
|
||||
@@ -295,7 +294,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
@SuppressWarnings("serial")
|
||||
public static class AfterInsertEvent<T> extends KeyBasedEventWithPayload<T> {
|
||||
|
||||
public AfterInsertEvent(Serializable key, String keySpace, Class<? extends T> type, T payload) {
|
||||
public AfterInsertEvent(Object key, String keySpace, Class<? extends T> type, T payload) {
|
||||
super(key, keySpace, type, payload);
|
||||
}
|
||||
}
|
||||
@@ -309,7 +308,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
@SuppressWarnings("serial")
|
||||
public static class BeforeUpdateEvent<T> extends KeyBasedEventWithPayload<T> {
|
||||
|
||||
public BeforeUpdateEvent(Serializable key, String keySpace, Class<? extends T> type, T payload) {
|
||||
public BeforeUpdateEvent(Object key, String keySpace, Class<? extends T> type, T payload) {
|
||||
super(key, keySpace, type, payload);
|
||||
}
|
||||
}
|
||||
@@ -325,7 +324,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
|
||||
private final Object existing;
|
||||
|
||||
public AfterUpdateEvent(Serializable key, String keySpace, Class<? extends T> type, T payload, Object existing) {
|
||||
public AfterUpdateEvent(Object key, String keySpace, Class<? extends T> type, T payload, Object existing) {
|
||||
super(key, keySpace, type, payload);
|
||||
this.existing = existing;
|
||||
}
|
||||
@@ -358,7 +357,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
@SuppressWarnings("serial")
|
||||
public static class BeforeDeleteEvent<T> extends KeyBasedEvent<T> {
|
||||
|
||||
public BeforeDeleteEvent(Serializable key, String keySpace, Class<? extends T> type) {
|
||||
public BeforeDeleteEvent(Object key, String keySpace, Class<? extends T> type) {
|
||||
super(key, keySpace, type);
|
||||
}
|
||||
}
|
||||
@@ -372,7 +371,7 @@ public class KeyValueEvent<T> extends ApplicationEvent {
|
||||
@SuppressWarnings("serial")
|
||||
public static class AfterDeleteEvent<T> extends KeyBasedEventWithPayload<T> {
|
||||
|
||||
public AfterDeleteEvent(Serializable key, String keySpace, Class<? extends T> type, T payload) {
|
||||
public AfterDeleteEvent(Object key, String keySpace, Class<? extends T> type, T payload) {
|
||||
super(key, keySpace, type, payload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
|
||||
/**
|
||||
@@ -24,6 +22,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
* @param <T>
|
||||
* @param <ID>
|
||||
*/
|
||||
public interface KeyValueRepository<T, ID extends Serializable> extends PagingAndSortingRepository<T, ID> {
|
||||
public interface KeyValueRepository<T, ID> extends PagingAndSortingRepository<T, ID> {
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.repository.support;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -38,7 +37,7 @@ import org.springframework.util.Assert;
|
||||
* @param <T>
|
||||
* @param <ID>
|
||||
*/
|
||||
public class SimpleKeyValueRepository<T, ID extends Serializable> implements KeyValueRepository<T, ID> {
|
||||
public class SimpleKeyValueRepository<T, ID> implements KeyValueRepository<T, ID> {
|
||||
|
||||
private final KeyValueOperations operations;
|
||||
private final EntityInformation<T, ID> entityInformation;
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.map;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@@ -36,9 +35,9 @@ import org.springframework.util.ClassUtils;
|
||||
*/
|
||||
public class MapKeyValueAdapter extends AbstractKeyValueAdapter {
|
||||
|
||||
@SuppressWarnings("rawtypes")//
|
||||
@SuppressWarnings("rawtypes") //
|
||||
private final Class<? extends Map> keySpaceMapType;
|
||||
private final Map<Serializable, Map<Serializable, Object>> store;
|
||||
private final Map<String, Map<Object, Object>> store;
|
||||
|
||||
/**
|
||||
* Create new {@link MapKeyValueAdapter} using {@link ConcurrentHashMap} as backing store type.
|
||||
@@ -54,7 +53,7 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter {
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public MapKeyValueAdapter(Class<? extends Map> mapType) {
|
||||
this(CollectionFactory.<Serializable, Map<Serializable, Object>> createMap(mapType, 100), mapType);
|
||||
this(CollectionFactory.createMap(mapType, 100), mapType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +62,7 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter {
|
||||
* @param store must not be {@literal null}.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public MapKeyValueAdapter(Map<Serializable, Map<Serializable, Object>> store) {
|
||||
public MapKeyValueAdapter(Map<String, Map<Object, Object>> store) {
|
||||
this(store, (Class<? extends Map>) ClassUtils.getUserClass(store));
|
||||
}
|
||||
|
||||
@@ -74,7 +73,7 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter {
|
||||
* @param keySpaceMapType must not be {@literal null}.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private MapKeyValueAdapter(Map<Serializable, Map<Serializable, Object>> store, Class<? extends Map> keySpaceMapType) {
|
||||
private MapKeyValueAdapter(Map<String, Map<Object, Object>> store, Class<? extends Map> keySpaceMapType) {
|
||||
|
||||
Assert.notNull(store, "Store must not be null.");
|
||||
Assert.notNull(keySpaceMapType, "Map type to be used for key spaces must not be null!");
|
||||
@@ -85,10 +84,10 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#put(java.io.Serializable, java.lang.Object, java.io.Serializable)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#put(java.lang.Object, java.lang.Object, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Object put(Serializable id, Object item, Serializable keyspace) {
|
||||
public Object put(Object id, Object item, String keyspace) {
|
||||
|
||||
Assert.notNull(id, "Cannot add item with null id.");
|
||||
Assert.notNull(keyspace, "Cannot add item for null collection.");
|
||||
@@ -98,27 +97,27 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#contains(java.io.Serializable, java.io.Serializable)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#contains(java.lang.Object, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(Serializable id, Serializable keyspace) {
|
||||
public boolean contains(Object id, String keyspace) {
|
||||
return get(id, keyspace) != null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#count(java.io.Serializable)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#count(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public long count(Serializable keyspace) {
|
||||
public long count(String keyspace) {
|
||||
return getKeySpaceMap(keyspace).size();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.io.Serializable, java.io.Serializable)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.lang.Object, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Object get(Serializable id, Serializable keyspace) {
|
||||
public Object get(Object id, String keyspace) {
|
||||
|
||||
Assert.notNull(id, "Cannot get item with null id.");
|
||||
return getKeySpaceMap(keyspace).get(id);
|
||||
@@ -126,10 +125,10 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#delete(java.io.Serializable, java.io.Serializable)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#delete(java.lang.Object, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Object delete(Serializable id, Serializable keyspace) {
|
||||
public Object delete(Object id, String keyspace) {
|
||||
|
||||
Assert.notNull(id, "Cannot delete item with null id.");
|
||||
return getKeySpaceMap(keyspace).remove(id);
|
||||
@@ -137,28 +136,28 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#getAllOf(java.io.Serializable)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#getAllOf(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Collection<?> getAllOf(Serializable keyspace) {
|
||||
public Collection<?> getAllOf(String keyspace) {
|
||||
return getKeySpaceMap(keyspace).values();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#entries(java.io.Serializable)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#entries(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public CloseableIterator<Entry<Serializable, Object>> entries(Serializable keyspace) {
|
||||
public CloseableIterator<Entry<Object, Object>> entries(String keyspace) {
|
||||
return new ForwardingCloseableIterator<>(getKeySpaceMap(keyspace).entrySet().iterator());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#deleteAllOf(java.io.Serializable)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#deleteAllOf(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void deleteAllOf(Serializable keyspace) {
|
||||
public void deleteAllOf(String keyspace) {
|
||||
getKeySpaceMap(keyspace).clear();
|
||||
}
|
||||
|
||||
@@ -186,11 +185,11 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter {
|
||||
* @param keyspace must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
protected Map<Serializable, Object> getKeySpaceMap(Serializable keyspace) {
|
||||
protected Map<Object, Object> getKeySpaceMap(String keyspace) {
|
||||
|
||||
Assert.notNull(keyspace, "Collection must not be null for lookup.");
|
||||
|
||||
Map<Serializable, Object> map = store.get(keyspace);
|
||||
Map<Object, Object> map = store.get(keyspace);
|
||||
|
||||
if (map != null) {
|
||||
return map;
|
||||
@@ -200,7 +199,7 @@ public class MapKeyValueAdapter extends AbstractKeyValueAdapter {
|
||||
return store.get(keyspace);
|
||||
}
|
||||
|
||||
private void addMapForKeySpace(Serializable keyspace) {
|
||||
store.put(keyspace, CollectionFactory.<Serializable, Object> createMap(keySpaceMapType, 1000));
|
||||
private void addMapForKeySpace(String keyspace) {
|
||||
store.put(keyspace, CollectionFactory.createMap(keySpaceMapType, 1000));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import static org.hamcrest.core.IsNull.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.keyvalue.test.util.IsEntry.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -148,7 +147,7 @@ public class MapKeyValueAdapterUnitTests {
|
||||
adapter.put("1", object1, COLLECTION_1);
|
||||
adapter.put("2", object2, COLLECTION_1);
|
||||
|
||||
CloseableIterator<Map.Entry<Serializable, Object>> iterator = adapter.entries(COLLECTION_1);
|
||||
CloseableIterator<Map.Entry<Object, Object>> iterator = adapter.entries(COLLECTION_1);
|
||||
|
||||
assertThat(iterator.next(), isEntry("1", object1));
|
||||
assertThat(iterator.next(), isEntry("2", object2));
|
||||
@@ -166,7 +165,7 @@ public class MapKeyValueAdapterUnitTests {
|
||||
adapter.put("1", object1, COLLECTION_1);
|
||||
adapter.put("2", object2, COLLECTION_2);
|
||||
|
||||
CloseableIterator<Map.Entry<Serializable, Object>> iterator = adapter.entries(COLLECTION_1);
|
||||
CloseableIterator<Map.Entry<Object, Object>> iterator = adapter.entries(COLLECTION_1);
|
||||
|
||||
assertThat(iterator.next(), isEntry("1", object1));
|
||||
assertThat(iterator.hasNext(), is(false));
|
||||
|
||||
Reference in New Issue
Block a user