Skip to content

Commit f915529

Browse files
feat(1449): update method reference in DefaultDynamoDbTableSchemaResolver to use fromClass
1 parent 64393f7 commit f915529

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

spring-cloud-aws-dynamodb/src/main/java/io/awspring/cloud/dynamodb/DefaultDynamoDbTableSchemaResolver.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@
1919
import java.util.List;
2020
import java.util.Map;
2121
import java.util.concurrent.ConcurrentHashMap;
22+
2223
import software.amazon.awssdk.enhanced.dynamodb.TableSchema;
2324

2425
/**
2526
* Default implementation with simple cache for {@link TableSchema}.
2627
*
2728
* @author Matej Nedic
2829
* @author Maciej Walkowiak
30+
* @author Marcus Voltolim
2931
*/
3032
public class DefaultDynamoDbTableSchemaResolver implements DynamoDbTableSchemaResolver {
33+
3134
private final Map<Class<?>, TableSchema> tableSchemaCache = new ConcurrentHashMap<>();
3235

3336
public DefaultDynamoDbTableSchemaResolver() {
@@ -42,10 +45,11 @@ public DefaultDynamoDbTableSchemaResolver(List<TableSchema<?>> tableSchemas) {
4245

4346
@Override
4447
public <T> TableSchema<T> resolve(Class<T> clazz) {
45-
return tableSchemaCache.computeIfAbsent(clazz, TableSchema::fromBean);
48+
return tableSchemaCache.computeIfAbsent(clazz, TableSchema::fromClass);
4649
}
4750

4851
Map<Class<?>, TableSchema> getTableSchemaCache() {
4952
return tableSchemaCache;
5053
}
54+
5155
}

spring-cloud-aws-dynamodb/src/test/java/io/awspring/cloud/dynamodb/DynamoDbTableSchemaResolverTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2020

2121
import java.util.List;
22+
2223
import org.junit.jupiter.api.Test;
2324
import software.amazon.awssdk.enhanced.dynamodb.TableSchema;
2425
import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema;
@@ -28,6 +29,7 @@
2829
*
2930
* @author Matej Nedic
3031
* @author Maciej Walkowiak
32+
* @author Marcus Voltolim
3133
*/
3234
class DynamoDbTableSchemaResolverTest {
3335

@@ -46,6 +48,21 @@ void tableSchemaResolved_successfully() {
4648
assertThat(defaultTableSchemaResolver.getTableSchemaCache()).hasSize(1);
4749
}
4850

51+
@Test
52+
void tableSchemaForImmutableResolved_successfully() {
53+
// given
54+
DefaultDynamoDbTableSchemaResolver defaultTableSchemaResolver = new DefaultDynamoDbTableSchemaResolver();
55+
// when
56+
TableSchema<PersonImmutable> tableSchema = defaultTableSchemaResolver.resolve(PersonImmutable.class);
57+
58+
// Call one more time to see if cache is being filled properly.
59+
defaultTableSchemaResolver.resolve(PersonImmutable.class);
60+
61+
// then
62+
assertThat(tableSchema).isNotNull();
63+
assertThat(defaultTableSchemaResolver.getTableSchemaCache()).hasSize(1);
64+
}
65+
4966
@Test
5067
void tableSchemaResolved_whenSchemaPassedThroughConstructor() {
5168
StaticTableSchema<Library> librarySchema = StaticTableSchema.builder(Library.class).build();
@@ -86,4 +103,5 @@ void tableSchemaResolver_fail_entity_not_annotated() {
86103

87104
static class Library {
88105
}
106+
89107
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2013-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.awspring.cloud.dynamodb;
17+
18+
import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbImmutable;
19+
20+
/**
21+
* Immutable version of {@link Person}.
22+
*
23+
* @author Marcus Voltolim
24+
*/
25+
@DynamoDbImmutable(builder = PersonImmutable.Builder.class)
26+
public class PersonImmutable extends Person {
27+
28+
private PersonImmutable(String firstName, String lastName) {
29+
super(firstName, lastName);
30+
}
31+
32+
public static class Builder {
33+
34+
private String firstName;
35+
private String lastName;
36+
37+
public Builder firstName(String firstName) {
38+
this.firstName = firstName;
39+
return this;
40+
}
41+
42+
public Builder lastName(String lastName) {
43+
this.lastName = lastName;
44+
return this;
45+
}
46+
47+
public PersonImmutable build() {
48+
return new PersonImmutable(firstName, lastName);
49+
}
50+
51+
}
52+
53+
}

0 commit comments

Comments
 (0)