List of usage examples for com.amazonaws.services.dynamodbv2.document.spec QuerySpec QuerySpec
public QuerySpec()
From source file:NYSEQuery.java
License:Open Source License
private static void query(String tableName) { Table table = null;/*from w ww. j a va2 s . c o m*/ try { // Create table if it does not exist yet if (!Tables.doesTableExist(dynamoDB, tableName)) { System.out.println("Table " + tableName + " is does not exist"); } else { table = dynamo.getTable(tableName); } // http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.SpecifyingConditions.html // select stockTicker, tradeDate, v from stock_eod // where stockTicker = 'LEA' and tradeDate between '02-Oct-2013' and '03-Oct-2013' QuerySpec spec = new QuerySpec().withProjectionExpression("stockTicker,tradeDate,v") .withKeyConditionExpression("stockTicker = :v_st and tradeDate between :v_sd and :v_ed") // .withFilterExpression("contains(tradeDate, :v_t)") .withValueMap(new ValueMap().withString(":v_st", "LEA").withString(":v_sd", "02-Oct-2013") .withString(":v_ed", "03-Oct-2013") // .withString(":v_td", "01-Oct-2013") // .withString(":v_t", "Oct") ).withConsistentRead(true); ItemCollection<QueryOutcome> items = table.query(spec); Iterator<Item> iterator = items.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next().toJSONPretty()); } } 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.clicktravel.infrastructure.persistence.aws.dynamodb.DynamoDocumentStoreTemplate.java
License:Apache License
private QuerySpec generateQuerySpec(final AttributeQuery query) { final QuerySpec querySpec = new QuerySpec().withHashKey(query.getAttributeName(), query.getCondition().getValues().iterator().next()); return querySpec; }
From source file:com.clicktravel.infrastructure.persistence.aws.dynamodb.QuerySpecBuilder.java
License:Apache License
private static QuerySpec buildWithHashKey(final AttributeQuery attributeQuery) { return new QuerySpec().withHashKey(attributeQuery.getAttributeName(), attributeQuery.getCondition().getValues().iterator().next()); }
From source file:com.erudika.para.persistence.AWSDynamoDAO.java
License:Apache License
private <P extends ParaObject> String readPageFromSharedTable(String appid, Pager pager, LinkedList<P> results) { String lastKeyFragment = ""; ValueMap valueMap = new ValueMap().withString(":aid", appid); NameMap nameMap = null;/*from w w w . java 2 s . co m*/ if (!StringUtils.isBlank(pager.getLastKey())) { lastKeyFragment = " and #stamp > :ts"; valueMap.put(":ts", pager.getLastKey()); nameMap = new NameMap().with("#stamp", Config._TIMESTAMP); } Index index = getSharedIndex(); QuerySpec spec = new QuerySpec().withMaxPageSize(pager.getLimit()).withMaxResultSize(pager.getLimit()) .withKeyConditionExpression(Config._APPID + " = :aid" + lastKeyFragment).withValueMap(valueMap) .withNameMap(nameMap); if (index != null) { Page<Item, QueryOutcome> items = index.query(spec).firstPage(); for (Item item : items) { P obj = ParaObjectUtils.setAnnotatedFields(item.asMap()); if (obj != null) { results.add(obj); } } } if (!results.isEmpty()) { return Long.toString(results.peekLast().getTimestamp()); } else { return null; } }
From source file:com.exorath.service.party.service.DynamoDatabaseProvider.java
License:Apache License
/** * Get the query spec for a search//from ww w . java 2 s . co m * * @param primKey The primary key to search with * @param uuid The value that should be looked for * @return Query spec that will return all matching results when ran */ private QuerySpec getQuerySpec(String primKey, String uuid) { HashMap<String, String> nameMap = new HashMap<>(); nameMap.put("#id", primKey); nameMap.put("#expire", EXPIRE); HashMap<String, Object> valueMap = new HashMap<>(); valueMap.put(":uuid", uuid); valueMap.put(":expire", System.currentTimeMillis()); return new QuerySpec().withKeyConditionExpression("#id = :uuid").withFilterExpression("#expire > :expire") .withNameMap(nameMap).withValueMap(valueMap); }
From source file:com.innoq.hagmans.bachelor.DynamoDBUtils.java
License:Open Source License
/** * Persists the given temperatures on DynamoDB * //from w ww .j a v a 2 s .c o m * @param tableName * The name of the table, where the records will be persisted * @param temperatureMap * A map containing the sensor names as the key, and as the value * a hashmap with the timestamp of the temperature as the key and * the temperature as the value * @param timestamp * The timestamp of the run */ public void putTemperatures(String tableName, HashMap<String, HashMap<String, String>> temperatureMap, long timestamp) { Table table = dynamoDB.getTable(tableName); for (String sensor : temperatureMap.keySet()) { QuerySpec spec = new QuerySpec().withHashKey(ATTRIBUTE_NAME_HASH_KEY, sensor).withRangeKeyCondition( new RangeKeyCondition(ATTRIBUTE_NAME_RANGE_KEY).eq(String.valueOf(timestamp))); ItemCollection<QueryOutcome> items = table.query(spec); Iterator<Item> iterator = items.iterator(); Item item = null; Map<String, String> temperatures = null; while (iterator.hasNext()) { item = iterator.next(); temperatures = item.getMap(ATTRIBUTE_NAME_TEMPERATURE); } if (temperatures == null) { temperatures = new HashMap<>(); } temperatures.putAll(temperatureMap.get(sensor)); table.putItem(new Item().withPrimaryKey(ATTRIBUTE_NAME_HASH_KEY, sensor, ATTRIBUTE_NAME_RANGE_KEY, String.valueOf(timestamp)).withMap(ATTRIBUTE_NAME_TEMPERATURE, temperatures)); System.out.println("PutItem succeeded!"); } }
From source file:com.innoq.hagmans.bachelor.DynamoDBUtils.java
License:Open Source License
/** * Gibt eine @HashMap mit allen Temperaturen zurck fr den bergebenen * Sensor//from w w w . j a v a 2 s. co m * * @param sensor * @param tableName * @return @Hashmap, die als Key einen Timestamp enthalten, zu dessen * Zeitpunkt die Daten des Sensors erfasst werden und die Values * sind eine Liste der Temperaturen des Sensors zum Timestamp */ public HashMap<String, HashMap<String, Object>> getTemperaturesForSensor(String sensor, String tableName) { Table table = dynamoDB.getTable(tableName); QuerySpec spec = new QuerySpec().withHashKey(ATTRIBUTE_NAME_HASH_KEY, sensor); ItemCollection<QueryOutcome> items = table.query(spec); Iterator<Item> iterator = items.iterator(); Item item = null; HashMap<String, HashMap<String, Object>> temperatureMap = new HashMap<>(); while (iterator.hasNext()) { item = iterator.next(); temperatureMap.put(item.getString(ATTRIBUTE_NAME_RANGE_KEY), new HashMap<>(item.getMap(ATTRIBUTE_NAME_TEMPERATURE))); } return temperatureMap; }
From source file:mx.iteso.desi.cloud.keyvalue.DynamoDBStorage.java
License:Apache License
@Override public Set<String> get(String search) { Set<String> ret = new HashSet<String>(); Table table = docClient.getTable(dbName); QuerySpec spec = new QuerySpec().withKeyConditionExpression("keyword = :v_kw") .withValueMap(new ValueMap().withString(":v_kw", search)); ItemCollection<QueryOutcome> items = table.query(spec); Iterator<Item> iterator = items.iterator(); Item item = null;//from w ww .j a v a 2 s . c om while (iterator.hasNext()) { item = iterator.next(); ret.add(item.get("value").toString()); } return ret; }
From source file:org.chodavarapu.jgitaws.repositories.PackDescriptionRepository.java
License:Eclipse Distribution License
public Observable<DfsPackDescription> getAllPackDescriptions(AmazonRepository repository) { return configuration.getDynamoClient() .getAllItems(configuration.getPackDescriptionsTableName(), new QuerySpec().withHashKey(REPOSITORY_NAME_ATTRIBUTE, repository.getRepositoryName()) .withScanIndexForward(true)) .map(item -> {/*from w w w .j a v a2s. c om*/ String name = item.getString(NAME_ATTRIBUTE); String description = item.getString(DESCRIPTION_ATTRIBUTE); return fromJson(description, new DfsPackDescription(repository.getDescription(), name)); }).doOnCompleted(() -> logger.debug("Retrieved packs list for repository {}", repository.getRepositoryName())); }
From source file:org.chodavarapu.jgitaws.repositories.RefRepository.java
License:Eclipse Distribution License
public Observable<Ref> getAllRefsSorted(String repositoryName) { return configuration.getDynamoClient() .getAllItems(configuration.getRefsTableName(), new QuerySpec() .withHashKey(REPOSITORY_NAME_ATTRIBUTE, repositoryName).withScanIndexForward(true)) .map(item -> {// w ww . ja v a 2 s.c o m String name = item.getString(NAME_ATTRIBUTE); String target = item.getString(TARGET_ATTRIBUTE); boolean isSymbolic = item.getBoolean(IS_SYMBOLIC_ATTRIBUTE); boolean isPeeled = item.getBoolean(IS_PEELED_ATTRIBUTE); String peeledTarget = item.getString(PEELED_TARGET_ATTRIBUTE); if (isSymbolic) { return new SymbolicRef(name, new ObjectIdRef.Unpeeled(Ref.Storage.PACKED, target, null)); } else { if (isPeeled) { if (peeledTarget == null) { return new ObjectIdRef.PeeledNonTag(Ref.Storage.PACKED, name, ObjectId.fromString(target)); } else { return new ObjectIdRef.PeeledTag(Ref.Storage.PACKED, name, ObjectId.fromString(target), ObjectId.fromString(peeledTarget)); } } else { return new ObjectIdRef.Unpeeled(Ref.Storage.PACKED, name, ObjectId.fromString(target)); } } }); }