13 Using an External MetaData Source
This chapter includes the following sections:
Use Case
Users want to establish a SaaS environment, where applications are shared by multiple clients.
Solution
Employ TopLink SaaS features, such as extensibility, multi-tenancy, and external metadata sources.
Components
-
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.
-
EclipseLink 2.4 or later.
Introduction to the Solution
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.
Using the eclipselink-orm.xml File Externally
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.
Main Tasks
To use an external metadata source for your mapping information, perform the following tasks:
Task 1: Configure the Persistence Unit
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); } }
Task 2: Configure the Server
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.
Additional Resources
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
):-
Bootstrapping in Java SE Environments
-
Container and Provider Contracts for Deployment and Bootstrapping
-
-
For more information about persistence unit properties, see
PersistenceUnitProperties
class in Java API Reference for Oracle TopLink. -
For more information about the APIs, see the following in Java Persistence API (JPA) Extensions Reference for Oracle TopLink: