Class MappingCassandraConverter
java.lang.Object
org.springframework.data.cassandra.core.convert.AbstractCassandraConverter
org.springframework.data.cassandra.core.convert.MappingCassandraConverter
- All Implemented Interfaces:
Aware
,BeanClassLoaderAware
,InitializingBean
,ApplicationContextAware
,EnvironmentAware
,EnvironmentCapable
,CassandraConverter
,EntityConverter<CassandraPersistentEntity<?>,
,CassandraPersistentProperty, Object, Object> EntityReader<Object,
,Object> EntityWriter<Object,
Object>
public class MappingCassandraConverter
extends AbstractCassandraConverter
implements ApplicationContextAware, EnvironmentAware, EnvironmentCapable, BeanClassLoaderAware
- Author:
- Alex Shvid, Matthew T. Adams, Oliver Gierke, Mark Paluch, Antoine Toulme, John Blum, Christoph Strobl, Frank Spitulski
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Conversion context holding references to simpleMappingCassandraConverter.ConversionContext.ValueConverter
andMappingCassandraConverter.ConversionContext.ContainerValueConverter
. -
Constructor Summary
ConstructorDescriptionCreate a newMappingCassandraConverter
with aCassandraMappingContext
.MappingCassandraConverter
(CassandraMappingContext mappingContext) Create a newMappingCassandraConverter
with the givenCassandraMappingContext
. -
Method Summary
Modifier and TypeMethodDescriptionConverts the given object into a value Cassandra will be able to store natively in a column.convertToColumnType
(Object value, ColumnType columnType) Converts the given object into a value Cassandra will be able to store natively in a column.protected <S> S
doReadEntity
(MappingCassandraConverter.ConversionContext context, CassandraValueProvider valueProvider, TypeInformation<? extends S> typeHint) Conversion method to materialize an object from aRow
,TupleValue
, orUdtValue
.com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry
Returns the configuredCodecRegistry
.Constructs a new instance ofMappingCassandraConverter.ConversionContext
with various converters to convert different Cassandra value types.getId
(Object object, CassandraPersistentEntity<?> entity) Returns the Id for an entity.protected Object
getPotentiallyConvertedSimpleRead
(Object value, TypeInformation<?> target) Checks whether we have a custom conversion for the given simple object.Returns theProjectionFactory
for this converter.Returns the configuredUserTypeResolver
.<R> R
project
(EntityProjection<R, ?> projection, com.datastax.oss.driver.api.core.cql.Row row) Apply a projection toRow
and return the projection return typeR
.<R> R
protected Object
readCollectionOrArray
(MappingCassandraConverter.ConversionContext context, Collection<?> source, TypeInformation<?> targetType) Reads the givenCollection
into a collection of the givenTypeInformation
.protected Object
readMap
(MappingCassandraConverter.ConversionContext context, Map<?, ?> source, TypeInformation<?> targetType) Reads the givenMap
into a map of the givenTypeInformation
.<R> R
Read aRow
into the requested targettype
.void
setApplicationContext
(ApplicationContext applicationContext) void
setBeanClassLoader
(ClassLoader classLoader) void
setCodecRegistry
(com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry codecRegistry) Sets theCodecRegistry
.void
setCodecRegistry
(Supplier<com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry> codecRegistry) Sets theSupplier
used for obtaining theCodecRegistry
to use.void
setEnvironment
(Environment environment) void
setSpELContext
(SpELContext spELContext) void
setUserTypeResolver
(UserTypeResolver userTypeResolver) Sets theUserTypeResolver
.void
void
write
(Object source, Object sink, CassandraPersistentEntity<?> entity) Methods inherited from class org.springframework.data.cassandra.core.convert.AbstractCassandraConverter
afterPropertiesSet, getConversionService, getCustomConversions, setCustomConversions, setInstantiators
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.data.cassandra.core.convert.CassandraConverter
convertToColumnType
-
Constructor Details
-
MappingCassandraConverter
public MappingCassandraConverter()Create a newMappingCassandraConverter
with aCassandraMappingContext
. -
MappingCassandraConverter
Create a newMappingCassandraConverter
with the givenCassandraMappingContext
.- Parameters:
mappingContext
- must not be null.
-
-
Method Details
-
getConversionContext
Constructs a new instance ofMappingCassandraConverter.ConversionContext
with various converters to convert different Cassandra value types.- Returns:
- the
MappingCassandraConverter.ConversionContext
. - See Also:
-
setApplicationContext
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Throws:
BeansException
-
setEnvironment
- Specified by:
setEnvironment
in interfaceEnvironmentAware
-
getEnvironment
- Specified by:
getEnvironment
in interfaceEnvironmentCapable
-
setSpELContext
-
setBeanClassLoader
- Specified by:
setBeanClassLoader
in interfaceBeanClassLoaderAware
-
getProjectionFactory
Description copied from interface:CassandraConverter
Returns theProjectionFactory
for this converter.- Specified by:
getProjectionFactory
in interfaceCassandraConverter
- Returns:
- will never be null.
-
setCodecRegistry
public void setCodecRegistry(com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry codecRegistry) Sets theCodecRegistry
.- Parameters:
codecRegistry
- must not be null.- Since:
- 3.0
-
setCodecRegistry
public void setCodecRegistry(Supplier<com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry> codecRegistry) Sets theSupplier
used for obtaining theCodecRegistry
to use.- Parameters:
codecRegistry
- must not be null.- Since:
- 4.3
-
getCodecRegistry
public com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry getCodecRegistry()Returns the configuredCodecRegistry
.- Specified by:
getCodecRegistry
in interfaceCassandraConverter
- Returns:
- the configured
CodecRegistry
. - Since:
- 3.0
-
setUserTypeResolver
Sets theUserTypeResolver
.- Parameters:
userTypeResolver
- must not be null.
-
getUserTypeResolver
Returns the configuredUserTypeResolver
.- Returns:
- the configured
UserTypeResolver
. - Since:
- 3.0
-
getMappingContext
- Specified by:
getMappingContext
in interfaceCassandraConverter
- Specified by:
getMappingContext
in interfaceEntityConverter<CassandraPersistentEntity<?>,
CassandraPersistentProperty, Object, Object>
-
getColumnTypeResolver
Description copied from interface:CassandraConverter
- Specified by:
getColumnTypeResolver
in interfaceCassandraConverter
- Returns:
- the
ColumnTypeResolver
-
project
public <R> R project(EntityProjection<R, ?> projection, com.datastax.oss.driver.api.core.cql.Row row) Description copied from interface:CassandraConverter
Apply a projection toRow
and return the projection return typeR
.Non-projecting
descriptors fall back toregular object materialization
.- Specified by:
project
in interfaceCassandraConverter
- 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
- Specified by:
read
in interfaceEntityReader<Object,
Object>
-
readRow
Read aRow
into the requested targettype
.- 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, TypeInformation<? extends S> typeHint) Conversion method to materialize an object from aRow
,TupleValue
, orUdtValue
. Can be overridden by subclasses.- Parameters:
context
- must not be nullvalueProvider
- must not be nulltypeHint
- theTypeInformation
to be used to unmarshall thisRow
.- Returns:
- the converted object, will never be null.
-
convertToColumnType
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 interfaceCassandraConverter
- Parameters:
obj
-Object
to convert; must not be null.- Returns:
- the result of the conversion.
-
convertToColumnType
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 interfaceCassandraConverter
- 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
- Specified by:
write
in interfaceEntityWriter<Object,
Object>
-
write
Description copied from interface:CassandraConverter
- Specified by:
write
in interfaceCassandraConverter
- Parameters:
source
- the source, must not be null.sink
- must not be null.entity
- must not be null.
-
getId
Description copied from interface:CassandraConverter
Returns the Id for an entity. It can return:- A singular value if for a simple
Id
orPrimaryKey
Id - A
MapId
for compositePrimaryKeyColumn
Id's - A the composite primary key for
PrimaryKey
using aPrimaryKeyClass
- Specified by:
getId
in interfaceCassandraConverter
- Parameters:
object
- must not be null.entity
- must not be null.- Returns:
- the id value or null, if the id is not set.
- A singular value if for a simple
-
getPotentiallyConvertedSimpleRead
Checks whether we have a custom conversion for the given simple object. Converts the given value if so, appliesEnum
handling or returns the value as is. Can be overridden by subclasses.- Since:
- 3.2
-
readCollectionOrArray
protected Object readCollectionOrArray(MappingCassandraConverter.ConversionContext context, Collection<?> source, TypeInformation<?> targetType) Reads the givenCollection
into a collection of the givenTypeInformation
. Will recursively resolve nestedList
s 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, TypeInformation<?> targetType) Reads the givenMap
into a map of the givenTypeInformation
. Will recursively resolve nestedMap
s 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.
-