Metadata Store

This page describes access to Oracle Metadata Store (MDS)

Links

  1. Overview in User guide
  2. Some alternate Java API, not explored

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 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 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());
}

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.

Page tags: mds metadata store
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License