Esempio n. 1
0
  @Override
  public Profile findOne(String profileName) {
    AmazonDynamoDB client = null;
    if (System.getProperty("useProxy") != null) {
      ClientConfiguration conf =
          new ClientConfiguration()
              .withProxyHost(System.getProperty("proxyHost"))
              .withProxyPort(Integer.valueOf(System.getProperty("proxyPort")))
              .withProxyUsername(System.getProperty("proxyUsername"))
              .withProxyPassword(System.getProperty("proxyPassword"));
      client = new AmazonDynamoDBClient(new ClasspathPropertiesFileCredentialsProvider(), conf);
    } else {
      client = new AmazonDynamoDBClient(new ClasspathPropertiesFileCredentialsProvider());
    }

    client.setRegion(Region.getRegion(Regions.AP_NORTHEAST_1));
    client.setEndpoint("https://dynamodb.ap-northeast-1.amazonaws.com");
    DynamoDBMapper mapper = new DynamoDBMapper(client);
    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    Map<String, Condition> scanFilter = new HashMap<String, Condition>();
    Condition scanCondition =
        new Condition()
            .withComparisonOperator(ComparisonOperator.EQ)
            .withAttributeValueList(new AttributeValue().withS(profileName));
    scanFilter.put("profile_name", scanCondition);
    scanExpression.setScanFilter(scanFilter);
    for (Profile p : mapper.scan(Profile.class, scanExpression)) {
      return p;
    }
    return null;
  }
  // returns list of items ordered so far by the user
  public CartItem decreaseQuantity(Long cartId) {
    DynamoDBMapper mapper = this.conn.getMapper();
    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    Map<String, Condition> scanFilter = new HashMap<String, Condition>();
    Condition scanCondition =
        new Condition()
            .withComparisonOperator(ComparisonOperator.EQ.toString())
            .withAttributeValueList(new AttributeValue().withN(cartId.toString()));

    scanFilter.put("CartId", scanCondition);
    scanExpression.setScanFilter(scanFilter);
    PaginatedScanList<CartItem> items = mapper.scan(CartItem.class, scanExpression);
    CartItem item = items.get(0);
    item.setQuantity(item.getQuantity() - 1);
    mapper.save(item);
    return item;
  }
  public void removeItemFromCart(Long cartId) {
    DynamoDBMapper mapper = this.conn.getMapper();
    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    Map<String, Condition> scanFilter = new HashMap<String, Condition>();
    Condition scanCondition =
        new Condition()
            .withComparisonOperator(ComparisonOperator.EQ.toString())
            .withAttributeValueList(new AttributeValue().withN(cartId.toString()));

    scanFilter.put("CartId", scanCondition);

    scanExpression.setScanFilter(scanFilter);
    System.out.println("Going to retrieve item.");
    PaginatedScanList<CartItem> items = mapper.scan(CartItem.class, scanExpression);
    System.out.println("Number of items retrived. " + items.size());
    System.out.println("Going to remove a cartItem with productId: " + items.get(0).getProductId());
    mapper.delete(items.get(0));
  }
Esempio n. 4
0
  public static ArrayList<Account> getAccountList() {
    AmazonDynamoDBClient ddb = LoginActivity.clientManager.ddb();
    DynamoDBMapper mapper = new DynamoDBMapper(ddb);

    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    try {
      PaginatedScanList<Account> result = mapper.scan(Account.class, scanExpression);

      ArrayList<Account> resultList = new ArrayList<Account>();
      for (Account up : result) {
        resultList.add(up);
      }

      return resultList;

    } catch (AmazonServiceException ex) {
      LoginActivity.clientManager.wipeCredentialsOnAuthError(ex);
    }

    return null;
  }
  public static void main(String[] args) {
    DynamoDBMapper mapper = new DynamoDBMapper(client);
    DynamoDBScanExpression expression = new DynamoDBScanExpression();

    expression.addFilterCondition(
        "ConfigType",
        new Condition()
            .withComparisonOperator(ComparisonOperator.EQ)
            .withAttributeValueList(new AttributeValue().withS("Override")));

    expression.addFilterCondition(
        "CountryCode",
        new Condition()
            .withComparisonOperator(ComparisonOperator.EQ)
            .withAttributeValueList(new AttributeValue().withS("US")));

    final List<ConfigObject> queryResults = mapper.scan(ConfigObject.class, expression);

    for (ConfigObject config : queryResults) {
      System.out.println(config);
    }
  }
  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;
  }