Пример #1
0
  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());
    }
  }
Пример #2
0
  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());
    }
  }
Пример #3
0
  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;
  }
Пример #4
0
  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());
  }
Пример #5
0
  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;
  }
Пример #6
0
  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;
  }