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
-
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
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 void
copyCouchbaseDocument
(CouchbaseDocument source, CouchbaseDocument target) Helper method to copy the internals from a source document into a target document.getTypeAlias
(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.void
setApplicationContext
(ApplicationContext applicationContext) void
setEntityCallbacks
(EntityCallbacks entityCallbacks) COPIED Set theEntityCallbacks
instance to use when invokingcallbacks
like theAfterConvertCallback
.void
write
(Object source, CouchbaseDocument target) protected void
writeInternal
(Object source, CouchbaseDocument target, CouchbasePersistentEntity<?> entity, boolean withId) Internal helper method to write the source object into the target document.protected void
writeInternal
(Object source, CouchbaseDocument target, TypeInformation<?> typeHint, boolean withId) Convert a source object into aCouchbaseDocument
target.Methods inherited from class org.springframework.data.couchbase.core.convert.AbstractCouchbaseConverter
afterPropertiesSet, convertForWriteIfNeeded, 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
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.
-
-
Method Details
-
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.
-
write
- Specified by:
write
in interfaceEntityWriter<Object,
CouchbaseDocument>
-
writeInternal
protected void writeInternal(Object source, CouchbaseDocument target, TypeInformation<?> typeHint, boolean withId) Convert a source object into aCouchbaseDocument
target.- Parameters:
source
- the source object.target
- the target document.typeHint
- the type information for the source.
-
copyCouchbaseDocument
Helper method to copy the internals from a source document into a target document.- Parameters:
source
- the source document.target
- the target document.
-
writeInternal
protected void writeInternal(Object source, CouchbaseDocument target, CouchbasePersistentEntity<?> entity, boolean withId) 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
-
getPotentiallyConvertedSimpleWrite
-
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
-