This chapter provides instructions for storing mapping information in a metadata source that is external to the running application, so you can dynamically override or extend mappings in a deployed application.
This chapter includes the following sections:
Users want to establish a SaaS environment, where applications are shared by multiple clients.
Employ TopLink SaaS features, such as extensibility, multi-tenancy, and external metadata sources.
TopLink 12c (12.1.2.0.0) or later.
Note:
TopLink's core functionality is provided by EclipseLink, the open source persistence framework from the Eclipse Foundation. EclipseLink implements Java Persistence API (JPA), Java Architecture for XML Binding (JAXB), and other standards-based persistence technologies, plus extensions to those standards. TopLink includes all of EclipseLink, plus additional functionality from Oracle.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.
With EclipseLink, you can use the eclipselink-orm.xml
file to support advanced mapping types and options. This file can override the standard JPA orm.xml
mapping configuration file.
To use an external metadata source for your mapping information, perform the following tasks:
In your persistence unit, specify the external metadata source by defining an eclipselink.metadata.source
property and assign as its value a class that implements org.eclipse.persistence.jpa.metadata.MetadataSource
. For example:
<property name="eclipselink.metadata-source" value="mypackage.MyMetadataSource"/>
You are free to provide the metadata location in your class as you choose, for example:
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://myserverlocation/rest/" + leagueId + "/orm"); return super.getEntityMappings(properties, classLoader, log); } }
To access the metadata file, the server must provide URL access to the mapping file by using any of the following:
Static file serving
A server-based solution with its own mapping file or a mapping file built on-demand from stored mapping information
Some other web technology.
See the following resources for more information about the technologies and tools used to implement the solutions in this chapter.
For additional information about JPA deployment, see the following sections of the JPA Specification (http://jcp.org/en/jsr/detail?id=317
):
Section 7.2, "Bootstrapping in Java SE Environments"
Chapter 7, "Container and Provider Contracts for Deployment and Bootstrapping"
For more information about persistence unit properties, see PersistenceUnitProperties
class in Oracle Fusion Middleware Java API Reference for EclipseLink.
For more information about the APIs, see the following in Java Persistence API (JPA) Extensions Reference for Oracle TopLink: