<html>
<head>
    <base href="https://docs.jboss.org/author">
            <link rel="stylesheet" href="/author/s/en/2172/19/5/_/styles/combined.css?spaceKey=TEIID&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://docs.jboss.org/author/display/TEIID/Custom+Metadata+Repository">Custom Metadata Repository</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://docs.jboss.org/author/display/~shawkins">Steven Hawkins</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h3. _Custom_ <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >If above provided metadata facilities are not sufficient for user&#39;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, <span class="diff-added-words"style="background-color: #dfd;">a</span> user can write a metadata facility that is based on reading data from a <span class="diff-changed-words">database<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">,</span></span> or a JCR repository. <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">For setting up build environment see</span> <span class="diff-added-words"style="background-color: #dfd;">See</span> [Setting up the build <span class="diff-changed-words">environment]<span class="diff-added-chars"style="background-color: #dfd;"> to start development</span>.</span> For Example: <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code:JAVA|title=Sample Java Code} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>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 <em>MetadataRepository</em> by name <em>INDEX</em>.</p>

<p>In the Dynamic VDB scenario, the built-in metadata repositories are:</p>

<h3><a name="CustomMetadataRepository-NATIVE"></a><em>NATIVE</em></h3>

<p>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.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Sample vdb.xml file</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;vdb name="{vdb-name}" version="1"&gt;
    &lt;model name="{model-name}" type="PHYSICAL"&gt;
        &lt;source name="AccountsDB" translator-name="oracle" connection-jndi-name="java:/oracleDS"/&gt;
        &lt;metadata type="NATIVE"&gt;&lt;/metadata&gt;
    &lt;/model&gt;
&lt;/vdb&gt;
</pre>
</div></div>

<h3><a name="CustomMetadataRepository-DDL"></a><em>DDL</em></h3>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Sample vdb.xml file</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;vdb name="{vdb-name}" version="1"&gt;
    &lt;model name="{model-name}" type="PHYSICAL"&gt;
        &lt;source name="AccountsDB" translator-name="oracle" connection-jndi-name="java:/oracleDS"/&gt;
        &lt;metadata type="DDL"&gt;
          **DDL Here**
        &lt;/metadata&gt;
    &lt;/model&gt;
&lt;/vdb&gt;
</pre>
</div></div>

<p>This is applicable to both source and view models. See <a href="/author/display/TEIID/DDL+Metadata" title="DDL Metadata">DDL Metadata</a> for more information on how to use this feature.</p>

<h3><a name="CustomMetadataRepository-DDLFILE"></a><em>DDL-FILE</em></h3>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Sample vdb.xml file</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;vdb name="{vdb-name}" version="1"&gt;
    &lt;model name="{model-name}" type="PHYSICAL"&gt;
        &lt;source name="AccountsDB" translator-name="oracle" connection-jndi-name="java:/oracleDS"/&gt;
        &lt;metadata type="DDL-FILE"&gt;/accounts.ddl&lt;/metadata&gt;
    &lt;/model&gt;
&lt;/vdb&gt;
</pre>
</div></div>

<p>This is applicable to both source and view models in zip VDB deployments. See <a href="/author/display/TEIID/DDL+Metadata" title="DDL Metadata">DDL Metadata</a> for more information on how to use this feature.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Chaining more than single repository</b><br />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:

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Sample vdb.xml file</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;vdb name="{vdb-name}" version="1"&gt;
    &lt;model name="{model-name}" type="PHYSICAL"&gt;
        &lt;source name="AccountsDB" translator-name="oracle" connection-jndi-name="java:/oracleDS"/&gt;
        &lt;metadata type="NATIVE,DDL"&gt;
          **DDL Here**
        &lt;/metadata&gt;
    &lt;/model&gt;
&lt;/vdb&gt;
</pre>
</div></div>
<p>For the above model, <em>NATIVE</em> importer is first used, then DDL importer used to add additional metadata to <em>NATIVE</em> imported metadata.</p></td></tr></table></div>


<h3><a name="CustomMetadataRepository-Custom"></a><em>Custom</em></h3>

<p>If above provided metadata facilities are not sufficient for user's needs then user can extend the <em>MetadataRepository</em> class provided in the <em>org.teiid.api</em> package to plug-in their own metadata facilities into 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 <a href="/author/display/TEIID/Setting+up+the+build+environment" title="Setting up the build environment">Setting up the build environment</a> to start development. For Example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Sample Java Code</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
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 */
        ...
    }
}
</pre>
</div></div>

<p>Then build a JAR archive with above implementation class and create file named <em>org.teiid.metadata.MetadataRepository</em> in <em>META-INF/services</em> directory with contents</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
com.something.CustomMetadataRepository
</pre>
</div></div>

<p>Now that the JAR file has been built, this needs to be deployed in the JBoss AS as module under <em>&lt;jboss-as&gt;/modules</em> directory. Follow the below steps to create a module.</p>

<ul>
        <li>Create a directory <em>&lt;jboss-as&gt;/modules/com/something/main</em></li>
</ul>


<ul>
        <li>Under this directory create "module.xml" file that looks like</li>
</ul>


<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Sample module.xml file</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;module xmlns="urn:jboss:module:1.0" name="com.something"&gt;
    &lt;resources&gt;
        &lt;resource-root path="something.jar" /&gt;
    &lt;/resources&gt;
    &lt;dependencies&gt;
        &lt;module name="javax.api"/&gt;
        &lt;module name="javax.resource.api"/&gt;
        &lt;module name="org.jboss.teiid.common-core"/&gt;
        &lt;module name="org.jboss.teiid.teiid-api" /&gt;
    &lt;/dependencies&gt;
&lt;/module&gt;
</pre>
</div></div>

<ul>
        <li>Copy the jar file under this same directory. Make sure you add any additional dependencies if required by your implementation class under dependencies.</li>
</ul>


<ul>
        <li>Restart the server</li>
</ul>


<p>The below XML fragment shows how to configure the VDB with the custom metadata repository created</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Sample vdb.xml file</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;vdb name="{vdb-name}" version="1"&gt;
    &lt;model name="{model-name}" type="PHYSICAL"&gt;
        &lt;source name="AccountsDB" translator-name="oracle" connection-jndi-name="java:/oracleDS"/&gt;
        &lt;metadata type="{metadata-repo-module}"&gt;&lt;/metadata&gt;
    &lt;/model&gt;
&lt;/vdb&gt;
</pre>
</div></div>

<p>Now when this VDB gets deployed, it will call the <em>CustomMetadataRepository</em> instance for metadata of the model. Using this you can define metadata for single model or for the whole VDB pragmatically.&nbsp;&nbsp; Be careful about holding state and synchronization in your repository instance. <tt>MetadataRepository</tt> instances are created on a per vdb basis and may be called concurrently for the load of multiple models.</p>

<p>See the <tt>MetadataFactory</tt> and the <tt>org.teiid.metadata</tt> package javadocs for metadata construction methods and objects.  For example if you use your own DDL, then call the <tt>MetadataFactory.parse(Reader)</tt> method.  If you need access to files in a VDB zip deployment, then use the <tt>MetadataFactory.getVDBResources</tt> method.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://docs.jboss.org/author/users/removespacenotification.action?spaceKey=TEIID">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://docs.jboss.org/author/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
        <a href="https://docs.jboss.org/author/display/TEIID/Custom+Metadata+Repository">View Online</a>
        |
        <a href="https://docs.jboss.org/author/pages/diffpagesbyversion.action?pageId=22872200&revisedVersion=9&originalVersion=8">View Changes</a>
                |
        <a href="https://docs.jboss.org/author/display/TEIID/Custom+Metadata+Repository?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>