Skip Headers
Oracle® Coherence Integration Guide for Oracle TopLink with Coherence Grid
Release 3.7.1

Part Number E23131-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

4 Using POF Serialization

Serialization is the process of encoding an object into a binary format. It is a critical component when working with Coherence as data must be moved around the network. The Portable Object Format (also referred to as POF) is a language agnostic binary format. POF was designed to be incredibly efficient in both space and time and has become a cornerstone element in working with Coherence. Using POF has many advantages ranging from performance benefits to language independence. It's recommended that you look closely at POF as your serialization solution when working with Coherence.

This chapter focuses only on the changes and additions that you need to make to your TopLink application files to make them eligible to participate in POF serialization. For more detailed information on using and configuring POF, see "Using Portable Object Format" in the Developers Guide for Oracle Coherence.

This chapter contains the following sections:

4.1 Implement a Serialization Routine

You must implement serialization routines that know how to serialize and deserialize your Entities. You can do this by implementing the PortableObject interface or by creating a serializer using the com.tangosol.io.pof.PofSerializer interface.

4.2 Define a Cache Configuration File

In the cache configuration file, create cache mappings corresponding to the Entities you will be working with. Identify the serializer (such as com.tangosol.io.pof.ConfigurablePofContext) and the POF configuration file pof-config.xml. Identify the EclipseLink cache store (such as oracle.eclipselink.coherence.integrated.EclipseLinkJPACacheStore) in the <cachestore-scheme> attribute.

Example 4-2 Sample Cache Configuration File

<?xml version="1.0"?>
<cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
              xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config http://xmlns.oracle.com/coherence/coherence-cache-config/1.0/coherence-cache-config.xsd">
  <caching-scheme-mapping>
    <cache-mapping>
        <cache-name>ATTORNEY_JPA_CACHE</cache-name>
        <scheme-name>eclipselink-jpa-distributed</scheme-name>
    </cache-mapping>
    <cache-mapping>
        <cache-name>CONTACT_JPA_CACHE</cache-name>
        <scheme-name>eclipselink-jpa-distributed-load</scheme-name>
    </cache-mapping>
...
additional cache mappings 
...
<caching-schemes>
    <distributed-scheme>
      <scheme-name>eclipselink-jpa-distributed-load</scheme-name>
      <service-name>EclipseLinkJPA</service-name>
 
    <serializer>
      <instance>
      <class-name>com.tangosol.io.pof.ConfigurablePofContext</class-name>
      <init-params>
        <init-param>
          <param-type>String</param-type>                 
          <param-value>trader-pof-config.xml</param-value>
        </init-param>
      </init-params>
      </instance>
    </serializer>
      <backing-map-scheme>
        <read-write-backing-map-scheme>
          <internal-cache-scheme>
            <local-scheme/>
          </internal-cache-scheme>
        </read-write-backing-map-scheme>
      </backing-map-scheme>
      <autostart>true</autostart>
    </distributed-scheme>
    <distributed-scheme>
      <scheme-name>eclipselink-jpa-distributed</scheme-name>
      <service-name>EclipseLinkJPA</service-name>
    <serializer>
      <instance>
      <class-name>com.tangosol.io.pof.ConfigurablePofContext</class-name>
      <init-params>
        <init-param>
          <param-type>String</param-type>
          <param-value>trader-pof-config.xml</param-value>
        </init-param>
      </init-params>
      </instance>
    </serializer>
 
      <backing-map-scheme>
        <read-write-backing-map-scheme>
          <internal-cache-scheme>
            <local-scheme/>
          </internal-cache-scheme>
          <!-- Define the cache scheme -->
          <cachestore-scheme>
            <class-scheme>
              <class-name>oracle.eclipselink.coherence.integrated.EclipseLinkJPACacheStore</class-name>
              <init-params>
                <init-param>
                  <param-type>java.lang.String</param-type>
                  <param-value>{cache-name}</param-value>
                </init-param>
                <init-param>
                  <param-type>java.lang.String</param-type>
                  <param-value>coherence-pu</param-value>
                </init-param>
              </init-params>
            </class-scheme>
          </cachestore-scheme>
        </read-write-backing-map-scheme>
      </backing-map-scheme>
      <autostart>true</autostart>
    </distributed-scheme>
  </caching-schemes>
</cache-config>

4.3 Provide a POF Configuration File

Provide a file that identifies the Entity classes that will participate in POF serialization. Coherence provides a POF configuration file which is named pof-config.xml by default. Use the file to assign type-ids to the Entity classes.

The POF configuration file must also contain type-id entries for the following classes:

Example 4-3 illustrates a sample POF configuration file that includes the TopLink Grid support files.

Example 4-3 Sample POF Configuration File

<?xml version="1.0"?>
<pof-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.oracle.com/coherence/coherence-pof-config"
    xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-pof-config http://xmlns.oracle.com/coherence/coherence-pof-config/1.0/coherence-pof-config.xsd">
  <user-type-list>
    <!-- include all "standard" Coherence POF user types -->
    <include>coherence-pof-config.xml</include>
     <user-type>
       <type-id>1163</type-id>
      <class-name>oracle.toplinkgrid.codesample.pof.models.trader.Attorney</class-name>
     </user-type>
   ...
   additional type IDs for Entity classes 
   ...
     <user-type>
       <type-id>1144</type-id>
       <class-name>oracle.eclipselink.coherence.integrated.internal.cache.WrapperInternal</class-name>
       <serializer>
         <class-name>oracle.eclipselink.coherence.integrated.cache.WrapperPofSerializer</class-name>
       </serializer>
     </user-type>
     <user-type>
       <type-id>1142</type-id>
       <class-name>oracle.eclipselink.coherence.integrated.internal.querying.EclipseLinkExtractor</class-name>
       <serializer>
         <class-name>oracle.eclipselink.coherence.integrated.cache.ExtractorSerializer</class-name>
       </serializer>
     </user-type>
     <user-type>
       <type-id>1141</type-id>
       <class-name>oracle.eclipselink.coherence.integrated.internal.cache.VersionPutProcessor</class-name>
     </user-type>
     <user-type>
       <type-id>1140</type-id>
       <class-name>oracle.eclipselink.coherence.integrated.internal.cache.VersionRemoveProcessor</class-name>
     </user-type>
     <user-type>
       <type-id>1139</type-id>
       <class-name>oracle.eclipselink.coherence.integrated.internal.cache.RelationshipUpdateProcessor</class-name>
     </user-type>
     <user-type>
       <type-id>1138</type-id>
       <class-name>oracle.eclipselink.coherence.integrated.internal.querying.EclipseLinkFilterFactory$SubClassOf</class-name>
     </user-type>
   </user-type-list>
 
   <allow-interfaces>true</allow-interfaces>
   <allow-subclasses>true</allow-subclasses>
 </pof-config>