blob: 3b12cbdd089b08a778834001bba109cb45d3f34f [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>Using an External Metadata Source | EclipseLink 2.4.x Understanding EclipseLink</title>
<meta name="generator" content="Oracle DARB XHTML Converter (Mode = document) - Version 1.0.11" />
<meta name="date" content="2012-12-13T9:16:50Z" />
<meta name="robots" content="noarchive" />
<meta name="doctitle" content="Using an External Metadata Source" />
<meta name="relnum" content="Release 2.4" />
<link rel="stylesheet" type="text/css" href="../../dcommon/style.css" media="screen" />
<link rel="copyright" href="../../dcommon/html/cpyr.htm" title="Copyright" type="text/html" />
<link rel="start" href="../../index.htm" title="Home" type="text/html" />
<link rel="contents" href="toc.htm" title="Contents" type="text/html" />
<link rel="prev" href="softwareasaservice004.htm" title="Previous" type="text/html" />
<link rel="next" href="multitenancy.htm" title="Next" type="text/html" />
<!-- START: Disqus --><script type="text/javascript"> var disqus_developer = 0; </script><!-- END: Disqus --><!-- START: Sharethis --><script type="text/javascript">var switchTo5x=true;</script><script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script><script type="text/javascript" src="http://s.sharethis.com/loader.js"></script> <!-- END: Sharethis --></head>
<body bgcolor="#FFFFFF"><iframe id="docheader" frameborder="0" framemargin="0" scrolling="no" src="../../dcommon/header.html"></iframe><script src="http://www.google.com/jsapi" type="text/javascript"></script><script type="text/javascript"> google.load('search', '1', {language : 'en'}); google.setOnLoadCallback(function() { var customSearchOptions = {}; var googleAnalyticsOptions = {}; googleAnalyticsOptions['queryParameter'] = 'q'; googleAnalyticsOptions['categoryParameter'] = ''; customSearchOptions['googleAnalyticsOptions'] = googleAnalyticsOptions; var customSearchControl = new google.search.CustomSearchControl( '016171230611334810008:enkkfjmsqju', customSearchOptions); customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET); var options = new google.search.DrawOptions(); options.setSearchFormRoot('cse-search-form'); customSearchControl.draw('cse', options); }, true);</script><link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css" type="text/css" /><div id="cse" style="width:100%;"></div>
<div class="header"><a id="top" name="top"></a>
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td align="left" valign="top"><font face="helvetica, arial, sans-serif"><b>EclipseLink Solutions Guide for EclipseLink</b><br />
Release 2.4</div></td>
<td valign="bottom" align="right" width="144">
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>&nbsp;</td>
<td align="center" valign="top"><a href="toc.htm"><img src="../../dcommon/images/contents.png" alt="Go To Table Of Contents" border="0" height="16" width="16" /><br />
<span class="mini">Contents</span></a></td><td>&nbsp;</td><td align="center"><a href="../../" target="_top" class="external text" title="Other searches" rel="nofollow"><img src="../../dcommon/images/search.png" alt="Search" style="border:0;" /><br /><span class="mini">Other&nbsp;Searches</span></a></td><td>&nbsp;</td><td align="center"><a href="../eclipselink_otlcg.pdf" title="PDF" target="_blank"><img src="../../dcommon/images/pdf_icon.png" style="padding-right:5px;border:0" alt="PDF"><br /><span class="mini">PDF</span></a></td><td align="center"><a href="#disqus_thread" title="Comments""><img src="../../dcommon/images/comments.png" style="padding-right:5px;border:0" alt="Comments"><br /><span class="mini">Comments</span></a>
</tr>
</table>
</td>
</tr>
</table>
<hr />
<table class="navigation simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100" align="center">
<tr>
<td align="center"><a href="softwareasaservice004.htm"><img src="../../dcommon/images/larrow.png" alt="Previous" border="0" height="16" width="16" /></a></td>
<td align="center"><a href="multitenancy.htm"><img src="../../dcommon/images/rarrow.png" alt="Next" border="0" height="16" width="16" /></a></td>
<td>&nbsp;</td>
</tr>
</table>
</div>
<!-- class="header" -->
<div class="ind"><!-- End Header -->
<p align="center"><font color="#FF0000">Beta Draft: 2012-12-13</font></p>
<a id="BABIAFJB" name="BABIAFJB"></a><a id="TLADG274" name="TLADG274"></a>
<div class="sect1"><!-- infolevel="all" infotype="General" -->
<h1 class="sect1"><font face="arial, helvetica, sans-serif" color="#330099">Using an External Metadata Source</font></h1>
<p>With EclipseLink, you can store your mapping information in a metadata source that is external to the running application. Because the mapping information is retrieved when the application creates the persistence unit, you can dynamically override or extend mappings in a deployed application.</p>
<a id="TLADG275" name="TLADG275"></a>
<div class="sect2"><!-- infolevel="all" infotype="General" --><a id="sthref110" name="sthref110"></a>
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Using the eclipselink-orm.xml File Externally</font></h2>
<p>With EclipseLink, you can use the <code>eclipselink-orm.xml</code> file to support advanced mapping types and options. This file can override the standard JPA <code>orm.xml</code> mapping configuration file.</p>
</div>
<!-- class="sect2" -->
<a id="TLADG276" name="TLADG276"></a>
<div class="sect2"><a id="sthref111" name="sthref111"></a>
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Main Tasks</font></h2>
<p>To use an external metadata source for your mapping information, perform the following tasks:</p>
<ul>
<li>
<p><a href="#BABEIJIG">Task 1: Configure the Persistence Unit</a></p>
</li>
<li>
<p><a href="#BABIGAGE">Task 2: Configure the Server</a></p>
</li>
</ul>
<a id="BABEIJIG" name="BABEIJIG"></a><a id="TLADG277" name="TLADG277"></a>
<div class="sect3">
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Task 1: Configure the Persistence Unit</font></h3>
<p>You can configure your persistence unit to use the external metadata by:</p>
<ul>
<li>
<p><a href="#CIAJFDDI">Accessing a Fixed Location</a></p>
</li>
<li>
<p><a href="#CIAFJHJE">Accessing an Application Context-Based Location</a></p>
</li>
</ul>
<a id="CIAJFDDI" name="CIAJFDDI"></a><a id="TLADG278" name="TLADG278"></a>
<div class="sect4">
<h4 class="sect4"><font face="arial, helvetica, sans-serif" color="#330099">Accessing a Fixed Location</font></h4>
<p>The easiest way to access an external file, such as the <code>eclipselink-orm.xml</code> file with additional mapping information, is by making the file available from a fixed URL on the web server.</p>
<p>Use the <code>eclipselink.metadata-source.xml.url</code> property, as shown in <a href="#CIACCCIA">Example 10-15</a>, to specify the location.</p>
<div class="example"><a id="CIACCCIA" name="CIACCCIA"></a><a id="TLADG279" name="TLADG279"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Example 10-15 Fixed Location</font></em></strong></p>
<pre xml:space="preserve" class="oac_no_warn">
&lt;property name="eclipselink.metadata-source" value="XML"/&gt;
&lt;property name="eclipselink.metadata-source.xml.url" value="http://myserverlocation/"/&gt;
</pre></div>
<!-- class="example" --></div>
<!-- class="sect4" -->
<a id="CIAFJHJE" name="CIAFJHJE"></a><a id="TLADG280" name="TLADG280"></a>
<div class="sect4">
<h4 class="sect4"><font face="arial, helvetica, sans-serif" color="#330099">Accessing an Application Context-Based Location</font></h4>
<p>For more complex requirements, such as providing tenant-specific extensions in a multi-tenant application, you can specify the location of the external metadata based on the application context.</p>
<p>Implement the <code>MetadataSource</code> interface, as shown in <a href="#CIACCIAD">Example 10-16</a>, to specify the location.</p>
<div class="example"><a id="CIACCIAD" name="CIACCIAD"></a><a id="TLADG281" name="TLADG281"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Example 10-16 Fixed Location</font></em></strong></p>
<pre xml:space="preserve" class="oac_no_warn">
&lt;property name="eclipselink.metadata-source" value="mypackage.MyMetadataSource"/&gt;
&lt;property name="eclipselink.metadata-source.xml.url" value="foo://bar"/&gt;
</pre></div>
<!-- class="example" -->
<p><a href="#CIADFJFI">Example 10-17</a> illustrates how to return a specific mapping file, based on the tenant.</p>
<div class="example"><a id="CIADFJFI" name="CIADFJFI"></a><a id="TLADG282" name="TLADG282"></a>
<p><strong><em><font face="arial, helvetica, sans-serif">Example 10-17 Tenant-specific Mapping File</font></em></strong></p>
<pre xml:space="preserve" class="oac_no_warn">
public class AdminMetadataSource extends XMLMetadataSource {
@Override
public XMLEntityMappings getEntityMappings(Map&lt;String, Object&gt; properties, ClassLoader classLoader, SessionLog log) {
String leagueId = (String) properties.get(LEAGUE_CONTEXT);
properties.put(PersistenceUnitProperties.METADATA_SOURCE_XML_URL, "http://myserverlocation/rest/" + leagueId + "/orm");
return super.getEntityMappings(properties, classLoader, log);
}
}
</pre></div>
<!-- class="example" --></div>
<!-- class="sect4" --></div>
<!-- class="sect3" -->
<a id="BABIGAGE" name="BABIGAGE"></a><a id="TLADG283" name="TLADG283"></a>
<div class="sect3">
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Task 2: Configure the Server</font></h3>
<p>To access the metadata file, the server must provide URL access to the mapping file by using any of the following:</p>
<ul>
<li>
<p>Static file serving</p>
</li>
<li>
<p>A server-based solution with its own mapping file or a mapping file built on-demand from stored mapping information</p>
</li>
<li>
<p>some other web technology.</p>
</li>
</ul>
</div>
<!-- class="sect3" --></div>
<!-- class="sect2" -->
<a id="TLADG284" name="TLADG284"></a>
<div class="sect2"><a id="sthref112" name="sthref112"></a>
<h2 class="sect2"><font face="arial, helvetica, sans-serif" color="#330099">Additional Resources</font></h2>
<p>See the following resources for more information about the technologies and tools used to implement the solutions in this chapter:</p>
<p>For additional information about JPA deployment, see the following sections of the JPA Specification (<code><a href="http://jcp.org/en/jsr/detail?id=317">http://jcp.org/en/jsr/detail?id=317</a></code>):</p>
<ul>
<li>
<p>Section 7.2, "Bootstrapping in Java SE Environments"</p>
</li>
<li>
<p>Chapter 7, "Container and Provider Contracts for Deployment and Bootstrapping"</p>
</li>
</ul>
<a id="TLADG285" name="TLADG285"></a>
<div class="sect3"><a id="sthref113" name="sthref113"></a>
<h3 class="sect3"><font face="arial, helvetica, sans-serif" color="#330099">Related Javadoc</font></h3>
<p>For more information, see the following APIs in <em>Oracle Fusion Middleware Java API Reference for EclipseLink</em>:</p>
<ul>
<li>
<p><code>PersistenceUnitProperties</code> class</p>
</li>
</ul>
</div>
<!-- class="sect3" --></div>
<!-- class="sect2" --></div>
<!-- class="sect1" --></div>
<!-- class="ind" -->
<!-- Start Footer -->
<div class="footer">
<hr />
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%">
<col width="33%" />
<col width="*" />
<col width="33%" />
<tr>
<td valign="bottom">
<table class="navigation simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100" align="center">
<col width="*" />
<col width="48%" />
<col width="48%" />
<tr>
<td>&nbsp;</td>
<td align="center"><a href="softwareasaservice004.htm"><img src="../../dcommon/images/larrow.png" alt="Previous" border="0" height="16" width="16" /></a></td>
<td align="center"><a href="multitenancy.htm"><img src="../../dcommon/images/rarrow.png" alt="Next" border="0" height="16" width="16" /></a></td>
</tr>
</table>
</td>
<td align="center" width="34%"><a href="http://www.eclipse.org/eclipselink/" title="EclipseLink home"><img src="../../dcommon/images/ellogo.png" alt="EclipseLink" width="150" border="0" /></a><br />
<td valign="bottom" align="right">
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="225">
<tr>
<td>&nbsp;</td>
<td align="center" valign="top"><a href="toc.htm"><img src="../../dcommon/images/contents.png" alt="Go To Table Of Contents" border="0" height="16" width="16" /><br />
<span class="mini">Contents</span></a></td><td>&nbsp;</td><td align="center"><a href="../../" target="_top" class="external text" title="Other searches" rel="nofollow"><img src="../../dcommon/images/search.png" alt="Search" style="border:0;" /><br /><span class="mini">Other&nbsp;Searches</span></a></td><td>&nbsp;</td><td align="center"><a href="../eclipselink_otlcg.pdf" title="PDF" target="_blank"><img src="../../dcommon/images/pdf_icon.png" style="padding-right:5px;border:0" alt="PDF"><br /><span class="mini">PDF</span></a></td><td align="center"><a href="#disqus_thread" title="Comments""><img src="../../dcommon/images/comments.png" style="padding-right:5px;border:0" alt="Comments"><br /><span class="mini">Comments</span></a>
</tr>
</table>
</td>
</tr>
</table>
</div>
<!-- class="footer" -->
<div id="copyright">Copyright &copy; 2012 by The Eclipse Foundation under the <a href="http://www.eclipse.org/org/documents/epl-v10.php">Eclipse Public License (EPL)</a><br /> <script type="text/javascript">var LastUpdated = document.lastModified;document.writeln ("Updated: " + LastUpdated);</script> </div><!-- START: Analytics --><script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-1608008-2']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script><!-- END: Analytics --><!-- START: Sharethis --><script>var options={ "publisher": "e2fe9e07-fab6-4f84-83ea-0991b429842c", "position": "right", "ad": { "visible": false, "openDelay": 5, "closeDelay": 0}};var st_hover_widget = new sharethis.widgets.hoverbuttons(options);</script><!-- END: Sharethis --><!-- START: Disqus --><div id="disqus_thread"></div> <script type="text/javascript"> var disqus_developer = 1;var disqus_shortname = 'eclipselinkdoc'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); </script> <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> <a href="http://disqus.com" class="dsq-brlink">Comments powered by <span class="logo-disqus">Disqus</span></a><!-- END: Disqus --></body>
</html>