From 5dbc48edd0fcdad22151eac17a646013e57904c2 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Mon, 6 Dec 2010 21:22:06 +0200 Subject: [PATCH] DATAKV-8 + add sorting params --- .../connection/DefaultSortParameters.java | 135 ++++++++++++++++++ .../redis/connection/SortParameters.java | 64 +++++++++ 2 files changed, 199 insertions(+) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultSortParameters.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/SortParameters.java diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultSortParameters.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultSortParameters.java new file mode 100644 index 000000000..727d11936 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultSortParameters.java @@ -0,0 +1,135 @@ +/* + * 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 byPattern 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.keyvalue.redis.connection; + + +/** + * Default implementation for {@link SortParameters}. + * @author Costin Leau + */ +public class DefaultSortParameters implements SortParameters { + + private byte[] byPattern; + private Range limit; + private byte[] getPattern; + private byte[] hashKey; + private Order order; + private Boolean alphabetic; + private byte[] storeKey; + + /** + * Constructs a new DefaultSortParameters instance. + */ + public DefaultSortParameters() { + this(null, null, null, null, null, null, null); + } + + /** + * Constructs a new DefaultSortParameters instance. + * + * @param limit + * @param order + * @param alphabetic + */ + public DefaultSortParameters(Range limit, Order order, Boolean alphabetic) { + this(null, limit, null, null, order, alphabetic, null); + } + + /** + * Constructs a new DefaultSortParameters instance. + * + * @param byPattern + * @param limit + * @param getPattern + * @param order + * @param alphabetic + * @param storeKey + */ + public DefaultSortParameters(byte[] by, Range limit, byte[] get, byte[] hashKey, Order order, Boolean alphabetic, + byte[] storeKey) { + super(); + this.byPattern = by; + this.limit = limit; + this.getPattern = get; + this.hashKey = hashKey; + this.order = order; + this.alphabetic = alphabetic; + this.storeKey = storeKey; + } + + @Override + public byte[] getByPattern() { + return byPattern; + } + + public void setByPattern(byte[] byPattern) { + this.byPattern = byPattern; + } + + @Override + public Range getLimit() { + return limit; + } + + public void setLimit(Range limit) { + this.limit = limit; + } + + @Override + public byte[] getGetPattern() { + return getPattern; + } + + public void setGetPattern(byte[] getPattern) { + this.getPattern = getPattern; + } + + @Override + public byte[] getHashKey() { + return hashKey; + } + + public void setHashKey(byte[] hashKey) { + this.hashKey = hashKey; + } + + @Override + public Order getOrder() { + return order; + } + + public void setOrder(Order order) { + this.order = order; + } + + @Override + public Boolean isAlphabetic() { + return alphabetic; + } + + public void setAlphabetic(Boolean alphabetic) { + this.alphabetic = alphabetic; + } + + @Override + public byte[] getStoreKey() { + return storeKey; + } + + public void setStoreKey(byte[] storeKey) { + this.storeKey = storeKey; + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/SortParameters.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/SortParameters.java new file mode 100644 index 000000000..e9cf29f39 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/SortParameters.java @@ -0,0 +1,64 @@ +/* + * 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.data.keyvalue.redis.connection; + +/** + * Parameters for the SORT operation. + * + * @author Costin Leau + */ +public interface SortParameters { + + public enum Order { + ASC, DESC + } + + /** + * Utility class wrapping the 'LIMIT' setting. + * + * @author Costin Leau + */ + static class Range { + private final long start; + private final long count; + + public Range(long start, long count) { + this.start = start; + this.count = count; + } + + long start() { + return start; + } + + long count() { + return count; + } + } + Order getOrder(); + + Boolean isAlphabetic(); + + byte[] getByPattern(); + + byte[] getGetPattern(); + + byte[] getHashKey(); + + byte[] getStoreKey(); + + Range getLimit(); +}