DATAREDIS-1179 - Polishing.

Reorder methods. Make MappingRedisConverter(RedisMappingContext) public. Tweak docs wording.

Original pull request: #548.
This commit is contained in:
Mark Paluch
2020-07-15 10:41:54 +02:00
parent 6c633947c1
commit f401be7e7a
4 changed files with 35 additions and 31 deletions

View File

@@ -296,34 +296,35 @@ redisTemplate()
[NOTE]
====
A `StreamMessageListenerContainer` may not be aware of any `@TypeAlias` used on domain types as those need to be resolved via a `MappingContext`. So please make sure to pre initialize the `RedisMappingContext` with the `initialEntitySet`.
A `StreamMessageListenerContainer` may not be aware of any `@TypeAlias` used on domain types as those need to be resolved through a `MappingContext`.
Make sure to initialize `RedisMappingContext` with a `initialEntitySet`.
[source,java]
----
@Bean
RedisMappingContext redisMappingContext() {
RedisMappingContext ctx = new RedisMappingContext();
ctx.setInitialEntitySet(Collections.singleton(Person.class));
return ctx;
RedisMappingContext ctx = new RedisMappingContext();
ctx.setInitialEntitySet(Collections.singleton(Person.class));
return ctx;
}
@Bean
RedisConverter redisConverter(RedisMappingContext mappingContext) {
return new MappingRedisConverter(mappingContext, null, null);
return new MappingRedisConverter(mappingContext);
}
@Bean
ObjectHashMapper hashMapper(RedisConverter converter) {
return new ObjectHashMapper(converter);
return new ObjectHashMapper(converter);
}
@Bean
StreamMessageListenerContainer streamMessageListenerContainer(RedisConnectionFactory connectionFactory, ObjectHashMapper hashMapper) {
StreamMessageListenerContainerOptions<String, ObjectRecord<String, Object>> options = StreamMessageListenerContainerOptions.builder()
.objectMapper(hashMapper)
.build();
StreamMessageListenerContainerOptions<String, ObjectRecord<String, Object>> options = StreamMessageListenerContainerOptions.builder()
.objectMapper(hashMapper)
.build();
return StreamMessageListenerContainer.create(connectionFactory, options);
return StreamMessageListenerContainer.create(connectionFactory, options);
}
----
====

View File

@@ -124,8 +124,9 @@ public class MappingRedisConverter implements RedisConverter, InitializingBean {
* Creates new {@link MappingRedisConverter}.
*
* @param context can be {@literal null}.
* @since 2.3.2
*/
MappingRedisConverter(RedisMappingContext context) {
public MappingRedisConverter(RedisMappingContext context) {
this(context, null, null, null);
}

View File

@@ -80,6 +80,19 @@ public class ObjectHashMapper implements HashMapper<Object, byte[], byte[]> {
this(new RedisCustomConversions());
}
/**
* Creates a new {@link ObjectHashMapper} using the given {@link RedisConverter} for conversion.
*
* @param converter must not be {@literal null}.
* @throws IllegalArgumentException if the given {@literal converter} is {@literal null}.
* @since 2.3.2
*/
public ObjectHashMapper(RedisConverter converter) {
Assert.notNull(converter, "Converter must not be null!");
this.converter = converter;
}
/**
* Creates new {@link ObjectHashMapper}.
*
@@ -107,19 +120,6 @@ public class ObjectHashMapper implements HashMapper<Object, byte[], byte[]> {
converter = mappingConverter;
}
/**
* Creates a new {@link ObjectHashMapper} using the given {@link RedisConverter} for conversion.
*
* @param converter must not be {@literal null}.
* @throws IllegalArgumentException if the given {@literal converter} is {@literal null}.
* @since 2.4
*/
public ObjectHashMapper(RedisConverter converter) {
Assert.notNull(converter, "Converter must not be null!");
this.converter = converter;
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.hash.HashMapper#toHash(java.lang.Object)

View File

@@ -29,6 +29,8 @@ import org.springframework.data.redis.core.mapping.RedisMappingContext;
import org.springframework.data.redis.hash.ObjectHashMapper;
/**
* Unit tests for {@link ObjectHashMapper}.
*
* @author Christoph Strobl
* @author Mark Paluch
*/