This is an automated email from the ASF dual-hosted git repository. kaspersor pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/metamodel.git
commit a08cae575dc63e2f06c8d55bd46e3858d91f6b69 Author: Kasper Sørensen <[email protected]> AuthorDate: Fri Feb 15 21:29:32 2019 -0800 Added the DynamoDB module to the `full` module. And created DC factory. --- dynamodb/pom.xml | 2 +- .../dynamodb/DynamoDbDataContextFactory.java | 58 ++++++++++++++++++++++ ...org.apache.metamodel.factory.DataContextFactory | 1 + full/pom.xml | 5 ++ 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/dynamodb/pom.xml b/dynamodb/pom.xml index 9d7e0dc..045d5e4 100644 --- a/dynamodb/pom.xml +++ b/dynamodb/pom.xml @@ -35,7 +35,7 @@ under the License. <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-dynamodb</artifactId> - <version>1.11.81</version> + <version>1.11.500</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> diff --git a/dynamodb/src/main/java/org/apache/metamodel/dynamodb/DynamoDbDataContextFactory.java b/dynamodb/src/main/java/org/apache/metamodel/dynamodb/DynamoDbDataContextFactory.java new file mode 100644 index 0000000..1e7273f --- /dev/null +++ b/dynamodb/src/main/java/org/apache/metamodel/dynamodb/DynamoDbDataContextFactory.java @@ -0,0 +1,58 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.metamodel.dynamodb; + +import org.apache.metamodel.DataContext; +import org.apache.metamodel.factory.AbstractDataContextFactory; +import org.apache.metamodel.factory.DataContextProperties; +import org.apache.metamodel.factory.ResourceFactoryRegistry; +import org.apache.metamodel.util.SimpleTableDef; + +import com.amazonaws.auth.AWSCredentialsProvider; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; +import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; +import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; + +public class DynamoDbDataContextFactory extends AbstractDataContextFactory { + + @Override + protected String getType() { + return "dynamodb"; + } + + @Override + public DataContext create(DataContextProperties properties, ResourceFactoryRegistry resourceFactoryRegistry) { + final AmazonDynamoDB client = + AmazonDynamoDBClientBuilder.standard().withCredentials(getCredentials(properties)).build(); + final SimpleTableDef[] tableDefs = properties.getTableDefs(); + return new DynamoDbDataContext(client, tableDefs); + } + + private AWSCredentialsProvider getCredentials(DataContextProperties properties) { + if (properties.getUsername() != null) { + final BasicAWSCredentials credentials = + new BasicAWSCredentials(properties.getUsername(), properties.getPassword()); + return new AWSStaticCredentialsProvider(credentials); + } else { + return DefaultAWSCredentialsProviderChain.getInstance(); + } + } +} diff --git a/dynamodb/src/main/resources/META-INF/services/org.apache.metamodel.factory.DataContextFactory b/dynamodb/src/main/resources/META-INF/services/org.apache.metamodel.factory.DataContextFactory new file mode 100644 index 0000000..dba2053 --- /dev/null +++ b/dynamodb/src/main/resources/META-INF/services/org.apache.metamodel.factory.DataContextFactory @@ -0,0 +1 @@ +org.apache.metamodel.dynamodb.DynamoDbDataContextFactory \ No newline at end of file diff --git a/full/pom.xml b/full/pom.xml index da78c7f..7ed94c7 100644 --- a/full/pom.xml +++ b/full/pom.xml @@ -167,6 +167,11 @@ under the License. </dependency> <dependency> <groupId>org.apache.metamodel</groupId> + <artifactId>MetaModel-dynamodb</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.metamodel</groupId> <artifactId>MetaModel-hbase</artifactId> <version>${project.version}</version> </dependency>
