15
15
*/
16
16
package io .awspring .cloud .autoconfigure .dynamodb ;
17
17
18
+ import java .io .IOException ;
19
+ import java .util .Optional ;
20
+
18
21
import io .awspring .cloud .autoconfigure .core .AwsClientBuilderConfigurer ;
19
22
import io .awspring .cloud .autoconfigure .core .AwsClientCustomizer ;
20
23
import io .awspring .cloud .autoconfigure .core .CredentialsProviderAutoConfiguration ;
21
24
import io .awspring .cloud .autoconfigure .core .RegionProviderAutoConfiguration ;
22
- import io .awspring .cloud .dynamodb .*;
23
- import java .io .IOException ;
24
- import java .util .Optional ;
25
+ import io .awspring .cloud .dynamodb .DefaultDynamoDbTableNameResolver ;
26
+ import io .awspring .cloud .dynamodb .DefaultDynamoDbTableSchemaResolver ;
27
+ import io .awspring .cloud .dynamodb .DynamoDbOperations ;
28
+ import io .awspring .cloud .dynamodb .DynamoDbTableNameResolver ;
29
+ import io .awspring .cloud .dynamodb .DynamoDbTableSchemaResolver ;
30
+ import io .awspring .cloud .dynamodb .DynamoDbTemplate ;
25
31
import org .springframework .beans .factory .ObjectProvider ;
26
32
import org .springframework .boot .autoconfigure .AutoConfiguration ;
27
33
import org .springframework .boot .autoconfigure .AutoConfigureAfter ;
@@ -64,34 +70,40 @@ public class DynamoDbAutoConfiguration {
64
70
@ ConditionalOnClass (name = "software.amazon.dax.ClusterDaxClient" )
65
71
static class DaxDynamoDbClient {
66
72
67
- @ ConditionalOnMissingBean
68
- @ Bean
69
- public DynamoDbClient daxDynamoDbClient (DynamoDbProperties properties ,
70
- AwsCredentialsProvider credentialsProvider ,
71
- AwsRegionProvider regionProvider ) throws IOException {
72
- DaxProperties daxProperties = properties .getDax ();
73
-
73
+ private software .amazon .dax .Configuration .Builder toAwsDaxConfiguration (DaxProperties daxProperties ) {
74
74
PropertyMapper propertyMapper = PropertyMapper .get ();
75
75
software .amazon .dax .Configuration .Builder configuration = software .amazon .dax .Configuration .builder ();
76
76
propertyMapper .from (daxProperties .getIdleTimeoutMillis ()).whenNonNull ()
77
- .to (configuration ::idleTimeoutMillis );
77
+ .to (configuration ::idleTimeoutMillis );
78
78
propertyMapper .from (daxProperties .getConnectionTtlMillis ()).whenNonNull ()
79
- .to (configuration ::connectionTtlMillis );
79
+ .to (configuration ::connectionTtlMillis );
80
80
propertyMapper .from (daxProperties .getConnectTimeoutMillis ()).whenNonNull ()
81
- .to (configuration ::connectTimeoutMillis );
81
+ .to (configuration ::connectTimeoutMillis );
82
82
propertyMapper .from (daxProperties .getRequestTimeoutMillis ()).whenNonNull ()
83
- .to (configuration ::requestTimeoutMillis );
83
+ .to (configuration ::requestTimeoutMillis );
84
84
propertyMapper .from (daxProperties .getWriteRetries ()).whenNonNull ().to (configuration ::writeRetries );
85
85
propertyMapper .from (daxProperties .getReadRetries ()).whenNonNull ().to (configuration ::readRetries );
86
86
propertyMapper .from (daxProperties .getClusterUpdateIntervalMillis ()).whenNonNull ()
87
- .to (configuration ::clusterUpdateIntervalMillis );
87
+ .to (configuration ::clusterUpdateIntervalMillis );
88
88
propertyMapper .from (daxProperties .getEndpointRefreshTimeoutMillis ()).whenNonNull ()
89
- .to (configuration ::endpointRefreshTimeoutMillis );
89
+ .to (configuration ::endpointRefreshTimeoutMillis );
90
90
propertyMapper .from (daxProperties .getMaxConcurrency ()).whenNonNull ().to (configuration ::maxConcurrency );
91
91
propertyMapper .from (daxProperties .getMaxPendingConnectionAcquires ()).whenNonNull ()
92
- .to (configuration ::maxPendingConnectionAcquires );
92
+ .to (configuration ::maxPendingConnectionAcquires );
93
93
propertyMapper .from (daxProperties .getSkipHostNameVerification ()).whenNonNull ()
94
- .to (configuration ::skipHostNameVerification );
94
+ .to (configuration ::skipHostNameVerification );
95
+
96
+ return configuration ;
97
+ }
98
+
99
+ @ ConditionalOnMissingBean
100
+ @ Bean
101
+ public DynamoDbClient daxDynamoDbClient (DynamoDbProperties properties ,
102
+ AwsCredentialsProvider credentialsProvider ,
103
+ AwsRegionProvider regionProvider ) throws IOException {
104
+ DaxProperties daxProperties = properties .getDax ();
105
+
106
+ software .amazon .dax .Configuration .Builder configuration = toAwsDaxConfiguration (daxProperties );
95
107
96
108
configuration .region (AwsClientBuilderConfigurer .resolveRegion (properties , regionProvider ))
97
109
.credentialsProvider (credentialsProvider ).url (properties .getDax ().getUrl ());
@@ -105,27 +117,7 @@ public DynamoDbAsyncClient daxDynamoDbAsyncClient(DynamoDbProperties properties,
105
117
AwsRegionProvider regionProvider ) throws IOException {
106
118
DaxProperties daxProperties = properties .getDax ();
107
119
108
- PropertyMapper propertyMapper = PropertyMapper .get ();
109
- software .amazon .dax .Configuration .Builder configuration = software .amazon .dax .Configuration .builder ();
110
- propertyMapper .from (daxProperties .getIdleTimeoutMillis ()).whenNonNull ()
111
- .to (configuration ::idleTimeoutMillis );
112
- propertyMapper .from (daxProperties .getConnectionTtlMillis ()).whenNonNull ()
113
- .to (configuration ::connectionTtlMillis );
114
- propertyMapper .from (daxProperties .getConnectTimeoutMillis ()).whenNonNull ()
115
- .to (configuration ::connectTimeoutMillis );
116
- propertyMapper .from (daxProperties .getRequestTimeoutMillis ()).whenNonNull ()
117
- .to (configuration ::requestTimeoutMillis );
118
- propertyMapper .from (daxProperties .getWriteRetries ()).whenNonNull ().to (configuration ::writeRetries );
119
- propertyMapper .from (daxProperties .getReadRetries ()).whenNonNull ().to (configuration ::readRetries );
120
- propertyMapper .from (daxProperties .getClusterUpdateIntervalMillis ()).whenNonNull ()
121
- .to (configuration ::clusterUpdateIntervalMillis );
122
- propertyMapper .from (daxProperties .getEndpointRefreshTimeoutMillis ()).whenNonNull ()
123
- .to (configuration ::endpointRefreshTimeoutMillis );
124
- propertyMapper .from (daxProperties .getMaxConcurrency ()).whenNonNull ().to (configuration ::maxConcurrency );
125
- propertyMapper .from (daxProperties .getMaxPendingConnectionAcquires ()).whenNonNull ()
126
- .to (configuration ::maxPendingConnectionAcquires );
127
- propertyMapper .from (daxProperties .getSkipHostNameVerification ()).whenNonNull ()
128
- .to (configuration ::skipHostNameVerification );
120
+ software .amazon .dax .Configuration .Builder configuration = toAwsDaxConfiguration (daxProperties );
129
121
130
122
configuration .region (AwsClientBuilderConfigurer .resolveRegion (properties , regionProvider ))
131
123
.credentialsProvider (credentialsProvider ).url (properties .getDax ().getUrl ());
@@ -144,7 +136,6 @@ public DynamoDbClient standardDynamoDbClient(AwsClientBuilderConfigurer awsClien
144
136
return awsClientBuilderConfigurer
145
137
.configure (DynamoDbClient .builder (), properties , configurer .getIfAvailable ()).build ();
146
138
}
147
-
148
139
}
149
140
150
141
@ Conditional (MissingDaxUrlCondition .class )
@@ -162,32 +153,39 @@ public DynamoDbAsyncClient standardDynamoDbAsyncClient(AwsClientBuilderConfigure
162
153
163
154
}
164
155
165
- @ ConditionalOnMissingBean
166
- @ ConditionalOnClass (DynamoDbEnhancedClient .class )
167
- @ Bean
168
- public DynamoDbEnhancedClient dynamoDbEnhancedClient (DynamoDbClient dynamoDbClient ) {
169
- return DynamoDbEnhancedClient .builder ().dynamoDbClient (dynamoDbClient ).build ();
170
- }
156
+ @ ConditionalOnClass (name = "software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient" )
157
+ @ Configuration (proxyBeanMethods = false )
158
+ static class DynamoDbEnhancedClientConfiguration {
159
+ @ ConditionalOnMissingBean
160
+ @ ConditionalOnClass (DynamoDbEnhancedClient .class )
161
+ @ Bean
162
+ public DynamoDbEnhancedClient dynamoDbEnhancedClient (DynamoDbClient dynamoDbClient ) {
163
+ return DynamoDbEnhancedClient .builder ().dynamoDbClient (dynamoDbClient ).build ();
164
+ }
171
165
172
- @ ConditionalOnMissingBean
173
- @ ConditionalOnClass (DynamoDbEnhancedAsyncClient .class )
174
- @ Bean
175
- public DynamoDbEnhancedAsyncClient dynamoDbEnhancedAsyncClient (DynamoDbAsyncClient dynamoDbClient ) {
176
- return DynamoDbEnhancedAsyncClient .builder ().dynamoDbClient (dynamoDbClient ).build ();
166
+ @ ConditionalOnMissingBean
167
+ @ ConditionalOnClass (DynamoDbEnhancedAsyncClient .class )
168
+ @ Bean
169
+ public DynamoDbEnhancedAsyncClient dynamoDbEnhancedAsyncClient (DynamoDbAsyncClient dynamoDbClient ) {
170
+ return DynamoDbEnhancedAsyncClient .builder ().dynamoDbClient (dynamoDbClient ).build ();
171
+ }
177
172
}
178
173
179
- @ ConditionalOnClass (DynamoDbTemplate .class )
180
- @ ConditionalOnMissingBean (DynamoDbOperations .class )
181
- @ Bean
182
- public DynamoDbTemplate dynamoDBTemplate (DynamoDbProperties properties ,
183
- DynamoDbEnhancedClient dynamoDbEnhancedClient , Optional <DynamoDbTableSchemaResolver > tableSchemaResolver ,
184
- Optional <DynamoDbTableNameResolver > tableNameResolver ) {
185
- DynamoDbTableSchemaResolver tableSchemaRes = tableSchemaResolver
174
+ @ ConditionalOnClass (name = "io.awspring.cloud.dynamodb.DynamoDbOperations" )
175
+ @ Configuration (proxyBeanMethods = false )
176
+ static class DynamoDbTemplateConfiguration {
177
+ @ ConditionalOnMissingBean (DynamoDbOperations .class )
178
+ @ Bean
179
+ public DynamoDbTemplate dynamoDBTemplate (DynamoDbProperties properties ,
180
+ DynamoDbEnhancedClient dynamoDbEnhancedClient , Optional <DynamoDbTableSchemaResolver > tableSchemaResolver ,
181
+ Optional <DynamoDbTableNameResolver > tableNameResolver ) {
182
+ DynamoDbTableSchemaResolver tableSchemaRes = tableSchemaResolver
186
183
.orElseGet (DefaultDynamoDbTableSchemaResolver ::new );
187
184
188
- DynamoDbTableNameResolver tableNameRes = tableNameResolver
185
+ DynamoDbTableNameResolver tableNameRes = tableNameResolver
189
186
.orElseGet (() -> new DefaultDynamoDbTableNameResolver (properties .getTablePrefix ()));
190
- return new DynamoDbTemplate (dynamoDbEnhancedClient , tableSchemaRes , tableNameRes );
187
+ return new DynamoDbTemplate (dynamoDbEnhancedClient , tableSchemaRes , tableNameRes );
188
+ }
191
189
}
192
190
193
191
static class MissingDaxUrlCondition extends NoneNestedConditions {
0 commit comments