-
-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
169 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...ava/io/awspring/cloud/autoconfigure/dynamodb/DynamoDbEnhancedClientAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2013-2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.awspring.cloud.autoconfigure.dynamodb; | ||
|
||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedAsyncClient; | ||
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient; | ||
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; | ||
import software.amazon.awssdk.services.dynamodb.DynamoDbClient; | ||
|
||
/** | ||
* {@link DynamoDbEnhancedClientAutoConfiguration Auto-configuration} for DynamoDB integration. | ||
* | ||
* @author Matej Nedic | ||
* @author Arun Patra | ||
* @since 3.0.0 | ||
*/ | ||
@AutoConfiguration | ||
@ConditionalOnClass({DynamoDbEnhancedClient.class, DynamoDbEnhancedAsyncClient.class}) | ||
@AutoConfigureAfter(DynamoDbClientAutoConfiguration.class) | ||
@ConditionalOnProperty(name = "spring.cloud.aws.dynamodb.enabled", havingValue = "true", matchIfMissing = true) | ||
public class DynamoDbEnhancedClientAutoConfiguration { | ||
|
||
@ConditionalOnMissingBean | ||
@Bean | ||
public DynamoDbEnhancedClient dynamoDbEnhancedClient(DynamoDbClient dynamoDbClient) { | ||
return DynamoDbEnhancedClient.builder().dynamoDbClient(dynamoDbClient).build(); | ||
} | ||
|
||
|
||
@ConditionalOnMissingBean | ||
@Bean | ||
public DynamoDbEnhancedAsyncClient dynamoDbEnhancedAsyncClient(DynamoDbAsyncClient dynamoDbAsyncClient) { | ||
return DynamoDbEnhancedAsyncClient.builder() | ||
.dynamoDbClient(dynamoDbAsyncClient) | ||
.build(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...main/java/io/awspring/cloud/autoconfigure/dynamodb/DynamoDbTemplateAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2013-2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.awspring.cloud.autoconfigure.dynamodb; | ||
|
||
import java.util.Optional; | ||
|
||
import io.awspring.cloud.dynamodb.DefaultDynamoDbTableNameResolver; | ||
import io.awspring.cloud.dynamodb.DefaultDynamoDbTableSchemaResolver; | ||
import io.awspring.cloud.dynamodb.DynamoDbOperations; | ||
import io.awspring.cloud.dynamodb.DynamoDbTableNameResolver; | ||
import io.awspring.cloud.dynamodb.DynamoDbTableSchemaResolver; | ||
import io.awspring.cloud.dynamodb.DynamoDbTemplate; | ||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient; | ||
import software.amazon.awssdk.services.dynamodb.DynamoDbClient; | ||
|
||
/** | ||
* {@link EnableAutoConfiguration Auto-configuration} for DynamoDB integration. | ||
* | ||
* @author Matej Nedic | ||
* @author Arun Patra | ||
* @since 3.0.0 | ||
*/ | ||
@AutoConfiguration | ||
@ConditionalOnClass({DynamoDbClient.class, DynamoDbEnhancedClient.class, DynamoDbTemplate.class}) | ||
@AutoConfigureAfter(DynamoDbEnhancedClientAutoConfiguration.class) | ||
@ConditionalOnProperty(name = "spring.cloud.aws.dynamodb.enabled", havingValue = "true", matchIfMissing = true) | ||
public class DynamoDbTemplateAutoConfiguration { | ||
|
||
@ConditionalOnMissingBean(DynamoDbOperations.class) | ||
@Bean | ||
public DynamoDbTemplate dynamoDBTemplate(DynamoDbProperties properties, | ||
DynamoDbEnhancedClient dynamoDbEnhancedClient, Optional<DynamoDbTableSchemaResolver> tableSchemaResolver, | ||
Optional<DynamoDbTableNameResolver> tableNameResolver) { | ||
DynamoDbTableSchemaResolver tableSchemaRes = tableSchemaResolver | ||
.orElseGet(DefaultDynamoDbTableSchemaResolver::new); | ||
|
||
DynamoDbTableNameResolver tableNameRes = tableNameResolver | ||
.orElseGet(() -> new DefaultDynamoDbTableNameResolver(properties.getTablePrefix())); | ||
return new DynamoDbTemplate(dynamoDbEnhancedClient, tableSchemaRes, tableNameRes); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters