我在需要多种查询类型的分页中使用Spring Boot和DynamoDB:
实体和存储库类在这里:
["Coke": ["1", "80"], "Appetizer": ["3", "70"], "Water": ["4", "70"],
"Noodle": ["2", "40"], "Pizza": ["7", "80"], "Steak": ["7", "60"]]
和
cd /path/to/tensorflow-models/research/slim
# export inference graph, success
python export_inference_graph.py --alsologtostderr --model_name=resnet_v1_50 --output_file=resnet_v1_50_inf_graph.pb
# freeze the inference graph with the trained weights, failed
python ~/.local/lib/python2.7/site-packages/tensorflow/python/tools/freeze_graph.py \
--input_graph=resnet_v1_50_inf_graph.pb \
--input_checkpoint=/path/to/models/resnet_v1_50.ckpt \
--input_binary=true --output_graph=frozen_resnet_v1_50.pb \
--output_node_names=resnet_v1_50/predictions/Reshape
现在,如果我尝试使用以下方法查询findAllByOrganizationId(UUID OrganizationId,Pageable pageable):
@DynamoDBTable(tableName = "organizationPersons")
public class OrganizationPersonsEntity {
@Id
private OrganizationPersonsEntityId id;
private UUID organizationId;
private UUID personId;
private String type;
private String sortKey;
private String personSortName;
public OrganizationPersonsEntity(){
}
public OrganizationPersonsEntity(UUID orgnizationId, UUID personId) {
setOrganizationId(orgnizationId);
setPersonId(personId);
}
public OrganizationPersonsEntity(UUID orgnizationId, UUID personId, String type, String personSortName) {
setOrganizationId(orgnizationId);
setPersonId(personId);
this.type = type;
this.personSortName = personSortName;
}
@DynamoDBHashKey
@DynamoDBIndexHashKey(globalSecondaryIndexName = "sortIndex")
public UUID getOrganizationId() {
return id != null ? id.getOrganizationId() : null;
}
public void setOrganizationId(UUID orgnizationId) {
if (id == null) {
id = new OrganizationPersonsEntityId();
}
this.id.setOrganizationId(orgnizationId);
}
@DynamoDBRangeKey
@DynamoDBIndexHashKey(globalSecondaryIndexName = "personIndex")
public UUID getPersonId() {
return id != null ? id.getPersonId(): null;
}
public void setPersonId(UUID personId) {
if (id == null) {
id = new OrganizationPersonsEntityId();
}
this.id.setPersonId(personId);
}
@DynamoDBAttribute
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@DynamoDBIndexRangeKey(globalSecondaryIndexNames = {"sortIndex"})
public String getSortKey() {
if (sortKey == null) {
return personSortName + "-" + id.organizationId + "-" + id.personId;
} else {
return sortKey;
}
}
public void setSortKey(String sortKey) {
this.sortKey = sortKey;
}
public static class OrganizationPersonsEntityId implements Serializable {
private static final long serialVersionUID = 1L;
private UUID organizationId;
private UUID personId;
public OrganizationPersonsEntityId() {
}
public OrganizationPersonsEntityId(UUID organizationId, UUID personId) {
this.organizationId = organizationId;
this.personId = personId;
}
@DynamoDBHashKey
public UUID getOrganizationId() {
return organizationId;
}
public void setOrganizationId(UUID id) {
this.organizationId = id;
}
@DynamoDBRangeKey
public UUID getPersonId() {
return personId;
}
public void setPersonId(UUID personId) {
this.personId = personId;
}
}
}
我得到一个错误,即使“ sortKey”定义为IndexRangeKey,也只能对personId进行排序。
@Repository
public interface OrganizationPersonsRepository extends
DynamoDBPagingAndSortingRepository<OrganizationPersonsEntity, UUID> {
Optional<List<OrganizationPersonsEntity>> findAllByPersonId(UUID personId);
Page<OrganizationPersonsEntity> findAllByOrganizationId(UUID organizationId, Pageable pageable);
Page<OrganizationPersonsEntity> findAllByOrganizationIdAndSortKeyBetween(UUID organizationId, String after, String before, Pageable pageRequest);
Page<OrganizationPersonsEntity> findAllByOrganizationIdAndSortKeyGreaterThanEqual(UUID organizationId, String after, Pageable pageRequest);
Page<OrganizationPersonsEntity> findAllByOrganizationIdAndSortKeyLessThanEqual(UUID organizationId, String before, Pageable pageRequest);
OrganizationPersonsEntity findByOrganizationIdAndPersonId(UUID organizationId, UUID personId);
default RepositoryPagingQuery<OrganizationPersonsEntity> findAllByOrganizationIdQuery(UUID organization) {
return (after, before, limit, ascending) -> {
PageRequest pageRequest = PageRequest.of(0, limit, ascending ? Sort.Direction.ASC : Sort.Direction.DESC, "sortKey");
if (after != null && before != null) {
return findAllByOrganizationIdAndSortKeyBetween(organization, after, before, pageRequest).getContent();
} else if (after != null) {
return findAllByOrganizationIdAndSortKeyGreaterThanEqual(organization, after, pageRequest).getContent();
} else if (before != null) {
return findAllByOrganizationIdAndSortKeyLessThanEqual(organization, before, pageRequest).getContent();
} else {
return findAllByOrganizationId(organization, pageRequest).getContent();
}
};
}
}
我希望有人能够提供帮助,谢谢。
版本Spring boot 2.0.1.RELEASE,Maven:com.github.derjust:spring-data-dynamodb:5.0.3,com.amazonaws:aws-java-sdk-dynamodb:jar:1.11.336