If above provided metadata facilities are not sufficient then a developer can extend the MetadataRepository class provided in the org.teiid.api jar to plug-in their own metadata facilities into the Teiid engine. For example, a user can write a metadata facility that is based on reading data from a database or a JCR repository. See Setting up the build environment to start development. For Example:
Sample Java Code
import org.teiid.metadata.MetadataRepository;
...
package com.something;
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 */
...
}
}
Then build a JAR archive with above implementation class and create file a named org.teiid.metadata.MetadataRepository in the META-INF/services directory with contents:
com.something.CustomMetadataRepository
Once the JAR file has been built, it needs to be deployed in the JBoss AS as a module under <jboss-as>/modules directory. Follow the below steps to create a module.
Sample module.xml file
<?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>
The below XML fragment shows how to configure the VDB with the custom metadata repository created
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>
Now when this VDB gets 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. Be careful about holding state and synchronization in your repository instance.