Package com.amazonaws.services.dynamodbv2.model

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


        CreateTableRequest createTableRequest = new CreateTableRequest();
        createTableRequest.setTableName(DynamoDBMapper.internalGetTableName(clazz, null, config));

        // 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 ) {
            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

        request.withKeySchema(new KeySchemaElement()
            .withAttributeName(SessionTableAttributes.SESSION_ID_KEY)
            .withKeyType(KeyType.HASH));

        request.withAttributeDefinitions(new AttributeDefinition()
            .withAttributeName(SessionTableAttributes.SESSION_ID_KEY)
            .withAttributeType(ScalarAttributeType.S));

        request.setProvisionedThroughput(new ProvisionedThroughput()
            .withReadCapacityUnits(readCapacityUnits)
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

        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 ) {
            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

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.