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,CassandraConverter,EntityConverter<CassandraPersistentEntity<?>,,CassandraPersistentProperty, Object, Object> EntityReader<Object,,Object> EntityWriter<Object,Object>
public class MappingCassandraConverter
extends AbstractCassandraConverter
implements ApplicationContextAware, BeanClassLoaderAware
- Author:
- Alex Shvid, Matthew T. Adams, Oliver Gierke, Mark Paluch, Antoine Toulme, John Blum, Christoph Strobl, Frank Spitulski
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classConversion context holding references to simpleMappingCassandraConverter.ConversionContext.ValueConverterandMappingCassandraConverter.ConversionContext.ContainerValueConverter. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a newMappingCassandraConverterwith aCassandraMappingContext.MappingCassandraConverter(CassandraMappingContext mappingContext) Create a newMappingCassandraConverterwith 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> SdoReadEntity(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.CodecRegistryReturns the configuredCodecRegistry.Constructs a new instance ofMappingCassandraConverter.ConversionContextwith various converters to convert different Cassandra value types.getId(Object object, CassandraPersistentEntity<?> entity) Returns the Id for an entity.protected ObjectgetPotentiallyConvertedSimpleRead(Object value, TypeInformation<?> target) Checks whether we have a custom conversion for the given simple object.Returns theProjectionFactoryfor this converter.Returns the configuredUserTypeResolver.<R> Rproject(EntityProjection<R, ?> projection, com.datastax.oss.driver.api.core.cql.Row row) Apply a projection toRowand return the projection return typeR.<R> Rprotected ObjectreadCollectionOrArray(MappingCassandraConverter.ConversionContext context, Collection<?> source, TypeInformation<?> targetType) Reads the givenCollectioninto a collection of the givenTypeInformation.protected ObjectreadMap(MappingCassandraConverter.ConversionContext context, Map<?, ?> source, TypeInformation<?> targetType) Reads the givenMapinto a map of the givenTypeInformation.<R> RRead aRowinto the requested targettype.voidsetApplicationContext(ApplicationContext applicationContext) voidsetBeanClassLoader(ClassLoader classLoader) voidsetCodecRegistry(com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry codecRegistry) Sets theCodecRegistry.voidsetUserTypeResolver(UserTypeResolver userTypeResolver) Sets theUserTypeResolver.voidvoidwrite(Object source, Object sink, CassandraPersistentEntity<?> entity) Methods inherited from class org.springframework.data.cassandra.core.convert.AbstractCassandraConverter
afterPropertiesSet, getConversionService, getCustomConversions, setCustomConversions, setInstantiatorsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.data.cassandra.core.convert.CassandraConverter
convertToColumnType
-
Constructor Details
-
MappingCassandraConverter
public MappingCassandraConverter()Create a newMappingCassandraConverterwith aCassandraMappingContext. -
MappingCassandraConverter
Create a newMappingCassandraConverterwith the givenCassandraMappingContext.- Parameters:
mappingContext- must not be null.
-
-
Method Details
-
getConversionContext
Constructs a new instance ofMappingCassandraConverter.ConversionContextwith various converters to convert different Cassandra value types.- Returns:
- the
MappingCassandraConverter.ConversionContext. - See Also:
-
setApplicationContext
- Specified by:
setApplicationContextin interfaceApplicationContextAware- Throws:
BeansException
-
setBeanClassLoader
- Specified by:
setBeanClassLoaderin interfaceBeanClassLoaderAware
-
getProjectionFactory
Description copied from interface:CassandraConverterReturns theProjectionFactoryfor this converter.- Specified by:
getProjectionFactoryin 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
-
getCodecRegistry
public com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry getCodecRegistry()Returns the configuredCodecRegistry.- Specified by:
getCodecRegistryin 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:
getMappingContextin interfaceCassandraConverter- Specified by:
getMappingContextin interfaceEntityConverter<CassandraPersistentEntity<?>,CassandraPersistentProperty, Object, Object>
-
getColumnTypeResolver
Description copied from interface:CassandraConverter- Specified by:
getColumnTypeResolverin 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:CassandraConverterApply a projection toRowand return the projection return typeR.Non-projectingdescriptors fall back toregular object materialization.- Specified by:
projectin 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:
readin interfaceEntityReader<Object,Object>
-
readRow
Read aRowinto 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- theTypeInformationto be used to unmarshall thisRow.- Returns:
- the converted object, will never be null.
-
convertToColumnType
Description copied from interface:CassandraConverterConverts the given object into a value Cassandra will be able to store natively in a column.- Specified by:
convertToColumnTypein interfaceCassandraConverter- Parameters:
obj-Objectto convert; must not be null.- Returns:
- the result of the conversion.
-
convertToColumnType
Description copied from interface:CassandraConverterConverts the given object into a value Cassandra will be able to store natively in a column.- Specified by:
convertToColumnTypein interfaceCassandraConverter- Parameters:
value-Objectto convert; must not be null.columnType-ColumnTypeused to describe the object type; must not be null.- Returns:
- the result of the conversion.
-
write
- Specified by:
writein interfaceEntityWriter<Object,Object>
-
write
Description copied from interface:CassandraConverter- Specified by:
writein interfaceCassandraConverter- Parameters:
source- the source, must not be null.sink- must not be null.entity- must not be null.
-
getId
Description copied from interface:CassandraConverterReturns the Id for an entity. It can return:- A singular value if for a simple
IdorPrimaryKeyId - A
MapIdfor compositePrimaryKeyColumnId's - A the composite primary key for
PrimaryKeyusing aPrimaryKeyClass
- Specified by:
getIdin 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, appliesEnumhandling 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 givenCollectioninto a collection of the givenTypeInformation. Will recursively resolve nestedLists as well. Can be overridden by subclasses.- Parameters:
source- must not be null.targetType- must not be null.- Returns:
- the converted
Collectionor array, will never be null.
-
readMap
protected Object readMap(MappingCassandraConverter.ConversionContext context, Map<?, ?> source, TypeInformation<?> targetType) Reads the givenMapinto a map of the givenTypeInformation. Will recursively resolve nestedMaps as well. Can be overridden by subclasses.- Parameters:
source- must not be null.targetType- must not be null.- Returns:
- the converted
Collectionor array, will never be null.
-