Skip to content

Commit cbdd1c6

Browse files
authored
Merge pull request #167 from amoscatelli/master
fix configuration via microprofile and table initialization
2 parents 7601e48 + ad5693e commit cbdd1c6

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

dynamodb-driver/src/main/java/org/eclipse/jnosql/communication/dynamodb/DynamoDBBuilders.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
import jakarta.nosql.Settings;
1919

20-
import static java.util.Optional.ofNullable;
21-
2220
final class DynamoDBBuilders {
2321

2422

@@ -27,11 +25,11 @@ private DynamoDBBuilders() {
2725
}
2826

2927
static void load(Settings settings, DynamoDBBuilder dynamoDB) {
30-
ofNullable(settings.get(DynamoDBConfigurations.ENDPOINT.get())).map(Object::toString).ifPresent(dynamoDB::endpoint);
31-
ofNullable(settings.get(DynamoDBConfigurations.REGION.get())).map(Object::toString).ifPresent(dynamoDB::region);
32-
ofNullable(settings.get(DynamoDBConfigurations.PROFILE.get())).map(Object::toString).ifPresent(dynamoDB::profile);
33-
ofNullable(settings.get(DynamoDBConfigurations.AWS_ACCESSKEY.get())).map(Object::toString).ifPresent(dynamoDB::awsAccessKey);
34-
ofNullable(settings.get(DynamoDBConfigurations.AWS_SECRET_ACCESS.get())).map(Object::toString).ifPresent(dynamoDB::awsSecretAccess);
28+
settings.get(DynamoDBConfigurations.ENDPOINT.get()).map(Object::toString).ifPresent(dynamoDB::endpoint);
29+
settings.get(DynamoDBConfigurations.REGION.get()).map(Object::toString).ifPresent(dynamoDB::region);
30+
settings.get(DynamoDBConfigurations.PROFILE.get()).map(Object::toString).ifPresent(dynamoDB::profile);
31+
settings.get(DynamoDBConfigurations.AWS_ACCESSKEY.get()).map(Object::toString).ifPresent(dynamoDB::awsAccessKey);
32+
settings.get(DynamoDBConfigurations.AWS_SECRET_ACCESS.get()).map(Object::toString).ifPresent(dynamoDB::awsSecretAccess);
3533
}
3634

3735
}

dynamodb-driver/src/main/java/org/eclipse/jnosql/communication/dynamodb/DynamoTableUtils.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Collections;
2929
import java.util.List;
3030
import java.util.Map;
31+
import java.util.Objects;
3132

3233
public final class DynamoTableUtils {
3334

@@ -71,20 +72,18 @@ public static ProvisionedThroughput createProvisionedThroughput(Long readCapacit
7172

7273
ProvisionedThroughput.Builder provisionedThroughputBuilder = ProvisionedThroughput.builder();
7374

74-
if (readCapacityUnits != null && readCapacityUnits.longValue() > 0)
75+
if (readCapacityUnits != null && readCapacityUnits.longValue() > 0) {
7576
provisionedThroughputBuilder.readCapacityUnits(readCapacityUnits);
76-
else {
77+
} else {
7778
provisionedThroughputBuilder.readCapacityUnits(READ_CAPACITY_UNITS);
7879
}
7980

80-
81-
if (writeCapacityUnit != null && writeCapacityUnit.longValue() > 0)
81+
if (writeCapacityUnit != null && writeCapacityUnit.longValue() > 0) {
8282
provisionedThroughputBuilder.writeCapacityUnits(writeCapacityUnit);
83-
else {
83+
} else {
8484
provisionedThroughputBuilder.writeCapacityUnits(READ_CAPACITY_UNITS);
8585
}
8686

87-
8887
return provisionedThroughputBuilder.build();
8988
}
9089

@@ -98,34 +97,37 @@ public static Map<String, ScalarAttributeType> createAttributesType() {
9897

9998
public static void manageTables(String tableName, DynamoDbClient client, Long readCapacityUnits, Long writeCapacityUnit) {
10099

101-
boolean hasTable = true;
100+
boolean hasTable = false;
102101
String lastName = null;
103102

104-
while (hasTable) {
103+
while (!hasTable) {
105104
try {
106-
ListTablesResponse response = null;
107-
if (lastName == null) {
108-
ListTablesRequest request = ListTablesRequest.builder().build();
109-
response = client.listTables(request);
110-
} else {
111-
ListTablesRequest request = ListTablesRequest.builder().exclusiveStartTableName(lastName).build();
112-
response = client.listTables(request);
105+
ListTablesRequest.Builder builder = ListTablesRequest.builder();
106+
if (Objects.nonNull(lastName)) {
107+
builder.exclusiveStartTableName(lastName);
113108
}
109+
ListTablesRequest request = builder.build();
110+
ListTablesResponse response = client.listTables(request);
114111

115112
List<String> tableNames = response.tableNames();
116113

117-
if (tableNames.size() == 0) {
118-
createTable(tableName, client, readCapacityUnits, writeCapacityUnit);
114+
if (tableNames.isEmpty()) {
115+
break;
119116
} else {
120-
lastName = response.lastEvaluatedTableName();
121-
if (lastName == null) {
122-
hasTable = false;
117+
if (tableNames.contains(tableName)) {
118+
hasTable = true;
119+
break;
123120
}
121+
Collections.reverse(tableNames);
122+
lastName = tableNames.stream().findFirst().get();
124123
}
125124
} catch (DynamoDbException e) {
126125
throw new RuntimeException(e);
127126
}
128127
}
128+
if (!hasTable) {
129+
createTable(tableName, client, readCapacityUnits, writeCapacityUnit);
130+
}
129131
}
130132

131133
private static void createTable(String tableName, DynamoDbClient client, Long readCapacityUnits, Long writeCapacityUnit) {

0 commit comments

Comments
 (0)