Search in sources :

Example 11 with ResourceNotFoundException

use of com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException in project gora by apache.

the class GoraDynamoDBTestDriver method checkResource.

/**
   * Checks if a resource exists or not
   * 
   * @param tableName
   *          Table name to be checked
   * @return
   */
public TableDescription checkResource(String tableName) {
    TableDescription tableDescription = null;
    try {
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        tableDescription = dynamoDBClient.describeTable(describeTableRequest).getTable();
    } catch (ResourceNotFoundException e) {
        tableDescription = null;
    }
    return tableDescription;
}
Also used : DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription)

Example 12 with ResourceNotFoundException

use of com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException in project aws-doc-sdk-examples by awsdocs.

the class UpdateItem method main.

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);
    }
    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 AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
    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!");
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) AttributeValueUpdate(com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) AmazonServiceException(com.amazonaws.AmazonServiceException) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Aggregations

ResourceNotFoundException (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)11 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)7 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 HashMap (java.util.HashMap)3 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)2 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 AmazonClientException (com.amazonaws.AmazonClientException)1 Table (com.amazonaws.services.dynamodbv2.document.Table)1 AttributeValueUpdate (com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate)1 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)1 DeleteTableRequest (com.amazonaws.services.dynamodbv2.model.DeleteTableRequest)1 DescribeTableResult (com.amazonaws.services.dynamodbv2.model.DescribeTableResult)1 GlobalSecondaryIndex (com.amazonaws.services.dynamodbv2.model.GlobalSecondaryIndex)1 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)1 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)1 ProvisionedThroughputDescription (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputDescription)1 ResourceInUseException (com.amazonaws.services.dynamodbv2.model.ResourceInUseException)1