public String verifyTableExists()

in src/main/java/com/amazonaws/services/dynamodbv2/util/TableHelper.java [35:80]


    public String verifyTableExists( 
        String tableName, 
        List<AttributeDefinition> definitions, 
        List<KeySchemaElement> keySchema,
        List<LocalSecondaryIndex> localIndexes) {
        
        DescribeTableResult describe = client.describeTable(new DescribeTableRequest().withTableName(tableName));
        if(! new HashSet<AttributeDefinition>(definitions).equals(new HashSet<AttributeDefinition>(describe.getTable().getAttributeDefinitions()))) {
            throw new ResourceInUseException("Table " + tableName + " had the wrong AttributesToGet." 
                + " Expected: " + definitions + " "
                + " Was: " + describe.getTable().getAttributeDefinitions());
        }
        
        if(! keySchema.equals(describe.getTable().getKeySchema())) {
            throw new ResourceInUseException("Table " + tableName + " had the wrong KeySchema." 
                + " Expected: " + keySchema + " "
                + " Was: " + describe.getTable().getKeySchema());
        }
        
        List<LocalSecondaryIndex> theirLSIs = null;
        if(describe.getTable().getLocalSecondaryIndexes() != null) {
            theirLSIs = new ArrayList<LocalSecondaryIndex>();
            for(LocalSecondaryIndexDescription description : describe.getTable().getLocalSecondaryIndexes()) {
                LocalSecondaryIndex lsi = new LocalSecondaryIndex()
                    .withIndexName(description.getIndexName())
                    .withKeySchema(description.getKeySchema())
                    .withProjection(description.getProjection());
                theirLSIs.add(lsi);
            }
        }
        
        if(localIndexes != null) {
            if(! new HashSet<LocalSecondaryIndex>(localIndexes).equals(new HashSet<LocalSecondaryIndex>(theirLSIs))) {
                throw new ResourceInUseException("Table " + tableName + " did not have the expected LocalSecondaryIndexes."
                    + " Expected: " + localIndexes
                    + " Was: " + theirLSIs);
            }
        } else {
            if(theirLSIs != null) {
                throw new ResourceInUseException("Table " + tableName + " had local secondary indexes, but expected none."
                    + " Indexes: " + theirLSIs);
            }
        }

        return describe.getTable().getTableStatus();
    }