Class PdxInstanceWrapper

java.lang.Object
org.springframework.geode.pdx.PdxInstanceWrapper
All Implemented Interfaces:
Serializable, org.apache.geode.cache.Document, org.apache.geode.internal.Sendable, org.apache.geode.pdx.PdxInstance

public class PdxInstanceWrapper extends Object implements org.apache.geode.pdx.PdxInstance, org.apache.geode.internal.Sendable
The PdxInstanceWrapper class is an implementation of the PdxInstance interface wrapping an existing PdxInstance object and decorating the functionality.
Since:
1.3.0
See Also:
  • Field Details

  • Constructor Details

    • PdxInstanceWrapper

      public PdxInstanceWrapper(org.apache.geode.pdx.PdxInstance pdxInstance)
      Constructs a new instance of PdxInstanceWrapper initialized with the given, required PdxInstance object used to back this wrapper.
      Parameters:
      pdxInstance - PdxInstance object used to back this wrapper; must not be null.
      Throws:
      IllegalArgumentException - if PdxInstance is null.
      See Also:
      • PdxInstance
  • Method Details

    • from

      public static Object from(Object target)
      Smart, null-safe factory method used to evaluate the given Object and wrap the Object in a new instance of PdxInstanceWrapper if the Object is an instance of PdxInstance or return the given Object as is.
      Parameters:
      target - Object to evaluate
      Returns:
      the Object wrapped in a new instance of PdxInstanceWrapper if Object is an instance of PdxInstance, otherwise returns the given Object.
      See Also:
    • from

      public static PdxInstanceWrapper from(org.apache.geode.pdx.PdxInstance pdxInstance)
      Factory method used to construct a new instance of PdxInstanceWrapper initialized with the given, required PdxInstance used to back the wrapper.
      Parameters:
      pdxInstance - PdxInstance object used to back this wrapper; must not be null.
      Returns:
      a new instance of PdxInstanceWrapper initialized with the given PdxInstance.
      Throws:
      IllegalArgumentException - if PdxInstance is null.
      See Also:
    • unwrap

      public static org.apache.geode.pdx.PdxInstance unwrap(org.apache.geode.pdx.PdxInstance pdxInstance)
      Null-safe factory method used to unwrap the given PdxInstance. If the given PdxInstance is an instance of PdxInstanceWrapper then this factory method will unwrap the PdxInstanceWrapper returning the underlying, delegate PdxInstance. Otherwise, the given PdxInstance is returned.
      Parameters:
      pdxInstance - PdxInstance to unwrap; may be null.
      Returns:
      the unwrapped PdxInstance.
      See Also:
    • getDelegate

      public org.apache.geode.pdx.PdxInstance getDelegate()
      Returns a reference to the configured, underlying PdxInstance backing this wrapper.
      Returns:
      a reference to the configured, underlying PdxInstance backing this wrapper; never null.
      See Also:
      • PdxInstance
    • getObjectMapper

      protected Optional<com.fasterxml.jackson.databind.ObjectMapper> getObjectMapper()
      Returns an Optional reference to a configured Jackson ObjectMapper used to deserialize the JSON generated from PDX back into an Object. This method is meant ot be overridden by subclasses.
      Returns:
      an Optional ObjectMapper.
      See Also:
    • getClassName

      public String getClassName()
      Specified by:
      getClassName in interface org.apache.geode.pdx.PdxInstance
    • isDeserializable

      public boolean isDeserializable()
      Specified by:
      isDeserializable in interface org.apache.geode.pdx.PdxInstance
    • isEnum

      public boolean isEnum()
      Specified by:
      isEnum in interface org.apache.geode.pdx.PdxInstance
    • getField

      public Object getField(String fieldName)
      Specified by:
      getField in interface org.apache.geode.cache.Document
      Specified by:
      getField in interface org.apache.geode.pdx.PdxInstance
    • getFieldNames

      public List<String> getFieldNames()
      Specified by:
      getFieldNames in interface org.apache.geode.cache.Document
    • getIdentifier

      public Object getIdentifier()
      Determines the identifier for, or identity of, this PdxInstance.
      Returns:
      the identifier for this PdxInstance; never null.
      Throws:
      IllegalStateException - if the PdxInstance does not have an id.
      See Also:
    • getId

      protected Object getId()
      Searches for a PDX field name called id on this PdxInstance and returns its value as the identifier for, or identity of, this PdxInstance.
      Returns:
      the value of the id field on this PdxInstance.
      Throws:
      IllegalStateException - if this PdxInstance does not have an id.
      See Also:
    • getAtIdentifier

      protected Object getAtIdentifier()
      Searches for a PDX field declared by the @identifier metadata field on this PdxInstance and returns the value of this field as the identifier for, or identity of, this PdxInstance.
      Returns:
      the value of the field declared in the @identifier metadata field on this PdxInstance.
      Throws:
      IllegalStateException - if the PdxInstance does not have an id.
      See Also:
      • PdxInstance
    • isIdentityField

      public boolean isIdentityField(String fieldName)
      Specified by:
      isIdentityField in interface org.apache.geode.pdx.PdxInstance
    • getObject

      public Object getObject()
      Materializes an Object from the PDX bytes described by this PdxInstance. If these PDX bytes describe an Object parsed from JSON, then the JSON is reconstructed from this PdxInstance and mapped to an instance of the type identified by the @type metadata PDX field using Jackson's ObjectMapper.
      Specified by:
      getObject in interface org.apache.geode.pdx.PdxInstance
      Returns:
      an Object constructed from the PDX bytes described by this PdxInstance.
      See Also:
    • createWriter

      public org.apache.geode.pdx.WritablePdxInstance createWriter()
      Specified by:
      createWriter in interface org.apache.geode.pdx.PdxInstance
    • hasField

      public boolean hasField(String fieldName)
      Specified by:
      hasField in interface org.apache.geode.cache.Document
    • sendTo

      public void sendTo(DataOutput out) throws IOException
      Specified by:
      sendTo in interface org.apache.geode.internal.Sendable
      Throws:
      IOException
    • toString

      public String toString()
      Returns a String representation of this PdxInstance.
      Specified by:
      toString in interface org.apache.geode.pdx.PdxInstance
      Overrides:
      toString in class Object
      Returns:
      a String representation of this PdxInstance.
      See Also: