public class MappingPdxSerializer extends Object implements org.apache.geode.pdx.PdxSerializer, ApplicationContextAware
PdxSerializer
implementation using the Spring Data for Apache Geode GemfireMappingContext
to read (deserialize) and write (serialize) entities from and to PDX.PdxReader
,
PdxSerializer
,
PdxWriter
,
ApplicationContext
,
ApplicationContextAware
,
ConversionService
,
Filter
,
PersistentEntity
,
PersistentProperty
,
PersistentPropertyAccessor
,
PropertyHandler
,
ConvertingPropertyAccessor
,
EntityInstantiator
,
EntityInstantiators
,
PersistentEntityParameterValueProvider
Modifier and Type | Class and Description |
---|---|
static interface |
MappingPdxSerializer.PdxSerializerResolver |
static class |
MappingPdxSerializer.PdxSerializerResolvers |
static class |
MappingPdxSerializer.TypeFilters |
Modifier and Type | Field and Description |
---|---|
protected static String |
COM_GEMSTONE_GEMFIRE_PACKAGE_NAME |
protected static String |
JAVA_PACKAGE_NAME |
protected static String |
ORG_APACHE_GEODE_PACKAGE_NAME |
protected static String |
ORG_SPRINGFRAMEWORK_PACKAGE_NAME |
Constructor and Description |
---|
MappingPdxSerializer()
Constructs a new instance of
MappingPdxSerializer using a default GemfireMappingContext
and DefaultConversionService . |
MappingPdxSerializer(GemfireMappingContext mappingContext,
ConversionService conversionService)
Constructs a new instance of
MappingPdxSerializer initialized with the given
GemfireMappingContext and ConversionService . |
Modifier and Type | Method and Description |
---|---|
static MappingPdxSerializer |
create(ConversionService conversionService)
Factory method used to construct a new instance of
MappingPdxSerializer initialized with
the given ConversionService and a provided GemfireMappingContext . |
static MappingPdxSerializer |
create(GemfireMappingContext mappingContext)
Factory method used to construct a new instance of
MappingPdxSerializer initialized with
the given mapping context supplying entity mapping meta-data,
using a provided, default ConversionService . |
static MappingPdxSerializer |
create(GemfireMappingContext mappingContext,
ConversionService conversionService)
Factory method used to construct a new instance of
MappingPdxSerializer initialized with
the given mapping context and conversion service . |
Object |
fromData(Class<?> type,
org.apache.geode.pdx.PdxReader pdxReader)
|
protected ConversionService |
getConversionService()
Returns a reference to the configured
ConversionService used to convert data store types
to application domain object types. |
protected Map<?,org.apache.geode.pdx.PdxSerializer> |
getCustomPdxSerializers()
Returns a
mapping of application domain types to custom
PDX serializers used to customize the serialization
for specific application domain types . |
protected EntityInstantiators |
getEntityInstantiators()
Returns the configured
EntityInstantiators handling instantiation for Pivotal GemFire persistent entities. |
protected org.slf4j.Logger |
getLogger()
Returns a reference to the configured
Logger used to log messages
about the functions of this PdxSerializer . |
protected GemfireMappingContext |
getMappingContext()
Returns a reference to the configured
mapping context used to handling mapping
logic between Pivotal GemFire persistent entities and application domain object types . |
protected GemfirePersistentEntity<?> |
getPersistentEntity(Class<?> entityType)
Looks up and returns the
PersistentEntity meta-data for the given entity Class type. |
protected GemfirePersistentEntity<?> |
getPersistentEntity(Object entity)
Looks up and returns the
PersistentEntity meta-data for the given entity object. |
protected Predicate<Class<?>> |
getTypeFilters()
|
static MappingPdxSerializer |
newMappingPdxSerializer()
Factory method used to construct a new instance of
MappingPdxSerializer initialized with
a provided GemfireMappingContext and default ConversionService . |
void |
register(MappingPdxSerializer.PdxSerializerResolver pdxSerializerResolver)
Registers the given
MappingPdxSerializer.PdxSerializerResolver , which will be used to resolve a custom PdxSerializer
for a entity property. |
protected org.apache.geode.pdx.PdxSerializer |
resolveCustomPdxSerializer(PersistentProperty<?> property)
|
protected EntityInstantiator |
resolveEntityInstantiator(PersistentEntity entity)
Looks up and returns a registered
EntityInstantiator used to construct and initialize an instance of
an object defined by the given PersistentEntity (meta-data). |
void |
setApplicationContext(ApplicationContext applicationContext)
Configures a reference to the Spring
ApplicationContext . |
void |
setCustomPdxSerializers(Map<?,org.apache.geode.pdx.PdxSerializer> customPdxSerializers)
Configures custom
PDX serializers used to customize the serialization for specific
application domain types . |
void |
setEntityInstantiators(EntityInstantiators entityInstantiators)
Configures the
EntityInstantiators used to create the instances
read by this PdxSerializer . |
void |
setEntityInstantiators(Map<Class<?>,EntityInstantiator> gemfireInstantiators)
Configures the
EntityInstantiators used to create the instances
read by this PdxSerializer . |
void |
setExcludeTypeFilters(Predicate<Class<?>> excludeTypeFilters)
|
void |
setIncludeTypeFilters(Predicate<Class<?>> includeTypeFilters)
|
boolean |
toData(Object value,
org.apache.geode.pdx.PdxWriter pdxWriter)
Serialize (write) the given
Object to PDX. |
protected static final String JAVA_PACKAGE_NAME
protected static final String COM_GEMSTONE_GEMFIRE_PACKAGE_NAME
protected static final String ORG_APACHE_GEODE_PACKAGE_NAME
protected static final String ORG_SPRINGFRAMEWORK_PACKAGE_NAME
public MappingPdxSerializer()
MappingPdxSerializer
using a default GemfireMappingContext
and DefaultConversionService
.public MappingPdxSerializer(GemfireMappingContext mappingContext, ConversionService conversionService)
MappingPdxSerializer
initialized with the given
GemfireMappingContext
and ConversionService
.mappingContext
- GemfireMappingContext
used by the MappingPdxSerializer
to map
between application domain object types and PDX serialized bytes based on the entity mapping meta-data.conversionService
- ConversionService
used by the MappingPdxSerializer
to convert
PDX serialized data to application object property types.IllegalArgumentException
- if either the GemfireMappingContext
or the ConversionService
is null.@NonNull public static MappingPdxSerializer newMappingPdxSerializer()
MappingPdxSerializer
initialized with
a provided GemfireMappingContext
and default ConversionService
.MappingPdxSerializer
.create(GemfireMappingContext, ConversionService)
,
newMappingContext()
,
newConversionService()
@NonNull public static MappingPdxSerializer create(@Nullable ConversionService conversionService)
MappingPdxSerializer
initialized with
the given ConversionService
and a provided GemfireMappingContext
.conversionService
- ConversionService
used to convert persistent values to entity properties.MappingPdxSerializer
initialized with the given ConversionService
.ConversionService
,
create(GemfireMappingContext, ConversionService)
,
newMappingContext()
@NonNull public static MappingPdxSerializer create(@Nullable GemfireMappingContext mappingContext)
MappingPdxSerializer
initialized with
the given mapping context
supplying entity mapping meta-data,
using a provided, default ConversionService
.mappingContext
- GemfireMappingContext
used to supply entity mapping meta-data.MappingPdxSerializer
initialized with
the given mapping context
.GemfireMappingContext
,
create(GemfireMappingContext, ConversionService)
,
newConversionService()
@NonNull public static MappingPdxSerializer create(@Nullable GemfireMappingContext mappingContext, @Nullable ConversionService conversionService)
MappingPdxSerializer
initialized with
the given mapping context
and conversion service
.
If either the mapping context
or the conversion service
are null, then this factory method will provide default instances for each.mappingContext
- GemfireMappingContext
used to map between application domain model object types
and PDX serialized bytes based on the entity's mapping meta-data.conversionService
- ConversionService
used to convert persistent values to entity properties.MappingPdxSerializer
.ConversionService
,
MappingPdxSerializer
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
ApplicationContext
.setApplicationContext
in interface ApplicationContextAware
applicationContext
- reference to the Spring ApplicationContext
.BeansException
ApplicationContext
@NonNull protected ConversionService getConversionService()
ConversionService
used to convert data store types
to application domain object types.ConversionService
.ConversionService
public void setCustomPdxSerializers(Map<?,org.apache.geode.pdx.PdxSerializer> customPdxSerializers)
PDX serializers
used to customize the serialization for specific
application domain types
.customPdxSerializers
- mapping
containing custom PDX serializers
used to customize the serialization of specific application domain types
.IllegalArgumentException
- if the custom PDX serializer mapping
is null.PdxSerializer
,
Map
@NonNull protected Map<?,org.apache.geode.pdx.PdxSerializer> getCustomPdxSerializers()
mapping
of application domain types
to custom
PDX serializers
used to customize the serialization
for specific application domain types
.mapping
of application domain types
to custom PDX serializers
.PdxSerializer
,
Map
public void setEntityInstantiators(@NonNull EntityInstantiators entityInstantiators)
EntityInstantiators
used to create the instances
read by this PdxSerializer
.entityInstantiators
- EntityInstantiators
used to create the instances
read by this PdxSerializer
; must not be null.EntityInstantiator
public void setEntityInstantiators(@NonNull Map<Class<?>,EntityInstantiator> gemfireInstantiators)
EntityInstantiators
used to create the instances
read by this PdxSerializer
.gemfireInstantiators
- mapping of types
to EntityInstantiator
objects;
must not be null.EntityInstantiator
,
Map
protected EntityInstantiators getEntityInstantiators()
EntityInstantiators
handling instantiation for Pivotal GemFire persistent entities.EntityInstantiators
handling instantiation for GemFire persistent entities.EntityInstantiators
@NonNull protected org.slf4j.Logger getLogger()
Logger
used to log messages
about the functions of this PdxSerializer
.Logger
.Logger
@NonNull protected GemfireMappingContext getMappingContext()
mapping context
used to handling mapping
logic between Pivotal GemFire persistent entities and application domain object types
.mapping context
for Pivotal GemFire.GemfireMappingContext
protected GemfirePersistentEntity<?> getPersistentEntity(@NonNull Object entity)
PersistentEntity
meta-data for the given entity object.entity
- actual persistent entity, application domain object.PersistentEntity
meta-data for the given entity object.GemfirePersistentEntity
,
getPersistentEntity(Class)
protected GemfirePersistentEntity<?> getPersistentEntity(@NonNull Class<?> entityType)
PersistentEntity
meta-data for the given entity Class
type.entityType
- Class
type of the actual persistent entity, application domain object Class
.PersistentEntity
meta-data for the given entity Class
type.GemfirePersistentEntity
,
getMappingContext()
public void setExcludeTypeFilters(@Nullable Predicate<Class<?>> excludeTypeFilters)
type filters
used to exclude (a.k.a. filter) types
serializable
by this PDX serializer
.
This operation is null-safe and rather than overriding the existing excluded type filters
,
this set operation combines the given exclude type filters
with
the exiting excluded type filters
joined by and.excludeTypeFilters
- type filters
used to exclude/filter types
serializable
by this PDX serializer
.Predicate
public void setIncludeTypeFilters(@Nullable Predicate<Class<?>> includeTypeFilters)
type filters
used to include types
serializable
by this PDX serializer
.
This operation is null-safe and rather than overriding the existing included type filters
,
this set operation combines the given include type filters
with
the exiting included type filters
joined by or.includeTypeFilters
- type filters
used to include types
serializable
by this PDX serializer
.Predicate
protected Predicate<Class<?>> getTypeFilters()
type filter
.Predicate
public void register(@NonNull MappingPdxSerializer.PdxSerializerResolver pdxSerializerResolver)
MappingPdxSerializer.PdxSerializerResolver
, which will be used to resolve a custom PdxSerializer
for a entity property.
The strategy, or criteria used to resolve the custom PdxSerializer
is up to the individual resolve
and can be based on things like the property type, or fully-qualified property name, etc.pdxSerializerResolver
- MappingPdxSerializer.PdxSerializerResolver
used to resolve a custom PdxSerializer
for a entity property.public Object fromData(@NonNull Class<?> type, @NonNull org.apache.geode.pdx.PdxReader pdxReader)
fromData
in interface org.apache.geode.pdx.PdxSerializer
type
- desired Class
type of the Object
; must not be null.pdxReader
- PdxReader
used to deserialize the PDX bytes back into an Object
of the desired Class
type; must not be null.Object
of Class
type deserialized from PDX or null if an Object
of Class
type cannot be deserialized from PDX.PdxReader
,
doFromData(Class, PdxReader)
,
getTypeFilters()
,
Class
,
Object
public boolean toData(@Nullable Object value, @NonNull org.apache.geode.pdx.PdxWriter pdxWriter)
Object
to PDX.toData
in interface org.apache.geode.pdx.PdxSerializer
value
- Object
to serialize.pdxWriter
- PdxWriter
used to serialize the given Object
to PDX.PdxSerializer
was able to serialize
the given Object
to PDX.PdxWriter
,
doToData(Object, PdxWriter)
,
getTypeFilters()
,
Object
@Nullable protected org.apache.geode.pdx.PdxSerializer resolveCustomPdxSerializer(@NonNull PersistentProperty<?> property)
property
- PersistentProperty
of the entity used to resolve a custom PdxSerializer
.PdxSerializer
for the given PersistentEntity
PersistentProperty
,
or null if no custom PdxSerializer
could be found.PersistentProperty
,
PdxSerializer
,
getCustomPdxSerializers()
protected EntityInstantiator resolveEntityInstantiator(@NonNull PersistentEntity entity)
EntityInstantiator
used to construct and initialize an instance of
an object defined by the given PersistentEntity
(meta-data).entity
- PersistentEntity
object used to lookup a custom, registered EntityInstantiator
for the entity.EntityInstantiator
for the given PersistentEntity
.EntityInstantiator
,
PersistentEntity
Copyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.