Class MappingCouchbaseConverter
java.lang.Object
org.springframework.data.couchbase.core.convert.AbstractCouchbaseConverter
org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter
- All Implemented Interfaces:
Aware
,InitializingBean
,ApplicationContextAware
,EntityConverter<CouchbasePersistentEntity<?>,
,CouchbasePersistentProperty, Object, CouchbaseDocument> EntityReader<Object,
,CouchbaseDocument> EntityWriter<Object,
,CouchbaseDocument> CouchbaseConverter
,CouchbaseWriter<Object,
CouchbaseDocument>
public class MappingCouchbaseConverter
extends AbstractCouchbaseConverter
implements ApplicationContextAware
A mapping converter for Couchbase. The converter is responsible for reading from and writing to entities and
converting it into a consumable database representation.
- Author:
- Michael Nitschinger, Oliver Gierke, Geoffrey Mina, Mark Paluch, Michael Reiche, Remi Bleuse, Vipul Gupta
-
Field Summary
Modifier and TypeFieldDescriptionprotected ApplicationContext
The overall application context.protected final MappingContext<? extends CouchbasePersistentEntity<?>,
CouchbasePersistentProperty> The generic mapping context.static final String
The default "type key", the name of the field that will hold type information.static final String
A "type key" (the name of the field that will hold type information) that is compatible with Sync Gateway (which doesn't allows underscores).protected CouchbaseTypeMapper
The Couchbase specific type mapper in use.Fields inherited from class org.springframework.data.couchbase.core.convert.AbstractCouchbaseConverter
conversions, conversionService, instantiators
-
Constructor Summary
ConstructorDescriptionMappingCouchbaseConverter
(MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext) Create a newMappingCouchbaseConverter
.MappingCouchbaseConverter
(MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext, String typeKey) Create a newMappingCouchbaseConverter
MappingCouchbaseConverter
(MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext, String typeKey, CustomConversions customConversions) Create a newMappingCouchbaseConverter
that will store class name for complex types in the typeKey attribute. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addCustomTypeKeyIfNecessary
(TypeInformation<?> type, Object source, CouchbaseDocument target) Add a custom type key if needed.protected static Collection<?>
asCollection
(Object source) Returns a collection from the given source object.protected void
copyCouchbaseDocument
(CouchbaseDocument source, CouchbaseDocument target) Helper method to copy the internals from a source document into a target document.protected Object
getPotentiallyConvertedSimpleRead
(Object value, CouchbasePersistentProperty target) Potentially convert simple values like ENUMs.getPotentiallyConvertedSimpleWrite
(CouchbasePersistentProperty value, ConvertingPropertyAccessor<Object> accessor) Deprecated.getPotentiallyConvertedSimpleWrite
(CouchbasePersistentProperty property, ConvertingPropertyAccessor<Object> accessor, boolean processValueConverter) This does process PropertyValueConversionsgetTypeAlias
(TypeInformation<?> info) protected Object
getValueInternal
(CouchbasePersistentProperty property, CouchbaseDocument source, Object parent, PersistentEntity entity) Loads the property value through the value provider.<R> R
read
(Class<R> clazz, CouchbaseDocument source) protected <R> R
read
(CouchbasePersistentEntity<R> entity, CouchbaseDocument source, Object parent) Read an incomingCouchbaseDocument
into the target entity.protected <R> R
read
(TypeInformation<R> type, CouchbaseDocument source) Read an incomingCouchbaseDocument
into the target entity.protected <R> R
read
(TypeInformation<R> type, CouchbaseDocument source, Object parent) Read an incomingCouchbaseDocument
into the target entity.readMap
(TypeInformation<?> type, CouchbaseDocument source, Object parent) Recursively parses the a map from the source document.<R> R
readValue
(Object value, CouchbasePersistentProperty prop, Object parent, boolean noDecrypt) Helper method to read the value based on the PersistentPropertyvoid
setApplicationContext
(ApplicationContext applicationContext) void
setEntityCallbacks
(EntityCallbacks entityCallbacks) COPIED Set theEntityCallbacks
instance to use when invokingcallbacks
like theAfterConvertCallback
.void
write
(Object source, CouchbaseDocument target) writeCollectionInternal
(Collection<?> source, CouchbaseList target, TypeInformation<?> type, CouchbasePersistentProperty prop, ConvertingPropertyAccessor accessor) Helper method to write the internal collection.protected void
writeInternalEntity
(Object source, CouchbaseDocument target, CouchbasePersistentEntity<?> entity, boolean withId, CouchbasePersistentProperty prop, boolean processValueConverter) Internal helper method to write the source object into the target document.void
writeInternalRoot
(Object source, CouchbaseDocument target, TypeInformation<?> typeHint, boolean withId, CouchbasePersistentProperty property, boolean processValueConverter) Convert a source object into aCouchbaseDocument
target.protected void
writePropertyInternal
(Object source, CouchbaseDocument target, CouchbasePersistentProperty prop, ConvertingPropertyAccessor accessor) Helper method to write a non-simple property into the target document.Methods inherited from class org.springframework.data.couchbase.core.convert.AbstractCouchbaseConverter
afterPropertiesSet, convertForWriteIfNeeded, convertForWriteIfNeeded, getConversions, getConversionService, getWriteClassFor, setCustomConversions, setInstantiators
-
Field Details
-
TYPEKEY_DEFAULT
The default "type key", the name of the field that will hold type information. -
TYPEKEY_SYNCGATEWAY_COMPATIBLE
A "type key" (the name of the field that will hold type information) that is compatible with Sync Gateway (which doesn't allows underscores).- See Also:
-
mappingContext
protected final MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> mappingContextThe generic mapping context. -
applicationContext
The overall application context. -
typeMapper
The Couchbase specific type mapper in use.
-
-
Constructor Details
-
MappingCouchbaseConverter
public MappingCouchbaseConverter() -
MappingCouchbaseConverter
public MappingCouchbaseConverter(MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext) Create a newMappingCouchbaseConverter
.- Parameters:
mappingContext
- the mapping context to use.
-
MappingCouchbaseConverter
public MappingCouchbaseConverter(MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext, String typeKey) Create a newMappingCouchbaseConverter
- Parameters:
mappingContext
- the mapping context to use.typeKey
- the attribute name to use to store complex types class name.
-
MappingCouchbaseConverter
public MappingCouchbaseConverter(MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext, String typeKey, CustomConversions customConversions) Create a newMappingCouchbaseConverter
that will store class name for complex types in the typeKey attribute.- Parameters:
mappingContext
- the mapping context to use.typeKey
- the attribute name to use to store complex types class name.customConversions
- the custom conversions to use
-
-
Method Details
-
asCollection
Returns a collection from the given source object.- Parameters:
source
- the source object.- Returns:
- the target collection.
-
getMappingContext
public MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> getMappingContext()- Specified by:
getMappingContext
in interfaceEntityConverter<CouchbasePersistentEntity<?>,
CouchbasePersistentProperty, Object, CouchbaseDocument>
-
getTypeKey
- Specified by:
getTypeKey
in interfaceCouchbaseConverter
- Returns:
- the name of the field that will hold type information.
-
getTypeAlias
- Specified by:
getTypeAlias
in interfaceCouchbaseConverter
- Returns:
- the alias value for the type
-
read
- Specified by:
read
in interfaceEntityReader<Object,
CouchbaseDocument>
-
read
Read an incomingCouchbaseDocument
into the target entity.- Type Parameters:
R
- the entity type.- Parameters:
type
- the type information of the target entity.source
- the document to convert.- Returns:
- the converted entity.
-
read
Read an incomingCouchbaseDocument
into the target entity.- Type Parameters:
R
- the entity type.- Parameters:
type
- the type information of the target entity.source
- the document to convert.parent
- an optional parent object.- Returns:
- the converted entity.
-
read
Read an incomingCouchbaseDocument
into the target entity.- Type Parameters:
R
- the entity type.- Parameters:
entity
- the target entity.source
- the document to convert.parent
- an optional parent object.- Returns:
- the converted entity.
-
getValueInternal
protected Object getValueInternal(CouchbasePersistentProperty property, CouchbaseDocument source, Object parent, PersistentEntity entity) Loads the property value through the value provider.- Parameters:
property
- the source property.source
- the source document.parent
- the optional parent.- Returns:
- the actual property value.
-
readMap
protected Map<Object,Object> readMap(TypeInformation<?> type, CouchbaseDocument source, Object parent) Recursively parses the a map from the source document.- Parameters:
type
- the type information for the document.source
- the source document.parent
- the optional parent.- Returns:
- the recursively parsed map.
-
getPotentiallyConvertedSimpleRead
protected Object getPotentiallyConvertedSimpleRead(Object value, CouchbasePersistentProperty target) Potentially convert simple values like ENUMs.- Parameters:
value
- the value to convert.target
- the target persistent property which may have an Encrypt annotation- Returns:
- the potentially converted object.
-
write
- Specified by:
write
in interfaceEntityWriter<Object,
CouchbaseDocument>
-
writeInternalRoot
public void writeInternalRoot(Object source, CouchbaseDocument target, TypeInformation<?> typeHint, boolean withId, CouchbasePersistentProperty property, boolean processValueConverter) Convert a source object into aCouchbaseDocument
target.- Parameters:
source
- the source object.target
- the target document.withId
- write out with the id.property
- will be null for the root
-
copyCouchbaseDocument
Helper method to copy the internals from a source document into a target document.- Parameters:
source
- the source document.target
- the target document.
-
writeInternalEntity
protected void writeInternalEntity(Object source, CouchbaseDocument target, CouchbasePersistentEntity<?> entity, boolean withId, CouchbasePersistentProperty prop, boolean processValueConverter) Internal helper method to write the source object into the target document.- Parameters:
source
- the source object.target
- the target document.entity
- the persistent entity to convert from.withId
- one of the top-level properties is the id for the document
-
writePropertyInternal
protected void writePropertyInternal(Object source, CouchbaseDocument target, CouchbasePersistentProperty prop, ConvertingPropertyAccessor accessor) Helper method to write a non-simple property into the target document.- Parameters:
source
- the source object.target
- the target document.prop
- the property information.
-
writeCollectionInternal
public CouchbaseList writeCollectionInternal(Collection<?> source, CouchbaseList target, TypeInformation<?> type, CouchbasePersistentProperty prop, ConvertingPropertyAccessor accessor) Helper method to write the internal collection.- Parameters:
source
- the source object.target
- the target document.- Returns:
- the created couchbase list.
-
getPotentiallyConvertedSimpleWrite
-
getPotentiallyConvertedSimpleWrite
@Deprecated public Object getPotentiallyConvertedSimpleWrite(CouchbasePersistentProperty value, ConvertingPropertyAccessor<Object> accessor) Deprecated.This does process PropertyValueConversions- Parameters:
value
-accessor
-- Returns:
-
getPotentiallyConvertedSimpleWrite
public Object getPotentiallyConvertedSimpleWrite(CouchbasePersistentProperty property, ConvertingPropertyAccessor<Object> accessor, boolean processValueConverter) This does process PropertyValueConversions- Parameters:
property
-accessor
-processValueConverter
-- Returns:
-
addCustomTypeKeyIfNecessary
protected void addCustomTypeKeyIfNecessary(TypeInformation<?> type, Object source, CouchbaseDocument target) Add a custom type key if needed.- Parameters:
type
- the type information.source
- th the source object.target
- the target document.
-
setApplicationContext
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
-
setEntityCallbacks
COPIED Set theEntityCallbacks
instance to use when invokingcallbacks
like theAfterConvertCallback
. Overrides potentially existingEntityCallbacks
.- Parameters:
entityCallbacks
- must not be null.- Throws:
IllegalArgumentException
- if the given instance is null.- Since:
- 3.0
-
readValue
public <R> R readValue(Object value, CouchbasePersistentProperty prop, Object parent, boolean noDecrypt) Helper method to read the value based on the PersistentProperty- Type Parameters:
R
- the target type.- Parameters:
value
- the value to convert.prop
- the persistent property - will have annotations (i.e. Encrypt for FLE)parent
- the optional parent.- Returns:
- the converted object.
-