Traditionally the metadata for a Virtual Database is built by Teiid Designer and supplied to Teiid engine through a VDB archive file. This VDB file contains the metadata files called INDEX files, that are then read by a specific instance of _MetadataRepository_ by name _INDEX_. |
In the Dynamic VDB scenario, currently there are two predefined facilities to define metadata |
In the Dynamic VDB scenario, the built-in metadata repositories are: |
h3. _NATIVE_ |
This is only applicable on source models (and is also the default), when used the metadata for the model is retrieved from the source database itself. |
{code:XML|title=Sample vdb.xml file} |
... |
{code} |
This is applicable to both source and view models. When _DDL_ is defined as metadata import type, the model's metadata can be defined as DDL. See [DDL Metadata] for more information on how to use this feature. |
|
h3. _DDL_FILE_ {code:XML|title=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="DDL-FILE">/accounts.ddl</metadata> </model> </vdb> {code} This is applicable to both source and view models in zip VDB deployments. See [DDL Metadata] for more information on how to use this feature. |
{tip:title=Chaining more than single repository} When defining the metadata import type for a model, user can define comma separated list of importers, such that all the repository instances defined by import types are consulted in the order they have configured to gather the metadata for the given model. For example: |
... |
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. {{MetadataRepository}} instances are created on a per vdb basis and may be called concurrently for the load of multiple models. |
See the {{MetadataFactory}} and the {{org.teiid.metadata}} package javadocs for metadata construction methods and objects. If you use your own DDL and call the {{MetadataFactory.parse(Reader)}} method. |
See the {{MetadataFactory}} and the {{org.teiid.metadata}} package javadocs for metadata construction methods and objects. For example if you use your own DDL, then call the {{MetadataFactory.parse(Reader)}} method. If you need access to files in a VDB zip deployment, then use the {{MetadataFactory.getVDBResources}} method. |
Traditionally the metadata for a Virtual Database is built by Teiid Designer and supplied to Teiid engine through a VDB archive file. This VDB file contains the metadata files called INDEX files, that are then read by a specific instance of MetadataRepository by name INDEX.
In the Dynamic VDB scenario, the built-in metadata repositories are:
This is only applicable on source models (and is also the default), when used the metadata for the model is retrieved from the source database itself.
<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="NATIVE"></metadata> </model> </vdb>
<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="DDL"> **DDL Here** </metadata> </model> </vdb>
This is applicable to both source and view models. See DDL Metadata for more information on how to use this feature.
<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="DDL-FILE">/accounts.ddl</metadata> </model> </vdb>
This is applicable to both source and view models in zip VDB deployments. See DDL Metadata for more information on how to use this feature.
Chaining more than single repository When defining the metadata import type for a model, user can define comma separated list of importers, such that all the repository instances defined by import types are consulted in the order they have configured to gather the metadata for the given model. For example: 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="NATIVE,DDL"> **DDL Here** </metadata> </model> </vdb> For the above model, NATIVE importer is first used, then DDL importer used to add additional metadata to NATIVE imported metadata. |
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 package to plug-in their own metadata facilities into Teiid engine. For example, use can write metadata facility that is based on reading data from database, or JCR repository etc. For setting up build environment see Setting up the build environment. For Example
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 named org.teiid.metadata.MetadataRepository in META-INF/services directory with contents
com.something.CustomMetadataRepository
Now that the JAR file has been built, this needs to be deployed in the JBoss AS as module under <jboss-as>/modules directory. Follow the below steps to create a module.
<?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
<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. MetadataRepository instances are created on a per vdb basis and may be called concurrently for the load of multiple models.
See the MetadataFactory and the org.teiid.metadata package javadocs for metadata construction methods and objects. For example if you use your own DDL, then call the MetadataFactory.parse(Reader) method. If you need access to files in a VDB zip deployment, then use the MetadataFactory.getVDBResources method.