Skip to content

Commit

Permalink
Revert "Update aws sdk version for dynamodb (#265)" (#272)
Browse files Browse the repository at this point in the history
This reverts commit f15c637.
  • Loading branch information
santitigaga authored Jun 24, 2022
1 parent f15c637 commit 713df9f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/main/java/co/com/bancolombia/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Constants {
public static final String PLUGIN_VERSION = "2.4.2";
public static final String GRADLE_WRAPPER_VERSION = "7.4.2";
public static final String KOTLIN_VERSION = "1.6.10";
public static final String AWS_BOM_VERSION = "2.17.209";
public static final String AWS_BOM_VERSION = "2.17.182";
public static final String COMMONS_JMS_VERSION = "0.3.0";
public static final String TOMCAT_EXCLUSION_KOTLIN =
"configurations {\n"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dependencies {
implementation project(':model')
implementation 'org.springframework:spring-context'
implementation 'software.amazon.awssdk:dynamodb-enhanced'
implementation 'com.amazonaws:aws-java-sdk-dynamodb:1.12.145'
implementation 'org.reactivecommons.utils:object-mapper-api:{{objectMapperVersion}}'
testImplementation 'org.reactivecommons.utils:object-mapper:{{objectMapperVersion}}'
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
package {{package}}.dynamodb;

import {{package}}.dynamodb.helper.TemplateAdapterOperations;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import org.reactivecommons.utils.ObjectMapper;
import org.springframework.stereotype.Repository;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedAsyncClient;
import software.amazon.awssdk.enhanced.dynamodb.Key;
import software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional;
import software.amazon.awssdk.enhanced.dynamodb.model.QueryEnhancedRequest;


@Repository
public class DynamoDBTemplateAdapter extends TemplateAdapterOperations<Object /*domain model*/, String, ModelEntity /*adapter model*/> /* implements Gateway from domain */ {
public DynamoDBTemplateAdapter(DynamoDbEnhancedAsyncClient connectionFactory, ObjectMapper mapper) {
public DynamoDBTemplateAdapter(AmazonDynamoDB connectionFactory, ObjectMapper mapper) {
/**
* Could be use mapper.mapBuilder if your domain model implement builder pattern
* super(repository, mapper, d -> mapper.mapBuilder(d,ObjectModel.ObjectModelBuilder.class).build());
* Or using mapper.map with the class of the object model
*/
super(connectionFactory, mapper, d -> mapper.map(d, Object.class /*domain model*/), "table_name", "secondary_index" /*index is optional*/);
super(connectionFactory, mapper, d -> mapper.map(d, Object.class /*domain model*/));
}

public List<Object /*domain model*/> getEntityBySomeKey(String partitionKey, String sortKey) {
QueryEnhancedRequest queryExpression = generateQueryExpression(partitionKey, sortKey);
return queryByIndex(queryExpression, "secondary_index" /*index is optional if you define in constructor*/);
}
public List<Object /*domain model*/> getEntityBySomeKey(String key) {
DynamoDBQueryExpression<ModelEntity /*adapter model*/> queryExpression = generateQueryExpression(key);
return query(queryExpression);
}

private QueryEnhancedRequest generateQueryExpression(String partitionKey, String sortKey) {
return QueryEnhancedRequest.builder()
.queryConditional(QueryConditional.keyEqualTo(Key.builder().partitionValue(partitionKey).build()))
.queryConditional(QueryConditional.sortGreaterThanOrEqualTo(Key.builder().sortValue(sortKey).build()))
.build();
}
private DynamoDBQueryExpression<ModelEntity /*adapter model*/> generateQueryExpression(String key) {
Map<String, AttributeValue> eav = new HashMap<>();
eav.put(":val1", new AttributeValue().withS(key));
DynamoDBQueryExpression<ModelEntity /*adapter model*/> queryExpression = new DynamoDBQueryExpression<ModelEntity /*adapter model*/>()
.withKeyConditionExpression("someKey = :val1")
.withExpressionAttributeValues(eav);
return queryExpression;
}
}

0 comments on commit 713df9f

Please sign in to comment.