Skip to content

Commit 4c8f167

Browse files
committed
DATAREDIS-533 - Polishing.
Remove empty lines after last inner class. Extract duplicate code in variable. Fix spelling. Update Reference Documentation. Remove merge leftovers. Original pull request: spring-projects#215.
1 parent 07d0b82 commit 4c8f167

File tree

10 files changed

+16
-33
lines changed

10 files changed

+16
-33
lines changed

src/main/asciidoc/new-features.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ New and noteworthy in the latest releases.
77
== New in Spring Data Redis 1.8
88

99
* Support for Redis http://redis.io/commands#geo[GEO] commands.
10+
* Support for Geospatial Indexes using Spring Data Repository abstractions (see <<redis.repositories.indexes.geospatial>>).
1011

1112
[[new-in-1.7.0]]
1213
== New in Spring Data Redis 1.7

src/main/asciidoc/reference/redis-repositories.adoc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ public class ApplicationConfig {
310310
== Secondary Indexes
311311
http://redis.io/topics/indexes[Secondary indexes] are used to enable lookup operations based on native Redis structures. Values are written to the according indexes on every save and are removed when objects are deleted or <<redis.repositories.expirations,expire>>.
312312

313+
[[redis.repositories.indexes.simple]]
313314
=== Simple Property Index
314315

315316
Given the sample `Person` entity we can create an index for _firstname_ by annotating the property with `@Indexed`.
@@ -421,9 +422,10 @@ public class ApplicationConfig {
421422
----
422423
====
423424

425+
[[redis.repositories.indexes.geospatial]]
424426
=== Geospatial Index
425427

426-
Assume the `Address` type contains a property `location` of type `Point` that holds the geo coordinates of the particular address. By annotating the property with `@GeoIndexed` those values will be added using Redis `GEO` commands.
428+
Assume the `Address` type contains a property `location` of type `Point` that holds the geo coordinates of the particular address. By annotating the property with `@GeoIndexed` those values will be added using Redis `GEO` commands.
427429

428430
====
429431
[source,java]
@@ -456,13 +458,13 @@ repository.save(rand); <3
456458
457459
repository.findByAddressLocationNear(new Point(15D, 37D), new Distance(200)); <4>
458460
----
459-
<1> finder declaration on nested property using Point and Distance.
460-
<2> finder declaration on nested property using Circle to search within.
461+
<1> Query method declaration on nested property using Point and Distance.
462+
<2> Query method declaration on nested property using Circle to search within.
461463
<3> `GEOADD persons:address:location 13.361389 38.115556 e2c7dcee-b8cd-4424-883e-736ce564363e`
462464
<4> `GEORADIUS persons:address:location 15.0 37.0 200.0 km`
463465
====
464466

465-
In the above example the lon/lat values are stored using `GEOADD` using the objects `id` as the members name. The finder methods allow usage of `Circle` or `Point, Distance` combinations for querying those values.
467+
In the above example the lon/lat values are stored using `GEOADD` using the objects `id` as the member's name. The finder methods allow usage of `Circle` or `Point, Distance` combinations for querying those values.
466468

467469
NOTE: It is **not** possible to combine `near`/`within` with other criteria.
468470

src/main/java/org/springframework/data/redis/core/IndexWriter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ protected void addKeyToIndex(byte[] key, IndexedData indexedData) {
206206
return;
207207
}
208208

209-
else if (indexedData instanceof SimpleIndexedPropertyValue) {
209+
if (indexedData instanceof SimpleIndexedPropertyValue) {
210210

211211
Object value = ((SimpleIndexedPropertyValue) indexedData).getValue();
212212

@@ -234,9 +234,7 @@ else if (indexedData instanceof SimpleIndexedPropertyValue) {
234234

235235
// keep track of indexes used for the object
236236
connection.sAdd(ByteUtils.concatAll(toBytes(indexedData.getKeyspace() + ":"), key, toBytes(":idx")), indexKey);
237-
}
238-
239-
else {
237+
} else {
240238
throw new IllegalArgumentException(
241239
String.format("Cannot write index data for unknown index type %s", indexedData.getClass()));
242240
}

src/main/java/org/springframework/data/redis/core/RedisKeyValueAdapter.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,9 @@ private RedisUpdateObject fetchDeletePathsFromHashAndUpdateIndex(RedisUpdateObje
516516
? ByteUtils.concatAll(toBytes(redisUpdateObject.keyspace), toBytes((":" + path)), toBytes(":"), value) : null;
517517

518518
if (connection.exists(existingValueIndexKey)) {
519-
520519
redisUpdateObject.addIndexToUpdate(new RedisUpdateObject.Index(existingValueIndexKey, DataType.SET));
521520
}
521+
522522
return redisUpdateObject;
523523
}
524524

@@ -545,13 +545,11 @@ private RedisUpdateObject fetchDeletePathsFromHashAndUpdateIndex(RedisUpdateObje
545545
}
546546

547547
String pathToUse = GeoIndexedPropertyValue.geoIndexName(path);
548-
if (connection.zRank(ByteUtils.concatAll(toBytes(redisUpdateObject.keyspace), toBytes(":"), toBytes(pathToUse)),
549-
toBytes(redisUpdateObject.targetId)) != null) {
548+
byte[] existingGeoIndexKey = ByteUtils.concatAll(toBytes(redisUpdateObject.keyspace), toBytes(":"),
549+
toBytes(pathToUse));
550550

551-
redisUpdateObject
552-
.addIndexToUpdate(new org.springframework.data.redis.core.RedisKeyValueAdapter.RedisUpdateObject.Index(
553-
ByteUtils.concatAll(toBytes(redisUpdateObject.keyspace), toBytes(":"), toBytes(pathToUse)),
554-
DataType.ZSET));
551+
if (connection.zRank(existingGeoIndexKey, toBytes(redisUpdateObject.targetId)) != null) {
552+
redisUpdateObject.addIndexToUpdate(new RedisUpdateObject.Index(existingGeoIndexKey, DataType.ZSET));
555553
}
556554

557555
return redisUpdateObject;

src/main/java/org/springframework/data/redis/core/RedisQueryEngine.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,11 @@ public <T> Collection<T> execute(final RedisOperationChain criteria, final Compa
9090
@Override
9191
public Map<byte[], Map<byte[], byte[]>> doInRedis(RedisConnection connection) throws DataAccessException {
9292

93-
String key = keyspace + ":";
94-
byte[][] keys = new byte[criteria.getSismember().size()][];
95-
int i = 0;
96-
for (Object o : criteria.getSismember()) {
97-
keys[i] = getAdapter().getConverter().getConversionService().convert(key + o, byte[].class);
98-
i++;
99-
}
100-
10193
List<byte[]> allKeys = new ArrayList<byte[]>();
10294
if (!criteria.getSismember().isEmpty()) {
10395
allKeys.addAll(connection.sInter(keys(keyspace + ":", criteria.getSismember())));
10496
}
97+
10598
if (!criteria.getOrSismember().isEmpty()) {
10699
allKeys.addAll(connection.sUnion(keys(keyspace + ":", criteria.getOrSismember())));
107100
}
@@ -229,5 +222,4 @@ public RedisOperationChain resolve(KeyValueQuery<?> query) {
229222
return (RedisOperationChain) query.getCritieria();
230223
}
231224
}
232-
233225
}

src/main/java/org/springframework/data/redis/core/convert/IndexedDataFactoryProvider.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,4 @@ public GeoIndexedPropertyValue createIndexedDataFor(Object value) {
8181
(Point) indexDefinition.valueTransformer().convert(value));
8282
}
8383
}
84-
8584
}

src/main/java/org/springframework/data/redis/repository/query/RedisOperationChain.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.springframework.util.ObjectUtils;
2828

2929
/**
30-
* Simple set of operations requried to run queries against Redis.
30+
* Simple set of operations required to run queries against Redis.
3131
*
3232
* @author Christoph Strobl
3333
* @since 1.7
@@ -36,7 +36,6 @@ public class RedisOperationChain {
3636

3737
private Set<PathAndValue> sismember = new LinkedHashSet<PathAndValue>();
3838
private Set<PathAndValue> orSismember = new LinkedHashSet<PathAndValue>();
39-
4039
private NearPath near;
4140

4241
public void sismember(String path, Object value) {
@@ -163,5 +162,4 @@ public Distance getDistance() {
163162
return (Distance) it.next();
164163
}
165164
}
166-
167165
}

src/main/java/org/springframework/data/redis/repository/query/RedisQueryCreator.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public class RedisQueryCreator extends AbstractQueryCreator<KeyValueQuery<RedisO
4141

4242
public RedisQueryCreator(PartTree tree, ParameterAccessor parameters) {
4343
super(tree, parameters);
44-
4544
}
4645

4746
/*
@@ -68,7 +67,6 @@ private RedisOperationChain from(Part part, Iterator<Object> iterator, RedisOper
6867
}
6968

7069
return sink;
71-
7270
}
7371

7472
/*
@@ -150,5 +148,4 @@ private NearPath getNearPath(Part part, Iterator<Object> iterator) {
150148

151149
return new NearPath(part.getProperty().toDotPath(), point, distance);
152150
}
153-
154151
}

src/test/java/org/springframework/data/redis/core/convert/PathIndexResolverUnitTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,5 +637,4 @@ static class GeoIndexedOnPoint {
637637
static class GeoIndexedOnArray {
638638
@GeoIndexed double[] location;
639639
}
640-
641640
}

src/test/java/org/springframework/data/redis/repository/RedisRepositoryIntegrationTestBase.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,5 +584,4 @@ public boolean equals(Object obj) {
584584
return true;
585585
}
586586
}
587-
588587
}

0 commit comments

Comments
 (0)