Example usage for com.amazonaws.services.dynamodbv2.model KeyType HASH

List of usage examples for com.amazonaws.services.dynamodbv2.model KeyType HASH

Introduction

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

Prototype

KeyType HASH

To view the source code for com.amazonaws.services.dynamodbv2.model KeyType HASH.

Click Source Link

Usage

From source file:com.rapid7.diskstorage.dynamodb.DynamoDBSingleRowStore.java

License:Open Source License

public static final CreateTableRequest createTableRequest(String tableName, long rcu, long wcu) {
    return new CreateTableRequest()
            .withAttributeDefinitions(new AttributeDefinition().withAttributeName(Constants.TITAN_HASH_KEY)
                    .withAttributeType(ScalarAttributeType.S))
            .withKeySchema(new KeySchemaElement().withAttributeName(Constants.TITAN_HASH_KEY)
                    .withKeyType(KeyType.HASH))
            .withTableName(tableName).withProvisionedThroughput(
                    new ProvisionedThroughput().withReadCapacityUnits(rcu).withWriteCapacityUnits(wcu));
}

From source file:com.rapid7.diskstorage.dynamodb.DynamoDBStore.java

License:Open Source License

public static final CreateTableRequest createTableRequest(String tableName, long rcu, long wcu) {
    CreateTableRequest req = new CreateTableRequest()
            .withAttributeDefinitions(/*from www .j av a  2s . c om*/
                    new AttributeDefinition().withAttributeName(Constants.TITAN_HASH_KEY)
                            .withAttributeType(ScalarAttributeType.S),
                    new AttributeDefinition().withAttributeName(Constants.TITAN_RANGE_KEY)
                            .withAttributeType(ScalarAttributeType.S))
            .withKeySchema(
                    new KeySchemaElement().withAttributeName(Constants.TITAN_HASH_KEY)
                            .withKeyType(KeyType.HASH),
                    new KeySchemaElement().withAttributeName(Constants.TITAN_RANGE_KEY)
                            .withKeyType(KeyType.RANGE))
            .withTableName(tableName).withProvisionedThroughput(
                    new ProvisionedThroughput().withReadCapacityUnits(rcu).withWriteCapacityUnits(wcu));
    return req;
}

From source file:com.rss.common.AWSDetails.java

License:Apache License

public static void main(String[] args) {
    String queueUrl = SQS.createQueue(new CreateQueueRequest(SQS_QUEUE_NAME)).getQueueUrl();
    System.out.println("Using Amazon SQS Queue: " + queueUrl);

    String publisherQueueUrl = SQS.createQueue(new CreateQueueRequest(SQS_PUBLISHER_QUEUE)).getQueueUrl();
    System.out.println("Using Amazon SQS Queue: " + publisherQueueUrl);

    String webserviceRequestQueueUrl = SQS.createQueue(new CreateQueueRequest(SQS_WEBSERVICE_REQUEST_QUEUE))
            .getQueueUrl();/*  w ww.ja va 2  s. com*/
    System.out.println("Using Amazon SQS Queue: " + webserviceRequestQueueUrl);

    if (!Tables.doesTableExist(DYNAMODB, JOBREQUEST_TABLE_NAME)) {
        System.out.println("Creating job request table...");
        DYNAMODB.createTable(new CreateTableRequest().withTableName(JOBREQUEST_TABLE_NAME)
                .withKeySchema(new KeySchemaElement("id", KeyType.HASH))
                .withAttributeDefinitions(new AttributeDefinition("id", ScalarAttributeType.S))
                .withProvisionedThroughput(new ProvisionedThroughput(50l, 50l)));
    }
    if (!Tables.doesTableExist(DYNAMODB, FEEDURL_REQUEST_TABLE_NAME)) {
        System.out.println("Creating feed url request table...");
        DYNAMODB.createTable(new CreateTableRequest().withTableName(FEEDURL_REQUEST_TABLE_NAME)
                .withKeySchema(new KeySchemaElement("id", KeyType.HASH))
                .withAttributeDefinitions(new AttributeDefinition("id", ScalarAttributeType.S))
                .withProvisionedThroughput(new ProvisionedThroughput(50l, 50l)));
    }
    if (!Tables.doesTableExist(DYNAMODB, SUBSCRIBER_TABLE_NAME)) {
        System.out.println("Creating subscriber table...");
        DYNAMODB.createTable(new CreateTableRequest().withTableName(SUBSCRIBER_TABLE_NAME)
                .withKeySchema(new KeySchemaElement("id", KeyType.HASH))
                .withAttributeDefinitions(new AttributeDefinition("id", ScalarAttributeType.S))
                .withProvisionedThroughput(new ProvisionedThroughput(50l, 50l)));
    }
    if (!Tables.doesTableExist(DYNAMODB, CHANNEL_TABLE_NAME)) {
        System.out.println("Creating channel table....");
        DYNAMODB.createTable(new CreateTableRequest().withTableName(CHANNEL_TABLE_NAME)
                .withKeySchema(new KeySchemaElement("id", KeyType.HASH))
                .withAttributeDefinitions(new AttributeDefinition("id", ScalarAttributeType.S))
                .withProvisionedThroughput(new ProvisionedThroughput(50l, 50l)));
    }
    if (!Tables.doesTableExist(DYNAMODB, FEED_URL_TABLE_NAME)) {
        System.out.println("Creating feedurl table....");
        DYNAMODB.createTable(new CreateTableRequest().withTableName(FEED_URL_TABLE_NAME)
                .withKeySchema(new KeySchemaElement("id", KeyType.HASH))
                .withAttributeDefinitions(new AttributeDefinition("id", ScalarAttributeType.S))
                .withProvisionedThroughput(new ProvisionedThroughput(50l, 50l)));
    }
    if (!Tables.doesTableExist(DYNAMODB, ARTICLE_TABLE_NAME)) {
        System.out.println("Creating article table....");
        DYNAMODB.createTable(new CreateTableRequest().withTableName(ARTICLE_TABLE_NAME)
                .withKeySchema(new KeySchemaElement("id", KeyType.HASH))
                .withAttributeDefinitions(new AttributeDefinition("id", ScalarAttributeType.S))
                .withProvisionedThroughput(new ProvisionedThroughput(50l, 50l)));
    }
    Tables.waitForTableToBecomeActive(DYNAMODB, JOBREQUEST_TABLE_NAME);
    Tables.waitForTableToBecomeActive(DYNAMODB, FEEDURL_REQUEST_TABLE_NAME);
    Tables.waitForTableToBecomeActive(DYNAMODB, SUBSCRIBER_TABLE_NAME);
    Tables.waitForTableToBecomeActive(DYNAMODB, CHANNEL_TABLE_NAME);
    Tables.waitForTableToBecomeActive(DYNAMODB, FEED_URL_TABLE_NAME);
    Tables.waitForTableToBecomeActive(DYNAMODB, ARTICLE_TABLE_NAME);
    System.out.println("Using AWS DynamoDB Table: " + JOBREQUEST_TABLE_NAME + "," + SUBSCRIBER_TABLE_NAME + ","
            + CHANNEL_TABLE_NAME);
}

From source file:com.stockcloud.deletestock.java

License:Open Source License

public static void main(String[] args) throws Exception {
    init();/*from w w  w. j  av a 2  s  . c om*/
    String csvString;
    URL url = null;
    URLConnection urlConn = null;
    InputStreamReader inStream = null;
    BufferedReader buff = null;
    // static AmazonDynamoDBClient dynamoDB;
    // String jb=symbol.substring(0, 3)+"+"+symbol.substring(3, 7);
    // System.out.println(jb);
    // String[] newsymbol=symbol.split(",");
    int i = 0;
    String symbol[] = { "ABT", "ABBV", "ACE", "ACN", "ACT", "ADBE", "ADT", "AET", "AFL", "ARG", "AA", "ALL",
            "ALTR", "AMZN", "AAPL", "BLL", "BAC", "BMS", "BBY", "BLK", "BSX", "CA", "COF", "CCL", "CAT", "CERN",
            "CVX", "CSCO", "COH", "KO", "COST", "DVN", "DTV", "DG", "DOV", "DOW", "DUK", "EBAY", "EOG", "EMR",
            "EFX", "EQR", "EXPE", "ESRX", "FB", "FE", "FLIR", "FMC", "F", "FOSL", "GME", "GPS", "GD", "GE",
            "GIS", "GS", "GOOG", "HOG", "HRS", "HCP", "HAS", "HES", "HD", "HST", "HUM", "ITW", "INTC", "ICE",
            "IBM", "INTU", "IVZ", "JOY", "JNPR", "KEY", "KMI", "KLAC", "KSS", "KR", "LB", "LRCX", "LM", "LEN",
            "LNC", "LOW", "MAC", "MMM", "M", "MAR", "MA", "MCD", "MRK", "MET", "MU", "MSFT", "MNST", "MS",
            "MOS", "MUR", "MYL" };
    // String
    // Num[]={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","3","2","3","4","5","6","7","8","9","10","1","2","3","4","5","6","7","8","9","10","1","2","3","4","5","6","7","8","9","10","1","2","3","4","5","6","7","8","9","10","1","2","3","4","5","6","7","8","9","10","1","2","3","4","5","6","7","8","9","10",}
    // loop to get the current data of every stocks(100)
    while (i < symbol.length) {
        url = new URL("http://quote.yahoo.com/d/quotes.csv?s=" + symbol[i] + "&f=osl1d1t1c1ohgv&e=.csv");
        urlConn = url.openConnection();
        inStream = new InputStreamReader(urlConn.getInputStream());
        buff = new BufferedReader(inStream);
        // get the quote as a csv string
        csvString = buff.readLine();
        // while(csvString!=null)

        // {
        // parse the csv string
        StringTokenizer tokenizer = new StringTokenizer(csvString, ",");
        String open = tokenizer.nextToken();
        String ticker = tokenizer.nextToken();
        String price = tokenizer.nextToken();
        String tradeDate = tokenizer.nextToken();
        String tradeTime = tokenizer.nextToken();

        System.out.println(
                "Symbol: " + ticker + " Price: " + price + " Date: " + tradeDate + " Time: " + tradeTime);

        // table
        try {
            String tableName = symbol[i] + "current";

            // Create table if it does not exist yet
            if (Tables.doesTableExist(dynamoDB, tableName)) {
                System.out.println("Table " + tableName + " is already ACTIVE");
            } else {
                // Create a table with a primary hash key named 'name',
                // which holds a string
                CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName)
                        .withKeySchema(
                                new KeySchemaElement().withAttributeName("Time").withKeyType(KeyType.HASH))
                        .withAttributeDefinitions(new AttributeDefinition().withAttributeName("Time")
                                .withAttributeType(ScalarAttributeType.S))
                        .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(1L)
                                .withWriteCapacityUnits(1L));
                TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest)
                        .getTableDescription();
                System.out.println("Created Table: " + createdTableDescription);

                // Wait for it to become active
                System.out.println("Waiting for " + tableName + " to become ACTIVE...");
                Tables.waitForTableToBecomeActive(dynamoDB, tableName);
            }
            Map<String, AttributeValue> item = newItem(ticker, price, tradeDate, tradeTime, open);
            PutItemRequest putItemRequest = new PutItemRequest(tableName, item);
            PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
            System.out.println("Result: " + putItemResult);

        }

        catch (AmazonServiceException ase) {
            System.out.println("Caught an AmazonServiceException, which means your request made it "
                    + "to AWS, but was rejected with an error response for some reason.");
            System.out.println("Error Message:    " + ase.getMessage());
            System.out.println("HTTP Status Code: " + ase.getStatusCode());
            System.out.println("AWS Error Code:   " + ase.getErrorCode());
            System.out.println("Error Type:       " + ase.getErrorType());
            System.out.println("Request ID:       " + ase.getRequestId());
        } catch (AmazonClientException ace) {
            System.out.println("Caught an AmazonClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with AWS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message: " + ace.getMessage());
        } // try over

        i++;
    } // whileover

    inStream.close();
    buff.close();

}

From source file:com.stockcloud.updatestock.java

License:Open Source License

public void update(String stockName) throws Exception {
    init();//from   www. j a v  a  2 s  .com
    String csvString;
    URL url = null;
    URLConnection urlConn = null;
    InputStreamReader inStream = null;
    BufferedReader buff = null;
    // static AmazonDynamoDBClient dynamoDB;
    // String jb=symbol.substring(0, 3)+"+"+symbol.substring(3, 7);
    // System.out.println(jb);
    // String[] newsymbol=symbol.split(",");
    int i = 0;
    String symbol = stockName;
    // String symbol[] = { "ABT", "ABBV", "ACE", "ACN", "ACT", "ADBE",
    // "ADT",
    // "AET", "AFL", "ARG", "AA", "ALL", "ALTR", "AMZN", "AAPL",
    // "BLL", "BAC", "BMS", "BBY", "BLK", "BSX", "CA", "COF", "CCL",
    // "CAT", "CERN", "CVX", "CSCO", "COH", "KO", "COST", "DVN",
    // "DTV", "DG", "DOV", "DOW", "DUK", "EBAY", "EOG", "EMR", "EFX",
    // "EQR", "EXPE", "ESRX", "FB", "FE", "FLIR", "FMC", "F", "FOSL",
    // "GME", "GPS", "GD", "GE", "GIS", "GS", "GOOG", "HOG", "HRS",
    // "HCP", "HAS", "HES", "HD", "HST", "HUM", "ITW", "INTC", "ICE",
    // "IBM", "INTU", "IVZ", "JOY", "JNPR", "KEY", "KMI", "KLAC",
    // "KSS", "KR", "LB", "LRCX", "LM", "LEN", "LNC", "LOW", "MAC",
    // "MMM", "M", "MAR", "MA", "MCD", "MRK", "MET", "MU", "MSFT",
    // "MNST", "MS", "MOS", "MUR", "MYL" };

    // String
    // Num[]={"1","2","3","4","5","6","7","8","9","10","11","12","13","14",
    // "15","16","17","18","19","20","21","22","23","24","25","26","27","28",
    // "29","30","3","2","3","4","5","6","7","8","9","10","1","2","3","4","5",
    // "6","7","8","9","10","1","2","3","4","5","6","7","8","9","10","1","2",
    // "3","4","5","6","7","8","9","10","1","2","3","4","5","6","7","8","9",
    // "10","1","2","3","4","5","6","7","8","9","10",}

    // loop to get the current data of every stocks(100)

    url = new URL("http://quote.yahoo.com/d/quotes.csv?s=" + symbol + "&f=osl1d1t1c1ohgv&e=.csv");
    urlConn = url.openConnection();
    inStream = new InputStreamReader(urlConn.getInputStream());
    buff = new BufferedReader(inStream);
    // get the quote as a csv string
    csvString = buff.readLine();
    // while(csvString!=null)

    // {
    // parse the csv string
    StringTokenizer tokenizer = new StringTokenizer(csvString, ",");
    String open = tokenizer.nextToken();
    String ticker = tokenizer.nextToken();
    String price = tokenizer.nextToken();
    String tradeDate = tokenizer.nextToken();
    String tradeTime = tokenizer.nextToken();

    System.out
            .println("Symbol: " + ticker + " Price: " + price + " Date: " + tradeDate + " Time: " + tradeTime);

    // table
    try {
        String tableName = symbol + "current";

        // Create table if it does not exist yet
        if (Tables.doesTableExist(dynamoDB, tableName)) {
            System.out.println("Table " + tableName + " is already ACTIVE");
        } else {
            // Create a table with a primary hash key named 'name',
            // which holds a string
            CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName)
                    .withKeySchema(new KeySchemaElement().withAttributeName("Time").withKeyType(KeyType.HASH))
                    .withAttributeDefinitions(new AttributeDefinition().withAttributeName("Time")
                            .withAttributeType(ScalarAttributeType.S))
                    .withProvisionedThroughput(
                            new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L));
            TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest)
                    .getTableDescription();
            System.out.println("Created Table: " + createdTableDescription);

            // Wait for it to become active
            System.out.println("Waiting for " + tableName + " to become ACTIVE...");
            Tables.waitForTableToBecomeActive(dynamoDB, tableName);
        }
        Map<String, AttributeValue> item = newItem(ticker, price, tradeDate, tradeTime, open);
        PutItemRequest putItemRequest = new PutItemRequest(tableName, item);
        PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
        System.out.println("Result: " + putItemResult);

    }

    catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to AWS, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with AWS, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    } // try over

    inStream.close();
    buff.close();

}

From source file:com.telefonica.iot.cygnus.backends.dynamo.DynamoDBBackendImpl.java

License:Open Source License

@Override
public void createTable(String tableName, String primaryKey) throws Exception {
    try {/*  w w  w  .  j a  v a2s.  c  o  m*/
        // Create the key schema for the given primary key
        ArrayList<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>();
        keySchema.add(new KeySchemaElement().withAttributeName(primaryKey).withKeyType(KeyType.HASH));

        // Create the attribute definitions
        ArrayList<AttributeDefinition> attrDefs = new ArrayList<AttributeDefinition>();
        attrDefs.add(new AttributeDefinition().withAttributeName(primaryKey).withAttributeType("N"));

        // Create the table request given the table name, the key schema and the attribute definitios
        CreateTableRequest tableRequest = new CreateTableRequest().withTableName(tableName)
                .withKeySchema(keySchema).withAttributeDefinitions(attrDefs).withProvisionedThroughput(
                        new ProvisionedThroughput().withReadCapacityUnits(5L).withWriteCapacityUnits(5L));

        // Create the table
        LOGGER.debug("Creating DynamoDB table " + tableName);
        Table table = dynamoDB.createTable(tableRequest);

        // Wait until the table is active
        LOGGER.debug("Waiting until the DynamoDB table " + tableName + " becomes active");
        table.waitForActive();
    } catch (Exception e) {
        LOGGER.error("Error while creating the DynamoDB table " + tableName + ". Details=" + e.getMessage());
    } // try catch
}

From source file:com.trk.aboutme.DynamoDB.DynamoDBManagerBooks.java

License:Open Source License

public static void createTable() {

    Log.d(TAG, "Create Books table called");

    AmazonDynamoDBClient ddb = Shelf.clientManager.ddb();

    KeySchemaElement kse = new KeySchemaElement().withAttributeName("pageID").withKeyType(KeyType.HASH);
    AttributeDefinition ad = new AttributeDefinition().withAttributeName("pageID")
            .withAttributeType(ScalarAttributeType.S);
    ProvisionedThroughput pt = new ProvisionedThroughput().withReadCapacityUnits(10l)
            .withWriteCapacityUnits(5l);

    CreateTableRequest request = new CreateTableRequest().withTableName(Constants.TABLE_NAME_PAGES)
            .withKeySchema(kse).withAttributeDefinitions(ad).withProvisionedThroughput(pt);

    try {/*  w  w  w. j  av a 2s.  c o m*/
        Log.d(TAG, "Sending Create table request");
        ddb.createTable(request);
        Log.d(TAG, "Create request response successfully recieved");
    } catch (AmazonServiceException ex) {
        Log.e(TAG, "Error sending create table request", ex);
        Shelf.clientManager.wipeCredentialsOnAuthError(ex);
    }
}

From source file:com.trk.aboutme.DynamoDB.DynamoDBManagerUsers.java

License:Open Source License

public static void createTable() {

    Log.d(TAG, "Create table called");

    AmazonDynamoDBClient ddb = Shelf.clientManager.ddb();

    KeySchemaElement kse = new KeySchemaElement().withAttributeName("userNo").withKeyType(KeyType.HASH);
    AttributeDefinition ad = new AttributeDefinition().withAttributeName("userNo")
            .withAttributeType(ScalarAttributeType.N);
    ProvisionedThroughput pt = new ProvisionedThroughput().withReadCapacityUnits(10l)
            .withWriteCapacityUnits(5l);

    CreateTableRequest request = new CreateTableRequest().withTableName(Constants.TEST_TABLE_NAME)
            .withKeySchema(kse).withAttributeDefinitions(ad).withProvisionedThroughput(pt);

    try {//from w w w.  j a va  2  s  .c om
        Log.d(TAG, "Sending Create table request");
        ddb.createTable(request);
        Log.d(TAG, "Create request response successfully recieved");
    } catch (AmazonServiceException ex) {
        Log.e(TAG, "Error sending create table request", ex);
        Shelf.clientManager.wipeCredentialsOnAuthError(ex);
    }
}

From source file:com.venu.springmvc.dao.AmazonDynamoDBDAO.java

License:Open Source License

public static void main(String[] args) throws Exception {
    init();//from   w w w  . j  a v a  2s  .  c om

    try {
        String tableName = "my-favorite-movies-table";

        // Create a table with a primary hash key named 'name', which holds a string
        CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName)
                .withKeySchema(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH))
                .withAttributeDefinitions(new AttributeDefinition().withAttributeName("name")
                        .withAttributeType(ScalarAttributeType.S))
                .withProvisionedThroughput(
                        new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L));

        // Create table if it does not exist yet
        TableUtils.createTableIfNotExists(dynamoDB, createTableRequest);
        // wait for the table to move into ACTIVE state
        TableUtils.waitUntilActive(dynamoDB, tableName);

        // Describe our new table
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
        System.out.println("Table Description: " + tableDescription);

        // Add an item
        Map<String, AttributeValue> item = newItem("Gundamma katha", 1989, "****", "James", "Sara", "Venu");
        PutItemRequest putItemRequest = new PutItemRequest(tableName, item);
        PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
        System.out.println("Result: " + putItemResult);

        // Add another item
        item = newItem("Manadesam", 1980, "*****", "James", "Billy Bob", "Abburi");
        putItemRequest = new PutItemRequest(tableName, item);
        putItemResult = dynamoDB.putItem(putItemRequest);
        System.out.println("Result: " + putItemResult);

        // Scan items for movies with a year attribute greater than 1985
        HashMap<String, Condition> scanFilter = new HashMap<String, Condition>();
        Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString())
                .withAttributeValueList(new AttributeValue().withN("1985"));
        scanFilter.put("year", condition);
        ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter);
        ScanResult scanResult = dynamoDB.scan(scanRequest);
        System.out.println("Result: " + scanResult);

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to AWS, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with AWS, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:com.vivastream.security.oauth2.common.util.DynamoDBInitializationHelper.java

License:Apache License

public static void createTokenTables(AmazonDynamoDBClient client, DynamoDBTokenSchema schema) {
    GlobalSecondaryIndex gsiAuthenticationIdToken = new GlobalSecondaryIndex() //
            .withIndexName(schema.getAccessIndexAuthenticationId()) //
            .withKeySchema(new KeySchemaElement(schema.getAccessColumnAuthenticationId(), KeyType.HASH)) //
            .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) //
            .withProjection(new Projection().withProjectionType(ProjectionType.KEYS_ONLY));

    GlobalSecondaryIndex gsiRefreshToken = new GlobalSecondaryIndex() //
            .withIndexName(schema.getAccessIndexRefreshToken()) //
            .withKeySchema(new KeySchemaElement(schema.getAccessColumnRefreshToken(), KeyType.HASH)) //
            .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) //
            .withProjection(new Projection().withProjectionType(ProjectionType.KEYS_ONLY));

    GlobalSecondaryIndex gsiClientIdAndUserName = new GlobalSecondaryIndex() //
            .withIndexName(schema.getAccessIndexClientIdAndUserName()) //
            .withKeySchema( //
                    new KeySchemaElement(schema.getAccessColumnClientId(), KeyType.HASH), //
                    new KeySchemaElement(schema.getAccessColumnUserName(), KeyType.RANGE) //
            ) ////from   w w  w  .  j a v  a 2  s  . c o  m
            .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) //
            .withProjection(new Projection().withProjectionType(ProjectionType.KEYS_ONLY));

    CreateTableRequest accessTableRequest = new CreateTableRequest() //
            .withTableName(schema.getAccessTableName()) //
            .withKeySchema(new KeySchemaElement(schema.getAccessColumnTokenId(), KeyType.HASH)) //
            .withGlobalSecondaryIndexes(gsiAuthenticationIdToken, gsiRefreshToken, gsiClientIdAndUserName) //
            .withAttributeDefinitions(
                    new AttributeDefinition(schema.getAccessColumnTokenId(), ScalarAttributeType.S), //
                    new AttributeDefinition(schema.getAccessColumnAuthenticationId(), ScalarAttributeType.S), //
                    new AttributeDefinition(schema.getAccessColumnRefreshToken(), ScalarAttributeType.S), //
                    new AttributeDefinition(schema.getAccessColumnClientId(), ScalarAttributeType.S), //
                    new AttributeDefinition(schema.getAccessColumnUserName(), ScalarAttributeType.S) //
            ) //
            .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) //
    ;

    CreateTableResult accessTableresponse = client.createTable(accessTableRequest);

    CreateTableRequest refreshTableRequest = new CreateTableRequest() //
            .withTableName(schema.getRefreshTableName()) //
            .withKeySchema(new KeySchemaElement(schema.getRefreshColumnTokenId(), KeyType.HASH)) //
            .withAttributeDefinitions(
                    new AttributeDefinition(schema.getRefreshColumnTokenId(), ScalarAttributeType.S) //
            ) //
            .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) //
    ;

    CreateTableResult refreshTableresponse = client.createTable(refreshTableRequest);
}