The sample below illustrates incorporating the Master Index (Repository) API into a custom Java class. It creates each object in a system object, and then creates the system object. Before inserting the new object into the database, the sample calls executeMatch to check for any matching records in the database.
Return to Working with the Master Index API
import javax.ejb.*;
import javax.naming.*;
import java.util.*;
import javax.rmi.PortableRemoteObject;
// eView imports
import com.stc.eindex.objects.*;
import com.stc.eindex.ejb.master.*;
import com.stc.eindex.master.*;
public class Match{
public static void main( String[] args ) {
// server connection parameters
String ORBhost = "localhost";
String ORBport = "3100";
// system record parameters
String system= "SUN";
String lid = "1234567890";
String objectType = "Person";
String status = "active";
String createUser= "Admin";
String createFunction = null;
Date createDate = new Date();
String updateUser= "Admin";
String updateFunction = null;
Date updateDate = new Date();
try {
// connect to server and get handle MasterController
Hashtable env = new Hashtable();
env.put("org.omg.CORBA.ORBInitialHost", ORBhost);
env.put("org.omg.CORBA.ORBInitialPort", ORBport);
Context jndiContext = new InitialContext(env);
Object obj = jndiContext.lookup("ejb/PersonMasterController");
MasterControllerHome home = (MasterControllerHome)
PortableRemoteObject.narrow(obj, MasterControllerHome.class);
MasterController mc = home.create();
// create a new person object
PersonObject person = new PersonObject();
person.setLastName("Smith");
person.setFirstName("John");
person.setGender("M");
person.setSSN("555441111");
person.setDOB( new Date() );
// add phone
PhoneObject phone = new PhoneObject();
phone.setPhoneType("CH");
phone.setPhone("6535554556");
person.addPhone(phone);
// add addresses
AddressObject address = new AddressObject();
address.setAddressType("H");
address.setAddressLine1("404 Huntington");
address.setAddressLine2("Apt. A");
address.setCity("Monrovia");
address.setStateCode("CA");
address.setPostalCode("91016");
person.addAddress(address);
// create system record
SystemObject so = new SystemObject(system, lid, objectType, status,
createUser, createFunction, createDate,
updateUser, updateFunction, updateDate, person);
// call the match function
MatchResult r = mc.executeMatch( so );
// print match result
System.out.println( "EUID: " + r.getEUID() );
} catch (NamingException e) {
System.out.println("Could not create JNDI API " + "context: " + e.toString());
} catch( Exception e ) {
e.printStackTrace();
}
}
}