19
19
import org .apache .commons .logging .LogFactory ;
20
20
import org .springframework .beans .factory .InitializingBean ;
21
21
import org .springframework .data .redis .connection .RedisConnectionFactory ;
22
+ import org .springframework .lang .NonNull ;
22
23
import org .springframework .lang .Nullable ;
23
24
import org .springframework .util .Assert ;
24
25
25
26
/**
26
27
* Base class for {@link RedisTemplate} defining common properties. Not intended to be used directly.
27
28
*
28
29
* @author Costin Leau
30
+ * @author John Blum
31
+ * @see org.springframework.beans.factory.InitializingBean
32
+ * TODO: Declare as abstract
29
33
*/
30
34
public class RedisAccessor implements InitializingBean {
31
35
@@ -34,45 +38,48 @@ public class RedisAccessor implements InitializingBean {
34
38
35
39
private @ Nullable RedisConnectionFactory connectionFactory ;
36
40
41
+ @ Override
37
42
public void afterPropertiesSet () {
38
- Assert . state ( getConnectionFactory () != null , "RedisConnectionFactory is required" );
43
+ getRequiredConnectionFactory ( );
39
44
}
40
45
41
46
/**
42
- * Returns the connectionFactory .
47
+ * Returns the factory configured to acquire connections and perform operations on the connected Redis instance .
43
48
*
44
- * @return Returns the connectionFactory. Can be {@literal null}
49
+ * @return the configured {@link RedisConnectionFactory}. Can be {@literal null}.
50
+ * @see RedisConnectionFactory
45
51
*/
46
52
@ Nullable
47
53
public RedisConnectionFactory getConnectionFactory () {
48
- return connectionFactory ;
54
+ return this . connectionFactory ;
49
55
}
50
56
51
57
/**
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.
54
60
*
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()
57
64
* @since 2.0
58
65
*/
66
+ @ NonNull
59
67
public RedisConnectionFactory getRequiredConnectionFactory () {
60
68
61
69
RedisConnectionFactory connectionFactory = getConnectionFactory ();
62
70
63
- if (connectionFactory == null ) {
64
- throw new IllegalStateException ("RedisConnectionFactory is required" );
65
- }
71
+ Assert .state (connectionFactory != null , "RedisConnectionFactory is required" );
66
72
67
73
return connectionFactory ;
68
74
}
69
75
70
76
/**
71
- * Sets the connection factory.
77
+ * Sets the factory used to acquire connections and perform operations on the connected Redis instance .
72
78
*
73
- * @param connectionFactory The connectionFactory to set.
79
+ * @param connectionFactory {@link RedisConnectionFactory} used to acquire connections.
80
+ * @see RedisConnectionFactory
74
81
*/
75
- public void setConnectionFactory (RedisConnectionFactory connectionFactory ) {
82
+ public void setConnectionFactory (@ Nullable RedisConnectionFactory connectionFactory ) {
76
83
this .connectionFactory = connectionFactory ;
77
84
}
78
85
}
0 commit comments