目录

Search

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

业务实体服务指南

业务实体服务指南

使用生成的 SDO 类的 Java 代码示例

使用生成的 SDO 类的 Java 代码示例

本示例显示的 Java 代码会基于 Java 类(由 MDM Hub 基于业务实体配置和业务实体服务配置生成)运行 Enterprise Java Bean (EJB) 调用。
该示例位于资源工具包中的以下文件:
C:\<
MDM Hub 安装目录
>\hub\resourcekit\samples\COS\source\java\com\informatica\mdm\sample\cs\GeneratedSDO.java
以下 Java 代码基于生成的类,并会运行 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.informatica.mdm.sdo.cs.base.CoFilter; import com.informatica.mdm.sdo.cs.base.CoFilterNode; import com.informatica.mdm.sdo.cs.base.Key; import com.siperian.sif.client.EjbSiperianClient; import com.siperian.sif.client.SiperianClient; import commonj.sdo.DataObject; import commonj.sdo.helper.DataFactory; import commonj.sdo.helper.HelperContext; import mdm.informatica.co_ors.*; import mdm.informatica.cs_ors.*; import java.io.PrintStream; import java.util.Arrays; import java.util.Properties; public class GeneratedSDO { public static void main(String[] args) throws CompositeServiceException { if(args.length != 3) { System.err.println("USAGE: GeneratedSDO <ors> <user> <pass>"); return; } new GeneratedSDO(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 GeneratedSDO(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(); // 1. Create new person WritePerson createPerson = (WritePerson)dataFactory.create(WritePerson.class); WritePersonParameters createPersonParameters = (WritePersonParameters)dataFactory.create(WritePersonParameters.class); createPersonParameters.setSystemName(systemName); createPerson.setParameters(createPersonParameters); Person person = (Person)dataFactory.create(Person.class); createPerson.setObject(person); person.getChangeSummary().beginLogging(); PersonRoot personRoot = (PersonRoot)dataFactory.create(PersonRoot.class); personRoot.setFirstName("John"); personRoot.setLastName("Smith"); person.setPerson(personRoot); person.getChangeSummary().endLogging(); dump("*** CREATE NEW PERSON ...", createPerson); WritePersonReturn createPersonResponse = (WritePersonReturn)client.process(callContext, (DataObject)createPerson); dump("*** PERSON CREATED:", createPersonResponse); String personRowId = createPersonResponse.getObject().getPerson().getRowidObject(); Key key = (Key)dataFactory.create(Key.class); key.setRowid(personRowId); CoFilterNode coFilterNode = (CoFilterNode)dataFactory.create(CoFilterNode.class); coFilterNode.setName(Person.class.getSimpleName()); coFilterNode.setKey(key); CoFilter coFilter = (CoFilter)dataFactory.create(CoFilter.class); coFilter.setObject(coFilterNode); ReadPersonParameters readPersonParameters = (ReadPersonParameters)dataFactory.create(ReadPersonParameters.class); readPersonParameters.setCoFilter(coFilter); ReadPerson readPerson = (ReadPerson)dataFactory.create(ReadPerson.class); readPerson.setParameters(readPersonParameters); dump("*** READ CREATED PERSON...", readPerson); ReadPersonReturn readPersonResponse = (ReadPersonReturn)client.process(callContext, (DataObject)readPerson); dump("*** READ RESULT:", readPersonResponse); person = readPersonResponse.getObject(); ((DataObject)person).detach(); person.getChangeSummary().beginLogging(); personRoot = person.getPerson(); // add new 'one' child LUGenderLookup genderCd = (LUGenderLookup)dataFactory.create(LUGenderLookup.class); genderCd.setGenderCode("M"); personRoot.setGenderCd(genderCd); // add two 'many' children PersonTelephoneNumbersPager phonePager = (PersonTelephoneNumbersPager)dataFactory.create(PersonTelephoneNumbersPager.class); PersonTelephoneNumbers phone1 = (PersonTelephoneNumbers)dataFactory.create(PersonTelephoneNumbers.class); phone1.setPhoneNumber("111-11-11"); PersonTelephoneNumbers phone2 = (PersonTelephoneNumbers)dataFactory.create(PersonTelephoneNumbers.class); phone2.setPhoneNumber("222-22-22"); phonePager.setItem(Arrays.asList(phone1, phone2)); personRoot.setTelephoneNumbers(phonePager); person.getChangeSummary().endLogging(); WritePerson updatePerson = (WritePerson)dataFactory.create(WritePerson.class); updatePerson.setObject(person); WritePersonParameters updatePersonParameters = (WritePersonParameters)dataFactory.create(WritePersonParameters.class); updatePersonParameters.setSystemName(systemName); updatePersonParameters.setInteractionId(""); updatePerson.setParameters(updatePersonParameters); dump("*** UPDATE PERSON...", updatePerson); WritePersonReturn updatePersonResponse = (WritePersonReturn)client.process(callContext, (DataObject)updatePerson); dump("*** PERSON UPDATED:", updatePersonResponse); coFilterNode.setDepth(3); readPersonParameters.setReadSystemFields(true); dump("*** READ UPDATED PERSON WITH CHILDREN (with system fields)...", readPerson); readPersonResponse = (ReadPersonReturn)client.process(callContext, (DataObject)readPerson); dump("*** READ RESULT:", readPersonResponse); person = readPersonResponse.getObject(); ((DataObject)person).detach(); person.getChangeSummary().beginLogging(); // delete one phone person.getPerson().getTelephoneNumbers().getItem().remove(0); // change gender genderCd = (LUGenderLookup)dataFactory.create(LUGenderLookup.class); genderCd.setGenderCode("F"); personRoot.setGenderCd(genderCd); person.getChangeSummary().endLogging(); WritePerson deletePhone = (WritePerson)dataFactory.create(WritePerson.class); deletePhone.setObject(person); WritePersonParameters deletePhoneParameters = (WritePersonParameters)dataFactory.create(WritePersonParameters.class); deletePhoneParameters.setSystemName(systemName); deletePhone.setParameters(deletePhoneParameters); dump("*** DELETE CHILD...", deletePhone); WritePersonReturn deletePhoneResponse = (WritePersonReturn)client.process(callContext, (DataObject)deletePhone); dump("*** CHILD DELETED:", deletePhoneResponse); readPersonParameters.setReadSystemFields(false); dump("*** READ PERSON AFTER CHILD WAS DELETEED...", readPerson); readPersonResponse = (ReadPersonReturn)client.process(callContext, (DataObject)readPerson); dump("*** READ RESULT:", readPersonResponse); person = readPersonResponse.getObject(); ((DataObject)person).detach(); person.getChangeSummary().beginLogging(); ((DataObject)person.getPerson()).delete(); person.getChangeSummary().endLogging(); WritePerson deletePerson = (WritePerson)dataFactory.create(WritePerson.class); deletePerson.setObject(person); WritePersonParameters deletePersonParameters = (WritePersonParameters)dataFactory.create(WritePersonParameters.class); deletePersonParameters.setSystemName(systemName); deletePerson.setParameters(deletePersonParameters); dump("*** DELETE PERSON...", deletePerson); WritePersonReturn deletePersonResponse = (WritePersonReturn)client.process(callContext, (DataObject)deletePerson); dump("*** PERSON DELETED:", deletePersonResponse); dump("*** TRY TO READ PERSON AFTER DELETE", readPerson); try { readPersonResponse = (ReadPersonReturn)client.process(callContext, (DataObject)readPerson); dump("*** READ RESULT:", readPersonResponse); } catch (CompositeServiceException e) { out.println("*** READ RESULT: " + e.getLocalizedMessage()); } } private void dump(String title, Object object) { DataObject dataObject = (DataObject)object; String xml = helperContext.getXMLHelper().save( dataObject, dataObject.getType().getURI(), dataObject.getType().getName()); out.println(title); out.println(xml); out.println(); } }