配置关系存储联接时,我可以从ActivePivot存储中进行一对多联接吗? [英] When configuring a relational store join, can I do a one-to-many join from the ActivePivot store?

查看:114
本文介绍了配置关系存储联接时,我可以从ActivePivot存储中进行一对多联接吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用关系商店,可以从ActivePivot商店到联接商店进行一对多联接.假设我的ActivePivot商店加入了SOME_ID上的另一个商店,但是另一个商店的密钥是SOME_ID,SOME_TYPE.然后就有可能:

Using Relational Stores, is it possible to do a one-to-many join from the ActivePivot store to a joining store. Suppose my ActivePivot store joins to another store on SOME_ID, but the key for the other store is SOME_ID,SOME_TYPE. Then it is possible to have:

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

但是,尝试进行连接时,会出现以下错误,因为在连接存储区中没有唯一的条目:

However, when the join is attempted, the following error is raised, because there is not a unique entry in the joining store:

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

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

I can see why there is a problem, because there single record in the AP store that really needs to become two separate records that join to each of the records in the join store, respectively, but I guess that can't happen unless JOIN_STORE:SOME_TYPE is also a field in the AP store.

是否可以通过AP商店进行这样的一对多联接?

Is there a way to make such a one-to-many join from the AP store happen?

谢谢

为清楚起见,AP存储中不存在SOME_TYPE(即使使用其他名称).我已经加入了所有公共字段,但是加入存储中有多个匹配项.匹配条目在一个不常见且在AP存储中不存在的字段上有所不同.

To be clear, SOME_TYPE does not exist in the AP store (even under a different name). I have joined on all the common fields, but there are more than one matching entries in the joining store. The matching entries differ on a field that is not common and does not exist in the AP store.

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

If I try to add a foreign key that does not exist in the AP store (even under a different name), I get:

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:

推荐答案

关系存储联接不会复制数据. 您不能使用关系存储的联接将一个条目联接到多个条目. 您不能将多个生产计算器与关系存储一起使用.

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.

根据您的项目体系结构和工作流程,您可以考虑在用于处理AP_Store的事务处理程序中添加逻辑.在此事务处理程序中,您可以检索Join_Store的条目,以便复制AP_Store的条目.

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.

您首先需要通过添加用于区分重复项的新字段来更改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

对于事务处理程序,您可以注入StoresUniverse以便检索Join_Store,然后使用Join_Store上的SOME_ID值进行搜索以检索需要创建的重复项的数量:

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
    }

这篇关于配置关系存储联接时,我可以从ActivePivot存储中进行一对多联接吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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