public AttributeDefinition unmarshall(JsonUnmarshallerContext context) throws Exception { AttributeDefinition attributeDefinition = new AttributeDefinition();
private void runTest(AmazonDynamoDB client) { CreateTableRequest request = new CreateTableRequest() .withAttributeDefinitions(new AttributeDefinition( "Name", ScalarAttributeType.S)) .withKeySchema(new KeySchemaElement("Name", KeyType.HASH)) .withProvisionedThroughput(new ProvisionedThroughput( new Long(10), new Long(10))) .withTableName("foo"); client.createTable(request); final TableDescription tableDescription = client.describeTable("foo").getTable(); assertNotNull("the description is not null", tableDescription); assertEquals("the table has the right name", "foo", tableDescription.getTableName()); assertEquals("the name has the right primary key", "Name", tableDescription.getKeySchema().get(0).getAttributeName()); } }
@Override public <T> CreateTableRequest generateCreateTableRequest(Class<T> clazz, DynamoDBMapperConfig config) { config = mergeConfig(config); final DynamoDBMapperTableModel<T> model = getTableModel(clazz, config); final CreateTableRequest request = new CreateTableRequest(); request.setTableName(getTableName(clazz, config)); request.withKeySchema(new KeySchemaElement(model.hashKey().name(), HASH)); if (model.rangeKeyIfExists() != null) { request.withKeySchema(new KeySchemaElement(model.rangeKey().name(), RANGE)); } request.setGlobalSecondaryIndexes(model.globalSecondaryIndexes()); request.setLocalSecondaryIndexes(model.localSecondaryIndexes()); for (final DynamoDBMapperFieldModel<T,Object> field : model.fields()) { if (field.keyType() != null || field.indexed()) { request.withAttributeDefinitions(new AttributeDefinition() .withAttributeType(ScalarAttributeType.valueOf(field.attributeType().name())) .withAttributeName(field.name()) ); } } return request; }
private static AttributeDefinition getKeyAttributeDefinition( Method keyGetter, ItemConverter converter) { final DynamoDBMapperFieldModel fieldModel = converter.getFieldModel(keyGetter); final String keyAttrName = fieldModel.getDynamoDBAttributeName(); final DynamoDBAttributeType keyType = fieldModel.getDynamoDBAttributeType(); if (keyType == DynamoDBAttributeType.S || keyType == DynamoDBAttributeType.N || keyType == DynamoDBAttributeType.B) { return new AttributeDefinition(keyAttrName, keyType.toString()); } throw new DynamoDBMappingException( "The key attribute must be in a scalar type " + "(String, Number or Binary)."); }
attributeDefinitions.add( new AttributeDefinition() .withAttributeName("ServiceID") .withAttributeType(ScalarAttributeType.N), new AttributeDefinition() .withAttributeName("ServiceName") .withAttributeType(ScalarAttributeType.S), ... );
import scala.collection.JavaConversions._ var attrDefs = Vector(new AttributeDefinition(), new AttributeDefinition()) request.setAttributeDefinitions(attrDefs)
public AttributeDefinition unmarshall(JsonUnmarshallerContext context) throws Exception { AwsJsonReader reader = context.getReader(); if (!reader.isContainer()) { reader.skipValue(); return null; } AttributeDefinition attributeDefinition = new AttributeDefinition(); reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("AttributeName")) { attributeDefinition.setAttributeName(StringJsonUnmarshaller.getInstance() .unmarshall(context)); } else if (name.equals("AttributeType")) { attributeDefinition.setAttributeType(StringJsonUnmarshaller.getInstance() .unmarshall(context)); } else { reader.skipValue(); } } reader.endObject(); return attributeDefinition; }
import scala.collection.JavaConverters._ var attrDefs = Vector(new AttributeDefinition(), new AttributeDefinition()) request.setAttributeDefinitions(attrDefs.asJavaCollection)
import collection.convert.wrapAsScala._ var attrDefs = Vector(new AttributeDefinition(), new AttributeDefinition()) request.setAttributeDefinitions(attrDefs)
attributeDefinitions.add(new AttributeDefinition() .withAttributeName("ServiceID") .withAttributeType(ScalarAttributeType.N));
/** * Returns the attribute definitions for the DynamoDB table. * * @return DynamoDB attribute definitions */ static Collection<AttributeDefinition> attributeDefinitions() { return Arrays.asList( new AttributeDefinition(PARENT, ScalarAttributeType.S), new AttributeDefinition(CHILD, ScalarAttributeType.S)); }
private void autoCreateTableIfNotExists() { if (autoCreateTable) { AttributeDefinition partitionKeyDefinition = new AttributeDefinition() .withAttributeName(partitionKeyName) .withAttributeType(ScalarAttributeType.S); KeySchemaElement partitionKeySchema = new KeySchemaElement() .withAttributeName(partitionKeyName) .withKeyType(KeyType.HASH); ProvisionedThroughput throughput = new ProvisionedThroughput() .withReadCapacityUnits(5L) .withWriteCapacityUnits(5L); try { TableUtils.createTableIfNotExists(dynamoDb, new CreateTableRequest() .withTableName(tableName) .withAttributeDefinitions(partitionKeyDefinition) .withKeySchema(partitionKeySchema) .withProvisionedThroughput(throughput)); } catch (AmazonDynamoDBException e) { throw new PersistenceException("Create table request failed", e); } } }
/** * Creates a DynamoDB Table with the correct properties to be used with a ProviderStore. */ public static CreateTableResult createTable(final AmazonDynamoDB ddb, final String tableName, final ProvisionedThroughput provisionedThroughput) { return ddb.createTable(Arrays.asList(new AttributeDefinition(DEFAULT_HASH_KEY, ScalarAttributeType.S), new AttributeDefinition(DEFAULT_RANGE_KEY, ScalarAttributeType.N)), tableName, Arrays.asList(new KeySchemaElement( DEFAULT_HASH_KEY, KeyType.HASH), new KeySchemaElement(DEFAULT_RANGE_KEY, KeyType.RANGE)), provisionedThroughput); }
@Override public Collection<AttributeDefinition> getAttributeDefinitions() { List<AttributeDefinition> definitions = new ArrayList<AttributeDefinition>(); definitions.add(new AttributeDefinition().withAttributeName(LEASE_KEY_KEY) .withAttributeType(ScalarAttributeType.S)); return definitions; } }
@Override public CreateTableResult createTable(String tableName, String hashKeyName) { List<AttributeDefinition> attributeDefinitions = new ArrayList<>(); attributeDefinitions.add(new AttributeDefinition(hashKeyName, ScalarAttributeType.S)); List<KeySchemaElement> ks = new ArrayList<>(); ks.add(new KeySchemaElement(hashKeyName, KeyType.HASH)); ProvisionedThroughput provisionedthroughput = new ProvisionedThroughput(this.readCapacityUnits, this.writeCapacityUnits); CreateTableRequest request = new CreateTableRequest() .withTableName(tableName) .withAttributeDefinitions(attributeDefinitions) .withKeySchema(ks) .withProvisionedThroughput(provisionedthroughput); return amazonDynamoDB.createTable(request); }
private boolean createTable(final String qName, final boolean dataIndexTable) { return createTable( qName, dataIndexTable ? () -> new CreateTableRequest().withTableName(qName).withAttributeDefinitions( new AttributeDefinition( DynamoDBRow.GW_PARTITION_ID_KEY, ScalarAttributeType.B)).withKeySchema( new KeySchemaElement(DynamoDBRow.GW_PARTITION_ID_KEY, KeyType.HASH)) : () -> new CreateTableRequest().withTableName(qName).withAttributeDefinitions( new AttributeDefinition(DynamoDBRow.GW_PARTITION_ID_KEY, ScalarAttributeType.B), new AttributeDefinition( DynamoDBRow.GW_RANGE_KEY, ScalarAttributeType.B)).withKeySchema( new KeySchemaElement(DynamoDBRow.GW_PARTITION_ID_KEY, KeyType.HASH), new KeySchemaElement(DynamoDBRow.GW_RANGE_KEY, KeyType.RANGE))); }
@Override public CreateTableRequest getTableSchema() { return super.getTableSchema() .withAttributeDefinitions( new AttributeDefinition() .withAttributeName(Constants.JANUSGRAPH_HASH_KEY) .withAttributeType(ScalarAttributeType.S)) .withKeySchema( new KeySchemaElement() .withAttributeName(Constants.JANUSGRAPH_HASH_KEY) .withKeyType(KeyType.HASH)); }
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(); }
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(); }
public static void createSessionTable(AmazonDynamoDBClient dynamo, String tableName, long readCapacityUnits, long writeCapacityUnits) { CreateTableRequest request = new CreateTableRequest().withTableName(tableName); request.withKeySchema(new KeySchemaElement().withAttributeName(DynamoSessionItem.SESSION_ID_ATTRIBUTE_NAME) .withKeyType(KeyType.HASH)); request.withAttributeDefinitions( new AttributeDefinition().withAttributeName(DynamoSessionItem.SESSION_ID_ATTRIBUTE_NAME) .withAttributeType(ScalarAttributeType.S)); request.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(readCapacityUnits) .withWriteCapacityUnits(writeCapacityUnits)); dynamo.createTable(request); }