Class MappingCassandraConverter

java.lang.Object
org.springframework.data.cassandra.core.convert.AbstractCassandraConverter
org.springframework.data.cassandra.core.convert.MappingCassandraConverter
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, CassandraConverter, org.springframework.data.convert.EntityConverter<CassandraPersistentEntity<?>,CassandraPersistentProperty,Object,Object>, org.springframework.data.convert.EntityReader<Object,Object>, org.springframework.data.convert.EntityWriter<Object,Object>

public class MappingCassandraConverter extends AbstractCassandraConverter implements org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.BeanClassLoaderAware
CassandraConverter that uses a MappingContext to do sophisticated mapping of domain objects to Row.
Author:
Alex Shvid, Matthew T. Adams, Oliver Gierke, Mark Paluch, Antoine Toulme, John Blum, Christoph Strobl, Frank Spitulski
  • Constructor Details

  • Method Details

    • getConversionContext

      protected MappingCassandraConverter.ConversionContext getConversionContext()
      Constructs a new instance of MappingCassandraConverter.ConversionContext with various converters to convert different Cassandra value types.
      Returns:
      the MappingCassandraConverter.ConversionContext.
      See Also:
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • setBeanClassLoader

      public void setBeanClassLoader(ClassLoader classLoader)
      Specified by:
      setBeanClassLoader in interface org.springframework.beans.factory.BeanClassLoaderAware
    • getProjectionFactory

      public org.springframework.data.projection.ProjectionFactory getProjectionFactory()
      Description copied from interface: CassandraConverter
      Returns the ProjectionFactory for this converter.
      Specified by:
      getProjectionFactory in interface CassandraConverter
      Returns:
      will never be null.
    • setCodecRegistry

      public void setCodecRegistry(com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry codecRegistry)
      Sets the CodecRegistry.
      Parameters:
      codecRegistry - must not be null.
      Since:
      3.0
    • getCodecRegistry

      public com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry getCodecRegistry()
      Returns the configured CodecRegistry.
      Specified by:
      getCodecRegistry in interface CassandraConverter
      Returns:
      the configured CodecRegistry.
      Since:
      3.0
    • setUserTypeResolver

      public void setUserTypeResolver(UserTypeResolver userTypeResolver)
      Parameters:
      userTypeResolver - must not be null.
    • getUserTypeResolver

      public UserTypeResolver getUserTypeResolver()
      Returns the configured UserTypeResolver.
      Returns:
      the configured UserTypeResolver.
      Since:
      3.0
    • getMappingContext

      public CassandraMappingContext getMappingContext()
      Specified by:
      getMappingContext in interface CassandraConverter
      Specified by:
      getMappingContext in interface org.springframework.data.convert.EntityConverter<CassandraPersistentEntity<?>,CassandraPersistentProperty,Object,Object>
    • getColumnTypeResolver

      public ColumnTypeResolver getColumnTypeResolver()
      Description copied from interface: CassandraConverter
      Returns the ColumnTypeResolver to resolve ColumnType for properties, TypeInformation, and values.
      Specified by:
      getColumnTypeResolver in interface CassandraConverter
      Returns:
      the ColumnTypeResolver
    • project

      public <R> R project(org.springframework.data.projection.EntityProjection<R,?> projection, com.datastax.oss.driver.api.core.cql.Row row)
      Description copied from interface: CassandraConverter
      Apply a projection to Row and return the projection return type R. Non-projecting descriptors fall back to regular object materialization.
      Specified by:
      project in interface CassandraConverter
      Parameters:
      projection - the projection descriptor, must not be null.
      row - must not be null.
      Returns:
      a new instance of the projection return type R.
    • read

      public <R> R read(Class<R> type, Object row)
      Specified by:
      read in interface org.springframework.data.convert.EntityReader<Object,Object>
    • readRow

      public <R> R readRow(Class<R> type, com.datastax.oss.driver.api.core.cql.Row row)
      Read a Row into the requested target type.
      Parameters:
      type - must not be null.
      row - must not be null.
      Returns:
      the converted valued.
    • doReadEntity

      protected <S> S doReadEntity(MappingCassandraConverter.ConversionContext context, CassandraValueProvider valueProvider, org.springframework.data.util.TypeInformation<? extends S> typeHint)
      Conversion method to materialize an object from a Row, TupleValue, or UdtValue. Can be overridden by subclasses.
      Parameters:
      context - must not be null
      valueProvider - must not be null
      typeHint - the TypeInformation to be used to unmarshall this Row.
      Returns:
      the converted object, will never be null.
    • convertToColumnType

      public Object convertToColumnType(Object obj)
      Description copied from interface: CassandraConverter
      Converts the given object into a value Cassandra will be able to store natively in a column.
      Specified by:
      convertToColumnType in interface CassandraConverter
      Parameters:
      obj - Object to convert; must not be null.
      Returns:
      the result of the conversion.
    • convertToColumnType

      public Object convertToColumnType(Object value, ColumnType columnType)
      Description copied from interface: CassandraConverter
      Converts the given object into a value Cassandra will be able to store natively in a column.
      Specified by:
      convertToColumnType in interface CassandraConverter
      Parameters:
      value - Object to convert; must not be null.
      columnType - ColumnType used to describe the object type; must not be null.
      Returns:
      the result of the conversion.
    • write

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

      public void write(Object source, Object sink, CassandraPersistentEntity<?> entity)
      Description copied from interface: CassandraConverter
      Converts and writes a source object into a sink using the given CassandraPersistentEntity.
      Specified by:
      write in interface CassandraConverter
      Parameters:
      source - the source, must not be null.
      sink - must not be null.
      entity - must not be null.
    • getId

      public Object getId(Object object, CassandraPersistentEntity<?> entity)
      Description copied from interface: CassandraConverter
      Returns the Id for an entity. It can return:
      Specified by:
      getId in interface CassandraConverter
      Parameters:
      object - must not be null.
      entity - must not be null.
      Returns:
      the id value or null, if the id is not set.
    • getPotentiallyConvertedSimpleRead

      protected Object getPotentiallyConvertedSimpleRead(Object value, org.springframework.data.util.TypeInformation<?> target)
      Checks whether we have a custom conversion for the given simple object. Converts the given value if so, applies Enum handling or returns the value as is. Can be overridden by subclasses.
      Since:
      3.2
    • readCollectionOrArray

      protected Object readCollectionOrArray(MappingCassandraConverter.ConversionContext context, Collection<?> source, org.springframework.data.util.TypeInformation<?> targetType)
      Reads the given Collection into a collection of the given TypeInformation. Will recursively resolve nested Lists as well. Can be overridden by subclasses.
      Parameters:
      source - must not be null.
      targetType - must not be null.
      Returns:
      the converted Collection or array, will never be null.
    • readMap

      protected Object readMap(MappingCassandraConverter.ConversionContext context, Map<?,?> source, org.springframework.data.util.TypeInformation<?> targetType)
      Reads the given Map into a map of the given TypeInformation. Will recursively resolve nested Maps as well. Can be overridden by subclasses.
      Parameters:
      source - must not be null.
      targetType - must not be null.
      Returns:
      the converted Collection or array, will never be null.