Class MappingCouchbaseConverter

java.lang.Object
org.springframework.data.couchbase.core.convert.AbstractCouchbaseConverter
org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.data.convert.EntityConverter<CouchbasePersistentEntity<?>,CouchbasePersistentProperty,Object,CouchbaseDocument>, org.springframework.data.convert.EntityReader<Object,CouchbaseDocument>, org.springframework.data.convert.EntityWriter<Object,CouchbaseDocument>, CouchbaseConverter, CouchbaseWriter<Object,CouchbaseDocument>

public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implements org.springframework.context.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 Details

    • TYPEKEY_DEFAULT

      public static final String TYPEKEY_DEFAULT
      The default "type key", the name of the field that will hold type information.
      See Also:
    • TYPEKEY_SYNCGATEWAY_COMPATIBLE

      public static final String 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 org.springframework.data.mapping.context.MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> mappingContext
      The generic mapping context.
    • applicationContext

      protected org.springframework.context.ApplicationContext applicationContext
      The overall application context.
    • typeMapper

      protected CouchbaseTypeMapper typeMapper
      The Couchbase specific type mapper in use.
  • Constructor Details

    • MappingCouchbaseConverter

      public MappingCouchbaseConverter()
    • MappingCouchbaseConverter

      public MappingCouchbaseConverter(org.springframework.data.mapping.context.MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> mappingContext)
      Parameters:
      mappingContext - the mapping context to use.
    • MappingCouchbaseConverter

      public MappingCouchbaseConverter(org.springframework.data.mapping.context.MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> mappingContext, String typeKey)
      Parameters:
      mappingContext - the mapping context to use.
      typeKey - the attribute name to use to store complex types class name.
    • MappingCouchbaseConverter

      public MappingCouchbaseConverter(org.springframework.data.mapping.context.MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> mappingContext, String typeKey, org.springframework.data.convert.CustomConversions customConversions)
      Create a new MappingCouchbaseConverter 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

      protected static Collection<?> asCollection(Object source)
      Returns a collection from the given source object.
      Parameters:
      source - the source object.
      Returns:
      the target collection.
    • getMappingContext

      public org.springframework.data.mapping.context.MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> getMappingContext()
      Specified by:
      getMappingContext in interface org.springframework.data.convert.EntityConverter<CouchbasePersistentEntity<?>,CouchbasePersistentProperty,Object,CouchbaseDocument>
    • getTypeKey

      public String getTypeKey()
      Specified by:
      getTypeKey in interface CouchbaseConverter
      Returns:
      the name of the field that will hold type information.
    • getTypeAlias

      public org.springframework.data.mapping.Alias getTypeAlias(org.springframework.data.util.TypeInformation<?> info)
      Specified by:
      getTypeAlias in interface CouchbaseConverter
      Returns:
      the alias value for the type
    • read

      public <R> R read(Class<R> clazz, CouchbaseDocument source)
      Specified by:
      read in interface org.springframework.data.convert.EntityReader<Object,CouchbaseDocument>
    • read

      protected <R> R read(org.springframework.data.util.TypeInformation<R> type, CouchbaseDocument source)
      Read an incoming CouchbaseDocument 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

      protected <R> R read(org.springframework.data.util.TypeInformation<R> type, CouchbaseDocument source, Object parent)
      Read an incoming CouchbaseDocument 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

      protected <R> R read(CouchbasePersistentEntity<R> entity, CouchbaseDocument source, Object parent)
      Read an incoming CouchbaseDocument 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, org.springframework.data.mapping.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(org.springframework.data.util.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

      public void write(Object source, CouchbaseDocument target)
      Specified by:
      write in interface org.springframework.data.convert.EntityWriter<Object,CouchbaseDocument>
    • writeInternalRoot

      public void writeInternalRoot(Object source, CouchbaseDocument target, org.springframework.data.util.TypeInformation<?> typeHint, boolean withId, CouchbasePersistentProperty property, boolean processValueConverter)
      Convert a source object into a CouchbaseDocument target.
      Parameters:
      source - the source object.
      target - the target document.
      withId - write out with the id.
      property - will be null for the root
    • copyCouchbaseDocument

      protected void copyCouchbaseDocument(CouchbaseDocument source, CouchbaseDocument target)
      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, org.springframework.data.mapping.model.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, org.springframework.data.util.TypeInformation<?> type, CouchbasePersistentProperty prop, org.springframework.data.mapping.model.ConvertingPropertyAccessor accessor)
      Helper method to write the internal collection.
      Parameters:
      source - the source object.
      target - the target document.
      Returns:
      the created couchbase list.
    • getPotentiallyConvertedSimpleWrite

      public Object getPotentiallyConvertedSimpleWrite(Object value)
    • getPotentiallyConvertedSimpleWrite

      @Deprecated public Object getPotentiallyConvertedSimpleWrite(CouchbasePersistentProperty value, org.springframework.data.mapping.model.ConvertingPropertyAccessor<Object> accessor)
      Deprecated.
      This does process PropertyValueConversions
      Parameters:
      value -
      accessor -
      Returns:
    • getPotentiallyConvertedSimpleWrite

      public Object getPotentiallyConvertedSimpleWrite(CouchbasePersistentProperty property, org.springframework.data.mapping.model.ConvertingPropertyAccessor<Object> accessor, boolean processValueConverter)
      This does process PropertyValueConversions
      Parameters:
      property -
      accessor -
      processValueConverter -
      Returns:
    • addCustomTypeKeyIfNecessary

      protected void addCustomTypeKeyIfNecessary(org.springframework.data.util.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

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
    • setEntityCallbacks

      public void setEntityCallbacks(org.springframework.data.mapping.callback.EntityCallbacks entityCallbacks)
      COPIED Set the EntityCallbacks instance to use when invoking callbacks like the AfterConvertCallback. Overrides potentially existing EntityCallbacks.
      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.