Retrieving Data from MDM server using the MDM Java API

In my previous Weblog MDM Connectivity to Java Applications. I have introduced the SAP MDM connector.
In this Weblog I will go deeper and show how to establish a connection and retrieve data from MDM using the connector APIs.

The classes in the MDM Java library expose the functionality of the MDM catalog to a java application. The main functionality are:

  1. Establishing connection
  2. catalog data model,
  3. multi-dimensional search
  4. catalog data retrieval
  5. catalog data management.

The main class in the library is the CatalogData class, which exposes all the services of the MDM Server.
Among the services that it provides outside of those of the MDM catalog itself are a local catalog data cache,
a pool of MDM Server connections, and full thread-safety. Other objects in the library exist to support the
CatalogData class. They are either used as arguments to methods or return values for methods and properties
of the CatalogData class.

The following code shows how to retrieve categories from the MDM repository.
Step 1: Obtain a connection to the MDM repository.
1.1 get the context :
Context ctx = new InitialContext();
1.2 lookup in the JDNI to get the connection factory class
IConnectionFactory connectionFactory = (IConnectionFactory)ctx.lookup("deployedAdapters/MDMEFactory/shareable/MDMEFactory");
1.3 Get Connection Spec to set connection properties
IConnectionSpec spec = connectionFactory.getConnectionSpec();
1.4 Set Connection Properties
spec.setPropertyValue("UserName", "Administrator");
spec.setPropertyValue("Password", "123456");
spec.setPropertyValue("Server", "server1");
spec.setPropertyValue("Port", "50000");
spec.setPropertyValue("RepositoryLanguage", "Chinese [HK]");
1.5 Get the Connection
IConnection connection = connectionFactory.getConnectionEx(spec);
Step 2 : obtain access to the native object
2.1 Retrieve Native inteface
INative nativeInterface = connection.retrieveNative();
2.2 Get the CatalogData the physical connection
CatalogData catalog = (CatalogData) nativeInterface.getNative(CatalogData.class.getName());
Step 3: Retrieve data from Catalog
3.1 Create ResultSetDefinition for products table
ResultSetDefinition resultdefenition = new ResultSetDefinition("Categories");
resultdefenition.AddField("Id");
3.2 Create Search object for Categories table
Search search = new Search("Categories");
3.3 Get Data from repository.
A2iResultSet rs = catalog.GetResultSet(search, resultdefenition, "Id", true, 0);
Once we have all the data in the result set, one can do manipulation on it and retrieve the data.
Step 4: Close the connection
connection.close();
The last step is configuration:
Step 5: Set the connector libraries in the application-j2ee-engine.xml file
The MDME Connector uses the SAP Connector Framework and MDME4J libraries as a shared library.
You need to add these libraries into the application-j2ee-engine.xml file.

 <?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE application-j2ee-engine SYSTEM "application-j2ee-engine.dtd"> &ltapplication-j2ee-engine> &ltreference reference-type="hard"> &ltreference-target provider-name="sap.com" target-type="library"> tc/conn/connectorframework </reference-target> </reference> &ltreference reference-type="hard"> &ltreference-target provider-name="sap.com" target-type="library">MDME4J</reference-target> </reference> &ltprovider-name&gtsap.com</provider-name> &ltfail-over-enable mode="disable"/></application-j2ee-engine>



SAP MDM TRAINING



SAP MDM TUTORIALS



SAP MDM INTERVIEW QUESTIONS

SAP Developer Network Latest Updates