DATAKV-36
+ fix compilation problem under the JDK (works fine in Eclipse) + added more javadocs
This commit is contained in:
@@ -22,7 +22,8 @@ import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.DataType;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters;
|
||||
import org.springframework.data.keyvalue.redis.core.query.SortQuery;
|
||||
import org.springframework.data.keyvalue.redis.serializer.RedisSerializer;
|
||||
|
||||
|
||||
/**
|
||||
@@ -102,10 +103,6 @@ public interface RedisOperations<K, V> {
|
||||
|
||||
Object exec();
|
||||
|
||||
List<V> sort(K key, SortParameters params);
|
||||
|
||||
Long sort(K key, SortParameters params, K destination);
|
||||
|
||||
// pubsub functionality on the template
|
||||
void convertAndSend(String destination, Object message);
|
||||
|
||||
@@ -191,4 +188,16 @@ public interface RedisOperations<K, V> {
|
||||
* @return hash operations bound to the given key.
|
||||
*/
|
||||
<HK, HV> BoundHashOperations<K, HK, HV> boundHashOps(K key);
|
||||
|
||||
|
||||
List<V> sort(SortQuery<K> query);
|
||||
|
||||
|
||||
<T> List<T> sort(SortQuery<K> query, RedisSerializer<T> resultSerializer);
|
||||
|
||||
|
||||
<T> List<T> sort(SortQuery<K> query, BulkMapper<T> bulkMapper);
|
||||
|
||||
|
||||
Long sort(SortQuery<K> query, K storeKey);
|
||||
}
|
||||
@@ -423,15 +423,16 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends Collection<V>> T deserializeValues(Collection<byte[]> rawValues, Class<? extends Collection> type) {
|
||||
return deserializeValues(rawValues, type, valueSerializer);
|
||||
return (T) deserializeValues(rawValues, type, valueSerializer);
|
||||
}
|
||||
|
||||
private <X, T extends Collection<X>> T deserializeValues(Collection<byte[]> rawValues, Class<? extends Collection> type, RedisSerializer<?> redisSerializer) {
|
||||
Collection<X> values = (List.class.isAssignableFrom(type) ? new ArrayList<X>(rawValues.size())
|
||||
: new LinkedHashSet<X>(rawValues.size()));
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends Collection<?>> T deserializeValues(Collection<byte[]> rawValues, Class<? extends Collection> type, RedisSerializer<?> redisSerializer) {
|
||||
Collection<Object> values = (List.class.isAssignableFrom(type) ? new ArrayList<Object>(rawValues.size())
|
||||
: new LinkedHashSet<Object>(rawValues.size()));
|
||||
for (byte[] bs : rawValues) {
|
||||
if (bs != null) {
|
||||
values.add((X) redisSerializer.deserialize(bs));
|
||||
values.add(redisSerializer.deserialize(bs));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -625,33 +626,6 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<V> sort(K key, final SortParameters params) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
|
||||
List<byte[]> rawValues = execute(new RedisCallback<List<byte[]>>() {
|
||||
@Override
|
||||
public List<byte[]> doInRedis(RedisConnection connection) {
|
||||
return connection.sort(rawKey, params);
|
||||
}
|
||||
}, true);
|
||||
|
||||
return deserializeValues(rawValues, List.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long sort(K key, final SortParameters params, K destination) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
final byte[] rawDestKey = rawKey(destination);
|
||||
|
||||
return execute(new RedisCallback<Long>() {
|
||||
@Override
|
||||
public Long doInRedis(RedisConnection connection) {
|
||||
return connection.sort(rawKey, params, rawDestKey);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertAndSend(String channel, Object message) {
|
||||
Assert.hasText(channel, "a non-empty channel is required");
|
||||
@@ -1955,11 +1929,13 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
|
||||
// Sort operations
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<V> sort(SortQuery<K> query) {
|
||||
return sort(query, valueSerializer);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> List<T> sort(SortQuery<K> query, RedisSerializer<T> resultSerializer) {
|
||||
final byte[] rawKey = rawKey(query.getKey());
|
||||
final SortParameters params = convertQuery(query, stringSerializer);
|
||||
@@ -1974,6 +1950,7 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
return (List<T>) deserializeValues(vals, List.class, resultSerializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> sort(SortQuery<K> query, BulkMapper<T> bulkMapper) {
|
||||
final byte[] rawKey = rawKey(query.getKey());
|
||||
final SortParameters params = convertQuery(query, stringSerializer);
|
||||
@@ -2002,16 +1979,16 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
return result;
|
||||
}
|
||||
|
||||
public void sort(SortQuery<K> query, K storeKey) {
|
||||
@Override
|
||||
public Long sort(SortQuery<K> query, K storeKey) {
|
||||
final byte[] rawStoreKey = rawKey(storeKey);
|
||||
final byte[] rawKey = rawKey(query.getKey());
|
||||
final SortParameters params = convertQuery(query, stringSerializer);
|
||||
|
||||
execute(new RedisCallback<Object>() {
|
||||
return execute(new RedisCallback<Long>() {
|
||||
@Override
|
||||
public Object doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
connection.sort(rawKey, params, rawStoreKey);
|
||||
return null;
|
||||
public Long doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.sort(rawKey, params, rawStoreKey);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import org.springframework.data.keyvalue.redis.connection.SortParameters.Order;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters.Range;
|
||||
|
||||
/**
|
||||
* Default implementation for {@link SortCriterion}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class DefaultSortCriterion<K> implements SortCriterion<K> {
|
||||
|
||||
@@ -19,6 +19,8 @@ import org.springframework.data.keyvalue.redis.connection.SortParameters.Order;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters.Range;
|
||||
|
||||
/**
|
||||
* Internal interface part of the Sort DSL. Exposes generic operations.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public interface SortCriterion<K> {
|
||||
|
||||
@@ -17,10 +17,16 @@ package org.springframework.data.keyvalue.redis.core.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisConnection;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters.Order;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters.Range;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
|
||||
/**
|
||||
* High-level abstraction over a Redis SORT (generified equivalent of {@link SortParameters}). To be used with {@link RedisTemplate}
|
||||
* (just as {@link SortParameters} is used by {@link RedisConnection}).
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public interface SortQuery<K> {
|
||||
|
||||
@@ -17,14 +17,14 @@ package org.springframework.data.keyvalue.redis.core.query;
|
||||
|
||||
|
||||
/**
|
||||
* Builder class for constructing {@link SortQuery}.
|
||||
* Simple builder class for constructing {@link SortQuery}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class SortQueryBuilder<K> extends DefaultSortCriterion<K> {
|
||||
|
||||
private static final String NO_SORT_KEY = "~";
|
||||
|
||||
|
||||
private SortQueryBuilder(K key) {
|
||||
super(key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user