Skip to content

Commit d4d13f1

Browse files
committed
fixes DynamoDBUtils
1 parent 980df22 commit d4d13f1

File tree

1 file changed

+86
-86
lines changed

1 file changed

+86
-86
lines changed

dynamodb-driver/src/main/java/org/jnosql/diana/dynamodb/DynamoDBUtils.java

Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -41,92 +41,92 @@
4141
import static org.jnosql.diana.dynamodb.ConfigurationAmazonEntity.KEY;
4242

4343
public class DynamoDBUtils {
44-
45-
private static final AttributeValue.Builder attributeValueBuilder = AttributeValue.builder();
46-
private static final Jsonb JSONB = JsonbSupplier.getInstance().get();
47-
48-
49-
public static <K, V> Map<String, AttributeValue> createAttributeValues(K key, V value){
50-
51-
Map<String, AttributeValue> createAttributeValues = createAttributeValues(key);
52-
String valueAsJson = JSONB.toJson(value);
53-
54-
AttributeValue valueAttributeValue = attributeValueBuilder.s(valueAsJson).build();
55-
createAttributeValues.put(VALUE,valueAttributeValue);
44+
45+
private static final AttributeValue.Builder attributeValueBuilder = AttributeValue.builder();
46+
private static final Jsonb JSONB = JsonbSupplier.getInstance().get();
47+
48+
49+
public static <K, V> Map<String, AttributeValue> createAttributeValues(K key, V value) {
50+
51+
Map<String, AttributeValue> createAttributeValues = createAttributeValues(key);
52+
String valueAsJson = JSONB.toJson(value);
53+
54+
AttributeValue valueAttributeValue = attributeValueBuilder.s(valueAsJson).build();
55+
createAttributeValues.put(VALUE, valueAttributeValue);
5656
return createAttributeValues;
57-
}
58-
59-
public static <K, V> Map<String, AttributeValue> createAttributeValues(K key){
60-
61-
Map<String, AttributeValue> map = new HashMap<>();
62-
AttributeValue keyAttributeValue = attributeValueBuilder.s(key.toString()).build();
63-
map.put(KEY,keyAttributeValue);
64-
57+
}
58+
59+
public static <K, V> Map<String, AttributeValue> createAttributeValues(K key) {
60+
61+
Map<String, AttributeValue> map = new HashMap<>();
62+
AttributeValue keyAttributeValue = attributeValueBuilder.s(key.toString()).build();
63+
map.put(KEY, keyAttributeValue);
64+
6565
return map;
66-
}
67-
68-
public static <K, V> Map<String, AttributeValue> createAttributeValues(KeyValueEntity<K> entity){
69-
return createAttributeValues(entity.getKey(),entity.getValue());
70-
}
71-
72-
public static <K> Collection<Map<String, AttributeValue>> createAttributeValues(Iterable<KeyValueEntity<K>> entities){
73-
74-
return StreamSupport.stream(entities.spliterator(),false)
75-
.map(e -> createAttributeValues(e))
76-
.collect(Collectors.toList());
77-
}
78-
79-
private static Map<String, List<WriteRequest>> createMapWriteRequest(Map<String, AttributeValue> map){
80-
return createMapWriteRequest(Arrays.asList(map));
81-
}
82-
83-
private static Map<String, List<WriteRequest>> createMapWriteRequest(Collection<Map<String, AttributeValue>> map){
84-
85-
PutRequest.Builder putRequestBuilder = PutRequest.builder();
86-
WriteRequest.Builder writeRequestBuilder = WriteRequest.builder();
87-
88-
return map
89-
.stream()
90-
.map(m -> putRequestBuilder.item(m).build())
91-
.map(p -> writeRequestBuilder.putRequest(p).build())
92-
.collect(Collectors.groupingBy(w -> w.toString(), Collectors.toList()));
93-
}
94-
95-
96-
public static <K> Map<String, List<WriteRequest>> createMapWriteRequest(Iterable<KeyValueEntity<K>> entities){
97-
98-
Collection<Map<String,AttributeValue>> attributeValues = createAttributeValues(entities);
99-
return createMapWriteRequest(attributeValues);
100-
}
101-
102-
public static <K> Map<String, AttributeValue> create(Iterable<K> keys){
103-
104-
Map<String, AttributeValue> map = StreamSupport.stream(keys.spliterator(),false)
105-
.map(e -> e.toString())
106-
.collect(Collectors.toMap(Function.identity(), k -> attributeValueBuilder.s(k).build()));
107-
108-
return Collections.unmodifiableMap(map);
109-
}
110-
111-
private static <K> Map<String, KeysAndAttributes> createKeysAndAttribute(Iterable<K> keys){
112-
113-
KeysAndAttributes.Builder keysAndAttributesBuilder = KeysAndAttributes.builder();
114-
115-
return StreamSupport.stream(keys.spliterator(),false)
116-
.collect(Collectors.toMap
117-
(
118-
e-> e.toString() ,
119-
k -> keysAndAttributesBuilder.projectionExpression(KEY).keys(createAttributeValues(k)).build())
120-
);
121-
}
122-
123-
public static <K> BatchGetItemRequest createBatchGetItemRequest(Iterable<K> keys) {
124-
BatchGetItemRequest.Builder batchGetItemRequestBuilder = BatchGetItemRequest.builder();
125-
return batchGetItemRequestBuilder.requestItems(createKeysAndAttribute(keys)).build();
126-
}
127-
128-
public static <K> GetItemRequest createGetItemRequest(K key,String tableName) {
129-
GetItemRequest.Builder getItemRequest = GetItemRequest.builder();
130-
return getItemRequest.tableName(tableName).key(createAttributeValues(key)).build();
131-
}
66+
}
67+
68+
public static <K, V> Map<String, AttributeValue> createAttributeValues(KeyValueEntity<K> entity) {
69+
return createAttributeValues(entity.getKey(), entity.getValue());
70+
}
71+
72+
public static <K> Collection<Map<String, AttributeValue>> createAttributeValues(Iterable<KeyValueEntity<K>> entities) {
73+
74+
return StreamSupport.stream(entities.spliterator(), false)
75+
.map(e -> createAttributeValues(e))
76+
.collect(Collectors.toList());
77+
}
78+
79+
private static Map<String, List<WriteRequest>> createMapWriteRequest(Map<String, AttributeValue> map) {
80+
return createMapWriteRequest(Arrays.asList(map));
81+
}
82+
83+
private static Map<String, List<WriteRequest>> createMapWriteRequest(Collection<Map<String, AttributeValue>> map) {
84+
85+
PutRequest.Builder putRequestBuilder = PutRequest.builder();
86+
WriteRequest.Builder writeRequestBuilder = WriteRequest.builder();
87+
88+
return map
89+
.stream()
90+
.map(m -> putRequestBuilder.item(m).build())
91+
.map(p -> writeRequestBuilder.putRequest(p).build())
92+
.collect(Collectors.groupingBy(w -> w.toString(), Collectors.toList()));
93+
}
94+
95+
96+
public static <K> Map<String, List<WriteRequest>> createMapWriteRequest(Iterable<KeyValueEntity<K>> entities) {
97+
98+
Collection<Map<String, AttributeValue>> attributeValues = createAttributeValues(entities);
99+
return createMapWriteRequest(attributeValues);
100+
}
101+
102+
public static <K> Map<String, AttributeValue> create(Iterable<K> keys) {
103+
104+
Map<String, AttributeValue> map = StreamSupport.stream(keys.spliterator(), false)
105+
.map(e -> e.toString())
106+
.collect(Collectors.toMap(Function.identity(), k -> attributeValueBuilder.s(k).build()));
107+
108+
return Collections.unmodifiableMap(map);
109+
}
110+
111+
private static <K> Map<String, KeysAndAttributes> createKeysAndAttribute(Iterable<K> keys) {
112+
113+
KeysAndAttributes.Builder keysAndAttributesBuilder = KeysAndAttributes.builder();
114+
115+
return StreamSupport.stream(keys.spliterator(), false)
116+
.collect(Collectors.toMap
117+
(
118+
e -> e.toString(),
119+
k -> keysAndAttributesBuilder.projectionExpression(KEY).keys(createAttributeValues(k)).build())
120+
);
121+
}
122+
123+
public static <K> BatchGetItemRequest createBatchGetItemRequest(Iterable<K> keys) {
124+
BatchGetItemRequest.Builder batchGetItemRequestBuilder = BatchGetItemRequest.builder();
125+
return batchGetItemRequestBuilder.requestItems(createKeysAndAttribute(keys)).build();
126+
}
127+
128+
public static <K> GetItemRequest createGetItemRequest(K key, String tableName) {
129+
GetItemRequest.Builder getItemRequest = GetItemRequest.builder();
130+
return getItemRequest.tableName(tableName).key(createAttributeValues(key)).build();
131+
}
132132
}

0 commit comments

Comments
 (0)