Package com.amazonaws.services.dynamodbv2.model

Examples of com.amazonaws.services.dynamodbv2.model.AttributeDefinition


      return false;
    }
    try {
      getClient().createTable(new CreateTableRequest().withTableName(appid).
          withKeySchema(new KeySchemaElement(Config._KEY, KeyType.HASH)).
          withAttributeDefinitions(new AttributeDefinition().withAttributeName(Config._KEY).
          withAttributeType(ScalarAttributeType.S)).
          withProvisionedThroughput(new ProvisionedThroughput(readCapacity, writeCapacity)));
    } catch (Exception e) {
      logger.error(null, e);
      return false;
View Full Code Here


        CreateTableRequest createTableRequest = new CreateTableRequest();
        createTableRequest.setTableName(DynamoDBMapper.getTableName(clazz, config, reflector));

        // Primary keys
        Method pHashKeyGetter = reflector.getPrimaryHashKeyGetter(clazz);
        AttributeDefinition pHashAttrDefinition = getKeyAttributeDefinition(pHashKeyGetter, reflector);
        createTableRequest.withKeySchema(new KeySchemaElement(pHashAttrDefinition.getAttributeName(), KeyType.HASH));
        // Primary range
        Method pRangeKeyGetter = reflector.getPrimaryRangeKeyGetter(clazz);
        AttributeDefinition pRangeAttrDefinition = null;
        if (pRangeKeyGetter != null) {
            pRangeAttrDefinition = getKeyAttributeDefinition(pRangeKeyGetter, reflector);
            createTableRequest.withKeySchema(new KeySchemaElement(pRangeAttrDefinition.getAttributeName(), KeyType.RANGE));
        }

        // Parse the index schema
        TableIndexesInfo indexesInfo = parseTableIndexes(clazz, reflector);
        if ( indexesInfo.getGlobalSecondaryIndexes().isEmpty() == false ) {
            createTableRequest.setGlobalSecondaryIndexes(indexesInfo.getGlobalSecondaryIndexes());
        }
        if ( indexesInfo.getLocalSecondaryIndexes().isEmpty() == false ) {
            // Add the primary hash key element into each LSI
            for (LocalSecondaryIndex lsi : indexesInfo.getLocalSecondaryIndexes()) {
                lsi.withKeySchema(new KeySchemaElement(pHashAttrDefinition.getAttributeName(), KeyType.HASH));
            }
            createTableRequest.setLocalSecondaryIndexes(indexesInfo.getLocalSecondaryIndexes());
        }

        // Aggregate all key attribute definitions
        Map<String, AttributeDefinition> attrDefinitions = new HashMap<String, AttributeDefinition>();
        // Hash key definition
        putAfterCheckConflict(attrDefinitions, pHashAttrDefinition);
        // Range key definition
        if (pRangeKeyGetter != null) {
            putAfterCheckConflict(attrDefinitions, pRangeAttrDefinition);
        }
        for (Method indexKeyGetter : indexesInfo.getIndexKeyGetters()) {
            AttributeDefinition indexKeyAttrDefinition = getKeyAttributeDefinition(indexKeyGetter, reflector);
            putAfterCheckConflict(attrDefinitions, indexKeyAttrDefinition);
        }
        createTableRequest.setAttributeDefinitions(attrDefinitions.values());

        return createTableRequest;
View Full Code Here

    private static AttributeDefinition getKeyAttributeDefinition(Method keyGetter, final DynamoDBReflector reflector) {
        String keyAttrName = reflector.getAttributeName(keyGetter);
        ArgumentMarshaller marshaller = reflector.getArgumentMarshaller(keyGetter);

        if (marshaller instanceof StringAttributeMarshaller) {
            return new AttributeDefinition(keyAttrName, ScalarAttributeType.S);
        } else if (marshaller instanceof NumberAttributeMarshaller) {
            return new AttributeDefinition(keyAttrName, ScalarAttributeType.N);
        } else if (marshaller instanceof BinaryAttributeMarshaller) {
            return new AttributeDefinition(keyAttrName, ScalarAttributeType.B);
        }

        throw new DynamoDBMappingException("The key attribute must be in a scalar type (String, Number or Binary).");
    }
View Full Code Here

    }

    private static void putAfterCheckConflict(Map<String, AttributeDefinition> map,
                                              AttributeDefinition attrDefinition) {
        String attrName = attrDefinition.getAttributeName();
        AttributeDefinition existingDefinition = map.get(attrName);
        if (existingDefinition != null && !existingDefinition.equals(attrDefinition)) {
            throw new DynamoDBMappingException(
                    "Found conflicting definitions for attribute [" + attrName + "]: " +
                    existingDefinition + " and " + attrDefinition + ".");
        } else {
            map.put(attrName, attrDefinition);
View Full Code Here

    private String hashKeyName2;

    @Before
    public void setUp() throws Exception {
        tableName1 = createTableName();
        AttributeDefinition hashAttr1 = createNumberAttributeDefinition();
        TableDescription tableDescription1 = createTable(tableName1, hashAttr1);
        hashKeyName1 = getHashKeyElement(tableDescription1.getKeySchema()).getAttributeName();

        tableName2 = createTableName();
        AttributeDefinition hashAttr2 = createNumberAttributeDefinition();
        TableDescription tableDescription2 = createTable(tableName2, hashAttr2);
        hashKeyName2 = getHashKeyElement(tableDescription2.getKeySchema()).getAttributeName();
    }
View Full Code Here

        Assert.assertNotNull(res.getConsumedCapacity().getCapacityUnits());
    }

    @Test
    public void deleteItemWithHashKeyAndRangeKey() {
        AttributeDefinition hashAttr = createStringAttributeDefinition("id");
        AttributeDefinition rangeAttr = createNumberAttributeDefinition("range");
        createTable(tableName, hashAttr, rangeAttr);

        AttributeValue hash = new AttributeValue("ad");
        AttributeValue range1 = new AttributeValue().withN("1");
        AttributeValue range2 = new AttributeValue().withN("2");
View Full Code Here

  protected AttributeDefinition createAttributeDefinition(
            String name,
            ScalarAttributeType type) {

    AttributeDefinition attr = new AttributeDefinition();
    attr.setAttributeName(name);
    attr.setAttributeType(type);
    return attr;
  }
View Full Code Here

    protected void createGenericTable(String tableName) {
        createGenericTable(tableName, "id");
    }

    protected void createGenericTable(String tableName, String hashKeyName) {
        AttributeDefinition hashAttr = createStringAttributeDefinition(hashKeyName);
        createTable(tableName, hashAttr);
    }
View Full Code Here

    protected void createGenericHashRangeTable(String tableName) {
        createGenericHashRangeTable(tableName, "id", "range");
    }

    protected void createGenericHashRangeTable(String tableName, String hashKeyName, String rangeKeyName) {
        AttributeDefinition hashAttr = createStringAttributeDefinition(hashKeyName);
        AttributeDefinition rangeAttr = createStringAttributeDefinition(rangeKeyName);
        createTable(tableName, hashAttr, rangeAttr);
    }
View Full Code Here

    }
  }

  @Test
  public void createTableWithSameHashAndRangeKey() {
    AttributeDefinition attr = createStringAttributeDefinition();
    try {
      createTable(createTableName(), attr, attr);
      Assert.assertTrue(false);// Should have thrown an exception
    } catch (AmazonServiceException ase) {
    }
View Full Code Here

TOP

Related Classes of com.amazonaws.services.dynamodbv2.model.AttributeDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.