Example usage for com.amazonaws.services.dynamodbv2.model ResourceNotFoundException getMessage

List of usage examples for com.amazonaws.services.dynamodbv2.model ResourceNotFoundException getMessage

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.model ResourceNotFoundException getMessage.

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:aws.example.dynamodb.PutItem.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    PutItem <table> <name> [field=value ...]\n\n" + "Where:\n"
            + "    table    - the table to put the item in.\n"
            + "    name     - a name to add to the table. If the name already\n"
            + "               exists, its entry will be updated.\n"
            + "Additional fields can be added by appending them to the end of the\n" + "input.\n\n"
            + "Example:\n" + "    PutItem Cellists Pau Language=ca Born=1876\n";

    if (args.length < 2) {
        System.out.println(USAGE);
        System.exit(1);/*from  w  w  w.  j a v  a2 s .c o  m*/
    }

    String table_name = args[0];
    String name = args[1];
    ArrayList<String[]> extra_fields = new ArrayList<String[]>();

    // any additional args (fields to add to database)?
    for (int x = 2; x < args.length; x++) {
        String[] fields = args[x].split("=", 2);
        if (fields.length == 2) {
            extra_fields.add(fields);
        } else {
            System.out.format("Invalid argument: %s\n", args[x]);
            System.out.println(USAGE);
            System.exit(1);
        }
    }

    System.out.format("Adding \"%s\" to \"%s\"", name, table_name);
    if (extra_fields.size() > 0) {
        System.out.println("Additional fields:");
        for (String[] field : extra_fields) {
            System.out.format("  %s: %s\n", field[0], field[1]);
        }
    }

    HashMap<String, AttributeValue> item_values = new HashMap<String, AttributeValue>();

    item_values.put("Name", new AttributeValue(name));

    for (String[] field : extra_fields) {
        item_values.put(field[0], new AttributeValue(field[1]));
    }

    final AmazonDynamoDBClient ddb = new AmazonDynamoDBClient();

    try {
        ddb.putItem(table_name, item_values);
    } catch (ResourceNotFoundException e) {
        System.err.format("Error: The table \"%s\" can't be found.\n", table_name);
        System.err.println("Be sure that it exists and that you've typed its name correctly!");
        System.exit(1);
    } catch (AmazonServiceException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}

From source file:aws.example.dynamodb.UpdateItem.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    UpdateItem <table> <name> <greeting>\n\n" + "Where:\n"
            + "    table    - the table to put the item in.\n"
            + "    name     - a name to update in the table. The name must exist,\n"
            + "               or an error will result.\n"
            + "Additional fields can be specified by appending them to the end of the\n" + "input.\n\n"
            + "Examples:\n" + "    UpdateItem SiteColors text default=000000 bold=b22222\n"
            + "    UpdateItem SiteColors background default=eeeeee code=d3d3d3\n\n";

    if (args.length < 3) {
        System.out.println(USAGE);
        System.exit(1);/*from   w  w  w.j a va  2 s . co  m*/
    }

    String table_name = args[0];
    String name = args[1];
    ArrayList<String[]> extra_fields = new ArrayList<String[]>();

    // any additional args (fields to add or update)?
    for (int x = 2; x < args.length; x++) {
        String[] fields = args[x].split("=", 2);
        if (fields.length == 2) {
            extra_fields.add(fields);
        } else {
            System.out.format("Invalid argument: %s\n", args[x]);
            System.out.println(USAGE);
            System.exit(1);
        }
    }

    System.out.format("Updating \"%s\" in %s\n", name, table_name);
    if (extra_fields.size() > 0) {
        System.out.println("Additional fields:");
        for (String[] field : extra_fields) {
            System.out.format("  %s: %s\n", field[0], field[1]);
        }
    }

    HashMap<String, AttributeValue> item_key = new HashMap<String, AttributeValue>();

    item_key.put("Name", new AttributeValue(name));

    HashMap<String, AttributeValueUpdate> updated_values = new HashMap<String, AttributeValueUpdate>();

    for (String[] field : extra_fields) {
        updated_values.put(field[0],
                new AttributeValueUpdate(new AttributeValue(field[1]), AttributeAction.PUT));
    }

    final AmazonDynamoDBClient ddb = new AmazonDynamoDBClient();

    try {
        ddb.updateItem(table_name, item_key, updated_values);
    } catch (ResourceNotFoundException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    } catch (AmazonServiceException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}

From source file:io.milton.s3.db.DynamoDBServiceImpl.java

License:Open Source License

/**
 * Retrieves information about the table, including the current status of
 * the table, the primary key schema and when the table was created.
 * //from ww w .  ja  v a2 s  .  c o  m
 * If the table does not exist, Amazon DynamoDB returns a
 * ResourceNotFoundException.
 * 
 * @param tableName
 *            - The name of the table
 * @return The response from the DescribeTable service method, as returned by AmazonDynamoDB
 */
private TableDescription describeTable(String tableName) {
    try {
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = dynamoDBClient.describeTable(describeTableRequest).getTable();
        if (tableDescription != null) {
            LOG.info("Table description of " + tableName + ": " + tableDescription);
        }
        return tableDescription;
    } catch (ResourceNotFoundException rnfe) {
        LOG.warn(rnfe.getMessage());
    }
    return null;
}

From source file:main.java.ddb.loader.DDBLoaderUtils.java

License:Apache License

static boolean isTableExist() {
    try {//from   ww  w  . j  a va2s  . c  om
        return TableStatus.ACTIVE.toString().equals(describeTable().getTableStatus());

    } catch (ResourceNotFoundException e) {
        DDBSampleLoader.log.error("Caught an ResourceNotFoundException ...");
        DDBSampleLoader.log.error("Error Message: " + e.getMessage());

        return false;
    }
}