Make Lettuce return converted tx results
DATAREDIS-208
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -71,7 +71,7 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea
|
||||
/** Synchronization monitor for the shared Connection */
|
||||
private final Object connectionMonitor = new Object();
|
||||
private String password;
|
||||
private boolean convertPipelineResults = true;
|
||||
private boolean convertPipelineAndTxResults = true;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>LettuceConnectionFactory</code> instance with
|
||||
@@ -108,7 +108,7 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea
|
||||
|
||||
public RedisConnection getConnection() {
|
||||
LettuceConnection connection = new LettuceConnection(getSharedConnection(), timeout, client, pool);
|
||||
connection.setConvertPipelineResults(convertPipelineResults);
|
||||
connection.setConvertPipelineAndTxResults(convertPipelineAndTxResults);
|
||||
return connection;
|
||||
}
|
||||
|
||||
@@ -302,24 +302,24 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea
|
||||
|
||||
/**
|
||||
* Specifies if pipelined results should be converted to the expected data
|
||||
* type. If false, results of {@link #closePipeline()} will be of the
|
||||
* type returned by the Jedis driver
|
||||
* type. If false, results of {@link LettuceConnection#closePipeline()} and {LettuceConnection#exec()}
|
||||
* will be of the type returned by the Lettuce driver
|
||||
*
|
||||
* @return Whether or not to convert pipeline results
|
||||
* @return Whether or not to convert pipeline and tx results
|
||||
*/
|
||||
public boolean getConvertPipelineResults() {
|
||||
return convertPipelineResults;
|
||||
public boolean getConvertPipelineAndTxResults() {
|
||||
return convertPipelineAndTxResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies if pipelined results should be converted to the expected data
|
||||
* type. If false, results of {@link #closePipeline()} will be of the
|
||||
* type returned by the Jedis driver
|
||||
* Specifies if pipelined and transaction results should be converted to the expected data
|
||||
* type. If false, results of {@link LettuceConnection#closePipeline()} and {LettuceConnection#exec()}
|
||||
* will be of the type returned by the Lettuce driver
|
||||
*
|
||||
* @param convertPipelineResults Whether or not to convert pipeline results
|
||||
* @param convertPipelineAndTxResults Whether or not to convert pipeline and tx results
|
||||
*/
|
||||
public void setConvertPipelineResults(boolean convertPipelineResults) {
|
||||
this.convertPipelineResults = convertPipelineResults;
|
||||
public void setConvertPipelineAndTxResults(boolean convertPipelineAndTxResults) {
|
||||
this.convertPipelineAndTxResults = convertPipelineAndTxResults;
|
||||
}
|
||||
|
||||
protected RedisAsyncConnection<byte[], byte[]> getSharedConnection() {
|
||||
|
||||
@@ -20,26 +20,19 @@ import java.util.Date;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.jboss.netty.channel.ChannelException;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.QueryTimeoutException;
|
||||
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
import org.springframework.data.redis.connection.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.ReturnType;
|
||||
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.ReturnType;
|
||||
import org.springframework.data.redis.connection.SortParameters;
|
||||
import org.springframework.data.redis.connection.SortParameters.Order;
|
||||
import org.springframework.data.redis.connection.convert.Converters;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.lambdaworks.redis.KeyValue;
|
||||
import com.lambdaworks.redis.RedisCommandInterruptedException;
|
||||
import com.lambdaworks.redis.RedisException;
|
||||
import com.lambdaworks.redis.ScoredValue;
|
||||
import com.lambdaworks.redis.ScriptOutputType;
|
||||
import com.lambdaworks.redis.SortArgs;
|
||||
@@ -59,7 +52,7 @@ abstract public class LettuceConverters extends Converters {
|
||||
private static final Converter<KeyValue<byte[], byte[]>, List<byte[]>> KEY_VALUE_TO_BYTES_LIST;
|
||||
private static final Converter<List<ScoredValue<byte[]>>, Set<Tuple>> SCORED_VALUES_TO_TUPLE_SET;
|
||||
private static final Converter<ScoredValue<byte[]>, Tuple> SCORED_VALUE_TO_TUPLE;
|
||||
private static final Converter<List<Object>, List<Object>> EXEC_RESULTS_CONVERTER;
|
||||
private static final Converter<Exception, DataAccessException> EXCEPTION_CONVERTER = new LettuceExceptionConverter();
|
||||
|
||||
static {
|
||||
DATE_TO_LONG = new Converter<Date, Long>() {
|
||||
@@ -108,16 +101,6 @@ abstract public class LettuceConverters extends Converters {
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
EXEC_RESULTS_CONVERTER = new Converter<List<Object>, List<Object>>() {
|
||||
public List<Object> convert(List<Object> source) {
|
||||
// Lettuce Empty list means null (watched variable modified)
|
||||
if(source.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Converter<Date, Long> dateToLong() {
|
||||
@@ -144,8 +127,8 @@ abstract public class LettuceConverters extends Converters {
|
||||
return SCORED_VALUE_TO_TUPLE;
|
||||
}
|
||||
|
||||
public static Converter<List<Object>, List<Object>> execResultsConverter() {
|
||||
return EXEC_RESULTS_CONVERTER;
|
||||
public static Converter<Exception, DataAccessException> exceptionConverter() {
|
||||
return EXCEPTION_CONVERTER;
|
||||
}
|
||||
|
||||
public static Long toLong(Date source) {
|
||||
@@ -173,19 +156,7 @@ abstract public class LettuceConverters extends Converters {
|
||||
}
|
||||
|
||||
public static DataAccessException toDataAccessException(Exception ex) {
|
||||
if (ex instanceof RedisCommandInterruptedException) {
|
||||
return new RedisSystemException("Redis command interrupted", ex);
|
||||
}
|
||||
if (ex instanceof RedisException) {
|
||||
return new RedisSystemException("Redis exception", ex);
|
||||
}
|
||||
if (ex instanceof ChannelException) {
|
||||
return new RedisConnectionFailureException("Redis connection failed", ex);
|
||||
}
|
||||
if (ex instanceof TimeoutException) {
|
||||
return new QueryTimeoutException("Redis command timed out", ex);
|
||||
}
|
||||
return new RedisSystemException("Unknown Lettuce exception", ex);
|
||||
return EXCEPTION_CONVERTER.convert(ex);
|
||||
}
|
||||
|
||||
public static ScriptOutputType toScriptOutputType(ReturnType returnType) {
|
||||
@@ -245,8 +216,4 @@ abstract public class LettuceConverters extends Converters {
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
public static List<Object> toExecResults(List<Object> source) {
|
||||
return EXEC_RESULTS_CONVERTER.convert(source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.jboss.netty.channel.ChannelException;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.QueryTimeoutException;
|
||||
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
|
||||
import com.lambdaworks.redis.RedisCommandInterruptedException;
|
||||
import com.lambdaworks.redis.RedisException;
|
||||
|
||||
/**
|
||||
* Converts Lettuce Exceptions to {@link DataAccessException}s
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
*
|
||||
*/
|
||||
public class LettuceExceptionConverter implements Converter<Exception, DataAccessException> {
|
||||
|
||||
public DataAccessException convert(Exception ex) {
|
||||
if (ex instanceof DataAccessException) {
|
||||
return (DataAccessException) ex;
|
||||
}
|
||||
if (ex instanceof RedisCommandInterruptedException) {
|
||||
return new RedisSystemException("Redis command interrupted", ex);
|
||||
}
|
||||
if (ex instanceof RedisException) {
|
||||
return new RedisSystemException("Redis exception", ex);
|
||||
}
|
||||
if (ex instanceof ChannelException) {
|
||||
return new RedisConnectionFailureException("Redis connection failed", ex);
|
||||
}
|
||||
if (ex instanceof TimeoutException) {
|
||||
return new QueryTimeoutException("Redis command timed out", ex);
|
||||
}
|
||||
return new RedisSystemException("Unknown Lettuce exception", ex);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user