Package com.amazonaws.services.dynamodbv2.model

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


    @Test
    public void howToCreateTable() throws InterruptedException {
        String TABLE_NAME = "myTableForMidLevelApi";
        Table table = dynamo.getTable(TABLE_NAME);
        // check if table already exists, and if so wait for it to become active
        TableDescription desc = table.waitForActiveOrDelete();
        if (desc != null) {
            System.out.println("Skip creating table which already exists and ready for use: "
                    + desc);
            return;
        }
View Full Code Here


     */
    private static boolean tableHasCorrectSchema(AmazonDynamoDBClient client, String tableName, String key) {
        DescribeTableRequest describeTableRequest = new DescribeTableRequest();
        describeTableRequest.setTableName(tableName);
        DescribeTableResult describeTableResult = client.describeTable(describeTableRequest);
        TableDescription tableDescription = describeTableResult.getTable();
        if (tableDescription.getAttributeDefinitions().size() != 1) {
            LOG.error("The number of attribute definitions does not match the existing table.");
            return false;
        }
        AttributeDefinition attributeDefinition = tableDescription.getAttributeDefinitions().get(0);
        if (!attributeDefinition.getAttributeName().equals(key)
                || !attributeDefinition.getAttributeType().equals(ScalarAttributeType.S.toString())) {
            LOG.error("Attribute name or type does not match existing table.");
            return false;
        }
        List<KeySchemaElement> KSEs = tableDescription.getKeySchema();
        if (KSEs.size() != 1) {
            LOG.error("The number of key schema elements does not match the existing table.");
            return false;
        }
        KeySchemaElement kse = KSEs.get(0);
View Full Code Here

     * A convenient blocking call that can be used, typically during table
     * creation, to wait for the table to become active by polling the table
     * every 5 seconds.
     */
    public TableDescription waitForActive() throws InterruptedException {
        TableDescription desc = describe();
        String status = desc.getTableStatus();
        for (;; status = desc.getTableStatus()) {
            if ("ACTIVE".equals(status))
                return desc;
            if ("CREATING".equals(status) || "UPDATING".equals(status)) {
                Thread.sleep(SLEEP_TIME_MILLIS);
                desc = describe();
View Full Code Here

     * deletion, to wait for the table to become deleted by polling the table
     * every 5 seconds.
     */
    public void waitForDelete() throws InterruptedException {
        try {
            TableDescription desc = describe();
            String status = desc.getTableStatus();
            for (;; status = desc.getTableStatus()) {
                if ("DELETING".equals(status)) {
                    Thread.sleep(SLEEP_TIME_MILLIS);
                    desc = describe();
                    continue;
                }
View Full Code Here

     * @return the table description if the table has become active; or null if
     *         the table has been deleted (or has never exists.);
     */
    public TableDescription waitForActiveOrDelete() throws InterruptedException {
        try {
            TableDescription desc = describe();
            String status = desc.getTableStatus();
            for (;; status = desc.getTableStatus()) {
                if ("ACTIVE".equals(status))
                    return desc;
                if ("CREATING".equals(status)
                ||  "UPDATING".equals(status)
                ||  "DELETING".equals(status)) {
View Full Code Here

    }

    @Override
    public int getSize() throws IOException {
        // The item count from describeTable is updated every ~6 hours
        TableDescription table = dynamo.describeTable(new DescribeTableRequest().withTableName(sessionTableName)).getTable();
        long itemCount = table.getItemCount();

        return (int)itemCount;
    }
View Full Code Here

    public static boolean doesTableExist(AmazonDynamoDBClient dynamo, String tableName) {
        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            addClientMarker(request);

            TableDescription table = dynamo.describeTable(request).getTable();
            if (table == null) return false;
            else return true;
        } catch (AmazonServiceException ase) {
            if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException")) return false;
            else throw ase;
View Full Code Here

        while (System.currentTimeMillis() < endTime) {
            try {
                DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
                addClientMarker(request);

                TableDescription tableDescription = dynamo.describeTable(request).getTable();
                if (tableDescription == null) continue;

                String tableStatus = tableDescription.getTableStatus();
                if (tableStatus.equals(TableStatus.ACTIVE.toString())) return;
            } catch (AmazonServiceException ase) {
                if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == false)
                    throw ase;
            }
View Full Code Here

     * @return True if a table already exists with the specified name, otherwise
     *         false.
     */
    public static boolean doesTableExist(AmazonDynamoDB dynamo, String tableName) {
        try {
            TableDescription table = dynamo.describeTable(new DescribeTableRequest(tableName)).getTable();
            return TableStatus.ACTIVE.toString().equals(table.getTableStatus());
        } catch (ResourceNotFoundException rnfe) {
            // This means the table doesn't exist in the account yet
            return false;
        }
    }
View Full Code Here

        throw new AmazonClientException("Interval must be > 0 and < timeout");
        long startTime = System.currentTimeMillis();
        long endTime = startTime + timeout;
        while (System.currentTimeMillis() < endTime) {
            try {
                TableDescription table = dynamo.describeTable(new DescribeTableRequest(tableName)).getTable();
                if (table != null && table.getTableStatus().equals(TableStatus.ACTIVE.toString()))
                    return;
            } catch (ResourceNotFoundException rnfe) {
                // ResourceNotFound means the table doesn't exist yet,
                // so ignore this error and just keep polling.
            }
View Full Code Here

TOP

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

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.