From c3b3c8c79cc4d37a72a48ae7d3579af1eeef065f Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Fri, 12 Nov 2010 18:40:31 +0200 Subject: [PATCH] + rename RedisKeyStore to KeyBound + add default implementations for BoundListOperations & co + wire RedisOperations into RedisTemplate --- .../redis/core/BoundListOperations.java | 2 +- .../core/DefaultBoundListOperations.java | 79 +++++++++++++++++++ .../datastore/redis/core/DefaultKeyBound.java | 36 +++++++++ .../{RedisKeyedStore.java => KeyBound.java} | 2 +- .../datastore/redis/core/RedisTemplate.java | 51 +++++++++++- 5 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundListOperations.java create mode 100644 spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultKeyBound.java rename spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/{RedisKeyedStore.java => KeyBound.java} (95%) diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundListOperations.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundListOperations.java index b2fe714f2..1c1e330c3 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundListOperations.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundListOperations.java @@ -22,7 +22,7 @@ import java.util.List; * * @author Costin Leau */ -public interface BoundListOperations extends RedisKeyedStore { +public interface BoundListOperations extends KeyBound { List range(int start, int end); diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundListOperations.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundListOperations.java new file mode 100644 index 000000000..82ebaf363 --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundListOperations.java @@ -0,0 +1,79 @@ +/* + * 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.core; + +import java.util.List; + + +/** + * Default implementation for {@link BoundListOperations}. + * + * @author Costin Leau + */ +public class DefaultBoundListOperations extends DefaultKeyBound implements BoundListOperations { + + private final ListOperations ops; + + public DefaultBoundListOperations(K key, RedisTemplate template) { + super(key); + this.ops = template.listOps(); + } + + @Override + public V index(int index) { + throw new UnsupportedOperationException(); + } + + @Override + public V leftPop() { + throw new UnsupportedOperationException(); + } + + @Override + public Integer leftPush(V value) { + throw new UnsupportedOperationException(); + } + + @Override + public Integer length() { + throw new UnsupportedOperationException(); + } + + @Override + public List range(int start, int end) { + throw new UnsupportedOperationException(); + } + + @Override + public Integer remove(int i, Object value) { + throw new UnsupportedOperationException(); + } + + @Override + public V rightPop() { + throw new UnsupportedOperationException(); + } + + @Override + public Integer rightPush(V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void trim(int start, int end) { + throw new UnsupportedOperationException(); + } +} \ No newline at end of file diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultKeyBound.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultKeyBound.java new file mode 100644 index 000000000..6c2dd57cc --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultKeyBound.java @@ -0,0 +1,36 @@ +/* + * 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.core; + + +/** + * Default {@link KeyBound} implementation. + * + * @author Costin Leau + */ +public class DefaultKeyBound implements KeyBound { + + private final K key; + + public DefaultKeyBound(K key) { + this.key = key; + } + + @Override + public K getKey() { + return key; + } +} diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisKeyedStore.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/KeyBound.java similarity index 95% rename from spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisKeyedStore.java rename to spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/KeyBound.java index 59612381a..29f336b7d 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisKeyedStore.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/KeyBound.java @@ -20,7 +20,7 @@ package org.springframework.datastore.redis.core; * * @author Costin Leau */ -public interface RedisKeyedStore { +public interface KeyBound { /** * Returns the key associated with this store. 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 6a12b8dad..6a2135d27 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 @@ -44,7 +44,7 @@ import org.springframework.util.ClassUtils; * * @author Costin Leau */ -public class RedisTemplate extends RedisAccessor { +public class RedisTemplate extends RedisAccessor implements RedisOperations { private boolean exposeConnection = false; private RedisSerializer keySerializer = new StringRedisSerializer(); @@ -179,4 +179,53 @@ public class RedisTemplate extends RedisAccessor { } } } + + // + // RedisOperations + // + + @Override + public Object exec() { + throw new UnsupportedOperationException(); + } + + @Override + public BoundListOperations forList(K key) { + return new DefaultBoundListOperations(key, this); + } + + @Override + public V get(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public V getSet(K key, V newValue) { + throw new UnsupportedOperationException(); + } + + @Override + public V increment(K key, int delta) { + throw new UnsupportedOperationException(); + } + + @Override + public ListOperations listOps() { + throw new UnsupportedOperationException(); + } + + @Override + public void multi() { + throw new UnsupportedOperationException(); + } + + @Override + public void set(K key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void watch(K key) { + throw new UnsupportedOperationException(); + } } \ No newline at end of file