Skip to content

Commit a4b3e93

Browse files
author
Alessandro Moscatelli
committed
cleaning whitespace formatting
Signed-off-by: Alessandro Moscatelli <[email protected]>
1 parent b959eac commit a4b3e93

File tree

3 files changed

+296
-296
lines changed

3 files changed

+296
-296
lines changed

dynamodb-driver/pom.xml

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<!-- ~ Copyright (c) 2017 Otávio Santana and others ~ All rights reserved.
3-
This program and the accompanying materials ~ are made available under the
4-
terms of the Eclipse Public License v1.0 ~ and Apache License v2.0 which
5-
accompanies this distribution. ~ The Eclipse Public License is available
6-
at http://www.eclipse.org/legal/epl-v10.html ~ and the Apache License v2.0
7-
is available at http://www.opensource.org/licenses/apache2.0.php. ~ ~ You
8-
may elect to redistribute this code under either of these licenses. ~ ~ Contributors:
9-
~ ~ Otavio Santana -->
10-
11-
<project xmlns="http://maven.apache.org/POM/4.0.0"
12-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
13-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
14-
<modelVersion>4.0.0</modelVersion>
15-
<parent>
16-
<groupId>org.eclipse.jnosql.communication</groupId>
17-
<artifactId>communication-driver</artifactId>
18-
<version>1.0.0-SNAPSHOT</version>
19-
</parent>
20-
21-
22-
<artifactId>dynamodb-driver</artifactId>
23-
24-
<dependencies>
25-
<dependency>
26-
<groupId>${project.groupId}</groupId>
27-
<artifactId>communication-key-value</artifactId>
28-
<version>${project.version}</version>
29-
</dependency>
30-
<dependency>
31-
<groupId>${project.groupId}</groupId>
32-
<artifactId>communication-driver-commons</artifactId>
33-
<version>${project.version}</version>
34-
</dependency>
35-
<dependency>
36-
<groupId>software.amazon.awssdk</groupId>
37-
<artifactId>dynamodb</artifactId>
38-
<version>2.15.40</version>
39-
</dependency>
40-
<dependency>
41-
<groupId>org.testcontainers</groupId>
42-
<artifactId>testcontainers</artifactId>
43-
<version>${testcontainers.version}</version>
44-
<scope>test</scope>
45-
</dependency>
46-
</dependencies>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- ~ Copyright (c) 2017 Otávio Santana and others ~ All rights reserved.
3+
This program and the accompanying materials ~ are made available under the
4+
terms of the Eclipse Public License v1.0 ~ and Apache License v2.0 which
5+
accompanies this distribution. ~ The Eclipse Public License is available
6+
at http://www.eclipse.org/legal/epl-v10.html ~ and the Apache License v2.0
7+
is available at http://www.opensource.org/licenses/apache2.0.php. ~ ~ You
8+
may elect to redistribute this code under either of these licenses. ~ ~ Contributors:
9+
~ ~ Otavio Santana -->
10+
11+
<project xmlns="http://maven.apache.org/POM/4.0.0"
12+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
13+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
14+
<modelVersion>4.0.0</modelVersion>
15+
<parent>
16+
<groupId>org.eclipse.jnosql.communication</groupId>
17+
<artifactId>communication-driver</artifactId>
18+
<version>1.0.0-SNAPSHOT</version>
19+
</parent>
20+
21+
22+
<artifactId>dynamodb-driver</artifactId>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>${project.groupId}</groupId>
27+
<artifactId>communication-key-value</artifactId>
28+
<version>${project.version}</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>${project.groupId}</groupId>
32+
<artifactId>communication-driver-commons</artifactId>
33+
<version>${project.version}</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>software.amazon.awssdk</groupId>
37+
<artifactId>dynamodb</artifactId>
38+
<version>2.15.40</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.testcontainers</groupId>
42+
<artifactId>testcontainers</artifactId>
43+
<version>${testcontainers.version}</version>
44+
<scope>test</scope>
45+
</dependency>
46+
</dependencies>
4747
</project>
Lines changed: 130 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,130 @@
1-
/*
2-
* Copyright (c) 2018 Otávio Santana and others
3-
* All rights reserved. This program and the accompanying materials
4-
* are made available under the terms of the Eclipse Public License v1.0
5-
* and Apache License v2.0 which accompanies this distribution.
6-
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7-
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8-
*
9-
* You may elect to redistribute this code under either of these licenses.
10-
*
11-
* Contributors:
12-
*
13-
* Otavio Santana
14-
*/
15-
package org.eclipse.jnosql.communication.dynamodb;
16-
17-
import jakarta.nosql.keyvalue.KeyValueEntity;
18-
import org.eclipse.jnosql.communication.driver.JsonbSupplier;
19-
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
20-
import software.amazon.awssdk.services.dynamodb.model.BatchGetItemRequest;
21-
import software.amazon.awssdk.services.dynamodb.model.GetItemRequest;
22-
import software.amazon.awssdk.services.dynamodb.model.KeysAndAttributes;
23-
import software.amazon.awssdk.services.dynamodb.model.PutRequest;
24-
import software.amazon.awssdk.services.dynamodb.model.WriteRequest;
25-
26-
import javax.json.bind.Jsonb;
27-
import java.util.Collection;
28-
import java.util.Collections;
29-
import java.util.HashMap;
30-
import java.util.List;
31-
import java.util.Map;
32-
import java.util.function.Function;
33-
import java.util.stream.Collectors;
34-
import java.util.stream.StreamSupport;
35-
36-
import static org.eclipse.jnosql.communication.dynamodb.ConfigurationAmazonEntity.KEY;
37-
import static org.eclipse.jnosql.communication.dynamodb.ConfigurationAmazonEntity.VALUE;
38-
39-
public class DynamoDBUtils {
40-
41-
private static final AttributeValue.Builder attributeValueBuilder = AttributeValue.builder();
42-
private static final Jsonb JSONB = JsonbSupplier.getInstance().get();
43-
44-
private DynamoDBUtils() {
45-
}
46-
47-
public static <K, V> Map<String, AttributeValue> createAttributeValues(K key, V value) {
48-
49-
Map<String, AttributeValue> createAttributeValues = createKeyAttributeValues(key);
50-
String valueAsJson = JSONB.toJson(value);
51-
52-
AttributeValue valueAttributeValue = attributeValueBuilder.s(valueAsJson).build();
53-
createAttributeValues.put(VALUE, valueAttributeValue);
54-
return createAttributeValues;
55-
}
56-
57-
public static <K, V> Map<String, AttributeValue> createKeyAttributeValues(K key) {
58-
Map<String, AttributeValue> map = new HashMap<>();
59-
AttributeValue keyAttributeValue = attributeValueBuilder.s(key.toString()).build();
60-
map.put(KEY, keyAttributeValue);
61-
62-
return map;
63-
}
64-
65-
public static <K, V> Collection<Map<String, AttributeValue>> createKeyAttributeValues(Iterable<K> keys) {
66-
return StreamSupport.stream(keys.spliterator(), false).map(
67-
k -> Collections.singletonMap(KEY, attributeValueBuilder.s(k.toString()).build())
68-
).collect(Collectors.toList());
69-
}
70-
71-
public static <K, V> Map<String, AttributeValue> createAttributeValues(KeyValueEntity entity) {
72-
return createAttributeValues(entity.getKey(), entity.getValue());
73-
}
74-
75-
public static <K> Collection<Map<String, AttributeValue>> createAttributeValues(Iterable<KeyValueEntity> entities) {
76-
77-
return StreamSupport.stream(entities.spliterator(), false)
78-
.map(e -> createAttributeValues(e))
79-
.collect(Collectors.toList());
80-
}
81-
82-
private static Map<String, List<WriteRequest>> createMapWriteRequest(Collection<Map<String, AttributeValue>> map, String tableName) {
83-
84-
PutRequest.Builder putRequestBuilder = PutRequest.builder();
85-
WriteRequest.Builder writeRequestBuilder = WriteRequest.builder();
86-
87-
return Collections.singletonMap(
88-
tableName,
89-
map
90-
.stream()
91-
.map(m -> putRequestBuilder.item(m).build())
92-
.map(p -> writeRequestBuilder.putRequest(p).build()).collect(Collectors.toList())
93-
);
94-
}
95-
96-
public static <K> Map<String, List<WriteRequest>> createMapWriteRequest(Iterable<KeyValueEntity> entities, String tableName) {
97-
Collection<Map<String, AttributeValue>> attributeValues = createAttributeValues(entities);
98-
createMapWriteRequest(attributeValues, tableName);
99-
return createMapWriteRequest(attributeValues, tableName);
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, String tableName) {
112-
113-
KeysAndAttributes.Builder keysAndAttributesBuilder = KeysAndAttributes.builder();
114-
115-
return Collections.singletonMap(
116-
tableName,
117-
keysAndAttributesBuilder.keys(createKeyAttributeValues(keys)).build()
118-
);
119-
}
120-
121-
public static <K> BatchGetItemRequest createBatchGetItemRequest(Iterable<K> keys, String tableName) {
122-
BatchGetItemRequest.Builder batchGetItemRequestBuilder = BatchGetItemRequest.builder();
123-
return batchGetItemRequestBuilder.requestItems(createKeysAndAttribute(keys, tableName)).build();
124-
}
125-
126-
public static <K> GetItemRequest createGetItemRequest(K key, String tableName) {
127-
GetItemRequest.Builder getItemRequest = GetItemRequest.builder();
128-
return getItemRequest.tableName(tableName).key(createKeyAttributeValues(key)).build();
129-
}
130-
}
1+
/*
2+
* Copyright (c) 2018 Otávio Santana and others
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.communication.dynamodb;
16+
17+
import jakarta.nosql.keyvalue.KeyValueEntity;
18+
import org.eclipse.jnosql.communication.driver.JsonbSupplier;
19+
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
20+
import software.amazon.awssdk.services.dynamodb.model.BatchGetItemRequest;
21+
import software.amazon.awssdk.services.dynamodb.model.GetItemRequest;
22+
import software.amazon.awssdk.services.dynamodb.model.KeysAndAttributes;
23+
import software.amazon.awssdk.services.dynamodb.model.PutRequest;
24+
import software.amazon.awssdk.services.dynamodb.model.WriteRequest;
25+
26+
import javax.json.bind.Jsonb;
27+
import java.util.Collection;
28+
import java.util.Collections;
29+
import java.util.HashMap;
30+
import java.util.List;
31+
import java.util.Map;
32+
import java.util.function.Function;
33+
import java.util.stream.Collectors;
34+
import java.util.stream.StreamSupport;
35+
36+
import static org.eclipse.jnosql.communication.dynamodb.ConfigurationAmazonEntity.KEY;
37+
import static org.eclipse.jnosql.communication.dynamodb.ConfigurationAmazonEntity.VALUE;
38+
39+
public class DynamoDBUtils {
40+
41+
private static final AttributeValue.Builder attributeValueBuilder = AttributeValue.builder();
42+
private static final Jsonb JSONB = JsonbSupplier.getInstance().get();
43+
44+
private DynamoDBUtils() {
45+
}
46+
47+
public static <K, V> Map<String, AttributeValue> createAttributeValues(K key, V value) {
48+
49+
Map<String, AttributeValue> createAttributeValues = createKeyAttributeValues(key);
50+
String valueAsJson = JSONB.toJson(value);
51+
52+
AttributeValue valueAttributeValue = attributeValueBuilder.s(valueAsJson).build();
53+
createAttributeValues.put(VALUE, valueAttributeValue);
54+
return createAttributeValues;
55+
}
56+
57+
public static <K, V> Map<String, AttributeValue> createKeyAttributeValues(K key) {
58+
Map<String, AttributeValue> map = new HashMap<>();
59+
AttributeValue keyAttributeValue = attributeValueBuilder.s(key.toString()).build();
60+
map.put(KEY, keyAttributeValue);
61+
62+
return map;
63+
}
64+
65+
public static <K, V> Collection<Map<String, AttributeValue>> createKeyAttributeValues(Iterable<K> keys) {
66+
return StreamSupport.stream(keys.spliterator(), false).map(
67+
k -> Collections.singletonMap(KEY, attributeValueBuilder.s(k.toString()).build())
68+
).collect(Collectors.toList());
69+
}
70+
71+
public static <K, V> Map<String, AttributeValue> createAttributeValues(KeyValueEntity entity) {
72+
return createAttributeValues(entity.getKey(), entity.getValue());
73+
}
74+
75+
public static <K> Collection<Map<String, AttributeValue>> createAttributeValues(Iterable<KeyValueEntity> entities) {
76+
77+
return StreamSupport.stream(entities.spliterator(), false)
78+
.map(e -> createAttributeValues(e))
79+
.collect(Collectors.toList());
80+
}
81+
82+
private static Map<String, List<WriteRequest>> createMapWriteRequest(Collection<Map<String, AttributeValue>> map, String tableName) {
83+
84+
PutRequest.Builder putRequestBuilder = PutRequest.builder();
85+
WriteRequest.Builder writeRequestBuilder = WriteRequest.builder();
86+
87+
return Collections.singletonMap(
88+
tableName,
89+
map
90+
.stream()
91+
.map(m -> putRequestBuilder.item(m).build())
92+
.map(p -> writeRequestBuilder.putRequest(p).build()).collect(Collectors.toList())
93+
);
94+
}
95+
96+
public static <K> Map<String, List<WriteRequest>> createMapWriteRequest(Iterable<KeyValueEntity> entities, String tableName) {
97+
Collection<Map<String, AttributeValue>> attributeValues = createAttributeValues(entities);
98+
createMapWriteRequest(attributeValues, tableName);
99+
return createMapWriteRequest(attributeValues, tableName);
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, String tableName) {
112+
113+
KeysAndAttributes.Builder keysAndAttributesBuilder = KeysAndAttributes.builder();
114+
115+
return Collections.singletonMap(
116+
tableName,
117+
keysAndAttributesBuilder.keys(createKeyAttributeValues(keys)).build()
118+
);
119+
}
120+
121+
public static <K> BatchGetItemRequest createBatchGetItemRequest(Iterable<K> keys, String tableName) {
122+
BatchGetItemRequest.Builder batchGetItemRequestBuilder = BatchGetItemRequest.builder();
123+
return batchGetItemRequestBuilder.requestItems(createKeysAndAttribute(keys, tableName)).build();
124+
}
125+
126+
public static <K> GetItemRequest createGetItemRequest(K key, String tableName) {
127+
GetItemRequest.Builder getItemRequest = GetItemRequest.builder();
128+
return getItemRequest.tableName(tableName).key(createKeyAttributeValues(key)).build();
129+
}
130+
}

0 commit comments

Comments
 (0)