Class NestedRecordUtils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classIdentity-based cache key for schema lookups: - compares TableSchema by identity (==) to avoid depending on its equals/hashCode semantics - compares attribute name by value -
Method Summary
Modifier and TypeMethodDescriptionstatic TableSchema<?>getListElementSchemaCached(Map<NestedRecordUtils.SchemaLookupKey, TableSchema<?>> cache, TableSchema<?> parentSchema, String attributeName, Map<NestedRecordUtils.SchemaLookupKey, Optional<TableSchema<?>>> nestedSchemaCache) Cached wrapper for resolving list element schema, storing results (including null) in the provided cache.static Optional<TableSchema<?>>getNestedSchemaCached(Map<NestedRecordUtils.SchemaLookupKey, Optional<TableSchema<?>>> cache, TableSchema<?> parentSchema, String attributeName) static TableSchema<?>getTableSchemaForListElement(TableSchema<?> rootSchema, String key) Resolves and returns theTableSchemafor the element type of list attribute from the provided root schema.static TableSchema<?>getTableSchemaForListElement(TableSchema<?> rootSchema, String key, Map<NestedRecordUtils.SchemaLookupKey, Optional<TableSchema<?>>> nestedSchemaCache) Same asgetTableSchemaForListElement(TableSchema, String)but allows callers to provide a shared per-operation cache for nested schema lookups.static StringreconstructCompositeKey(String path, String attributeName) Converts a dot-separated path to a composite key using nested object delimiters.static Map<String,TableSchema<?>> resolveSchemasPerPath(Map<String, AttributeValue> attributesToSet, TableSchema<?> rootSchema) Traverses the attribute keys representing flattened nested structures and resolves the correspondingTableSchemafor each nested path.static Map<String,TableSchema<?>> resolveSchemasPerPath(Map<String, AttributeValue> attributesToSet, TableSchema<?> rootSchema, Map<NestedRecordUtils.SchemaLookupKey, Optional<TableSchema<?>>> nestedSchemaCache) Same asresolveSchemasPerPath(Map, TableSchema)but allows callers to provide a shared per-operation cache for nested schema lookups.
-
Method Details
-
getTableSchemaForListElement
Resolves and returns theTableSchemafor the element type of list attribute from the provided root schema.This method is useful when dealing with lists of nested objects in a DynamoDB-enhanced table schema, particularly in scenarios where the list is part of a flattened nested structure.
If the provided key contains the nested object delimiter (e.g.,
_NESTED_ATTR_UPDATE_), the method traverses the nested hierarchy based on that path to locate the correct schema for the target attribute. Otherwise, it directly resolves the list element type from the root schema using reflection.If the list element type is not annotated with
@DynamoDbBeanor@DynamoDbImmutable(e.g. when a custom converter handles serialization via@DynamoDbConvertedBy), this method returnsnullto indicate that no schema introspection is possible or necessary for that element type.- Parameters:
rootSchema- The rootTableSchemarepresenting the top-level entity.key- The key representing the list attribute, either flat or nested (using a delimiter).- Returns:
- The
TableSchemarepresenting the list element type, ornullif the element type is not a DynamoDB-annotated class. - Throws:
IllegalArgumentException- If no converter is found for the attribute or if the converter has no type parameters.
-
getTableSchemaForListElement
public static TableSchema<?> getTableSchemaForListElement(TableSchema<?> rootSchema, String key, Map<NestedRecordUtils.SchemaLookupKey, Optional<TableSchema<?>>> nestedSchemaCache) Same asgetTableSchemaForListElement(TableSchema, String)but allows callers to provide a shared per-operation cache for nested schema lookups. -
resolveSchemasPerPath
public static Map<String,TableSchema<?>> resolveSchemasPerPath(Map<String, AttributeValue> attributesToSet, TableSchema<?> rootSchema) Traverses the attribute keys representing flattened nested structures and resolves the correspondingTableSchemafor each nested path.The method constructs a mapping between each unique nested path (represented as dot-delimited strings) and the corresponding
TableSchemaobject derived from the root schema. It supports resolving schemas for arbitrarily deep nesting, using the_NESTED_ATTR_UPDATE_pattern as a path delimiter.This is typically used in update or transformation flows where fields from nested objects are represented as flattened keys in the attribute map (e.g.,
parent_NESTED_ATTR_UPDATE_child).- Parameters:
attributesToSet- A map of flattened attribute keys to values, where keys may represent paths to nested attributes.rootSchema- The rootTableSchemaof the top-level entity.- Returns:
- A map where the key is the nested path (e.g.,
"parent.child") and the value is theTableSchemacorresponding to that level in the object hierarchy.
-
resolveSchemasPerPath
public static Map<String,TableSchema<?>> resolveSchemasPerPath(Map<String, AttributeValue> attributesToSet, TableSchema<?> rootSchema, Map<NestedRecordUtils.SchemaLookupKey, Optional<TableSchema<?>>> nestedSchemaCache) Same asresolveSchemasPerPath(Map, TableSchema)but allows callers to provide a shared per-operation cache for nested schema lookups. -
reconstructCompositeKey
Converts a dot-separated path to a composite key using nested object delimiters. Example:reconstructCompositeKey("parent.child", "attr")returns"parent_NESTED_ATTR_UPDATE_child_NESTED_ATTR_UPDATE_attr"- Parameters:
path- the dot-separated path; may be null or emptyattributeName- the attribute name to append; must not be null- Returns:
- the composite key with nested object delimiters
-
getNestedSchemaCached
public static Optional<TableSchema<?>> getNestedSchemaCached(Map<NestedRecordUtils.SchemaLookupKey, Optional<TableSchema<?>>> cache, TableSchema<?> parentSchema, String attributeName) Cached wrapper aroundEnhancedClientUtils.getNestedSchema(software.amazon.awssdk.enhanced.dynamodb.TableSchema<?>, java.lang.String). Cache key is based on (parent schema identity, attribute name). -
getListElementSchemaCached
public static TableSchema<?> getListElementSchemaCached(Map<NestedRecordUtils.SchemaLookupKey, TableSchema<?>> cache, TableSchema<?> parentSchema, String attributeName, Map<NestedRecordUtils.SchemaLookupKey, Optional<TableSchema<?>>> nestedSchemaCache) Cached wrapper for resolving list element schema, storing results (including null) in the provided cache.getTableSchemaForListElement(TableSchema, String, Map)returnsnullwhen the list element type is not a DynamoDB-annotated class (e.g. when a custom converter handles serialization). Callers should check for null before attempting to introspect the returned schema.
-