Red Hat Training

A Red Hat training course is available for Red Hat JBoss Data Virtualization

10.5. Custom

If above provided metadata facilities are not sufficient for user's needs then user can extend the MetadataRepository class provided in the org.teiid.api JAR to plug-in their own metadata facilities into the Red Hat JBoss Data Virtualization engine.
  1. Users can write metadata facility that is based on reading data from database or a JCR repository or so forth. Here is an example:
    package com.something;
    
    import org.teiid.metadata.MetadataRepository;
    ...
    			
    public class CustomMetadataRepository extends MetadataRepository {
        @Override
        public void loadMetadata(MetadataFactory factory, ExecutionFactory executionFactory, Object connectionFactory)
            throws TranslatorException {
            /* Provide implementation and fill the details in factory */
            ...
        }
    }
    
  2. Build a JAR archive with above implementation class and create file named org.teiid.metadata.MetadataRepository in the META-INF/services directory with these contents:
    com.something.CustomMetadataRepository
    
  3. Deploy the JAR to Red Hat JBoss EAP as a module under the modules directory. Follow the below steps to create a module.
    • Create a directory called modules/com/something/main.
    • Under this directory create a "module.xml" file that looks like:
      <?xml version="1.0" encoding="UTF-8"?>
      <module xmlns="urn:jboss:module:1.0" name="com.something">
          <resources>
              <resource-root path="something.jar" />
          </resources>
          <dependencies>
              <module name="javax.api"/>
              <module name="javax.resource.api"/>
              <module name="org.jboss.teiid.common-core"/>
              <module name="org.jboss.teiid.teiid-api" />
          </dependencies>
      </module>
      
    • Copy the jar file under this same directory. Make sure you add any additional dependencies if required by your implementation class under dependencies.
    • Restart the server.
This is how you configure the VDB with the custom metadata repository you have created:

Example 10.4. Sample vdb.xml file

<vdb name="{vdb-name}" version="1">
    <model name="{model-name}" type="PHYSICAL">
        <source name="AccountsDB" translator-name="oracle" connection-jndi-name="java:/oracleDS"/>
        <metadata type="{metadata-repo-module}"></metadata>
    </model>
</vdb>
When the VDB is deployed, it will call the CustomMetadataRepository instance for metadata of the model. Using this you can define metadata for single model or for the whole VDB pragmatically.

Important

Be careful about holding state and synchronization in your repository instance.