Skip to content

Commit 3d9ab1a

Browse files
committed
fixed checkstyle and used StringBuilder
1 parent e2225c5 commit 3d9ab1a

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/extensions/AutoGeneratedTimestampRecordExtension.java

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,14 @@ public WriteModification beforeWrite(DynamoDbExtensionContext.BeforeWrite contex
153153
} else if (value.hasL() && !value.l().isEmpty() && value.l().get(0).hasM()) {
154154
TableSchema<?> elementListSchema = getTableSchemaForListElement(context.tableSchema(), key);
155155

156-
List<AttributeValue> updatedList = value.l().stream()
156+
List<AttributeValue> updatedList = value.l()
157+
.stream()
157158
.map(listItem -> listItem.hasM() ?
158-
AttributeValue.builder().m(processNestedObject(listItem.m(), elementListSchema, currentInstant)).build() : listItem)
159+
AttributeValue.builder()
160+
.m(processNestedObject(listItem.m(),
161+
elementListSchema,
162+
currentInstant))
163+
.build() : listItem)
159164
.collect(Collectors.toList());
160165
updatedItems.put(key, AttributeValue.builder().l(updatedList).build());
161166
}
@@ -165,7 +170,8 @@ public WriteModification beforeWrite(DynamoDbExtensionContext.BeforeWrite contex
165170

166171
stringTableSchemaMap.forEach((path, schema) -> {
167172
Collection<String> customMetadataObject = schema.tableMetadata()
168-
.customMetadataObject(CUSTOM_METADATA_KEY, Collection.class).orElse(null);
173+
.customMetadataObject(CUSTOM_METADATA_KEY, Collection.class)
174+
.orElse(null);
169175

170176
if (customMetadataObject != null) {
171177
customMetadataObject.forEach(
@@ -203,7 +209,8 @@ private TableSchema<?> getTableSchemaForListElement(TableSchema<?> rootSchema, S
203209
}
204210
String attributeName = parts[parts.length - 1];
205211
listElementSchema = TableSchema.fromClass(
206-
Class.forName(currentSchema.converterForAttribute(attributeName).type().rawClassParameters().get(0).rawClass().getName()));
212+
Class.forName(currentSchema.converterForAttribute(attributeName)
213+
.type().rawClassParameters().get(0).rawClass().getName()));
207214
}
208215
} catch (ClassNotFoundException e) {
209216
throw new IllegalArgumentException("Class not found for field name: " + key, e);
@@ -219,11 +226,16 @@ private Map<String, TableSchema<?>> resolveSchemasPerPath(Map<String, AttributeV
219226
for (String key : attributesToSet.keySet()) {
220227
String[] parts = NESTED_OBJECT_PATTERN.split(key);
221228

222-
String path = "";
229+
StringBuilder pathBuilder = new StringBuilder();
223230
TableSchema<?> currentSchema = rootSchema;
224231

225232
for (int i = 0; i < parts.length - 1; i++) {
226-
path = path.isEmpty() ? parts[i] : path + "." + parts[i];
233+
if (pathBuilder.length() > 0) {
234+
pathBuilder.append(".");
235+
}
236+
pathBuilder.append(parts[i]);
237+
238+
String path = pathBuilder.toString();
227239

228240
if (!schemaMap.containsKey(path)) {
229241
Optional<? extends TableSchema<?>> nestedSchema = getNestedSchema(currentSchema, parts[i]);
@@ -253,7 +265,7 @@ private Map<String, AttributeValue> processNestedObject(Map<String, AttributeVal
253265
Collection<String> customMetadataObject = nestedSchema.tableMetadata()
254266
.customMetadataObject(CUSTOM_METADATA_KEY, Collection.class).orElse(null);
255267

256-
if (customMetadataObject!= null) {
268+
if (customMetadataObject != null) {
257269
customMetadataObject.forEach(
258270
key -> insertTimestampInItemToTransform(updatedNestedMap, String.valueOf(key),
259271
nestedSchema.converterForAttribute(key), currentInstant));
@@ -268,11 +280,17 @@ private Map<String, AttributeValue> processNestedObject(Map<String, AttributeVal
268280
&& nestedValue.l().get(0).hasM()) {
269281
try {
270282
TableSchema<?> listElementSchema = TableSchema.fromClass(
271-
Class.forName(nestedSchema.converterForAttribute(nestedKey).type().rawClassParameters().get(0).rawClass().getName()));
272-
List<AttributeValue> updatedList = nestedValue.l().stream()
273-
.map(listItem -> listItem.hasM() ?
274-
AttributeValue.builder().m(processNestedObject(listItem.m(), listElementSchema, currentInstant)).build() : listItem)
275-
.collect(Collectors.toList());
283+
Class.forName(nestedSchema.converterForAttribute(nestedKey)
284+
.type().rawClassParameters().get(0).rawClass().getName()));
285+
List<AttributeValue> updatedList = nestedValue
286+
.l()
287+
.stream()
288+
.map(listItem -> listItem.hasM() ?
289+
AttributeValue.builder()
290+
.m(processNestedObject(listItem.m(),
291+
listElementSchema,
292+
currentInstant)).build() : listItem)
293+
.collect(Collectors.toList());
276294
updatedNestedMap.put(nestedKey, AttributeValue.builder().l(updatedList).build());
277295
} catch (ClassNotFoundException e) {
278296
throw new IllegalArgumentException("Class not found for field name: " + nestedKey, e);

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/update/UpdateExpressionUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,17 @@ private static List<SetAction> setActionsFor(Map<String, AttributeValue> attribu
9090
if (key.contains(NESTED_OBJECT_UPDATE)) {
9191
TableSchema currentSchema = tableSchema;
9292
List<String> pathFieldNames = Arrays.asList(PATTERN.split(key));
93-
String attributeName = pathFieldNames.get(pathFieldNames.size()-1);
93+
String attributeName = pathFieldNames.get(pathFieldNames.size() - 1);
9494

95-
for(int i = 0; i < pathFieldNames.size() - 1; i++ ) {
95+
for (int i = 0; i < pathFieldNames.size() - 1; i++) {
9696
Optional<? extends TableSchema<?>> nestedSchema = getNestedSchema(currentSchema, pathFieldNames.get(i));
9797
if (nestedSchema.isPresent()) {
9898
currentSchema = nestedSchema.get();
9999
}
100100
}
101101

102-
actions.add(setValue(key, value, UpdateBehaviorTag.resolveForAttribute(attributeName, currentSchema.tableMetadata())));
102+
actions.add(setValue(key, value,
103+
UpdateBehaviorTag.resolveForAttribute(attributeName, currentSchema.tableMetadata())));
103104
} else {
104105
actions.add(setValue(key, value, UpdateBehaviorTag.resolveForAttribute(key, tableSchema.tableMetadata())));
105106
}

0 commit comments

Comments
 (0)