|
| 1 | +/* |
| 2 | + * Copyright (c) 2017 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 | + |
| 16 | +package org.jnosql.diana.dynamodb; |
| 17 | + |
| 18 | +import java.net.URI; |
| 19 | + |
| 20 | +import org.jnosql.diana.api.Settings; |
| 21 | + |
| 22 | +import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; |
| 23 | +import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClientBuilder; |
| 24 | +import software.amazon.awssdk.services.dynamodb.DynamoDbClient; |
| 25 | +import software.amazon.awssdk.services.dynamodb.DynamoDbClientBuilder; |
| 26 | + |
| 27 | + |
| 28 | +public class DynamoDBConfiguration { |
| 29 | + |
| 30 | + protected DynamoDbClientBuilder builder = DynamoDbClient.builder(); |
| 31 | + protected DynamoDbAsyncClientBuilder builderAsync = DynamoDbAsyncClient.builder(); |
| 32 | + |
| 33 | + |
| 34 | + public void syncBuilder(DynamoDbClientBuilder builder) throws NullPointerException { |
| 35 | + //requireNonNull(builder, "builder is required"); |
| 36 | + this.builder = builder; |
| 37 | + } |
| 38 | + |
| 39 | + public void asyncBuilder(DynamoDbAsyncClientBuilder builderAsync) throws NullPointerException{ |
| 40 | +// requireNonNull(builderAsync, "asyncBuilder is required"); |
| 41 | + this.builderAsync = builderAsync; |
| 42 | + } |
| 43 | + |
| 44 | + public void setEndPoint(String endpoint) { |
| 45 | + builder.endpointOverride(URI.create(endpoint)); |
| 46 | + builderAsync.endpointOverride(URI.create(endpoint)); |
| 47 | + } |
| 48 | + |
| 49 | + protected DynamoDbClient getDynamoDB(Settings settings) { |
| 50 | + DynamoDBBuilderSync dynamoDB = new DynamoDBBuilderSync(); |
| 51 | + DynamoDBBuilders.load(settings, dynamoDB); |
| 52 | + return dynamoDB.build(); |
| 53 | + } |
| 54 | + |
| 55 | + protected DynamoDbAsyncClient getDynamoDBAsync(Settings settings) { |
| 56 | + DynamoDBBuilderASync dynamoDB = new DynamoDBBuilderASync(); |
| 57 | + DynamoDBBuilders.load(settings, dynamoDB); |
| 58 | + return dynamoDB.build(); |
| 59 | + } |
| 60 | +} |
0 commit comments