List of usage examples for com.amazonaws.services.dynamodbv2.document DynamoDB createTable
public Table createTable(CreateTableRequest req)
From source file:io.venable.amazonaws.dynamo.table.builder.TableBuilder.java
License:Apache License
/** * Creates the table for the given {@link DynamoDB}. * * @param dynamoDB the {@link DynamoDB} instance * @return the {@link CreateTableResult} from the create request * @since 0.2//from w w w .ja va 2s. c o m */ public Table create(DynamoDB dynamoDB) { CreateTableRequest createTableRequest = buildCreateTableRequest(); return dynamoDB.createTable(createTableRequest); }
From source file:org.diksha.common.dyutils.SchedulerDynamoTable.java
License:Apache License
public void createDynamoTable(DynamoDB dynamoDB) { try {// w w w . j a va 2 s . com System.out.println(toString()); ArrayList<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>(); keySchema.add(new KeySchemaElement().withAttributeName(hashKeyName).withKeyType(KeyType.HASH)); ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>(); attributeDefinitions .add(new AttributeDefinition().withAttributeName(hashKeyName).withAttributeType(hashKeyType)); if (rangeKeyType != null) { if (!rangeKeyType.isEmpty()) { attributeDefinitions.add(new AttributeDefinition().withAttributeName(rangeKeyName) .withAttributeType(rangeKeyType)); } } if (additionalAttributes.size() > 0) { for (int cnt = 0; cnt < additionalAttributes.size(); cnt++) { String[] args = (additionalAttributes.get(cnt).toString()).split(":"); if (args.length == 2) { attributeDefinitions.add( new AttributeDefinition().withAttributeName(args[0]).withAttributeType(args[1])); } } } CreateTableRequest request = new CreateTableRequest().withTableName(tableName).withKeySchema(keySchema) .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(readCapacityUnits) .withWriteCapacityUnits(writeCapacityUnits)); ArrayList<LocalSecondaryIndex> localSecondaryIndexes = new ArrayList<LocalSecondaryIndex>(); ArrayList<GlobalSecondaryIndex> globalSecondaryIndexes = new ArrayList<GlobalSecondaryIndex>(); if (rangeKeyType != null) { if (!rangeKeyType.isEmpty()) { if (rangeKeyTypeGlobalOrLocal.equals("L")) { localSecondaryIndexes .add(new LocalSecondaryIndex().withIndexName(rangeKeyName + "-Index") .withKeySchema( new KeySchemaElement().withAttributeName(hashKeyName) .withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(rangeKeyName) .withKeyType(KeyType.RANGE)) .withProjection( new Projection().withProjectionType(ProjectionType.KEYS_ONLY))); } else { globalSecondaryIndexes .add(new GlobalSecondaryIndex().withIndexName(rangeKeyName + "-Index") .withKeySchema( new KeySchemaElement().withAttributeName(hashKeyName) .withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(rangeKeyName) .withKeyType(KeyType.RANGE)) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits(indexReadCapacityUnits) .withWriteCapacityUnits(indexWriteCapacityUnits)) .withProjection( new Projection().withProjectionType(ProjectionType.KEYS_ONLY))); } } } if (indices.size() > 0) { for (int cnt = 0; cnt < indices.size(); cnt++) { SchedulerDynamoTableIndex schedulerDynamoTableIndex = indices.get(cnt); if (schedulerDynamoTableIndex.isGlobal()) { // System.out.println("IS GLOBAL"); globalSecondaryIndexes.add(schedulerDynamoTableIndex.getGlobalSecondaryIndex()); // System.out.println("size = " + globalSecondaryIndexes.size()); } } } if (localSecondaryIndexes.size() > 0) request.setLocalSecondaryIndexes(localSecondaryIndexes); if (globalSecondaryIndexes.size() > 0) request.setGlobalSecondaryIndexes(globalSecondaryIndexes); request.setAttributeDefinitions(attributeDefinitions); System.out.println("Issuing CreateTable request for " + tableName); Table table = dynamoDB.createTable(request); System.out.println("Waiting for " + tableName + " to be created...this may take a while..."); table.waitForActive(); } catch (Exception e) { System.err.println("CreateTable request failed for " + tableName); System.err.println(e.getMessage()); } }
From source file:org.wildfly.camel.test.common.aws.DynamoDBUtils.java
License:Apache License
public static TableDescription createTable(AmazonDynamoDB client, String tableName) throws InterruptedException { CreateTableRequest tableReq = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement("Id", KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition("Id", ScalarAttributeType.N)) .withProvisionedThroughput(new ProvisionedThroughput(10L, 10L)) .withStreamSpecification(new StreamSpecification().withStreamEnabled(true) .withStreamViewType(StreamViewType.NEW_AND_OLD_IMAGES)); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.createTable(tableReq); return table.waitForActive(); }