目录

Search

  1. 前言
  2. 业务实体服务简介
  3. Enterprise Java Bean 业务实体服务调用
  4. 具象状态传输业务实体服务调用
  5. 简单对象访问协议业务实体服务调用
  6. 用于交叉引用记录和 BVT 计算的服务
  7. 支持企业关联服务
  8. 清理、分析和转换业务实体数据的外部调用
  9. 使用 REST API 添加业务实体记录

业务实体服务指南

业务实体服务指南

使用标准 SDO 类的 Java 代码示例

使用标准 SDO 类的 Java 代码示例

本示例显示的 Java 代码会运行基于标准服务数据对象 (SDO) 类的 Enterprise Java Bean (EJB) 调用。
该示例位于资源工具包中的以下文件:
C:\<
MDM Hub 安装目录
>\hub\resourcekit\samples\COS\source\java\com\informatica\mdm\sample\cs\DynamicSDO.java
以下 Java 代码基于标准 SDO 类,并会运行 EJB 业务实体服务调用,从而创建 Person 基础对象记录、添加多个子记录、删除一个子记录以及删除该 Person 记录和所有子记录:
package com.informatica.mdm.sample.cs; import com.informatica.mdm.cs.CallContext; import com.informatica.mdm.cs.api.CompositeServiceException; import com.informatica.mdm.cs.client.CompositeServiceClient; import com.siperian.sif.client.EjbSiperianClient; import com.siperian.sif.client.SiperianClient; import commonj.sdo.DataObject; import commonj.sdo.Property; import commonj.sdo.Type; import commonj.sdo.helper.DataFactory; import commonj.sdo.helper.HelperContext; import java.io.PrintStream; import java.util.Arrays; import java.util.Properties; public class DynamicSDO { public static void main(String[] args) throws CompositeServiceException { if(args.length != 3) { System.err.println("USAGE: DynamicSDO <ors> <user> <pass>"); return; } new DynamicSDO(args[0], args[1], args[2]).execute(); } private String orsId; private String user; private String pass; private HelperContext helperContext; private PrintStream out = System.out; public DynamicSDO(String orsId, String user, String pass) { this.orsId = orsId; this.user = user; this.pass = pass; } public void execute() throws CompositeServiceException { String systemName = "Admin"; Properties config = new Properties(); config.put(SiperianClient.SIPERIANCLIENT_PROTOCOL, EjbSiperianClient.PROTOCOL_NAME); CompositeServiceClient client = CompositeServiceClient.newCompositeServiceClient(config); CallContext callContext = new CallContext(orsId, user, pass); helperContext = client.getHelperContext(callContext); DataFactory dataFactory = helperContext.getDataFactory(); // types for Read requests Type coFilterType = helperContext.getTypeHelper().getType("urn:cs-base.informatica.mdm", "CoFilter"); Type coFilterNodeType = helperContext.getTypeHelper().getType("urn:cs-base.informatica.mdm", "CoFilterNode"); Type keyType = helperContext.getTypeHelper().getType("urn:cs-base.informatica.mdm", "Key"); // ReadCO & WriteCO request types Type readPersonType = helperContext.getTypeHelper().getType("urn:cs-ors.informatica.mdm", "ReadPerson"); Type writePersonType = helperContext.getTypeHelper().getType("urn:cs-ors.informatica.mdm", "WritePerson"); // 1. Create new person DataObject createPerson = dataFactory.create(writePersonType); DataObject createPersonParameters = createPerson.createDataObject("parameters"); createPersonParameters.setString("systemName", systemName); DataObject person = createPerson.createDataObject("object"); person.getChangeSummary().beginLogging(); DataObject personRoot = person.createDataObject("Person"); personRoot.setString("firstName", "John"); personRoot.setString("lastName", "Smith"); person.getChangeSummary().endLogging(); dump("*** CREATE NEW PERSON ...", createPerson); DataObject createPersonResponse = client.process(callContext, createPerson); dump("*** PERSON CREATED:", createPersonResponse); String personRowId = createPersonResponse.getString("object/Person/rowidObject"); DataObject readPerson = dataFactory.create(readPersonType); DataObject readPersonParameters = readPerson.createDataObject("parameters"); DataObject coFilter = readPersonParameters.createDataObject("coFilter"); DataObject coFilterNode = coFilter.createDataObject("object"); coFilterNode.set("name", "Person"); DataObject key = coFilterNode.createDataObject("key"); key.set("rowid", personRowId); dump("*** READ CREATED PERSON...", readPerson); DataObject readPersonResponse = client.process(callContext, readPerson); dump("*** READ RESULT:", readPersonResponse); person = readPersonResponse.getDataObject("object"); person.detach(); person.getChangeSummary().beginLogging(); personRoot = person.getDataObject("Person"); // add new 'one' child DataObject genderCd = personRoot.createDataObject("genderCd"); genderCd.setString("genderCode", "M"); // add two 'many' children DataObject phonePager = personRoot.createDataObject("TelephoneNumbers"); Property item = phonePager.getInstanceProperty("item"); Type phoneType = item.getType(); DataObject phone1 = dataFactory.create(phoneType); phone1.setString("phoneNumber", "111-11-11"); DataObject phone2 = dataFactory.create(phoneType); phone2.setString("phoneNumber", "222-22-22"); phonePager.setList(item, Arrays.asList(phone1, phone2)); person.getChangeSummary().endLogging(); DataObject updatePerson = dataFactory.create(writePersonType); updatePerson.setDataObject("object", person); DataObject updatePersonParameters = updatePerson.createDataObject("parameters"); updatePersonParameters.setString("systemName", systemName); updatePersonParameters.setString("interactionId", ""); dump("*** UPDATE PERSON...", updatePerson); DataObject updatePersonResponse = client.process(callContext, updatePerson); dump("*** PERSON UPDATED:", updatePersonResponse); coFilterNode.set("depth", 3); readPersonParameters.setBoolean("readSystemFields", true); dump("*** READ UPDATED PERSON WITH CHILDREN...", readPerson); readPersonResponse = client.process(callContext, readPerson); dump("*** READ RESULT:", readPersonResponse); person = readPersonResponse.getDataObject("object"); person.detach(); person.getChangeSummary().beginLogging(); genderCd = person.getDataObject("Person").createDataObject("genderCd"); genderCd.setString("genderCode", "F"); // delete one phone DataObject phoneItem = person.getDataObject("Person/TelephoneNumbers/item[1]"); phoneItem.delete(); person.getChangeSummary().endLogging(); DataObject deletePhone = dataFactory.create(writePersonType); deletePhone.setDataObject("object", person); DataObject deletePhoneParameters = deletePhone.createDataObject("parameters"); deletePhoneParameters.setString("systemName", systemName); dump("*** DELETE CHILD...", deletePhone); DataObject deletePhoneResponse = client.process(callContext, deletePhone); dump("*** CHILD DELETED:", deletePhoneResponse); readPersonParameters.setBoolean("readSystemFields", false); dump("*** READ PERSON AFTER CHILD WAS DELETEED...", readPerson); readPersonResponse = client.process(callContext, readPerson); dump("*** READ RESULT:", readPersonResponse); person = readPersonResponse.getDataObject("object"); person.detach(); person.getChangeSummary().beginLogging(); person.getDataObject("Person").detach(); person.getChangeSummary().endLogging(); DataObject deletePerson = dataFactory.create(writePersonType); deletePerson.setDataObject("object", person); DataObject deletePersonParameters = deletePerson.createDataObject("parameters"); deletePersonParameters.setString("systemName", systemName); dump("*** DELETE PERSON...", deletePerson); DataObject deletePersonResponse = client.process(callContext, deletePerson); dump("*** PERSON DELETED:", deletePersonResponse); dump("*** TRY TO READ PERSON AFTER DELETE", readPerson); try { readPersonResponse = client.process(callContext, readPerson); dump("*** READ RESULT:", readPersonResponse); } catch (CompositeServiceException e) { out.println("*** READ RESULT: " + e.getLocalizedMessage()); } } private void dump(String title, DataObject dataObject) { String xml = helperContext.getXMLHelper().save( dataObject, dataObject.getType().getURI(), dataObject.getType().getName()); out.println(title); out.println(xml); out.println(); } }