Skip to content

Commit e4c4c7e

Browse files
committed
Refactor RedisAccessor.
* Annotate API with missing Spring @nonnull and @nullable annotations. * Redefine afterPropertiesSet() in terms of getRequiredConnectionFactory(). * Edit Javadoc. Closes #2493
1 parent 3d5eb4b commit e4c4c7e

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

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

+21-14
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@
1919
import org.apache.commons.logging.LogFactory;
2020
import org.springframework.beans.factory.InitializingBean;
2121
import org.springframework.data.redis.connection.RedisConnectionFactory;
22+
import org.springframework.lang.NonNull;
2223
import org.springframework.lang.Nullable;
2324
import org.springframework.util.Assert;
2425

2526
/**
2627
* Base class for {@link RedisTemplate} defining common properties. Not intended to be used directly.
2728
*
2829
* @author Costin Leau
30+
* @author John Blum
31+
* @see org.springframework.beans.factory.InitializingBean
32+
* TODO: Declare as abstract
2933
*/
3034
public class RedisAccessor implements InitializingBean {
3135

@@ -34,45 +38,48 @@ public class RedisAccessor implements InitializingBean {
3438

3539
private @Nullable RedisConnectionFactory connectionFactory;
3640

41+
@Override
3742
public void afterPropertiesSet() {
38-
Assert.state(getConnectionFactory() != null, "RedisConnectionFactory is required");
43+
getRequiredConnectionFactory();
3944
}
4045

4146
/**
42-
* Returns the connectionFactory.
47+
* Returns the factory configured to acquire connections and perform operations on the connected Redis instance.
4348
*
44-
* @return Returns the connectionFactory. Can be {@literal null}
49+
* @return the configured {@link RedisConnectionFactory}. Can be {@literal null}.
50+
* @see RedisConnectionFactory
4551
*/
4652
@Nullable
4753
public RedisConnectionFactory getConnectionFactory() {
48-
return connectionFactory;
54+
return this.connectionFactory;
4955
}
5056

5157
/**
52-
* Returns the required {@link RedisConnectionFactory} or throws {@link IllegalStateException} if the connection
53-
* factory is not set.
58+
* Returns the required {@link RedisConnectionFactory}, throwing an {@link IllegalStateException}
59+
* if the {@link RedisConnectionFactory} is not set.
5460
*
55-
* @return the associated {@link RedisConnectionFactory}.
56-
* @throws IllegalStateException if the connection factory is not set.
61+
* @return the configured {@link RedisConnectionFactory}.
62+
* @throws IllegalStateException if the {@link RedisConnectionFactory} is not set.
63+
* @see #getConnectionFactory()
5764
* @since 2.0
5865
*/
66+
@NonNull
5967
public RedisConnectionFactory getRequiredConnectionFactory() {
6068

6169
RedisConnectionFactory connectionFactory = getConnectionFactory();
6270

63-
if (connectionFactory == null) {
64-
throw new IllegalStateException("RedisConnectionFactory is required");
65-
}
71+
Assert.state(connectionFactory != null, "RedisConnectionFactory is required");
6672

6773
return connectionFactory;
6874
}
6975

7076
/**
71-
* Sets the connection factory.
77+
* Sets the factory used to acquire connections and perform operations on the connected Redis instance.
7278
*
73-
* @param connectionFactory The connectionFactory to set.
79+
* @param connectionFactory {@link RedisConnectionFactory} used to acquire connections.
80+
* @see RedisConnectionFactory
7481
*/
75-
public void setConnectionFactory(RedisConnectionFactory connectionFactory) {
82+
public void setConnectionFactory(@Nullable RedisConnectionFactory connectionFactory) {
7683
this.connectionFactory = connectionFactory;
7784
}
7885
}

0 commit comments

Comments
 (0)