<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 (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-changed-lines" >If above provided [metadata facilities|Metadata Repositories] are not sufficient then a developer can extend the _MetadataRepository_ class provided in the _org.teiid.api_ <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">package</span> <span class="diff-added-words"style="background-color: #dfd;">jar</span> 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: <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code:JAVA|title=Sample Java Code} <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">import org.teiid.metadata.MetadataRepository; <br> <br></td></tr>
            <tr><td class="diff-unchanged" >package com.something; <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>If above provided <a href="/author/display/TEIID/Metadata+Repositories" title="Metadata Repositories">metadata facilities</a> are not sufficient then a developer can extend the <em>MetadataRepository</em> class provided in the <em>org.teiid.api</em> 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 <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;">
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 */
        ...
    }
}
</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. </p>

<h4><a name="CustomMetadataRepository-DevelopmentConsiderations"></a><em>Development Considerations</em></h4>

<ul>
        <li><tt>MetadataRepository</tt> instances are created on a per vdb basis and may be called concurrently for the load of multiple models.</li>
</ul>


<ul>
        <li>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.</li>
</ul>


<ul>
        <li>Use the <tt>MetadataFactory.addPermission</tt> and add <tt>MetadataFactory.addColumnPermission</tt> method to grant permissions on the given metadata objects to the named roles.  The roles should be declared in your vdb.xml, which is also where they are typically tied to container roles.</li>
</ul>

    </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=12&originalVersion=11">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>