Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/sandbox/gelernter/External Mappings"

m (New page: {{EclipseLink_UserGuide |info=y |toc=n |api=y |apis= *[http://www.eclipse.org/eclipselink/api/2.3/org/eclipse/persistence/xxx.html xxx] |examples=y |example= *[[EclipseLink/Examples/JPA/Me...)
 
m
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{EclipseLink_UserGuide
+
{{EclipseLink_UserGuide  
 
|info=y
 
|info=y
 
|toc=n
 
|toc=n
 +
|eclipselink=y
 +
|eclipselinktype=JPA
 
|api=y
 
|api=y
 
|apis=
 
|apis=
*[http://www.eclipse.org/eclipselink/api/2.3/org/eclipse/persistence/xxx.html xxx]
+
* [[http://www.eclipse.org/eclipselink/api/latest/org/eclipse/persistence/jpa/metadata/MetadataSource.html| MetadataSource]]
 +
* [[http://www.eclipse.org/eclipselink/api/latest/org/eclipse/persistence/config/PersistenceUnitProperties.html#METADATA_SOURCE| METADATA_SOURCE]]
 +
* [[http://www.eclipse.org/eclipselink/api/latest/org/eclipse/persistence/config/PersistenceUnitProperties.html#METADATA_SOURCE_XML_FILE| METADATA_SOURCE_XML_FILE]]
 +
* [[http://www.eclipse.org/eclipselink/api/latest/org/eclipse/persistence/config/PersistenceUnitProperties.html#METADATA_SOURCE_XML_URL| METADATA_SOURCE_XML_URL]]
 
|examples=y
 
|examples=y
 
|example=
 
|example=
*[[EclipseLink/Examples/JPA/MetadataSource|MetadataSource]]
+
*[[EclipseLink/Examples/JPA/Extensibility|Extensible Entities]]
}}  
+
*[[EclipseLink/Examples/MySports|MySports Example]]
 +
}}
 +
===******SANDBOX VERSION******===
 +
''This page is under construction''
 +
= External Mappings=
  
= Externalized Mappings =
+
{{EclipseLink_NewIn
 +
|version=2.3}}
 +
<br>
 +
<br>
  
 +
You can store mapping information using a metadata source external to the running application. This allows you to dynamically integrate mapping overrides and extended mappings into deployed applications. The mapping information is retrieved when the application's persistence unit is being created. This feature can be used for any mapping customization including [[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Extensible_Entities| Extensible JPA Entities]].
  
''This feature is new in EclipseLink 2.3.''
+
To configure external mapping, you must:
  
''This page is under development.''
+
# [[# Configuring the Persistence Unit|Configure the client persistence unit]]
 +
# [[# Configuring the Server|Configure the server]]
  
You can store mappings using a <tt>MetadataSource</tt> external to the running application so that mapping overrides and extended mappings can be more dynamically integrated into deployed applications.
+
== Configuring the Persistence Unit ==
  
= EclipseLink JPA MetadataSource =
+
The simplest way to store mappings externally is to make the <tt>eclipselink-orm.xml</tt> file with the additional mapping information available on a Web server as a file. A more \complex way is to establish a server process that stores the mapping information and supports dynamically updating this information.
  
Starting with [http://www.eclipse.org/eclipselink/releases/2.3.0.php EclipseLink 2.3.0] developers can now
+
=== Accessing a Mapping File at a Fixed URL ===
  
You can store mapping information outside an application and can have it retrieved when the application's persistence unit is being created. This feature can be used for any mapping customization including [[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Extensible_Entities| Extensible JPA Entities]].
+
To access an external mapping file at a fixed URL for a persistence unit, use the <tt>eclipselink.metadata-source</tt> and <tt>eclipselink.metadata-source.xml</tt> properties, for example:
 
+
== The Basics ==
+
 
+
In order to make use of this capability you must
+
 
+
# Configure the client persistence unit
+
# Configure the server
+
 
+
=== 1. Client PU ===
+
 
+
The external storage of mappings can be as simple as making the eclipselink-orm.xml file with the additional mapping information available on a web server as a file but can be more complex involving a server process that stores the mapping information and supports dynamically updating this information.
+
 
+
If you simply want to access the mapping file at a fixed URL for your persistence unit you can use:
+
  
 
<source lang="xml">
 
<source lang="xml">
Line 43: Line 44:
 
</source>
 
</source>
  
If however you are building a more complex solution involving a calculated location based on application context you will need to implement the MetadataSource interface. This could be used to have tenant specific extensions in a Multitenant application. To configure this you will need to setup the properties as:
+
=== Mapping a Location Based on the Application Context ===
 +
 
 +
For more complex requirement, for example, to provide tenant-specific extensions in a multi-tenant application, you can specify the location of the mapping information based on application context. To do so, implement the <tt>MetadataSource</tt> interface, and set the properties as follows:
  
 
<source lang="xml">
 
<source lang="xml">
Line 50: Line 53:
 
</source>
 
</source>
  
In the MySports example application a JAX-RS (RESTful) service is built that returns the mapping file per tenant. This is done like:
+
In the following example, (from the the [[http://wiki.eclipse.org/EclipseLink/Examples/MySports MySports]] example application), a JAX-RS (RESTful) service is built that returns the mapping file per tenant:
  
 
<source lang="java">
 
<source lang="java">
Line 64: Line 67:
 
</source>
 
</source>
  
=== 2. Mapping Server ===
+
==Configuring the Server ==
  
The mapping server needs to provide URL access to a mapping file. This can be done using many different web technologies ranging from static file serving to a rich server based solution with its own persistent store of XML files or mapping information stored in a more granular form and put together into mapping documents on demand.
+
The server must provide URL access to a mapping file. This can be done using a number of Web technologies, including:
 +
* Static file serving
 +
* Server-based solution with its own persistent store of XML files or mapping information stored in a granular form and put together into mapping documents on demand
  
The MySports example referenced below implements a JAX-RS based solution with the mapping extensions stored as separate JPA entities themselves and combined together on demand to create a tenant specific mapping override file with that tenant's extension mappings.
+
See the [[http://wiki.eclipse.org/EclipseLink/Examples/MySports MySports]] example application for an implementation of a JAX-RS based solution. The mapping extensions are stored as separate JPA entities and combined together on demand to create a tenant-specific mapping override file with that tenant's extension mappings.
  
== Learn More ==
+
'''''//Expand this section with actual instructions and examples//'''''
 
+
* [[EclipseLink/Examples/JPA/EclipseLink-ORM.XML | eclipselink-orm.xml example]]: Using EclipseLInk extended mapping file.
+
* [[EclipseLink/Examples/JPA/Extensibility | Extensible JPA Entities]]
+
* [[EclipseLink/Examples/JPA/Multitenant | Multitenant Entities]]
+
* [[EclipseLink/Examples/MySports | MySports Example]]: Integrated use of Multitenant extensible entities with a REST based admin server acting as the MetadataSource.
+
 
+
{{EclipseLink_JPA
+
|up=      [[EclipseLink/UserGuide/JPA/Advanced_JPA_Development|Advanced JPA Development]]
+
}}
+

Latest revision as of 09:30, 4 July 2011

EclipseLink JPA

******SANDBOX VERSION******

This page is under construction

External Mappings

EL NewIn.png New in version 2.3.



You can store mapping information using a metadata source external to the running application. This allows you to dynamically integrate mapping overrides and extended mappings into deployed applications. The mapping information is retrieved when the application's persistence unit is being created. This feature can be used for any mapping customization including Extensible JPA Entities.

To configure external mapping, you must:

  1. Configure the client persistence unit
  2. Configure the server

Configuring the Persistence Unit

The simplest way to store mappings externally is to make the eclipselink-orm.xml file with the additional mapping information available on a Web server as a file. A more \complex way is to establish a server process that stores the mapping information and supports dynamically updating this information.

Accessing a Mapping File at a Fixed URL

To access an external mapping file at a fixed URL for a persistence unit, use the eclipselink.metadata-source and eclipselink.metadata-source.xml properties, for example:

<property name="eclipselink.metadata-source" value="XML"/>
<property name="eclipselink.metadata-source.xml.url" value="foo://bar"/>

Mapping a Location Based on the Application Context

For more complex requirement, for example, to provide tenant-specific extensions in a multi-tenant application, you can specify the location of the mapping information based on application context. To do so, implement the MetadataSource interface, and set the properties as follows:

<property name="eclipselink.metadata-source" value="mypackage.MyMetadataSource"/>
<property name="eclipselink.metadata-source.xml.url" value="foo://bar"/>

In the following example, (from the the [MySports] example application), a JAX-RS (RESTful) service is built that returns the mapping file per tenant:

public class AdminMetadataSource extends XMLMetadataSource {
 
    @Override
    public XMLEntityMappings getEntityMappings(Map<String, Object> properties, ClassLoader classLoader, SessionLog log) {
        String leagueId = (String) properties.get(LEAGUE_CONTEXT);
        properties.put(PersistenceUnitProperties.METADATA_SOURCE_XML_URL, "http://foo.bar/rest/" + leagueId + "/orm");
        return super.getEntityMappings(properties, classLoader, log);
    }
}

Configuring the Server

The server must provide URL access to a mapping file. This can be done using a number of Web technologies, including:

  • Static file serving
  • Server-based solution with its own persistent store of XML files or mapping information stored in a granular form and put together into mapping documents on demand

See the [MySports] example application for an implementation of a JAX-RS based solution. The mapping extensions are stored as separate JPA entities and combined together on demand to create a tenant-specific mapping override file with that tenant's extension mappings.

//Expand this section with actual instructions and examples//

Back to the top