Example usage for com.amazonaws.services.dynamodbv2.model ComparisonOperator GT

List of usage examples for com.amazonaws.services.dynamodbv2.model ComparisonOperator GT

Introduction

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

Prototype

ComparisonOperator GT

To view the source code for com.amazonaws.services.dynamodbv2.model ComparisonOperator GT.

Click Source Link

Usage

From source file:AmazonDynamoDBSample_PutThrottled.java

License:Open Source License

public static void main(String[] args) throws Exception {
    init();/*from   w  w w . j  ava 2  s. c o m*/

    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("Bill & Ted's Excellent Adventure", 1989, "****", "James",
                "Sara");
        PutItemRequest putItemRequest = new PutItemRequest(tableName, item);
        PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
        System.out.println("Result: " + putItemResult);

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

        Thread[] thrds = new Thread[16];
        for (int i = 0; i < thrds.length; i++) {
            thrds[i] = newItemCreationThread(tableName, i);
            thrds[i].start();
        }
        for (Thread thrd : thrds) {
            thrd.join();
        }

        // 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:br.com.faccilitacorretor.middleware.dynamo.AmazonDynamoDBSample.java

License:Open Source License

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

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

        // 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("name").withKeyType(KeyType.HASH))
                    .withAttributeDefinitions(new AttributeDefinition().withAttributeName("name")
                            .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.awaitTableToBecomeActive(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("Bill & Ted's Excellent Adventure", 1989, "****", "James",
                "Sara");
        PutItemRequest putItemRequest = new PutItemRequest(tableName, item);
        PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
        System.out.println("Result: " + putItemResult);

        // Add another item
        item = newItem("Airplane", 1980, "*****", "James", "Billy Bob");
        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.alertlogic.aws.kinesis.test1.webserver.GetCountsServlet.java

License:Open Source License

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    MultiMap<String> params = new MultiMap<>();
    UrlEncoded.decodeTo(req.getQueryString(), params, "UTF-8");

    // We need both parameters to properly query for counts
    if (!params.containsKey(PARAMETER_RESOURCE) || !params.containsKey(PARAMETER_RANGE_IN_SECONDS)) {
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return;//from   w w  w  . j  a  va  2 s .c o  m
    }

    // Parse query string as a single integer - the number of seconds since "now" to query for new counts
    String resource = params.getString(PARAMETER_RESOURCE);
    int rangeInSeconds = Integer.parseInt(params.getString(PARAMETER_RANGE_IN_SECONDS));

    Calendar c = Calendar.getInstance();
    c.add(Calendar.SECOND, -1 * rangeInSeconds);
    Date startTime = c.getTime();
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("Querying for counts of resource %s since %s", resource,
                DATE_FORMATTER.get().format(startTime)));
    }

    DynamoDBQueryExpression<HttpReferrerPairsCount> query = new DynamoDBQueryExpression<>();
    HttpReferrerPairsCount hashKey = new HttpReferrerPairsCount();
    hashKey.setResource(resource);
    query.setHashKeyValues(hashKey);

    Condition recentUpdates = new Condition().withComparisonOperator(ComparisonOperator.GT)
            .withAttributeValueList(new AttributeValue().withS(DATE_FORMATTER.get().format(startTime)));
    query.setRangeKeyConditions(Collections.singletonMap("timestamp", recentUpdates));

    List<HttpReferrerPairsCount> counts = mapper.query(HttpReferrerPairsCount.class, query);

    // Return the counts as JSON
    resp.setContentType("application/json");
    resp.setStatus(HttpServletResponse.SC_OK);
    JSON.writeValue(resp.getWriter(), counts);
}

From source file:com.boundary.aws.dynamodb.QueryDynamoDB.java

License:Open Source License

public static void main(String[] args) throws Exception {
    init();/*from w ww  .  j  a  v a2 s.  c o  m*/

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

        // Create table if it does not exist yet
        if (Tables.doesTableExist(dynamoDB, tableName)) {
            System.out.println("Table " + tableName + " is already ACTIVE");
        } else {
            System.out.println("Table to query " + tableName + "does not exist");
        }

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

            Condition hashKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.EQ)
                    .withAttributeValueList(new AttributeValue().withS("Matrix"));

            Map<String, Condition> keyConditions = new HashMap<String, Condition>();
            keyConditions.put("name", hashKeyCondition);

            QueryRequest queryRequest = new QueryRequest().withTableName(tableName)
                    .withKeyConditions(keyConditions);

            QueryResult queryResult = dynamoDB.query(queryRequest);
            System.out.println("Result: " + queryResult);

            Thread.sleep(5000);
        }

    } 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.github.sdmcraft.slingdynamo.demo.App.java

License:Open Source License

/**
 * Main1./*from ww w.  ja va2  s.c  om*/
 *
 * @param args the args
 * @throws Exception the exception
 */
public static void main1(String[] args) throws Exception {
    init();

    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));
        TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest)
                .getTableDescription();
        System.out.println("Created Table: " + createdTableDescription);

        // Wait for it to become active
        waitForTableToBecomeAvailable(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("Bill & Ted's Excellent Adventure", 1989, "****", "James",
                "Sara");
        PutItemRequest putItemRequest = new PutItemRequest(tableName, item);
        PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
        System.out.println("Result: " + putItemResult);

        // Add another item
        item = newItem("Airplane", 1980, "*****", "James", "Billy Bob");
        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.hussi.aws.dynamoDB.AmazonDynamoDBSample.java

License:Open Source License

public static void main(String[] args) throws Exception {
    init();/*from w  ww . ja  v  a2  s  .  c  o m*/

    try {
        String tableName = "hussi_first_dynamo_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("Bill & Ted's Excellent Adventure", 1989, "****", "James",
                "Sara");
        PutItemRequest putItemRequest = new PutItemRequest(tableName, item);
        PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
        System.out.println("Result: " + putItemResult);

        // Add another item
        item = newItem("Airplane", 1980, "*****", "James", "Billy Bob");
        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.kinesis.datavis.servlet.GetBidRqCountsServlet.java

License:Open Source License

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    MultiMap<String> params = new MultiMap<>();
    UrlEncoded.decodeTo(req.getQueryString(), params, "UTF-8");

    // We need both parameters to properly query for counts
    if (!params.containsKey(PARAMETER_RESOURCE) || !params.containsKey(PARAMETER_RANGE_IN_SECONDS)) {
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return;// w w w  .  ja  v  a 2 s. c  o  m
    }

    // Parse query string as a single integer - the number of seconds since "now" to query for new counts
    String resource = params.getString(PARAMETER_RESOURCE);
    int rangeInSeconds = Integer.parseInt(params.getString(PARAMETER_RANGE_IN_SECONDS));

    Calendar c = Calendar.getInstance();
    c.add(Calendar.SECOND, -1 * rangeInSeconds);
    Date startTime = c.getTime();
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("Querying for counts of resource %s since %s", resource,
                DATE_FORMATTER.get().format(startTime)));
    }

    DynamoDBQueryExpression<BidRequestCount> query = new DynamoDBQueryExpression<>();

    BidRequestCount hashKey = new BidRequestCount();
    hashKey.setHashKey(Ticker.getInstance().hashKey());

    query.setHashKeyValues(hashKey);

    Condition recentUpdates = new Condition().withComparisonOperator(ComparisonOperator.GT)
            .withAttributeValueList(new AttributeValue().withS(DATE_FORMATTER.get().format(startTime)));
    //        Condition attrFilter =
    //                new Condition().
    //                        withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS(resource));

    query.setRangeKeyConditions(Collections.singletonMap("timestamp", recentUpdates));
    //        query.setQueryFilter(Collections.singletonMap("wh", attrFilter));

    List<BidRequestCount> counts = mapper.query(BidRequestCount.class, query);

    //        System.out.println(counts.size());
    // Return the counts as JSON
    resp.setContentType("application/json");
    resp.setStatus(HttpServletResponse.SC_OK);
    JSON.writeValue(resp.getWriter(), counts);
}

From source file:com.kirana.dao.OrderDaoImpl.java

@Override
public List<Order> getOrderByShopId(long shopId) throws Exception {
    DynamoDBMapper mapper = new DynamoDBMapper(dbClient);

    Date startTime = new Date(0L);
    SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
    String startTimeStr = dateFormatter.format(startTime);

    Condition rangeKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString())
            .withAttributeValueList(new AttributeValue().withS(startTimeStr));

    DynamoDBQueryExpression<Order> queryExpression = new DynamoDBQueryExpression<Order>()
            .withHashKeyValues(new Order(shopId)).withRangeKeyCondition("created_at", rangeKeyCondition);
    queryExpression.setConsistentRead(false);

    return mapper.query(Order.class, queryExpression);

}

From source file:com.numenta.taurus.service.TaurusClient.java

License:Open Source License

/**
 * Get list of tweets for the given metric filtered by the given time range returning the
 * results as they become available asynchronously.
 *
 * @param metricName The metric name to retrieve the tweets from
 * @param from       The start time (aggregated) inclusive.
 * @param to         The end time (aggregated) inclusive.
 * @param callback   Callback for asynchronous call. It will be called on every {@link Tweet}
 *//* w ww .j  ava  2 s  .c  o  m*/
public void getTweets(String metricName, Date from, Date to, DataCallback<Tweet> callback)
        throws GrokException, IOException {
    if (metricName == null) {
        throw new ObjectNotFoundException("Cannot get tweets without metric name");
    }

    final TaurusDataFactory dataFactory = TaurusApplication.getInstance().getDataFactory();
    final SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US);
    timestampFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    // Key conditions
    Map<String, Condition> keyConditions = new HashMap<>();

    // uid = modelId
    Condition modelIdCond = new Condition().withComparisonOperator(ComparisonOperator.EQ)
            .withAttributeValueList(new AttributeValue(metricName));
    keyConditions.put("metric_name", modelIdCond);

    Condition timestampCondition;
    if (from != null && to != null) {
        // timestamp >= from and timestamp <=to
        timestampCondition = new Condition().withComparisonOperator(ComparisonOperator.BETWEEN)
                .withAttributeValueList(new AttributeValue().withS(timestampFormat.format(from)),
                        new AttributeValue().withS(timestampFormat.format(to)));
        keyConditions.put("agg_ts", timestampCondition);
    } else if (from != null) {
        // timestamp >= from
        timestampCondition = new Condition().withComparisonOperator(ComparisonOperator.GT)
                .withAttributeValueList(new AttributeValue().withS(timestampFormat.format(from)));
        keyConditions.put("agg_ts", timestampCondition);
    } else if (to != null) {
        // timestamp <= to
        timestampCondition = new Condition().withComparisonOperator(ComparisonOperator.LT)
                .withAttributeValueList(new AttributeValue().withS(timestampFormat.format(to)));
        keyConditions.put("agg_ts", timestampCondition);
    }

    // Prepare query request
    QueryRequest query = new QueryRequest().withTableName(TWEETS_TABLE)
            .withAttributesToGet("tweet_uid", "userid", "text", "username", "agg_ts", "created_at",
                    "retweet_count")
            .withKeyConditions(keyConditions).withScanIndexForward(false)
            .withIndexName("taurus.metric_data-metric_name_index");

    QueryResult result;
    String tweetId;
    String userId;
    String userName;
    String text;
    Date created;
    Date aggregated;
    AttributeValue retweet;
    int retweetCount;
    Map<String, AttributeValue> lastKey;
    try {
        do {
            // Get results
            result = _awsClient.query(query);
            for (Map<String, AttributeValue> item : result.getItems()) {
                tweetId = item.get("tweet_uid").getS();
                userId = item.get("userid").getS();
                text = item.get("text").getS();
                userName = item.get("username").getS();
                aggregated = DataUtils.parseGrokDate(item.get("agg_ts").getS());
                created = DataUtils.parseGrokDate(item.get("created_at").getS());

                // "retweet_count" is optional
                retweet = item.get("retweet_count");
                if (retweet != null && retweet.getN() != null) {
                    retweetCount = Integer.parseInt(retweet.getN());
                } else {
                    retweetCount = 0;
                }
                if (!callback.onData(dataFactory.createTweet(tweetId, aggregated, created, userId, userName,
                        text, retweetCount))) {
                    // Canceled by the user
                    break;
                }
            }
            // Make sure to get all pages
            lastKey = result.getLastEvaluatedKey();
            query.setExclusiveStartKey(lastKey);
        } while (lastKey != null);
    } catch (AmazonClientException e) {
        // Wraps Amazon's unchecked exception as IOException
        throw new IOException(e);
    }
}

From source file:com.raoul.walkfoframe.web.DynamoDBManager.java

License:Open Source License

public static ArrayList<Wofhonorees> getWOFhonorees(Date timestamp) {
    System.out.println("---------    getWOFhonorees called --------   " + HWOFameApplication.clientManager);
    AmazonDynamoDB ddb = null;/*from  ww  w. jav  a 2s.  c o  m*/
    try {
        ddb = HWOFameApplication.clientManager;
        // System.out.println(" AmazonDynamoDB : "+HWOFameApplication.clientManager.ddb());
    } catch (Exception e) {
        System.out.println("--------------  exception generate --------------");
        e.printStackTrace();
    }
    System.out.println("---------    getWOFhonorees called ddb :--------   " + ddb);
    DynamoDBMapper mapper = new DynamoDBMapper(ddb);

    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd");
    dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
    long milis = timestamp.getTime();
    String timestampString = dateFormatter.format(milis);

    scanExpression.addFilterCondition("datelastupdate",
            new Condition().withComparisonOperator(ComparisonOperator.GT.toString())
                    .withAttributeValueList(new AttributeValue().withN(timestampString)));

    try {
        PaginatedScanList<Wofhonorees> result = mapper.scan(Wofhonorees.class, scanExpression);

        ArrayList<Wofhonorees> resultList = new ArrayList<Wofhonorees>();
        for (Wofhonorees up : result) {
            resultList.add(up);
        }
        System.out.println("---------    getWOFhonorees called return --------   " + resultList);
        return resultList;

    } catch (AmazonServiceException ex) {
        System.out.println("---------    getWOFhonorees called Exception generate --------   ");
        //HWOFameApplication.clientManager.wipeCredentialsOnAuthError(ex);
    }
    System.out.println("---------    getWOFhonorees called return --------   " + null);
    return null;
}