List of usage examples for com.amazonaws.services.dynamodbv2.document RangeKeyCondition RangeKeyCondition
public RangeKeyCondition(String attrName)
From source file:com.clicktravel.infrastructure.persistence.aws.dynamodb.RangeKeyConditionBuilder.java
License:Apache License
public static RangeKeyCondition build(final String attributeName, final Object value, final Operators comparisonOperator) { Check.isNotEmptyOrNull("attributeName", attributeName); Check.isNotNull("conditionValue", value); final RangeKeyCondition rangeKeyCondition = new RangeKeyCondition(attributeName); switch (comparisonOperator) { case EQUALS:/*from w w w . j a va 2 s. c o m*/ rangeKeyCondition.eq(value); break; case GREATER_THAN_OR_EQUALS: rangeKeyCondition.ge(value); break; case LESS_THAN_OR_EQUALS: rangeKeyCondition.le(value); break; default: throw new InvalidConditionOperatorException(String .format("Operation %s not valid for range key condition.", comparisonOperator.toString())); } return rangeKeyCondition; }
From source file:com.envirover.spl.stream.MAVLinkMessagesTable.java
License:Open Source License
@Override public Iterable<MAVLinkRecord> query(String deviceId, Date startTime, Date endTime, Integer msgId) throws IOException { RangeKeyCondition timeInterval;/*from w w w . j a v a 2 s. c o m*/ if (startTime == null && endTime == null) { timeInterval = null; } else if (startTime == null && endTime != null) { timeInterval = new RangeKeyCondition(ATTR_TIME).le(endTime.getTime()); } else if (startTime != null && endTime == null) { timeInterval = new RangeKeyCondition(ATTR_TIME).ge(startTime.getTime()); } else { timeInterval = new RangeKeyCondition(ATTR_TIME).between(startTime.getTime(), endTime.getTime()); } QueryFilter filter = new QueryFilter(ATTR_MSG_ID).eq(msgId); return new MAVLinkRecordIterable(table.query(ATTR_DEVICE_ID, deviceId, timeInterval, filter).iterator()); }
From source file:com.innoq.hagmans.bachelor.DynamoDBUtils.java
License:Open Source License
/** * Persists the given temperatures on DynamoDB * //ww w .j a va 2 s. c om * @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:ws.salient.aws.dynamodb.DynamoDBStore.java
License:Apache License
public Session get(Command command, KnowledgeRepository repository, Properties properties, Injector parentInjector, Sessions sessions, QuerySpec sessionQuery) { String sessionId = command.getSessionId(); String accountId = command.getAccountId(); SecretKeySpec secretKey;//from w w w.java 2s . c o m ByteBuffer encryptedKey; Session session = new Session(sessionId); Page<Item, QueryOutcome> page = dynamodb.getTable("SalientSession").query(sessionQuery).firstPage(); if (page != null && page.size() > 0) { try { Item result = page.iterator().next(); encryptedKey = ByteBuffer.wrap((byte[]) result.getMap("secretKey").get("encrypted")); if (encryptedKey != null) { DecryptResult decrypt = kms.decrypt(new DecryptRequest() .addEncryptionContextEntry("accountId", accountId) .addEncryptionContextEntry("sessionId", sessionId).withCiphertextBlob(encryptedKey)); byte[] key = decrypt.getPlaintext().array(); secretKey = new SecretKeySpec(key, (String) result.getMap("secretKey").get("algorithm")); } else { secretKey = null; } result = decrypt(result, secretKey, "properties", "session"); properties = json.readValue(result.getBinary("properties"), Properties.class); String knowledgeBaseId = result.getString("knowledgeBaseId"); KnowledgeBase knowledgeBase = repository.getKnowledgeBase(knowledgeBaseId); String timestamp = result.getString("timestamp"); session.init(knowledgeBase, properties, parentInjector, Instant.parse(timestamp), result.getBinary("session"), sessions); int processCount = session.getProcessCount(); List<Item> eventItems = new LinkedList(); ItemCollection<QueryOutcome> query = dynamodb.getTable("SalientSessionEvent") .query(new QuerySpec().withConsistentRead(true).withHashKey("sessionId", sessionId) .withRangeKeyCondition(new RangeKeyCondition("timestamp").gt(timestamp))); query.pages().forEach((eventPage) -> { eventPage.forEach((eventItem) -> { eventItems.add(eventItem); }); }); List<Command> commands = new LinkedList(); eventItems.forEach((eventItem) -> { try { eventItem = decrypt(eventItem, secretKey, "command"); byte[] value = eventItem.getBinary("command"); ObjectInputStream objectIn = new ObjectInputStream(new ByteArrayInputStream(value)) { protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { return session.getKnowledgeBase().getContainer().getClassLoader() .loadClass(desc.getName()); } }; Command event = (Command) objectIn.readObject(); if (event instanceof WorkItem) { session.getWorkItemHandlers().forEach((handler) -> { handler.getCompletedWorkItemIds().add(((WorkItem) event).getWorkItemId()); }); } commands.add(event); } catch (ClassNotFoundException | IOException ex) { throw new RuntimeException(ex); } }); commands.forEach((event) -> { session.accept(event); }); session.getWorkItemHandlers().forEach((handler) -> { handler.getCompletedWorkItemIds().clear(); }); } catch (IOException ex) { throw new RuntimeException(ex); } } else { GenerateDataKeyResult dataKey = generateEncryptionKey(accountId, sessionId); byte[] key = dataKey.getPlaintext().array(); secretKey = new SecretKeySpec(key, "AES"); encryptedKey = dataKey.getCiphertextBlob(); KnowledgeBase knowledgeBase = repository.getKnowledgeBase(command.getKnowledgeBaseId()); session.init(knowledgeBase, properties, parentInjector, command.getTimestamp(), sessions); } session.setEncryptedKey(encryptedKey); session.setSecretKey(secretKey); return session; }