Skip to content

Commit 88af4b3

Browse files
DATAREDIS-425 - Update JavaDoc.
1 parent aea2e07 commit 88af4b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+712
-168
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@
2626
import org.springframework.util.CollectionUtils;
2727

2828
/**
29+
* {@link IndexWriter} takes care of writing <a href="http://redis.io/topics/indexes">secondary index</a> structures to
30+
* Redis. Depending on the type of {@link IndexedData} it uses eg. Sets with specific names to add actually referenced
31+
* keys to. While doing so {@link IndexWriter} also keeps track of all indexes associated with the root types key, which
32+
* allows to remove the root key from all indexes in case of deletion.
33+
*
2934
* @author Christoph Strobl
35+
* @since 1.7
3036
*/
3137
class IndexWriter {
3238

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
import org.springframework.data.keyvalue.annotation.KeySpace;
2727

2828
/**
29+
* {@link RedisHash} marks Objects as aggregate roots to be stored in a Redis hash.
30+
*
2931
* @author Christoph Strobl
32+
* @since 1.7
3033
*/
3134
@Persistent
3235
@Documented
@@ -36,13 +39,19 @@
3639
public @interface RedisHash {
3740

3841
/**
39-
* The key space aka prefix to distinguish between domain types.
42+
* The prefix to distinguish between domain types.
4043
*
4144
* @return
45+
* @see KeySpace
4246
*/
4347
@KeySpace
4448
String value() default "";
4549

50+
/**
51+
* Time before expire in seconds. Superseded by {@link TimeToLive}.
52+
*
53+
* @return positive number when expiration should be applied.
54+
*/
4655
long timeToLive() default -1L;
4756

4857
}

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,79 @@
1717

1818
import java.nio.charset.Charset;
1919

20+
import org.springframework.context.ApplicationEvent;
2021
import org.springframework.data.redis.util.ByteUtils;
2122

2223
/**
24+
* {@link RedisKeyExpiredEvent} is Redis specific {@link ApplicationEvent} published when a specific key in Redis
25+
* expires. It might but must not hold the expired value itself next to the key.
26+
*
2327
* @author Christoph Strobl
28+
* @since 1.7
2429
*/
25-
public class RedisKeyExpiredEvent extends RedisKeyspaceEvent {
30+
public class RedisKeyExpiredEvent<T> extends RedisKeyspaceEvent {
2631

2732
private final byte[][] args;
2833
private final Object value;
2934

35+
/**
36+
* Creates new {@link RedisKeyExpiredEvent}.
37+
*
38+
* @param key
39+
*/
3040
public RedisKeyExpiredEvent(byte[] key) {
3141
this(key, null);
3242
}
3343

44+
/**
45+
* Creates new {@link RedisKeyExpiredEvent}
46+
*
47+
* @param key
48+
* @param value
49+
*/
3450
public RedisKeyExpiredEvent(byte[] key, Object value) {
3551
super(key);
3652

3753
args = ByteUtils.split(key, ':');
3854
this.value = value;
3955
}
4056

57+
/**
58+
* Gets the keyspace in which the expiration occured.
59+
*
60+
* @return {@literal null} if it could not be determined.
61+
*/
4162
public String getKeyspace() {
4263

43-
if (args.length == 2) {
64+
if (args.length >= 2) {
4465
return new String(args[0], Charset.forName("UTF-8"));
4566
}
4667

4768
return null;
4869
}
4970

71+
/**
72+
* Get the expired objects id;
73+
*
74+
* @return
75+
*/
5076
public byte[] getId() {
5177
return args.length == 2 ? args[1] : args[0];
5278
}
5379

80+
/**
81+
* Get the expired Object
82+
*
83+
* @return {@literal null} if not present.
84+
*/
5485
public Object getValue() {
5586
return value;
5687
}
5788

89+
/*
90+
* (non-Javadoc)
91+
* @see java.util.EventObject#toString()
92+
*/
5893
@Override
5994
public String toString() {
6095
return "RedisKeyExpiredEvent [keyspace=" + getKeyspace() + ", id=" + getId() + "]";

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

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@
3636
import org.springframework.data.keyvalue.core.KeyValueAdapter;
3737
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty;
3838
import org.springframework.data.redis.connection.Message;
39+
import org.springframework.data.redis.connection.MessageListener;
3940
import org.springframework.data.redis.connection.RedisConnection;
4041
import org.springframework.data.redis.connection.RedisConnectionFactory;
4142
import org.springframework.data.redis.core.convert.CustomConversions;
4243
import org.springframework.data.redis.core.convert.IndexResolverImpl;
44+
import org.springframework.data.redis.core.convert.KeyspaceConfiguration;
4345
import org.springframework.data.redis.core.convert.MappingRedisConverter;
4446
import org.springframework.data.redis.core.convert.RedisConverter;
4547
import org.springframework.data.redis.core.convert.RedisData;
@@ -52,9 +54,37 @@
5254
import org.springframework.util.Assert;
5355

5456
/**
55-
* Redis specific {@link KeyValueAdapter} implementation. Uses binary codec to read/write data from/to Redis.
57+
* Redis specific {@link KeyValueAdapter} implementation. Uses binary codec to read/write data from/to Redis. Objects
58+
* are stored in a Redis Hash using the value of {@link RedisHash}, the {@link KeyspaceConfiguration} or just
59+
* {@link Class#getName()} as a prefix. <br />
60+
* <strong>Example</strong>
61+
*
62+
* <pre>
63+
* <code>
64+
* &#64;RedisHash("persons")
65+
* class Person {
66+
* &#64;Id String id;
67+
* String name;
68+
* }
69+
*
70+
*
71+
* prefix ID
72+
* | |
73+
* V V
74+
* hgetall persons:5d67b7e1-8640-4475-beeb-c666fab4c0e5
75+
* 1) id
76+
* 2) 5d67b7e1-8640-4475-beeb-c666fab4c0e5
77+
* 3) name
78+
* 4) Rand al'Thor
79+
* </code>
80+
* </pre>
81+
*
82+
* <br />
83+
* The {@link KeyValueAdapter} is <strong>not</strong> intended to store simple types such as {@link String} values.
84+
* Please use {@link RedisTemplate} for this purpose.
5685
*
5786
* @author Christoph Strobl
87+
* @since 1.7
5888
*/
5989
public class RedisKeyValueAdapter extends AbstractKeyValueAdapter implements ApplicationContextAware,
6090
ApplicationListener<RedisKeyspaceEvent> {
@@ -113,6 +143,8 @@ public RedisKeyValueAdapter(RedisOperations<?, ?> redisOps, RedisMappingContext
113143
}
114144

115145
/**
146+
* Creates new {@link RedisKeyValueAdapter} with specific {@link RedisConverter}.
147+
*
116148
* @param redisOps must not be {@literal null}.
117149
* @param mappingContext must not be {@literal null}.
118150
*/
@@ -461,13 +493,25 @@ private void initKeyExpirationListener() {
461493
}
462494

463495
/**
496+
* {@link MessageListener} implementation used to capture Redis keypspace notifications. Tries to read a previously
497+
* created phantom key {@code keyspace:id:phantom} to provide the expired object as part of the published
498+
* {@link RedisKeyExpiredEvent}.
499+
*
464500
* @author Christoph Strobl
501+
* @since 1.7
465502
*/
466503
static class MappingExpirationListener extends KeyExpirationEventMessageListener {
467504

468505
private final RedisOperations<?, ?> ops;
469506
private final RedisConverter converter;
470507

508+
/**
509+
* Creates new {@link MappingExpirationListener}.
510+
*
511+
* @param listenerContainer
512+
* @param ops
513+
* @param converter
514+
*/
471515
public MappingExpirationListener(RedisMessageListenerContainer listenerContainer, RedisOperations<?, ?> ops,
472516
RedisConverter converter) {
473517

@@ -476,6 +520,10 @@ public MappingExpirationListener(RedisMessageListenerContainer listenerContainer
476520
this.converter = converter;
477521
}
478522

523+
/*
524+
* (non-Javadoc)
525+
* @see org.springframework.data.redis.listener.KeyspaceEventMessageListener#onMessage(org.springframework.data.redis.connection.Message, byte[])
526+
*/
479527
@Override
480528
public void onMessage(Message message, byte[] pattern) {
481529

@@ -525,14 +573,13 @@ private boolean isKeyExpirationMessage(Message message) {
525573
* {@link ReferenceResolver} using {@link RedisKeyValueAdapter} to read and convert referenced entities.
526574
*
527575
* @author Christoph Strobl
576+
* @since 1.7
528577
*/
529578
static class ReferenceResolverImpl implements ReferenceResolver {
530579

531580
private RedisKeyValueAdapter adapter;
532581

533-
ReferenceResolverImpl() {
534-
535-
}
582+
ReferenceResolverImpl() {}
536583

537584
/**
538585
* @param adapter must not be {@literal null}.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* Redis specific implementation of {@link KeyValueTemplate}.
2525
*
2626
* @author Christoph Strobl
27+
* @since 1.7
2728
*/
2829
public class RedisKeyValueTemplate extends KeyValueTemplate {
2930

@@ -51,9 +52,14 @@ public RedisMappingContext getMappingContext() {
5152
*
5253
* @author Christoph Strobl
5354
* @param <T>
55+
* @since 1.7
5456
*/
5557
public static abstract class RedisKeyValueCallback<T> implements KeyValueCallback<T> {
5658

59+
/*
60+
* (non-Javadoc)
61+
* @see org.springframework.data.keyvalue.core.KeyValueCallback#doInKeyValue(org.springframework.data.keyvalue.core.KeyValueAdapter)
62+
*/
5763
@Override
5864
public T doInKeyValue(KeyValueAdapter adapter) {
5965
return doInRedis((RedisKeyValueAdapter) adapter);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,26 @@
1818
import org.springframework.context.ApplicationEvent;
1919

2020
/**
21+
* Redis specific {@link ApplicationEvent} published when a key expires in Redis.
22+
*
2123
* @author Christoph Strobl
24+
* @since 1.7
2225
*/
2326
public class RedisKeyspaceEvent extends ApplicationEvent {
2427

28+
/**
29+
* Creates new {@link RedisKeyspaceEvent}.
30+
*
31+
* @param key The key that expired. Must not be {@literal null}.
32+
*/
2533
public RedisKeyspaceEvent(byte[] key) {
2634
super(key);
2735
}
2836

37+
/*
38+
* (non-Javadoc)
39+
* @see java.util.EventObject#getSource()
40+
*/
2941
public byte[] getSource() {
3042
return (byte[]) super.getSource();
3143
}

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

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.io.Serializable;
1919
import java.util.ArrayList;
20-
import java.util.Arrays;
2120
import java.util.Collection;
2221
import java.util.Comparator;
2322
import java.util.LinkedHashMap;
@@ -33,23 +32,39 @@
3332
import org.springframework.data.redis.connection.RedisConnection;
3433
import org.springframework.data.redis.core.convert.RedisData;
3534
import org.springframework.data.redis.repository.query.RedisOperationChain;
35+
import org.springframework.data.redis.util.ByteUtils;
3636

3737
/**
3838
* Redis specific {@link QueryEngine} implementation.
3939
*
4040
* @author Christoph Strobl
41+
* @since 1.7
4142
*/
42-
public class RedisQueryEngine extends QueryEngine<RedisKeyValueAdapter, RedisOperationChain, Comparator<?>> {
43+
class RedisQueryEngine extends QueryEngine<RedisKeyValueAdapter, RedisOperationChain, Comparator<?>> {
4344

45+
/**
46+
* Creates new {@link RedisQueryEngine} with defaults.
47+
*/
4448
public RedisQueryEngine() {
4549
this(new RedisCriteriaAccessor(), null);
4650
}
4751

52+
/**
53+
* Creates new {@link RedisQueryEngine}.
54+
*
55+
* @param criteriaAccessor
56+
* @param sortAccessor
57+
* @see QueryEngine#QueryEngine(CriteriaAccessor, SortAccessor)
58+
*/
4859
public RedisQueryEngine(CriteriaAccessor<RedisOperationChain> criteriaAccessor,
4960
SortAccessor<Comparator<?>> sortAccessor) {
5061
super(criteriaAccessor, sortAccessor);
5162
}
5263

64+
/*
65+
* (non-Javadoc)
66+
* @see org.springframework.data.keyvalue.core.QueryEngine#execute(java.lang.Object, java.lang.Object, int, int, java.io.Serializable, java.lang.Class)
67+
*/
5368
public <T> Collection<T> execute(final RedisOperationChain criteria, final Comparator<?> sort, int offset, int rows,
5469
final Serializable keyspace, Class<T> type) {
5570

@@ -74,9 +89,7 @@ public Map<byte[], Map<byte[], byte[]>> doInRedis(RedisConnection connection) th
7489

7590
for (byte[] id : allKeys) {
7691

77-
byte[] singleKey = Arrays.copyOf(keyspaceBin, id.length + keyspaceBin.length);
78-
System.arraycopy(id, 0, singleKey, keyspaceBin.length, id.length);
79-
92+
byte[] singleKey = ByteUtils.concat(keyspaceBin, id);
8093
rawData.put(id, connection.hGetAll(singleKey));
8194
}
8295

@@ -103,12 +116,20 @@ public Map<byte[], Map<byte[], byte[]>> doInRedis(RedisConnection connection) th
103116
return result;
104117
}
105118

119+
/*
120+
* (non-Javadoc)
121+
* @see org.springframework.data.keyvalue.core.QueryEngine#execute(java.lang.Object, java.lang.Object, int, int, java.io.Serializable)
122+
*/
106123
@Override
107124
public Collection<?> execute(final RedisOperationChain criteria, Comparator<?> sort, int offset, int rows,
108125
final Serializable keyspace) {
109126
return execute(criteria, sort, offset, rows, keyspace, Object.class);
110127
}
111128

129+
/*
130+
* (non-Javadoc)
131+
* @see org.springframework.data.keyvalue.core.QueryEngine#count(java.lang.Object, java.io.Serializable)
132+
*/
112133
@Override
113134
public long count(final RedisOperationChain criteria, final Serializable keyspace) {
114135

@@ -129,6 +150,10 @@ public Long doInRedis(RedisConnection connection) throws DataAccessException {
129150
});
130151
}
131152

153+
/**
154+
* @author Christoph Strobl
155+
* @since 1.7
156+
*/
132157
static class RedisCriteriaAccessor implements CriteriaAccessor<RedisOperationChain> {
133158

134159
@Override

0 commit comments

Comments
 (0)