首页 文章

将数据插入ATG中的链接存储库

提问于
浏览
0

我有一个要求,我在 ABC repository中有两个表 employeeXYZ 存储库中有 address_details .

employee 的一列具有 address_details 的外键引用 .

在这里,我有 primaryKeyaddress_details ,并且 primaryKey 参考我必须在 employee 中插入我的数据 .

所以我的RDF是这样的:

RDF 1:(Repository1: ABC

<item-descriptor name=”employee” >
 <table name=”employee”>
   <property name=”empId” data-type=”string” column-name=”emp_id”
     required=”true”/>
   <property name=”address” column-name=”address_id” item-type=”address”
     repository=”XYZ” required=”true”/>
 </table>
</item-descriptor>

RDF 2 :( Repsitory2: XYZ

<item-descriptor name=”address” >
  <table name=”address_details”>
    <property name=”addressId” data-type=”string” column-name=”address_id”/>
    <property name=”streetName” column-name=”street_name” data-type=”string”/>
    <property name=”city” column-name=”city” data-type=”string” />
  </table>
</item-descriptor>

我将所有地址存储在表 address_details 中 . 我必须将 employee 映射到这些地址 .

我在这里尝试的方法是首先获取_118573_的 Address ,然后设置 employee 的属性类型 address 并将其添加到 employee 表中 . 这有效 .

但是我想单独在一个调用中插入 employee 数据?

有关如何使用 RepositoryItemMutableRepositoryItem 进行此操作的任何建议?

1 回答

  • 0

    通过插入一个调用,我假设你的意思是你想以原子方式提交所有插入 . 没有机制在一个SQL语句中执行多个插入 - 您必须为您创建的每个项调用一次MutableRepository.addItem() . 以下代码将允许您将存储库工作包装在事务中,以便一次性提交所有数据 .

    TransactionManager tm = ...
    TransactionDemarcation td = new TransactionDemarcation ();
    try {
      try {
        td.begin(tm);
    
        // Create all items and call MutableRepository.addItem() for each of them.
      }
      finally {
        td.end();
      }
    }
    catch (TransactionDemarcationException exc) {
      logError(exc);
    }
    

相关问题