Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<module>test/service-test-utils</module>
<module>test/test-utils</module>
<module>test/codegen-generated-classes-test</module>
<module>test/dynamodb-mapper-v2</module>
<module>test/sdk-benchmarks</module>
<module>test/http-client-benchmarks</module>
<module>test/module-path-tests</module>
Expand Down
114 changes: 114 additions & 0 deletions test/dynamodb-mapper-v2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>software.amazon.awssdk</groupId>
<artifactId>dynamodb-mapper-v2</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>DynamoDB Mapper for AWS SDK v2</name>
<description>Port of the v1 DynamoDBMapper to work with the v2 DynamoDbClient</description>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<awssdk.version>2.31.9</awssdk.version>
</properties>

<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>dynamodb</artifactId>
<version>${awssdk.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>

<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.12.5</version>
<optional>true</optional>
</dependency>

<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>DynamoDBLocal</artifactId>
<version>1.25.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.almworks.sqlite4java</groupId>
<artifactId>sqlite4java</artifactId>
<version>1.0.392</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-native-libs</id>
<phase>process-test-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>test</includeScope>
<includeTypes>so,dll,dylib</includeTypes>
<outputDirectory>${project.build.directory}/native-libs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<sqlite4java.library.path>${project.build.directory}/native-libs</sqlite4java.library.path>
</systemPropertyVariables>
<environmentVariables>
<DDB_LOCAL_TELEMETRY>0</DDB_LOCAL_TELEMETRY>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright 2015-2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* 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:
*
* http://aws.amazon.com/apache2.0
*
* This file 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 software.amazon.awssdk.dynamodb.datamodeling;

import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
import java.util.Map;

/**
* Abstract implementation of {@code IDynamoDBMapper}. Stripped to load path for POC.
*/
public abstract class AbstractDynamoDBMapper implements IDynamoDBMapper {

private final DynamoDBMapperConfig config;

protected AbstractDynamoDBMapper(final DynamoDBMapperConfig defaults) {
this.config = DynamoDBMapperConfig.DEFAULT.merge(defaults);
}

protected AbstractDynamoDBMapper() {
this(DynamoDBMapperConfig.DEFAULT);
}

protected final String getTableName(Class<?> clazz, Object object, DynamoDBMapperConfig config) {
if (config.getObjectTableNameResolver() != null && object != null) {
return config.getObjectTableNameResolver().getTableName(object, config);
}
return getTableName(clazz, config);
}

protected final String getTableName(Class<?> clazz, DynamoDBMapperConfig config) {
if (config.getTableNameResolver() == null) {
return DynamoDBMapperConfig.DefaultTableNameResolver.INSTANCE.getTableName(clazz, config);
}
return config.getTableNameResolver().getTableName(clazz, config);
}

protected final DynamoDBMapperConfig mergeConfig(DynamoDBMapperConfig overrides) {
return this.config.merge(overrides);
}

@Override
public <T> DynamoDBMapperTableModel<T> getTableModel(Class<T> clazz) {
return getTableModel(clazz, config);
}

@Override
public <T> DynamoDBMapperTableModel<T> getTableModel(Class<T> clazz, DynamoDBMapperConfig config) {
throw new UnsupportedOperationException("operation not supported in " + getClass());
}

@Override
public <T> T load(Class<T> clazz, Object hashKey, DynamoDBMapperConfig config) {
return load(clazz, hashKey, (Object)null, config);
}

@Override
public <T> T load(Class<T> clazz, Object hashKey) {
return load(clazz, hashKey, (Object)null, config);
}

@Override
public <T> T load(Class<T> clazz, Object hashKey, Object rangeKey) {
return load(clazz, hashKey, rangeKey, config);
}

@Override
public <T> T load(Class<T> clazz, Object hashKey, Object rangeKey, DynamoDBMapperConfig config) {
throw new UnsupportedOperationException("operation not supported in " + getClass());
}

@Override
public <T> T load(T keyObject) {
return load(keyObject, config);
}

@Override
public <T> T load(T keyObject, DynamoDBMapperConfig config) {
throw new UnsupportedOperationException("operation not supported in " + getClass());
}

@Override
public <T> T marshallIntoObject(Class<T> clazz, Map<String, AttributeValue> itemAttributes) {
return marshallIntoObject(clazz, itemAttributes, config);
}

public <T> T marshallIntoObject(Class<T> clazz, Map<String, AttributeValue> itemAttributes, DynamoDBMapperConfig config) {
throw new UnsupportedOperationException("operation not supported in " + getClass());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright 2013-2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* 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:
*
* http://aws.amazon.com/apache2.0
*
* This file 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 software.amazon.awssdk.dynamodb.datamodeling;

import java.util.Map;

import software.amazon.awssdk.services.dynamodb.model.AttributeValue;

/**
* A hook allowing a custom transform/untransform of the raw attribute
* values immediately before writing them into DynamoDB and immediately
* after reading them out of DynamoDB, but with extra context about
* the model class not available at the raw AmazonDynamoDB level.
* <p>
* This interface contains both a {@code transform} method and a corresponding
* {@code untransform} method. These methods SHOULD be inverses, such that
* untransform(transform(value)) == value.
*/
public interface AttributeTransformer {
/**
* Parameters for the {@code transform} and {@code untransform} methods,
* so we don't have to break the interface in order to add additional
* parameters.
* <p>
* Consuming code should NOT implement this interface.
*/
interface Parameters<T> {
/**
* Returns the raw attribute values to be transformed or untransformed.
* The returned map is not modifiable.
*
* @return the raw attribute values to transform or untransform
*/
Map<String, AttributeValue> getAttributeValues();

/**
* Returns true if this transformation is being called as part of a
* partial update operation. If true, the attributes returned by
* {@link #getAttributeValues()} do not represent the entire new
* item, but only a snapshot of the attributes which are getting
* new values.
* <p>
* Implementations which do not support transforming a partial
* view of an item (for example, because they need to calculate a
* signature based on all of the item's attributes that won't be valid
* if only a subset of the attributes are taken into consideration)
* should check this flag and throw an exception rather than than
* corrupting the data in DynamoDB.
* <p>
* This method always returns {@code false} for instances passed to
* {@link AttributeTransformer#untransform(Parameters)}.
*
* @return true if this operation is a partial update, false otherwise
*/
boolean isPartialUpdate();

/**
* @return the type of the model class we're transforming to or from
*/
Class<T> getModelClass();

/**
* @return the mapper config for this operation
*/
DynamoDBMapperConfig getMapperConfig();

/**
* @return the name of the DynamoDB table the attributes were read
* from or will be written to
*/
String getTableName();

/**
* @return the name of the hash key for the table
*/
String getHashKeyName();

/**
* @return the name of the range key for the table, if it has one,
* otherwise {@code null}
*/
String getRangeKeyName();
}

/**
* Transforms the input set of attribute values derived from the model
* object before writing them into DynamoDB.
*
* @param parameters transformation parameters
* @return the transformed attribute value map
*/
Map<String, AttributeValue> transform(Parameters<?> parameters);

/**
* Untransform the input set of attribute values read from DynamoDB before
* creating a model object from them.
*
* @param parameters transformation parameters
* @return the untransformed attribute value map
*/
Map<String, AttributeValue> untransform(Parameters<?> parameters);
}
Loading
Loading