【发布时间】:2017-09-15 20:21:39
【问题描述】:
如何从 corda 自定义表中获取数据? 我的示例代码如下:-
Api layer -- getIous() method
{
Field attributeValue=IOUSchemaV1.PersistentIOU.class.getDeclaredField("value");
CriteriaExpression currencyIndex = Builder.equal(attributeValue, "12");
QueryCriteria.VaultCustomQueryCriteria criteria = new
QueryCriteria.VaultCustomQueryCriteria(currencyIndex);
vaultStates = services.vaultQueryByCriteria(criteria,IOUState.class);
}
-
在 ExamplePlugin 中,我添加了下面的架构注册代码
public class ExamplePlugin extends CordaPluginRegistry implements WebServerPluginRegistry { @NotNull @Override public Set<MappedSchema> getRequiredSchemas() { Set<MappedSchema> requiredSchemas = new HashSet<>(); requiredSchemas.add(new IOUSchemaV1()); return requiredSchemas; }}
-
我的 Schema 类是 ---
public final class IOUSchema { } @CordaSerializable public class IOUSchemaV1 extends MappedSchema { public IOUSchemaV1() { super(IOUSchema.class, 1, ImmutableList.of(PersistentIOU.class)); } @Entity @Table(name = "iou_states") public static class PersistentIOU extends PersistentState { @Column(name = "sender_name") private final String senderName; @Column(name = "recipient_name") private final String recipientName; @Column(name = "value") private final int value; public PersistentIOU(String senderName, String recipientName, int value) { this.senderName = senderName; this.recipientName = recipientName; this.value = value; } public String getSenderName() { return senderName; } public String getRecipientName() { return recipientName; } public int getValue() { return value; }} }
-
我的州有:-
public class IOUState implements LinearState, QueryableState { --- some code goes here and below methods as well.--- @Override public PersistentState generateMappedObject(MappedSchema schema) { if (schema instanceof IOUSchemaV1) { return new IOUSchemaV1.PersistentIOU( this.sender.getName().toString(), this.recipient.getName().toString(), this.iou.getValue()); } else { throw new IllegalArgumentException("Unrecognised schema $schema"); } } @Override public Iterable<MappedSchema> supportedSchemas() { return ImmutableList.of(new IOUSchemaV1()); } }
但我总是遇到异常。
引起:net.corda.core.node.services.VaultQueryException:
请在您的 CorDapp 的 CordaPluginRegistry 配置中注册实体 'com.example.schema.IOUSchemaV1' 类(requiredSchemas 属性) 并确保您已声明(在supportedSchemas()中)并映射(在generateMappedObject()中) 关联合约状态的 QueryableState 接口实现中的架构。
谁能帮忙解决这个问题。
【问题讨论】:
标签: corda