我们正在尝试使用状态为查询条件的保管库查询从自定义表中获取数据。但是我们得到的状态带有一个模型类,该类包含数据库中的旧值而不是新值。有人可以指出一个示例,该示例从自定义表中获取数据并将其映射到corda中的模型类。
从架构到状态的映射]。确保您的状态实现了QueryableState类。
@Override public PersistentState generateMappedObject(MappedSchema schema) {
if (schema instanceof IOUSchemaV1) {
return new IOUSchemaV1.PersistentIOU(
this.lender.getName().toString(),
this.borrower.getName().toString(),
this.value,
this.linearId.getId());
} else {
throw new IllegalArgumentException("Unrecognised schema $schema");
}
}
然后您可以使用像这样的保管库查询来查询数据库>
QueryCriteria queryCriteria = new QueryCriteria.VaultQueryCriteria().withStatus(Vault.StateStatus.UNCONSUMED); List<StateAndRef<IOUState>> iouStates = getServiceHub().getVaultService() .queryBy(IOUState, queryCriteria).getStates();