LATEST VERSION: 8.1.0 - CHANGELOG
Pivotal GemFire® v8.1

Program Your Application to Use IPdxInstance

Program Your Application to Use IPdxInstance

An IPdxInstance is a lightweight wrapper around PDX serialized bytes. It provides applications with run-time access to fields of a PDX serialized object.

You can configure your cache to return an IPdxInstance when a PDX serialized object is deserialized instead of deserializing the object to a domain class. You can then program your application code that reads your entries to handle IPdxInstances fetched from the cache.

Note: This option applies only to entry retrieval that you explicitly code using methods like EntryEvent.getNewValue and Region.get, as you do inside functions or in cache listener code. This does not apply to querying because the query engine retrieves the entries and handles object access for you.
Note: IPdxInstance overrides any custom implementation you might have coded for your object's equals and hashcode methods.

Procedure

  1. In the cache.xml file of the server member where entry fetches are run, set the <pdx> read-serialized attribute to true.

    Data is not necessarily accessed on the member that you have coded for it. For example, if a client application runs a function on a server, the actual data access is done on the server, so you set read-serialized to true on the server.

    For example:
    // Cache configuration setting PDX read behavior
                  <cache>
                    <pdx read-serialized="true" />
    ... </cache>
  2. Write the application code that fetches data from the cache to handle a IPdxInstance. If you are sure you will only retrieve IPdxInstances from the cache, you can code only for that. In many cases, a IPdxInstance or a domain object may be returned from your cache entry retrieval operation, so you should check the object type and handle each possible type.

    See Creating an IPdxInstance with IPdxInstanceFactory for an example of this.

If you configure your cache to allow PDX serialized reads, cache fetches return the data in the form it is found. If the object is not serialized, the fetch returns the domain object. If the object is serialized, the fetch returns the PdxInstance for the object.

Note: If you are using IPdxInstances, you cannot use delta propagation to apply changes to PDX serialized objects.

For example, in client/server applications that are programmed and configured to handle all data activity from the client, PDX serialized reads done on the server side will always return the IPdxInstance. This is because all of data is serialized for transfer from the client and you are not performing any server-side activities that would deserialize the objects in the server cache.

In mixed situations, such as where a server cache is populated from client operations and also from data loads done on the server side, fetches done on the server can return a mix of IPdxInstances and domain objects.

When fetching data in a cache with PDX serialized reads enabled, the safest approach is to code to handle both types, receiving an Object from the fetch operation, checking the type and casting as appropriate.