我可以在 DynamoDB 中插入一个对象(用 @DynamoDBTable 注释(,使用以下代码
@Autowired
private SdnInformationRepository sdnInformationRepository;
SdnInformation inf = new SdnInformation();
inf.setFirstName("firstname");
inf.setLastName("lastname");
sdnInformationRepository.save(inf);
这是我的存储库
public interface SdnInformationRepository extends
CrudRepository<SdnInformation, String> {
}
和我的模型
@DynamoDBTable(tableName = "SdnList")
public class SdnInformation {
@DynamoDBHashKey(attributeName = "Id")
@DynamoDBAutoGeneratedKey
private String id;
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
这里一切正常。我想知道是否可以一次插入一个列表/一组 SdnInformation 对象?如果我单独插入大量此类对象,则需要花费太多时间。 所以我想要类似的东西
Set<SdnInformation> listToInsert = new HashSet<SdnInformation>();
... some code to fill my set with thousands of objects ...
sdnInformationRepository.save(listToInsert);
DynamoDB 不支持同时插入多个项目。批处理多个请求(最多 25 个(是可能的,但它们仍被 Dynamo 视为单独的请求(即某些请求可能会成功,某些请求可能会失败(。
当然,在高级别上,映射器可以假装它正在插入项目列表,但在底层仍然会有单独的操作。
更新(基于评论(
如果您追求的是速度,则可以并行化插入。只要您有可用的写入容量,您就可以通过这种方式获得很多速度改进。但它可能会很快变得昂贵。并且每个分区的限制为 1000 次插入/秒。