Example usage for com.amazonaws.services.dynamodbv2.document.spec QuerySpec withKeyConditionExpression

List of usage examples for com.amazonaws.services.dynamodbv2.document.spec QuerySpec withKeyConditionExpression

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.document.spec QuerySpec withKeyConditionExpression.

Prototype

public QuerySpec withKeyConditionExpression(String keyConditionExpression) 

Source Link

Document

When a key condition expression is specified, the corresponding name-map and value-map can optionally be specified via #withNameMap(Map) and #withValueMap(Map) .

Usage

From source file:org.diksha.common.dyutils.DyDBUtils.java

License:Apache License

public static ArrayList<String> listOpenExecutionsFromDynamo(String config) {
    ArrayList<String> retValue = new ArrayList<String>();

    DynamoDB dynamoDB = getDynamoDB();/*  w  ww  .  ja  va 2  s  .c om*/
    Table table = dynamoDB.getTable("SchedulerWorkflowState");
    Index index = table.getIndex("loopStateIndex");

    ItemCollection<QueryOutcome> items = null;
    QuerySpec querySpec = new QuerySpec();

    querySpec.withKeyConditionExpression("loopState = :v_state")
            .withValueMap(new ValueMap().withString(":v_state", "PROCESSING"));

    items = index.query(querySpec);

    Iterator<Item> iterator = items.iterator();
    int totalActualCount = 0;
    Item item;

    while (iterator.hasNext()) {

        item = iterator.next();

        retValue.add(item.getString("clientId"));

    }

    return retValue;

}

From source file:org.diksha.common.dyutils.DyDBUtils.java

License:Apache License

public static int countActiveJobs() {
    DynamoDB dynamoDB = getDynamoDB();//ww w  . j a v  a2s.c om

    Table table = dynamoDB.getTable("SchedulerWorkflowState");
    Index index = table.getIndex("loopStateIndex");

    ItemCollection<QueryOutcome> items = null;
    QuerySpec querySpec = new QuerySpec();

    int count = 0;

    querySpec.withKeyConditionExpression("loopState = :v_state")
            .withValueMap(new ValueMap().withString(":v_state", "PROCESSING"));
    items = index.query(querySpec);
    Iterator<Item> iterator = items.iterator();

    while (iterator.hasNext()) {

        iterator.next();
        count++;
    }

    return count;

}

From source file:org.diksha.common.dyutils.DyDBUtils.java

License:Apache License

public static void listActiveJobs(String optionalExecutionId) {
    DynamoDB dynamoDB = getDynamoDB();//from  w w  w. j ava2s  .co m

    Table table = dynamoDB.getTable("SchedulerWorkflowState");
    Index index = table.getIndex("loopStateIndex");

    ItemCollection<QueryOutcome> items = null;
    QuerySpec querySpec = new QuerySpec();

    if ((optionalExecutionId != null) && !optionalExecutionId.isEmpty()) {
        querySpec.withKeyConditionExpression("loopState = :v_state and begins_with(clientId, :v_eid)")
                .withValueMap(new ValueMap().withString(":v_state", "PROCESSING").withString(":v_eid",
                        optionalExecutionId));

    } else {

        querySpec.withKeyConditionExpression("loopState = :v_state")
                .withValueMap(new ValueMap().withString(":v_state", "PROCESSING"));
    }

    items = index.query(querySpec);
    Iterator<Item> iterator = items.iterator();

    System.out.format("%20s %7s %28s %40s\n", "CronExpression", "Loop Count", "Next Scheduled Time       ",
            " ExecutionId");
    while (iterator.hasNext()) {

        Item item = iterator.next();

        System.out.format("%20s %7s %28s %40s\n", item.get("cronExpression"), item.get("loopCount"),
                item.get("lastProposedTimeDate"), item.get("clientId"));

    }

}