<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/Runtime+Updates">Runtime Updates</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://docs.jboss.org/author/display/~shawkins">Steven Hawkins</a>
    </h4>
        <br/>
                         <h4>Changes (3)</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" >h1. Data Updates <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >Data change events are used by Teiid to invalidate result set cache entries.  Result set cache entries are tracked by the tables that contributed to their results. By default Teiid will capture internal data events against physical sources and distribute them across the cluster. This approach has several limitations.  First updates are scoped only to their originating VDB/version.  Second updates made out side of Teiid are not captured. To increase data consistency external change data capture tools can be used to send events to Teiid.  From within a Teiid cluster the {{org.teiid.events.EventDistributorFactory}} and {{org.teiid.events.EventDistributor}} can be used to distribute change events.  The {{EventDistributorFactory}} can be looked up by its name _&quot;teiid/event\-distributor\-factory&quot;_. See <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">the example below.</span> <span class="diff-added-words"style="background-color: #dfd;">[Programmatic Control] for a dataModification example.</span> <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">{code:lang=java|title=Usage of the EventDistributor} <br>InitialContext ctx = new InitialContext(); <br>EventDistributorFactory edf = (EventDistributorFactory)ctx.lookup(&quot;teiid/event-distributor-factory&quot;); <br>EventDistributor ed = edf.getEventDistributor(); <br>ed.dataModification(vdbName, vdbVersion, schema, tableName); <br>{code} <br> <br>This will distribute a change event for schema.tableName in vdb vdbName.vdbVersion. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >When externally capturing all update events, _&quot;detect\-change\-events&quot;_ property in the teiid subsystem in can be set to _false_, to not duplicate change events. By default, this property is set to _true_. <br> <br>{tip: Runtime Metadata Updates} <br></td></tr>
            <tr><td class="diff-changed-lines" >Using the {{org.teiid.events.EventDistributor}} interface you can also update runtime metadata. Please check the <span class="diff-changed-words">API<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;"> and see [Programmatic Control] for a sample usage</span>.</span> <br></td></tr>
            <tr><td class="diff-unchanged" >{tip} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>Teiid supports several mechanisms for updating the runtime system.</p>

<h1><a name="RuntimeUpdates-DataUpdates"></a>Data Updates</h1>

<p>Data change events are used by Teiid to invalidate result set cache entries.  Result set cache entries are tracked by the tables that contributed to their results. By default Teiid will capture internal data events against physical sources and distribute them across the cluster. This approach has several limitations.  First updates are scoped only to their originating VDB/version.  Second updates made out side of Teiid are not captured. To increase data consistency external change data capture tools can be used to send events to Teiid.  From within a Teiid cluster the <tt>org.teiid.events.EventDistributorFactory</tt> and <tt>org.teiid.events.EventDistributor</tt> can be used to distribute change events.  The <tt>EventDistributorFactory</tt> can be looked up by its name <em>"teiid/event&#45;distributor&#45;factory"</em>. See <a href="/author/display/TEIID/Programmatic+Control" title="Programmatic Control">Programmatic Control</a> for a dataModification example.</p>

<p>When externally capturing all update events, <em>"detect&#45;change&#45;events"</em> property in the teiid subsystem in can be set to <em>false</em>, to not duplicate change events. By default, this property is set to <em>true</em>.</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>Using the <tt>org.teiid.events.EventDistributor</tt> interface you can also update runtime metadata. Please check the API.</td></tr></table></div>

<p>The use of the other <tt>EventDistributor</tt> methods to manually distribute other events is not always necessary.  Check the <a href="/author/display/TEIID/System+Procedures" title="System Procedures">System Procedures</a> for SQL based updates.</p>

<h1><a name="RuntimeUpdates-RuntimeMetadataUpdates"></a>Runtime Metadata Updates</h1>

<p>Runtime updates via system procedures and DDL statements are by default ephemeral.  They are effective across the cluster only for the currently running vdbs. With the next vdb start the values will revert to whatever is stored in the vdb.  Updates may be made persistent though by configuring a <tt>org.teiid.metadata.MetadataRepository</tt>. An instance of a <tt>MetadataRepository</tt> can be installed via VDB file. In Designer based VDB, you can edit the vdb.xml file in the META-INF directory or use Dynamic VDB file as below.</p>

<div class="code panel" style="border-width: 1px;"><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="VIRTUAL"&gt;
         &lt;metadata type="{jboss-as-module-name}"&gt;&lt;/metadata&gt;
    &lt;/model&gt;
&lt;/vdb&gt;
</pre>
</div></div>

<p>In the above code fragment, replace the {jboss-as-module-name} with a JBoss AS module name that has library that implements the  <tt>org.teiid.metadata.MetadataRepository</tt> interface and defines file "META-INF/services/org.teiid.metadata.MetadataRepository" with name of the implementation file.</p>

<p>The <tt>MetadataRepository</tt> repository instance may fully implement as many of the methods as needed and return null from any unneeded getter.</p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>It is not recommended to directly manipulate <tt>org.teiid.metadata.AbstractMetadataRecord</tt> instances. System procedures and DDL statements should be used instead since the effects will be distributed through the cluster and will not introduce inconsistencies.</td></tr></table></div>

<p><tt>org.teiid.metadata.AbstractMetadataRecord</tt> objects passed to the <tt>MetadataRepository</tt> have not yet been modified. If the <tt>MetadataRepository</tt> cannot persist the update, then a <tt>RuntimeException</tt> should be thrown to prevent the update from being applied by the runtime engine.</p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>The MetadataRepository can be accessed by multiple threads both during load or at runtime with through DDL statements.  Your implementation should handle any needed synchronization.</td></tr></table></div>

<h3><a name="RuntimeUpdates-CostingUpdates"></a>Costing Updates</h3>
<p>See the Reference for the system procedures <tt>SYSADMIN.setColumnStats</tt> and <tt>SYSADMIN.setTableStats</tt>. To make costing updates persistent <tt>MetadataRepository</tt> implementations should be provided for: </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;">
TableStats getTableStats(String vdbName, int vdbVersion, Table table);
void setTableStats(String vdbName, int vdbVersion, Table table, TableStats tableStats);
ColumnStats getColumnStats(String vdbName, int vdbVersion, Column column);
void setColumnStats(String vdbName, int vdbVersion, Column column, ColumnStats columnStats);
</pre>
</div></div>


<h3><a name="RuntimeUpdates-SchemaUpdates"></a>Schema Updates</h3>
<p>See the Reference for supported DDL statements.  To make schema updates persistent implementations should be provided for:</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;">
String getViewDefinition(String vdbName, int vdbVersion, Table table);
void setViewDefinition(String vdbName, int vdbVersion, Table table, String viewDefinition);
String getInsteadOfTriggerDefinition(String vdbName, int vdbVersion, Table table, Table.TriggerEvent triggerOperation);
void setInsteadOfTriggerDefinition(String vdbName, int vdbVersion, Table table, Table.TriggerEvent triggerOperation, String triggerDefinition);
boolean isInsteadOfTriggerEnabled(String vdbName, int vdbVersion, Table table, Table.TriggerEvent triggerOperation);
void setInsteadOfTriggerEnabled(String vdbName, int vdbVersion, Table table, Table.TriggerEvent triggerOperation, boolean enabled);
String getProcedureDefinition(String vdbName, int vdbVersion, Procedure procedure);
void setProcedureDefinition(String vdbName, int vdbVersion, Procedure procedure, String procedureDefinition);                        
LinkedHashMap&lt;String, String&gt; getProperties(String vdbName, int vdbVersion, AbstractMetadataRecord record);
void setProperty(String vdbName, int vdbVersion, AbstractMetadataRecord record, String name, String value);
</pre>
</div></div>
    </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/Runtime+Updates">View Online</a>
        |
        <a href="https://docs.jboss.org/author/pages/diffpagesbyversion.action?pageId=18646196&revisedVersion=8&originalVersion=7">View Changes</a>
                |
        <a href="https://docs.jboss.org/author/display/TEIID/Runtime+Updates?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>