diff --git a/spring-datastore-redis/pom.xml b/spring-datastore-redis/pom.xml index e88a04f15..95b738e3c 100644 --- a/spring-datastore-redis/pom.xml +++ b/spring-datastore-redis/pom.xml @@ -21,6 +21,10 @@ org.springframework spring-beans + + org.springframework + spring-core + org.springframework spring-tx diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisTemplate.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisTemplate.java index 6e89cdb5e..3cfa23777 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisTemplate.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisTemplate.java @@ -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 converter = new SimpleRedisSerializer(); 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; } diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/support/converter/RedisConverter.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/serializer/RedisSerializer.java similarity index 68% rename from spring-datastore-redis/src/main/java/org/springframework/datastore/redis/support/converter/RedisConverter.java rename to spring-datastore-redis/src/main/java/org/springframework/datastore/redis/serializer/RedisSerializer.java index 150ebf114..486155e26 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/support/converter/RedisConverter.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/serializer/RedisSerializer.java @@ -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 { + + byte[] serialize(T object); + + T deserialize(byte[] bytes); +} diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/serializer/SimpleRedisSerializer.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/serializer/SimpleRedisSerializer.java new file mode 100644 index 000000000..308f2e33f --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/serializer/SimpleRedisSerializer.java @@ -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 implements RedisSerializer { + + private Converter serializer = new SerializingConverter(); + private Converter deserializer = new DeserializingConverter(); + + @Override + public T deserialize(byte[] bytes) { + return (T) deserializer.convert(bytes); + } + + @Override + public byte[] serialize(T object) { + return serializer.convert(object); + } +} diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/support/converter/DefaultRedisConverter.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/support/converter/DefaultRedisConverter.java deleted file mode 100644 index 4d5866f62..000000000 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/support/converter/DefaultRedisConverter.java +++ /dev/null @@ -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); - } - -}