Metadata Store

This page describes access to Oracle Metadata Store (MDS)

Links

  1. Overview in User guide
  2. Some alternate Java API, not explored
  3. User-modifiable OIM metadata files

Connect

First, get a connection to a database-based MDS in the Oracle schema "DEV_MDS" for application named "oim"

String userName = "DEV_MDS";
String password = "oracle";
String jdbcConnectionString = "jdbc:oracle:thin:dev_mds@localhost:1521:orcl";
String applicationName = "oim";
dbMetadataStore = new DBMetadataStore(userName, password, jdbcConnectionString, applicationName);

Create a MDSInstance

Obtain an instance which points to some part of metadata tree (root in this example)

MetadataStore dbMetadataStore = getMetadataStore();
NamespaceConfig dbNamespaceConfig = new NamespaceConfig(Namespace.create("/"), dbMetadataStore);
PConfig persistenceConfig = new PConfig(new NamespaceConfig[] { dbNamespaceConfig });
MDSConfig dbConfig = new MDSConfig(null, persistenceConfig, null);
dbMDSInstance = MDSInstance.getOrCreateInstance("TEST_Metadata", dbConfig, true);

Read document

Get and a document "/db/FLAT FILE_GTC.xml" from MDS as java.io.Reader

DocumentName docName = DocumentName.create( "/db/FLAT FILE_GTC.xml");
MDSSession mdsSession = mdsInstance.createSession(new SessionOptions(IsolationLevel.READ_COMMITTED, null, null), null);
PManager mdsPManager = mdsSession.getPersistenceManager();
PContext mdsContext = mdsSession.getPContext();
PDocument mdsDocument = mdsPManager.getDocument(mdsContext, docName);
Reader reader = mdsDocument.read().getCharacterStream();

Create/update document

Create or update a document "/db/FLAT FILE_GTC.xml" in MDS from a file at "FLAT FILE_GTC.xml"

DocumentName docName = DocumentName.create("/db/FLAT FILE_GTC.xml");
MDSSession mdsSession = mdsInstance.createSession(new SessionOptions(IsolationLevel.READ_COMMITTED, null, null), null);
PManager mdsPManager = mdsSession.getPersistenceManager();
InputSource docContents = new InputSource(new FileReader("FLAT FILE_GTC.xml"));
PContext mdsPContext = mdsSession.getPContext();
InternalPManager iPManager = (InternalPManager)mdsPManager;
PDocument existingDocument = iPManager.getDocument(mdsPContext, docName);
PTransaction mdsTran = mdsSession.getPTransaction();
PDocument document = existingDocument == null
  ? mdsTran.createDocument(docName, docContents)
  : mdsTran.saveDocument(existingDocument, true, docContents);
mdsSession.flushChanges();

Delete document

String documentPath = "/someDir/someDoc.xml";
MDSInstance mdsInstance = getMDSInstance();
MDSTransfer transferInstance = MDSTransfer.getInstance(mdsInstance);
ArrayList<String> listOfFiles = new ArrayList<String>();
listOfFiles.add(documentPath);
TransferUnitList transferUnitList = TransferUnitList.create(mdsInstance, listOfFiles, null, true, true);
transferInstance.delete(transferUnitList, false);

Query

Create query

Create query for element named "myElement", package "/", document selection template "%" (any), recursive search on

QueryItem tag = new QueryItem("http://xmlns.oracle.com", "myElement");
ElementCondition elementcondition = ConditionFactory.createElementCondition(tag);
NameCondition nameCondition = ConditionFactory.createNameCondition("/", "%", true);
MOQuery query = QueryFactory.createMOQuery(mdsInstance, nameCondition.and(elementcondition));

Execute and print as XML text

Execute query and print results as plain text (Warning: you shall provide some extra knowledge here to tell XML from non-XML files)

Iterator results = query.execute();
MDSSession mdsSession = mdsInstance.createSession(new SessionOptions(IsolationLevel.READ_COMMITTED, null, null), null);
 
while (results.hasNext()) {
  MOResult result = (MOResult)results.next();
  String absoluteName = result.getAbsoluteName();
 
  Reader reader;
  if(this is XML text) {
    MetadataObject mobj = mdsSession.getMetadataObject(result.getMOReference());
    reader = mobj.getParts().get(0).getContent().getInputSource().getCharacterStream();
  } else {
    StreamedObject so = StreamedObject.getStreamedObject(mdsSession, absoluteName);
    reader = new InputStreamReader(so.getContents());
  }
  StringBuilder sb = new StringBuilder(10000);
  while(true) {
    int ch = reader.read();
    if(ch < 0)
      break;
    sb.append((char)ch);
  }
  System.out.println(sb.toString());
}

Query for a specific element

In the following example we query for all EventHandler type definitions in MDS. We are looking for all documents containing the "eventhandlers" elements and print the contents of all "action-handler"s.

MDSInstance mdsInstance = ...;
MDSSession session = mdsInstance.createSession(new SessionOptions(IsolationLevel.READ_COMMITTED, null, null), null);
QueryItem tag = new QueryItem("http://www.oracle.com/schema/oim/platform/kernel", "eventhandlers");
ElementCondition elementcondition = ConditionFactory.createElementCondition(tag);
NameCondition filecondition = ConditionFactory.createNameCondition("/", "%", true);
Condition condition = filecondition.and(elementcondition);
DocumentQuery docQuery = QueryFactory.createDocumentQuery(mdsInstance, condition);
 
Iterator results = docQuery.execute();
 
while (results.hasNext()) {
  DocumentResult er = (DocumentResult)results.next();
  MOReference moref = er.getMOName().getMDSReference().getMOReference();
 
  MetadataObject mobj = session.getMetadataObject(moref);
  Document doc = mobj.getDocument();
  doc.getDocumentElement().normalize();
  NodeList nl = doc.getElementsByTagName("action-handler");
  for (int k = 0; k < nl.getLength(); ++k) {
    Element elt = (Element)nl.item(k);
    System.out.println("name=" + elt.getAttribute("name"));
    System.out.println("class=" + elt.getAttribute("class"));
    System.out.println("entity-type=" + elt.getAttribute("entity-type"));
    System.out.println("operation=" + elt.getAttribute("operation"));
    System.out.println("order=" + elt.getAttribute("order"));
    System.out.println("stage=" + elt.getAttribute("stage"));
    System.out.println("sync=" + elt.getAttribute("sync"));
    System.out.println();
  }
}

prints:

name=InitiateSodCheck
class=oracle.iam.sod.eventhandlers.InitiateSodCheck
entity-type=ANY
operation=PROVISION
order=9979
stage=preprocess
sync=FALSE

name=InitiateSodCheck
class=oracle.iam.sod.eventhandlers.InitiateSodCheck
entity-type=ANY
operation=MODIFYRESOURCE
order=9979
stage=preprocess
sync=FALSE

...

Direct DB access

Delete all versions if documents whose name begins with 'HR' (DANGEROUS!):

delete from mds_components where comp_contentid in (select path_contentid from mds_paths where path_name like 'HR%');
delete from mds_paths where path_name like 'HR%';
commit;

Support in oimtool

The oimtool utility supports all basic operations with MDS.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License