<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/Embedded+Guide">Embedded Guide</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://docs.jboss.org/author/display/~kylin">Kylin Soong</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" >Embedded provides a the {{Admin}} interface via the {{EmbeddedServer.getAdmin}} method.  Not all methods are implemented for embedded - for example those that deal with data sources.  Also the deploy method may only deploy VDB xml artifacts. <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h1. Logging <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">Teiid default use JUL(Java Util Logging ), JBoss LogManager is a replacement of JUL that fixes or works around many serious problems and several new features be added, like bridging functionality, colored format pattern, etc. Refer to [Using JBoss LogManager with Teiid Embedded |TEIID:Using JBoss LogManager with Teiid Embedded]for details. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">Alternatively, the interface for Teiid embedded&#39;s logging is {{org.teiid.logging.Logger}} in teiid-api jar. The Logger instance is associated with the {{org.teiid.logging.LogManager}} via static method {{LogManager.setLogListener()}}. If no Logger is set, then default JUL will be performed. <br> <br> <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h1. Other Differences Between Teiid Embedded and an AS Deployment <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>Embedded is a light-weight version of Teiid for use in any Java 6&#43; JRE.  JBoss AS nor any application server is not required.  This feature/kit are still evolving.  Please consult the source examples and even unit tests utilizing the EmbeddedServer for a more complete guide as to its use.</p>

<h1><a name="EmbeddedGuide-Configuration"></a>Configuration</h1>

<p>The primary way to configure Teiid Embedded is with the <tt>EmbeddedConfiguration</tt> class.  It is provided to the <tt>EmbeddedServer</tt> at start-up and dictates much of the behavior of the embedded instance.  From there the running server instance may have translators and VDBs deployed as needed.  Additional modifications to the <tt>EmbeddedConfiguration</tt> after the server is started will not have an effect.</p>

<p>In many cases an <tt>EmbeddedConfiguration</tt> instance can just be instantiated and passed to the <tt>EmbeddedServer</tt> without the need to set additional properties.  Many properties, including those used to configure the BufferManager, will be given a similar name to their server side counter part - for example setProcessorBatchSize.</p>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>Most of the default configuration values for memory and threads assume that there is only 1 Teiid instance in the vm.  If you are using multiple Teiid Embedded instances in the same vm, then memory and thread resources should be configured manually.</td></tr></table></div>

<h2><a name="EmbeddedGuide-TheClasspath"></a>The Classpath</h2>

<p>Your application is responsible for having the appropriate classpath to utilize Teiid embedded.  Typically you will want to include all of the jars from the embedded kit's lib directory.  As needed by your deployment you should include jars from the optional folder along with any jars needed to provide source access.  Hibernate core 4.1.6 or compatible is needed, but not included in the kit, if you wish to utilize the JDBC translator support for dependent joins using temp tables.</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>osgi</b><br />All Teiid jars can also be deployed as bundles in a OSGI container like Karaf. If you are working with Karaf, a feature.xml file is available in maven repo for your convenience. Usage pattern is below
<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;">
  features:addurl mvn:org.jboss.teiid/teiid/8.6.0.Final/xml/karaf-features
  features:install -v teiid
</pre>
</div></div></td></tr></table></div>
<p>If you are trying run Teidd Embedded with Maven based project and using maven to pull artifacts, the <tt>runtime</tt>, <tt>admin</tt>, <tt>connector</tt>, <tt>translator</tt> dependencies are necessary as below</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;">
&lt;dependency&gt;
&lt;groupId&gt;org.jboss.teiid&lt;/groupId&gt;
&lt;artifactId&gt;teiid-runtime&lt;/artifactId&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
&lt;groupId&gt;org.jboss.teiid&lt;/groupId&gt;
&lt;artifactId&gt;teiid-admin&lt;/artifactId&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
&lt;groupId&gt;org.jboss.teiid.connectors&lt;/groupId&gt;
&lt;artifactId&gt;translator-SOURCE&lt;/artifactId&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
&lt;groupId&gt;org.jboss.teiid.connectors&lt;/groupId&gt;
&lt;artifactId&gt;connector-SOURCE&lt;/artifactId&gt;
&lt;classifier&gt;lib&lt;/classifier&gt;
&lt;/dependency&gt;

</pre>
</div></div>



<h2><a name="EmbeddedGuide-VDBDeployment"></a>VDB Deployment</h2>

<p>VDBs may be deployed in several ways in Embedded.</p>

<p><b>VDB Metadata API</b></p>

<p>VDB deployment can be done directly through VDB metadata objects that are the underpinning of vdb.xml deployment.  Models (schemas) are deployed as a set to form a named vdb - see the <tt>EmbeddedServer.deployVDB</tt> method.</p>

<p><b>XML Deployment</b></p>

<p>Similar to a server based &#45;vdb.xml deployment an <tt>InputStream</tt> may be given to a vdb.xml file - see the <tt>EmbeddedServer.deployVDB(InputStream)</tt> method.</p>

<p><b>Zip Deployment</b></p>

<p>Similar to a server based .vdb deployment a <tt>URL</tt> may be given to a zip file - see the <tt>EmbeddedServer.deployVDBZip</tt> method.  The use of the zip lib for dependency loading is not enabled in Embedded.  See <a href="/author/display/TEIID/Dynamic+VDBs" title="Dynamic VDBs">Dynamic VDBs</a> and <a href="/author/display/TEIID/Metadata+Repositories" title="Metadata Repositories">Metadata Repositories</a> for more on a typical vdb zip structure.  Teiid Designer 7 and later VDBs are also supported via this method, but are subject to all of the limitations/differences highlighted in this guide.</p>

<p><b>Translators</b></p>

<p>Translators instances can be scoped to a VDB in AS using declarations in a vdb.xml file, however named instances in embedded are scoped to the entire <tt>EmbeddedServer</tt> and must be registered via the <tt>EmbeddedServer.addTranslator</tt> methods.  Note that there are two <tt>addTranslator</tt> methods:</p>
<ul>
        <li><tt>addTranslator(Class&lt;? extends ExecutionFactory&gt; clazz)</tt> &#45; Adds a default instance of the ExecutionFactory, using the default name either from the Translator annotation or the class name.</li>
</ul>


<ul>
        <li><tt>addTranslator(String name, ExecutionFactory&lt;?, ?&gt; ef)</tt> &#45; Adds a pre-initialized (ExecutionFactory.start() must have already been called) instance of the ExecutionFactory,&nbsp; using the given translator name,&nbsp; this is functionally equivalent to using a vdb.xml translator override.</li>
</ul>


<p>A new server instance does not assume any translators are deployed and does not perform any sort of library scanning to find translators.</p>

<p><b>Sources</b></p>

<p>The Embedded Server will still attempt to lookup the given JNDI connection factory names via JNDI.  In most non-container environments it is likely that no such bindings exist.  In this case the Embedded Server instance must have <tt>ConnectionFactoryProvider</tt> instances manually registered, either using the <tt>EmbeddedServer.addConnectionFactory</tt> method, or the&nbsp; <tt>EmbeddedServer.addConnectionFactoryProvider</tt> method to implement <tt>ConnectionFactoryProvider</tt> registering.  Note that the Embedded Server does not have built-in pooling logic, so to make better use of a standard <tt>java.sql.DataSource</tt> or to enable proper use of <tt>javax.sql.XADataSource</tt> you must first configure the instance via a third-party connection pool.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example Deployment</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">EmbeddedServer es = new EmbeddedServer();
EmbeddedConfiguration ec = new EmbeddedConfiguration();
//set any configuration properties
ec.setUseDisk(false);
es.start(ec);

//example of adding a translator by pre-initialized ExecutionFactory and given translator name
H2ExecutionFactory ef = new H2ExecutionFactory()
ef.setSupportsDirectQueryProcedure(true);
ef.start();
es.addTranslator("translator-h2", ef);

//add a Connection Factory with a third-party connection pool
DataSource ds = EmbeddedHelper.newDataSource("org.h2.Driver", "jdbc:h2:mem://localhost/~/account", "sa", "sa");
es.addConnectionFactory("java:/accounts-ds", ds);

//add a vdb

//physical model
ModelMetaData mmd = new ModelMetaData();
mmd.setName("my-schema");
mmd.addSourceMapping("my-schema", "translator-h2", "java:/accounts-ds");

//virtual model
ModelMetaData mmd1 = new ModelMetaData();
mmd1.setName("virt");
mmd1.setModelType(Type.VIRTUAL);
mmd1.setSchemaSourceType("ddl");
mmd1.setSchemaText("create view \"my-view\" OPTIONS (UPDATABLE 'true') as select * from \"my-table\"");

es.deployVDB("test", mmd, mmd1);

</pre>
</div></div>

<h1><a name="EmbeddedGuide-Accessfromclientapplications"></a>Access from client applications</h1>

<p>Typically when Teiid is deployed as Embedded Server, and if your end user application is also deployed in the same virtual machine as the Teiid Embedded, you can use "Local JDBC Connection", to access to your virtual database. For example:</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;">
  EmbeddedServer es = ...
  Driver driver = es.getDriver();
  Connection conn = driver.connect("jdbc:teiid:&lt;vdb-name&gt;", null);
  // do work with conn; create statement and execute it
  conn.close();
</pre>
</div></div>

<p>This is the most efficient method as it does not impose any serialization of objects.</p>

<p>If your client application is deployed in remote VM, or your client application is not a JAVA based application then accesses to the Teiid Embedded is not possible through above mechanism. In those situations, you need to open a socket based connection from remote client application to the Embedded Teiid Server. By default, when you start the Embedded Teiid Sever it does not add any capabilities to accept remote JDBC/ODBC based connections. If you would like to expose the functionality to accept remote JDBC/ODBC connection requests, then configure necessary "transports" during the initialization of the Teiid Embedded Server. The example below shows a sample code to enable a ODBC transport</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;">
  EmbeddedServer es = new EmbeddedServer()
  SocketConfiguration s = new SocketConfiguration();
  s.setBindAddress("&lt;host-name&gt;");
  s.setPortNumber(35432);
  s.setProtocol(WireProtocol.pg);
  EmbeddedConfiguration config = new EmbeddedConfiguration();
  config.addTransport(s);
  es.start(config);
</pre>
</div></div>

<p>if you want to add a JDBC transport, follow the instructions above, however set the protocol to "WireProtocol.teiid" and choose a different port number. Once the above server is running, you can use same <a href="/author/display/TEIID/Connecting+to+a+Teiid+Server" title="Connecting to a Teiid Server">instructions</a> as Teiid Server to access Embedded Teiid Server from remote client application. Note that you can add multiple transports to single Embedded Server instance, to expose different transports.</p>

<h1><a name="EmbeddedGuide-Security"></a>Security</h1>

<p>The primary interface for Teiid embedded's security is the <tt>org.teiid.security.SecurityHelper</tt> in the engine jar.  The SecurityHelper instance is associated with with the EmbeddedServer via <tt>EmbeddedConfiguration.setSecurityHelper</tt>.  If no SecurityHelper is set, then no authentication will be performed.  A SecurityHelper controls authentication and associates a security context with a thread.  How a security context is obtained can depend upon the security domain name.  The default security domain name is "teiid-security" and can be changed via <tt>EmbeddedConfiguration.setSecurityDomain</tt>.  The effective security domain may also be configured via a transport of the VDB.</p>

<p>See the <a href="https://github.com/teiid/teiid/blob/master/jboss-integration/src/main/java/org/teiid/jboss/JBossSecurityHelper.java" class="external-link" rel="nofollow">JBoss Security Helper source</a> for an example of expected mechanics.</p>

<p>You can just return null from negotiateGssLogin unless you want to all GSS authentications from JDBC/ODBC.</p>

<h3><a name="EmbeddedGuide-Example"></a>Example</h3>

<p><a href="https://github.com/teiid/teiid-embedded-examples/tree/master/embedded-portfolio-security" class="external-link" rel="nofollow">embedded-portfolio-security</a> demonstrates how to implement security authentication in Teiid Embedded:</p>
<ul>
        <li><a href="https://github.com/teiid/teiid-embedded-examples/blob/master/common/src/main/java/org/teiid/example/EmbeddedSecurityHelper.java" class="external-link" rel="nofollow">EmbeddedSecurityHelper</a> is the implementation of <tt>org.teiid.security.SecurityHelper</tt></li>
        <li><a href="https://raw.githubusercontent.com/teiid/teiid-embedded-examples/master/embedded-portfolio-security/src/main/resources/users.properties" class="external-link" rel="nofollow">users.properties</a> and <a href="https://raw.githubusercontent.com/teiid/teiid-embedded-examples/master/embedded-portfolio-security/src/main/resources/roles.properties" class="external-link" rel="nofollow">roles.properties</a> in class path user to pre define users and roles</li>
        <li><a href="https://raw.githubusercontent.com/teiid/teiid-embedded-examples/master/common/src/main/resources/picketbox/authentication.conf" class="external-link" rel="nofollow">application-policy</a>'s name in authentication.conf should match to security domain(<tt>EmbeddedConfiguration.setSecurityDomain</tt>)</li>
</ul>


<h1><a name="EmbeddedGuide-Transactions"></a>Transactions</h1>

<p>Transaction processing requires setting the <tt>TransactionManager</tt> in the <tt>EmbeddedConfiguration</tt> used to start the <tt>EmbeddedServer</tt>.  A client facing <tt>javax.sql.DataSource</tt> is not provided for embedded.  However the usage of provided <tt>java.sql.Driver</tt> should be sufficient as the embedded server is by default able to detect thread bound transactions and appropriately propagate the transaction to threads launched as part of request processing.  The usage of local connections is also permitted.</p>

<h1><a name="EmbeddedGuide-AdminApi"></a>AdminApi</h1>

<p>Embedded provides a the <tt>Admin</tt> interface via the <tt>EmbeddedServer.getAdmin</tt> method.  Not all methods are implemented for embedded - for example those that deal with data sources.  Also the deploy method may only deploy VDB xml artifacts.</p>

<h1><a name="EmbeddedGuide-Logging"></a>Logging</h1>

<p>Teiid default use JUL(Java Util Logging ), JBoss LogManager is a replacement of JUL that fixes or works around many serious problems and several new features be added, like bridging functionality, colored format pattern, etc. Refer to <a href="/author/display/TEIID/Using+JBoss+LogManager+with+Teiid+Embedded" title="Using JBoss LogManager with Teiid Embedded">Using JBoss LogManager with Teiid Embedded </a>for details.</p>

<p>Alternatively, the interface for Teiid embedded's logging is <tt>org.teiid.logging.Logger</tt> in teiid-api jar. The Logger instance is associated with the <tt>org.teiid.logging.LogManager</tt> via static method <tt>LogManager.setLogListener()</tt>. If no Logger is set, then default JUL will be performed.</p>



<h1><a name="EmbeddedGuide-OtherDifferencesBetweenTeiidEmbeddedandanASDeployment"></a>Other Differences Between Teiid Embedded and an AS Deployment</h1>

<ul>
        <li>There is no default JDBC/ODBC socket transport in embedded.  You are expected to obtain a <tt>Driver</tt> connection via the <tt>EmbeddedServer.getDriver</tt> method. If you want remote JDBC/ODBC transport see above on how to add a transport.</li>
        <li>A <tt>MetadataRepository</tt> is scoped to a VDB in AS, but is scoped to the entire <tt>EmbeddedServer</tt> instance and must be registered via the <tt>EmbeddedServer.addMetadataRepository</tt> method.</li>
        <li>MDC logging values are not available as Java logging lacks the concept of a mapped diagnostic context.</li>
        <li>Translator overrides in vdb.xml files is not supported.</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/Embedded+Guide">View Online</a>
        |
        <a href="https://docs.jboss.org/author/pages/diffpagesbyversion.action?pageId=54493200&revisedVersion=27&originalVersion=26">View Changes</a>
                |
        <a href="https://docs.jboss.org/author/display/TEIID/Embedded+Guide?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>