Fusion Middleware Documentation
Advanced Search


Solutions Guide for Oracle TopLink
Close Window

Table of Contents

Show All | Collapse

13 Using an External MetaData Source

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 contains 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 Release 1 (12.1.2) 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.

13.1 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.

13.2 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.

13.3 Main Tasks

To use an external metadata source for your mapping information, perform the following tasks:

13.3.1 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);
    }
}

13.3.2 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.

13.4 Additional Resources

See the following resources for more information about the technologies and tools used to implement the solutions in this chapter.