+ refresh serializer contract
+ add Spring 3 based serialization
This commit is contained in:
@@ -21,6 +21,10 @@
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
|
||||
@@ -22,7 +22,8 @@ import java.lang.reflect.Proxy;
|
||||
|
||||
import org.springframework.datastore.redis.connection.RedisConnection;
|
||||
import org.springframework.datastore.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.datastore.redis.support.converter.RedisConverter;
|
||||
import org.springframework.datastore.redis.serializer.RedisSerializer;
|
||||
import org.springframework.datastore.redis.serializer.SimpleRedisSerializer;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -45,7 +46,7 @@ import org.springframework.util.ClassUtils;
|
||||
public class RedisTemplate extends RedisAccessor {
|
||||
|
||||
private boolean exposeConnection = false;
|
||||
private RedisConverter converter = null;
|
||||
private RedisSerializer<Object> converter = new SimpleRedisSerializer<Object>();
|
||||
|
||||
public RedisTemplate() {
|
||||
}
|
||||
@@ -121,7 +122,7 @@ public class RedisTemplate extends RedisAccessor {
|
||||
this.exposeConnection = exposeConnection;
|
||||
}
|
||||
|
||||
public void setRedisConverter(RedisConverter converter) {
|
||||
public void setRedisConverter(RedisSerializer converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010 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.datastore.redis.support.converter;
|
||||
|
||||
/**
|
||||
* Basic interface serialization and deserialization from object to byte[]. Nothing is specifc to Redis
|
||||
* @author Mark Pollack
|
||||
*
|
||||
*/
|
||||
public interface RedisConverter {
|
||||
|
||||
byte[] serialize(Object object);
|
||||
|
||||
Object deserialize(byte[] bytes);
|
||||
}
|
||||
/*
|
||||
* Copyright 2010 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.datastore.redis.serializer;
|
||||
|
||||
/**
|
||||
* Basic interface serialization and deserialization of Objects to byte arrays.
|
||||
*
|
||||
* @author Mark Pollack
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public interface RedisSerializer<T> {
|
||||
|
||||
byte[] serialize(T object);
|
||||
|
||||
T deserialize(byte[] bytes);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010 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.datastore.redis.serializer;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.serializer.support.DeserializingConverter;
|
||||
import org.springframework.core.serializer.support.SerializingConverter;
|
||||
|
||||
/**
|
||||
* Simple Redis serializer delegating to the default serializer in Spring 3.
|
||||
*
|
||||
* @author Mark Pollack
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class SimpleRedisSerializer<T> implements RedisSerializer<T> {
|
||||
|
||||
private Converter<Object, byte[]> serializer = new SerializingConverter();
|
||||
private Converter<byte[], Object> deserializer = new DeserializingConverter();
|
||||
|
||||
@Override
|
||||
public T deserialize(byte[] bytes) {
|
||||
return (T) deserializer.convert(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(T object) {
|
||||
return serializer.convert(object);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 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.datastore.redis.support.converter;
|
||||
|
||||
import org.springframework.commons.serializer.DeserializingConverter;
|
||||
import org.springframework.commons.serializer.SerializingConverter;
|
||||
import org.springframework.commons.serializer.java.JavaStreamingConverter;
|
||||
|
||||
/**
|
||||
* Implementation using Java Serialization
|
||||
*
|
||||
* @author Mark Pollack
|
||||
*
|
||||
*/
|
||||
public class DefaultRedisConverter implements RedisConverter {
|
||||
|
||||
private DeserializingConverter fromBytes = new DeserializingConverter(new JavaStreamingConverter());
|
||||
private SerializingConverter toBytes = new SerializingConverter(new JavaStreamingConverter());
|
||||
|
||||
public Object deserialize(byte[] bytes) {
|
||||
return fromBytes.convert(bytes);
|
||||
}
|
||||
|
||||
public byte[] serialize(Object object) {
|
||||
return toBytes.convert(object);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user