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:
- Establishing connection
- catalog data model,
- multi-dimensional search
- catalog data retrieval
- 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(“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”);
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
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"> <application-j2ee-engine> <reference reference-type="hard"> <reference-target provider-name="sap.com" target-type="library"> tc/conn/connectorframework </reference-target> </reference> <reference reference-type="hard"> <reference-target provider-name="sap.com" target-type="library">MDME4J</reference-target> </reference> <provider-name>sap.com</provider-name> <fail-over-enable mode="disable"/> </application-j2ee-engine>