3

使用关系存储,是否可以从 ActivePivot 存储到加入存储进行一对多联接。假设我的 ActivePivot 存储连接到 SOME_ID 上的另一个存储,但另一个存储的键是 SOME_ID,SOME_TYPE。那么就有可能:

AP_STORE SOME_ID | JOIN_STORE SOME_ID | JOIN_STORE SOME_TYPE
------------------------------------------------------------
      1          |      1             | TYPE1
      1          |      1             | TYPE2

但是,当尝试加入时,会引发以下错误,因为加入存储中没有唯一的条目:

Caused by: com.quartetfs.fwk.QuartetRuntimeException: Impossible to find exactly 1 entry from store with key: Key 

我可以看到为什么会出现问题,因为 AP 存储中的单个记录确实需要成为两个单独的记录,分别连接到连接存储中的每个记录,但我想除非 JOIN_STORE 否则不会发生: SOME_TYPE 也是 AP 存储中的一个字段。

有没有办法从 AP 商店进行这种一对多的加入?

谢谢

编辑:需要明确的是,AP 商店中不存在 SOME_TYPE(即使使用不同的名称)。我已加入所有常用字段,但加入商店中有多个匹配条目。匹配条目在不常见且在 AP 存储中不存在的字段上有所不同。

如果我尝试添加 AP 商店中不存在的外键(即使使用不同的名称),我会得到:

Caused by: com.quartetfs.fwk.QuartetRuntimeException: com.quartetfs.fwk.AgentException: On join 'AP_STORE=>JOIN_STORE' the store 'AP_STORE' does not contain the foreign key 'FIELD_ONLY_IN_JOIN_STORE' in its fields:
4

2 回答 2

3

A relational store join does not duplicate the data. You cannot, using the join of the relational stores, join one entry to multiple ones. You cannot use a multiple producing calculator with the relational stores neither.

Depending of your project architecture and workflow, you can consider adding a logic in the transaction handler used to feed your AP_Store. In this transaction handler, you could retrieve the entries of your Join_Store in order to duplicate the entries of your AP_Store.

You'll first need to change your AP_Store keys by adding a new fields used to differentiate your duplicates.

    AP_STORE SOME_ID | AP_STORE SOME_DUPLICATE_ID |JOIN_STORE SOME_ID | JOIN_STORE SOME_TYPE
    -----------------------------------------------------------------------------------------        
          1          |            1               |         1         |       TYPE1
          1          |            2               |         1         |       TYPE2

For your transaction handler you can inject the StoresUniverse in order to retrieve your Join_Store and then do a search using the SOME_ID value on the Join_Store to retrieve the number of duplicates you'll need to create:

    IRelationalStore joinStore = storeUniverse.get("Join_Store");
    List<IRelationalEntry> joinEntries = joinStore.search("SOME_ID",apStoreObject.get("SOME_ID"));
    for(int i = 0; i < joinEntries.size(); i++) {
       // Clone apStoreObject, add a SOME_DUPLICATE_ID value and add it to the list of objects to add in your AP_Store
    }
于 2012-09-21T08:53:15.323 回答
0

要将您的 AP 商店加入到joiningStore,您需要提供一组字段,这在 2 个商店之间是通用的。没有像这些字段是每个商店的关键字段这样的约束。

然后,如果您的 AP 存储中有一个表示 SOME_TYPE 的字段,只需将其添加为外键。

<property name="joins">
    <list>
        <bean class="com.quartetfs.tech.store.description.impl.JoinDescription">
             <property name="targetStoreName" value="JoiningStore" /> 
             <property name="foreignKeys" value="SOME_TYPE" /> 
        </bean>
    </list>
</property>

如果joined store和joining store中的field有不同的名字,可以用一个map来描述joined store外键和joining field中关联字段的关系:

<property name="joins">
    <list>
        <bean class="com.quartetfs.tech.store.description.impl.JoinDescription">
             <property name="targetStoreName" value="JoiningStore" /> 
             <property name="foreignKeyMap" >
                 <map>
                      <entry key="AP_SOME_TYPE" value="SOME_TYPE" />
                 </map>
             </property>
        </bean>
    </list>
</property>
于 2012-09-21T06:55:48.147 回答