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/Examples/JPA/Extensible"

Line 10: Line 10:
 
This example illustrates how EclipseLink 2.2 can be used to build a domain model that allows addition 'extension' properties, relationships, and types to added and used in the application.  
 
This example illustrates how EclipseLink 2.2 can be used to build a domain model that allows addition 'extension' properties, relationships, and types to added and used in the application.  
  
'''NOTE: This functionality is being formalized into new features for [[EclipseLink/Development/Indigo|EclipseLink Indigo (2.3)]] in its [[EclipseLink/DesignDocs/Extensibility|Extensibility]] features.
+
''NOTE: This functionality is being formalized into new features for [[EclipseLink/Development/Indigo|EclipseLink Indigo (2.3)]] in its [[EclipseLink/DesignDocs/Extensibility|Extensibility]] features.''
 +
 
 +
=== Getting the Code ===
 +
 
 +
The example is being developed within the trunk of EclipseLink:
 +
* SVN: [http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/jpa.employee/eclipselink.example.jpa.employee.extensions/]
 +
 
 +
=== Usage Instructions ===
 +
 
 +
=== Code Examples ===
 +
 
 +
The following are code snippets extracted from the example to illustrate key use-cases.
 +
 
 +
==== Values Extensions ====
 +
 
 +
Values extensions use a separate table to store the extension properties. In this example the Employee entity type uses values extensions and is configured as:
 +
 
 +
<source lang="java">
 +
    @Transient
 +
 
 +
    @ValuesExtensions(table = @Table(name = "emp_ext"),
 +
            id = @Column(name = "EXT_ID"),
 +
            value = @Column(name = "EXT_VALUE"))
 +
    private Map<String, Object> extensions;
 +
</source>
 +
 
 +
It is annotated as @Transient so that the default JPA mappings are not applied. The configuration section below shows how the mapping is actually enabled.
 +
 
 +
==== Flex Extensions ====
 +
 
 +
In this example the Address class uses flex extensions and is configured as:
 +
 
 +
<source lang="java">
 +
    @Transient
 +
   
 +
    @FlexExtensions(initial=5, create=false)
 +
    private Map<String, Object> extensions = new HashMap<String, Object>();
 +
</source>
 +
 
 +
==== Configuration ====
 +
 
 +
In order to enable the extensions a session customizer is used. This will use the ExtensionManagerHelper to enable extensions usage in the specified classes.
 +
 
 +
'''[http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/jpa.employee/eclipselink.example.jpa.employee.extensions/src/model/extensions/ExtensionsCustomizer.java src/model.extensions.ExtensionsCustomizer]'''
 +
 
 +
<source lang="java">
 +
public class ExtensionsCustomizer implements SessionCustomizer {
 +
 
 +
    public void customize(Session session) throws Exception {
 +
        ExtensionManagerHelper helper = new ExtensionManagerHelper(session);
 +
 
 +
        helper.initializeValueExtensions(Employee.class, "extensions");
 +
        helper.initializeFlexExtensions(Address.class, "extensions");
 +
    }
 +
}
 +
</source>

Revision as of 11:32, 2 March 2011

Catnicon.gifUNDER CONSTRUCTION

Extensible Entities Example

This example illustrates how EclipseLink 2.2 can be used to build a domain model that allows addition 'extension' properties, relationships, and types to added and used in the application.

NOTE: This functionality is being formalized into new features for EclipseLink Indigo (2.3) in its Extensibility features.

Getting the Code

The example is being developed within the trunk of EclipseLink:

Usage Instructions

Code Examples

The following are code snippets extracted from the example to illustrate key use-cases.

Values Extensions

Values extensions use a separate table to store the extension properties. In this example the Employee entity type uses values extensions and is configured as:

    @Transient
 
    @ValuesExtensions(table = @Table(name = "emp_ext"), 
            id = @Column(name = "EXT_ID"), 
            value = @Column(name = "EXT_VALUE"))
    private Map<String, Object> extensions;

It is annotated as @Transient so that the default JPA mappings are not applied. The configuration section below shows how the mapping is actually enabled.

Flex Extensions

In this example the Address class uses flex extensions and is configured as:

    @Transient
 
    @FlexExtensions(initial=5, create=false)
    private Map<String, Object> extensions = new HashMap<String, Object>();

Configuration

In order to enable the extensions a session customizer is used. This will use the ExtensionManagerHelper to enable extensions usage in the specified classes.

src/model.extensions.ExtensionsCustomizer

public class ExtensionsCustomizer implements SessionCustomizer {
 
    public void customize(Session session) throws Exception {
        ExtensionManagerHelper helper = new ExtensionManagerHelper(session);
 
        helper.initializeValueExtensions(Employee.class, "extensions"); 
        helper.initializeFlexExtensions(Address.class, "extensions"); 
    }
}

Back to the top