搜索

49.11. 8.OneToMany

download PDF

注释 @OneToMany 的目的是允许处理 List<?> 字段定义了 POJO 类,或者从包含重复组的记录中使用。

*Restrictions OneToMany*

请注意,很多绑定不允许处理在层次结构的多个级别上定义的重复性

在以下情况下,关系 OneToMany ONLY WORKS:

  • 阅读包含重复组的 FIX 消息(标签/密钥组)
  • 生成带有重复数据的 CSV
注解名称记录类型级别

OneToMany

all

属性

参数名称typeinfo

mappedTo

string

可选 - string - 与 Class> 的 List<Type 类型关联的类名称

问题单 1:使用重复数据生成 CSV

以下是我们想要的 CSV 输出:

Claus,Ibsen,Camel in Action 1,2010,35
Claus,Ibsen,Camel in Action 2,2012,35
Claus,Ibsen,Camel in Action 3,2013,35
Claus,Ibsen,Camel in Action 4,2014,35

Remark:重复数据涉及书的标题及其发布日期,而姓氏和年龄是通用的

以及用于对其进行建模的类。Author 类包含 Book 列表。

使用重复数据生成 CSV

@CsvRecord(separator=",")
public class Author {

    @DataField(pos = 1)
    private String firstName;

    @DataField(pos = 2)
    private String lastName;

    @OneToMany
    private List<Book> books;

    @DataField(pos = 5)
    private String Age;
}

public class Book {

    @DataField(pos = 3)
    private String title;

    @DataField(pos = 4)
    private String year;
}

非常简单!!!!

case 2:阅读包含标签/密钥组的 FIX 消息

以下是我们在我们的模型中要处理的信息:

8=FIX 4.19=2034=135=049=INVMGR56=BRKR
1=BE.CHM.00111=CHM0001-0158=this is a camel - bindy test
22=448=BE000124567854=1
22=548=BE000987654354=2
22=648=BE000999999954=3
10=220

标签 22、48 和 54 重复

和代码

读取包含标签/密钥组的 FIX 消息

public class Order {

    @Link Header header;

    @Link Trailer trailer;

    @KeyValuePairField(tag = 1) // Client reference
    private String account;

    @KeyValuePairField(tag = 11) // Order reference
    private String clOrdId;

    @KeyValuePairField(tag = 58) // Free text
    private String text;

    @OneToMany(mappedTo = "org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Security")
    List<Security> securities;
}

public class Security {

    @KeyValuePairField(tag = 22) // Fund ID type (Sedol, ISIN, ...)
    private String idSource;

    @KeyValuePairField(tag = 48) // Fund code
    private String securityCode;

    @KeyValuePairField(tag = 54) // Movement type ( 1 = Buy, 2 = sell)
    private String side;
}
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.