从Corda自定义表中获取数据时出错 [英] Error While Fetching Data from Corda Custom Tables

查看:47
本文介绍了从Corda自定义表中获取数据时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Corda Custom表中获取数据?
我的示例代码如下:-

How to fetch data from corda Custom tables? my sample code is as follows :-

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);
}




  1. 在ExamplePlugin我在下面的代码中添加了模式注册

  1. In ExamplePlugin I added below code for schema registration

public class ExamplePlugin extends CordaPluginRegistry implements 
WebServerPluginRegistry
{
@NotNull
@Override
public Set<MappedSchema> getRequiredSchemas()
{
    Set<MappedSchema> requiredSchemas = new HashSet<>();
    requiredSchemas.add(new IOUSchemaV1());
    return requiredSchemas;
}

}

我的模式类是---

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());
}
}


但一直以来,我都低于例外。

But all the time i am getting below exception.

原因:net.corda.core.node.services.VaultQueryException:

Caused by: net.corda.core.node.services.VaultQueryException:

请在您的CorDapp的CordaPluginRegistry配置(requiredSchemas属性)
中注册实体'com.example.schema.IOUSchemaV1'类,并确保已声明(在supportedSchemas()中)和映射(在generateMappedObject( ))
相关合同状态的QueryableState接口实现中的架构。

Please register the entity 'com.example.schema.IOUSchemaV1' class in your CorDapp's CordaPluginRegistry configuration (requiredSchemas attribute) and ensure you have declared (in supportedSchemas()) and mapped (in generateMappedObject()) the schema in the associated contract state's QueryableState interface implementation.

任何人都可以帮助解决此问题。

Can anyone please help to resolve this.

推荐答案

尝试从插件声明中删除实现WebServerPluginRegistry

Try deleting implements WebServerPluginRegistry from your plugin declaration.

这篇关于从Corda自定义表中获取数据时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆