List of usage examples for com.amazonaws.services.dynamodbv2.document Table getIndex
public Index getIndex(String indexName)
From source file:com.clicktravel.infrastructure.persistence.aws.dynamodb.DynamoDocumentStoreTemplate.java
License:Apache License
private <T extends Item> Collection<T> executeQuery(final AttributeQuery query, final Class<T> itemClass) { final ItemConfiguration itemConfiguration = getItemConfiguration(itemClass); final String tableName = databaseSchemaHolder.schemaName() + "." + itemConfiguration.tableName(); final Table table = dynamoDBClient.getTable(tableName); final List<T> totalItems = new ArrayList<>(); if (itemConfiguration.hasIndexOn(query.getAttributeName()) && query.getCondition().getComparisonOperator() == Operators.EQUALS) { final QuerySpec querySpec = generateQuerySpec(query); final ItemCollection<QueryOutcome> queryOutcome; if (itemConfiguration.primaryKeyDefinition().propertyName().equals(query.getAttributeName())) { // if the query is for the has then call query on table queryOutcome = table.query(querySpec); } else {//from w ww. j a v a 2 s .c o m final Index index = table.getIndex(query.getAttributeName() + "_idx"); queryOutcome = index.query(querySpec); } final Iterator<com.amazonaws.services.dynamodbv2.document.Item> iterator = queryOutcome.iterator(); while (iterator != null && iterator.hasNext()) { final com.amazonaws.services.dynamodbv2.document.Item item = iterator.next(); totalItems.add(stringToItem(item.toJSON(), itemClass)); } } else { logger.debug("Performing table scan with query: " + query); ScanSpec scanSpec = null; try { scanSpec = generateScanSpec(query, itemClass); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new PersistenceResourceFailureException("Could not create ScanSpec for query: " + query, e); } final ItemCollection<ScanOutcome> scanOutcome = table.scan(scanSpec); final Iterator<com.amazonaws.services.dynamodbv2.document.Item> iterator = scanOutcome.iterator(); while (iterator.hasNext()) { final com.amazonaws.services.dynamodbv2.document.Item item = iterator.next(); totalItems.add(stringToItem(item.toJSON(), itemClass)); } } return totalItems; }
From source file:com.erudika.para.persistence.AWSDynamoUtils.java
License:Apache License
/** * Returns the Index object for the shared table. * @return the Index object or null/*from w w w .j a v a 2s .c o m*/ */ public static Index getSharedIndex() { if (ddb == null) { getClient(); } try { Table t = ddb.getTable(getTableNameForAppid(SHARED_TABLE)); if (t != null) { return t.getIndex(getSharedIndexName()); } } catch (Exception e) { logger.info("Could not get shared index: {}.", e.getMessage()); } return null; }
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 w w . ja v a2s. c o m 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();//from w w w .java2s . co m 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 a v a 2 s . 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")); } }