private void createNodeHistoryItems( NodeHistory nHistoryDB, String nid, String time, String values) { nHistoryDB.setNodeID(nid); nHistoryDB.setTime(time); nHistoryDB.setSAValues(values); mapper.save(nHistoryDB); String hashKey = nid; String rangeKey = time; NodeHistory nhKey = new NodeHistory(); nhKey.setNodeID(hashKey); Condition rangeKeyCondition = new Condition() .withComparisonOperator(ComparisonOperator.EQ.toString()) .withAttributeValueList(new AttributeValue().withS(rangeKey)); DynamoDBQueryExpression<NodeHistory> queryExpression = new DynamoDBQueryExpression<NodeHistory>() .withHashKeyValues(nhKey) .withRangeKeyCondition("Time", rangeKeyCondition); List<NodeHistory> latestNodeHistory = mapper.query(NodeHistory.class, queryExpression); System.out.println("Item created: "); for (NodeHistory nh : latestNodeHistory) { System.out.format( "SerialNumber=%s, Time=%s, SAValues=%s\n", nh.getNodeID(), nh.getTime(), nh.getSAValues()); } }
private void printNodeHistoryItems(String nid, String time) { String hashKey = nid; String rangeKey = time; NodeHistory nhKey = new NodeHistory(); nhKey.setNodeID(hashKey); List<NodeHistory> latestNodeHistory; if (time != null) { Condition rangeKeyCondition = new Condition() .withComparisonOperator(ComparisonOperator.EQ.toString()) .withAttributeValueList(new AttributeValue().withS(rangeKey)); DynamoDBQueryExpression<NodeHistory> queryExpression = new DynamoDBQueryExpression<NodeHistory>() .withHashKeyValues(nhKey) .withRangeKeyCondition("Time", rangeKeyCondition); latestNodeHistory = mapper.query(NodeHistory.class, queryExpression); } else { DynamoDBQueryExpression<NodeHistory> queryExpression = new DynamoDBQueryExpression<NodeHistory>().withHashKeyValues(nhKey); latestNodeHistory = mapper.query(NodeHistory.class, queryExpression); } for (NodeHistory nh : latestNodeHistory) { System.out.format( "SerialNumber=%s, Time=%s, SAValues=%s\n", nh.getNodeID(), nh.getTime(), nh.getSAValues()); } }
private void deleteNodeHistoryItem(String nid, String time) { DynamoDBMapperConfig config = new DynamoDBMapperConfig(DynamoDBMapperConfig.ConsistentReads.CONSISTENT); NodeHistory updatedItem; NodeHistory deletedItem; if (time != null) { updatedItem = mapper.load(NodeHistory.class, nid, time, config); mapper.delete(updatedItem); deletedItem = mapper.load(NodeHistory.class, updatedItem.getNodeID(), updatedItem.getTime(), config); } else { updatedItem = mapper.load(NodeHistory.class, nid, config); mapper.delete(updatedItem); deletedItem = mapper.load(NodeHistory.class, updatedItem.getNodeID(), config); } if (deletedItem == null) System.out.println("Done - The item is deleted."); else System.out.println("Fail - The item is still remained."); }
private List<NodeHistoryEntity> transform(List<NodeHistory> target) { List<NodeHistoryEntity> list = new ArrayList<>(); for (NodeHistory item : target) { NodeHistoryEntity temp = new NodeHistoryEntity(); temp.setNID(item.getNodeID()); temp.setSAValues(item.getSAValues()); temp.setTime(item.getTime()); list.add(temp); } return list; }
private void updateNodeHistoryItem(String nid, String time, String values) { NodeHistory itemRetrieved; if (time != null) { itemRetrieved = mapper.load(NodeHistory.class, nid, time); itemRetrieved.setTime(time); } else itemRetrieved = mapper.load(NodeHistory.class, nid); itemRetrieved.setSAValues(values); System.out.println("Item updated: "); System.out.format( "SerialNumber=%s, Time=%s, SAValues=%s\n", itemRetrieved.getNodeID(), itemRetrieved.getTime(), itemRetrieved.getSAValues()); }
public List<NodeHistoryEntity> findNodeHistoriesbyNodeID(String id) { DynamoDBScanExpression scanExpression = new DynamoDBScanExpression(); scanExpression.addFilterCondition( "NodeID", new Condition() .withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withS(id))); List<NodeHistory> scanResult = mapper.scan(NodeHistory.class, scanExpression); List<NodeHistoryEntity> list = new ArrayList<>(); for (NodeHistory n : scanResult) { NodeHistoryEntity nhe = new NodeHistoryEntity(); nhe.setNID(n.getNodeID()); nhe.setTime(n.getTime()); nhe.setSAValues(n.getSAValues()); list.add(nhe); } return list; }
private List<NodeHistoryEntity> findNodeHistories(String nid, String time) { String hashKey = nid; String rangeKey = time; NodeHistory nhKey = new NodeHistory(); nhKey.setNodeID(hashKey); List<NodeHistory> latestNodeHistory; if (time != null) { Condition rangeKeyCondition = new Condition() .withComparisonOperator(ComparisonOperator.EQ.toString()) .withAttributeValueList(new AttributeValue().withS(rangeKey)); DynamoDBQueryExpression<NodeHistory> queryExpression = new DynamoDBQueryExpression<NodeHistory>() .withHashKeyValues(nhKey) .withRangeKeyCondition("Time", rangeKeyCondition); latestNodeHistory = mapper.query(NodeHistory.class, queryExpression); } else { DynamoDBQueryExpression<NodeHistory> queryExpression = new DynamoDBQueryExpression<NodeHistory>().withHashKeyValues(nhKey); latestNodeHistory = mapper.query(NodeHistory.class, queryExpression); } List<NodeHistoryEntity> list = new ArrayList<>(); for (NodeHistory n : latestNodeHistory) { NodeHistoryEntity ret = new NodeHistoryEntity(); ret.setNID(n.getNodeID()); ret.setTime(n.getTime()); ret.setSAValues(n.getSAValues()); list.add(ret); } return list; }