Java 类com.amazonaws.services.dynamodbv2.document.PrimaryKey 实例源码

项目:aws-dynamodb-examples    文件:MoviesItemOps06.java   
public static void main(String[] args)  {

        AmazonDynamoDBClient client = new AmazonDynamoDBClient();
        client.setEndpoint("http://localhost:8000");
        DynamoDB dynamoDB = new DynamoDB(client);

        Table table = dynamoDB.getTable("Movies");

        // Conditional delete (will fail)

        DeleteItemSpec deleteItemSpec = new DeleteItemSpec()
            .withPrimaryKey(new PrimaryKey("year", 2015, "title", "The Big New Movie"))
            .withConditionExpression("info.rating <= :val")
            .withValueMap(new ValueMap()
                   .withNumber(":val", 5.0));

        System.out.println("Attempting a conditional delete...");
        try {
            table.deleteItem(deleteItemSpec);
            System.out.println("DeleteItem succeeded");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("DeleteItem failed");
        }

    }
项目:outland    文件:DefaultGroupStorage.java   
@Override
public Void removeRelation(Group group, String relationHashKey, String relationRangeKey) {

  Table table = dynamoDB.getTable(groupGraphTableName);

  final PrimaryKey key = new PrimaryKey(
      GroupStorage.SUBJECT_KEY, relationHashKey,
      GroupStorage.OBJECT_RELATION_KEY, relationRangeKey
  );

  DynamoDbCommand<DeleteItemOutcome> cmd = new DynamoDbCommand<>("removeRelation",
      () -> table.deleteItem(key),
      () -> {
        throw new RuntimeException("removeRelation");
      },
      dynamodbGraphWriteHystrix,
      metrics);

  final DeleteItemOutcome deleteItemOutcome = cmd.execute();

  logger.info("{} /dynamodb_remove_item_result=[{}]",
      kvp("op", "removeRelation",
          "appkey", group.getKey(),
          "hash_key", relationHashKey,
          "range_key", relationRangeKey,
          "result", "ok"),
      deleteItemOutcome.getDeleteItemResult().toString());

  return null;
}
项目:aws-auto-operations-using-lambda    文件:LambdaLock.java   
boolean updateItem(String key, long currentTimeMillis, int expiredIntervalMillis, Context context) {

        AmazonDynamoDB client = createDynamoDBClient(cc);

        String functionName = context.getFunctionName();
        try {
            long sec = currentTimeMillis - expiredIntervalMillis;

            DynamoDB dynamoDB = new DynamoDB(client);
            Table table = dynamoDB.getTable(TABLE_NAME);

            Map<String, String> expressionAttributeNames = new HashMap<>();
            expressionAttributeNames.put("#created_time", COL_CREATED_TIME);

            Map<String, Object> expressionAttributeValues = new HashMap<>();
            expressionAttributeValues.put(":now", currentTimeMillis);
            expressionAttributeValues.put(":expired", sec);

            table.updateItem(new PrimaryKey(COL_FUNCTION_NAME, functionName, COL_KEY, key), "set #created_time = :now", // UpdateExpression
                    "#created_time < :expired", // ConditionExpression
                    expressionAttributeNames, expressionAttributeValues);

            return true;
        } catch (ConditionalCheckFailedException e) {
            return false;
        } finally {
            client.shutdown();
        }
    }
项目:aws-auto-operations-using-lambda    文件:LambdaLock.java   
boolean updateItem(String key, long currentTimeMillis, int expiredIntervalMillis, Context context) {

        AmazonDynamoDB client = createDynamoDBClient(cc);

        String functionName = context.getFunctionName();
        try {
            long sec = currentTimeMillis - expiredIntervalMillis;

            DynamoDB dynamoDB = new DynamoDB(client);
            Table table = dynamoDB.getTable(TABLE_NAME);

            Map<String, String> expressionAttributeNames = new HashMap<>();
            expressionAttributeNames.put("#created_time", COL_CREATED_TIME);

            Map<String, Object> expressionAttributeValues = new HashMap<>();
            expressionAttributeValues.put(":now", currentTimeMillis);
            expressionAttributeValues.put(":expired", sec);

            table.updateItem(new PrimaryKey(COL_FUNCTION_NAME, functionName, COL_KEY, key), "set #created_time = :now", // UpdateExpression
                    "#created_time < :expired", // ConditionExpression
                    expressionAttributeNames, expressionAttributeValues);

            return true;
        } catch (ConditionalCheckFailedException e) {
            return false;
        } finally {
            client.shutdown();
        }
    }
项目:aws-auto-operations-using-lambda    文件:LambdaLock.java   
boolean updateItem(String key, long currentTimeMillis, int expiredIntervalMillis, Context context) {

        AmazonDynamoDB client = createDynamoDBClient(cc);

        String functionName = context.getFunctionName();
        try {
            long sec = currentTimeMillis - expiredIntervalMillis;

            DynamoDB dynamoDB = new DynamoDB(client);
            Table table = dynamoDB.getTable(TABLE_NAME);

            Map<String, String> expressionAttributeNames = new HashMap<>();
            expressionAttributeNames.put("#created_time", COL_CREATED_TIME);

            Map<String, Object> expressionAttributeValues = new HashMap<>();
            expressionAttributeValues.put(":now", currentTimeMillis);
            expressionAttributeValues.put(":expired", sec);

            table.updateItem(new PrimaryKey(COL_FUNCTION_NAME, functionName, COL_KEY, key), "set #created_time = :now", // UpdateExpression
                    "#created_time < :expired", // ConditionExpression
                    expressionAttributeNames, expressionAttributeValues);

            return true;
        } catch (ConditionalCheckFailedException e) {
            return false;
        } finally {
            client.shutdown();
        }
    }
项目:aws-auto-operations-using-lambda    文件:LambdaLock.java   
boolean updateItem(String key, long currentTimeMillis, int expiredIntervalMillis, Context context) {

        AmazonDynamoDB client = createDynamoDBClient(cc);

        String functionName = context.getFunctionName();
        try {
            long sec = currentTimeMillis - expiredIntervalMillis;

            DynamoDB dynamoDB = new DynamoDB(client);
            Table table = dynamoDB.getTable(TABLE_NAME);

            Map<String, String> expressionAttributeNames = new HashMap<>();
            expressionAttributeNames.put("#created_time", COL_CREATED_TIME);

            Map<String, Object> expressionAttributeValues = new HashMap<>();
            expressionAttributeValues.put(":now", currentTimeMillis);
            expressionAttributeValues.put(":expired", sec);

            table.updateItem(new PrimaryKey(COL_FUNCTION_NAME, functionName, COL_KEY, key), "set #created_time = :now", // UpdateExpression
                    "#created_time < :expired", // ConditionExpression
                    expressionAttributeNames, expressionAttributeValues);

            return true;
        } catch (ConditionalCheckFailedException e) {
            return false;
        } finally {
            client.shutdown();
        }
    }
项目:java-persistence    文件:DdbIndex.java   
private PrimaryKey toPrimaryKey(IndexKey key) {
    PrimaryKey pk = new PrimaryKey()
        .addComponent(_hkName, key.getHashKey());
    if ( null != _rkName ) {
        pk.addComponent(_rkName, key.getRangeKey());
    }
    return pk;
}
项目:serverless    文件:BookGetOne.java   
@Override
  public String handleRequest(Book request, Context context) {

    Item outcome = DynamoDBUtil.getTable().getItem(new PrimaryKey("id", request.getId()));
    if (null != outcome) {
        return outcome.toJSONPretty();
    }
return null;
  }
项目:aws-dynamodb-examples    文件:MoviesItemOps02.java   
public static void main(String[] args)  {

        AmazonDynamoDBClient client = new AmazonDynamoDBClient();
        client.setEndpoint("http://localhost:8000");
        DynamoDB dynamoDB = new DynamoDB(client);

        Table table = dynamoDB.getTable("Movies");

        int year = 2015;
        String title = "The Big New Movie";

        final Map<String, Object> infoMap = new HashMap<String, Object>();
        infoMap.put("plot",  "Nothing happens at all.");
        infoMap.put("rating",  0.0);
        Item item = new Item()
            .withPrimaryKey(new PrimaryKey("year", year, "title", title))
            .withMap("info", infoMap);

        // Attempt a conditional write.  We expect this to fail.

        PutItemSpec putItemSpec = new PutItemSpec()
            .withItem(item)
            .withConditionExpression("attribute_not_exists(#yr) and attribute_not_exists(title)")
            .withNameMap(new NameMap()
                .with("#yr", "year"));

        System.out.println("Attempting a conditional write...");
        try {
            table.putItem(putItemSpec);
            System.out.println("PutItem succeeded: " + table.getItem("year", year, "title", title).toJSONPretty());
        } catch (ConditionalCheckFailedException e) {
            e.printStackTrace(System.err);
            System.out.println("PutItem failed");
        }
    }
项目:aws-dynamodb-examples    文件:MoviesItemOps05.java   
public static void main(String[] args)  {

        AmazonDynamoDBClient client = new AmazonDynamoDBClient();
        client.setEndpoint("http://localhost:8000");
        DynamoDB dynamoDB = new DynamoDB(client);

        Table table = dynamoDB.getTable("Movies");

        int year = 2015;
        String title = "The Big New Movie";

        // Conditional update (will fail)

        UpdateItemSpec updateItemSpec = new UpdateItemSpec()
            .withPrimaryKey(new PrimaryKey("year", 2015, "title",  "The Big New Movie"))
            .withUpdateExpression("remove info.actors[0]")
            .withConditionExpression("size(info.actors) > :num")
            .withValueMap(new ValueMap().withNumber(":num", 3));

        System.out.println("Attempting a conditional update...");
        try {
            table.updateItem(updateItemSpec);
            System.out.println("UpdateItem succeeded: " + table.getItem("year", year, "title", title).toJSONPretty());
        } catch (ConditionalCheckFailedException e) {
            e.printStackTrace();
            System.out.println("UpdateItem failed");
        }

    }
项目:AwsCommons    文件:AbstractDynamoTable.java   
@Override
public void truncate() {
    getAll()
            .parallelStream()
            .forEach(p -> table.deleteItem(new PrimaryKey("id", p.getId())));
}
项目:AwsCommons    文件:AbstractDynamoTable.java   
@Override
public void delete(final String id) {
    table.deleteItem(new PrimaryKey("id", id));
}
项目:logback-ext    文件:DynamoDbAppender.java   
protected PrimaryKey createEventId(ILoggingEvent event) {
    return new PrimaryKey(primaryKey, UUID.randomUUID().toString());
}
项目:serverless    文件:BookDelete.java   
@Override
public String handleRequest(Book request, Context context) {

    DeleteItemOutcome outcome = DynamoDBUtil.getTable().deleteItem(new PrimaryKey("id", request.getId()));

    String result = "Item deleted: " + outcome.getDeleteItemResult().getSdkHttpMetadata().getHttpStatusCode();

    return result;
}
项目:drill-dynamo-adapter    文件:DynamoQueryBuilder.java   
private void setPrimaryKey(FilterLeaf leaf, PrimaryKey pk) {

    }