48.10. 8.OneToMany
アノテーション @OneToMany の目的は、POJO クラスで定義された List<?>
フィールドを操作できるようにすること、または反復グループを含むレコードから操作できるようにすることです。
*Restrictions OneToMany*
*Restrictions OneToMany*
bindy の 1 対多では、階層の複数のレベルで定義された繰り返しを処理できないことに注意してください。
OneToMany の関係は、次の場合にのみ機能します。
- 反復グループ (= タグ/キーのグループ) を含む FIX メッセージの読み取り
- 反復データを含む CSV の生成
アノテーション名 | レコードの種類 | レベル |
---|---|---|
OneToMany | all | プロパティー |
パラメーター名 | type | Info |
---|---|---|
mappedTo | string | オプション - 文字列 - List<Type of the Class> の型に関連付けられたクラス名 |
ケース 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
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
備考 : 反復データは本のタイトルとその発行日に関するもので、姓名と年齢が一般的です。
そして、これをモデル化するために使用されるクラス。Author クラスには、書籍リストが含まれています。
反復データを含む 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; }
@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;
}
とてもシンプルですね!!!
ケース 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
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; }
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;
}