Class MappingJdbcConverter

java.lang.Object
org.springframework.data.relational.core.conversion.AbstractRelationalConverter
org.springframework.data.relational.core.conversion.MappingRelationalConverter
org.springframework.data.jdbc.core.convert.MappingJdbcConverter
All Implemented Interfaces:
Aware, ApplicationContextAware, EnvironmentCapable, JdbcConverter, org.springframework.data.relational.core.conversion.RelationalConverter

public class MappingJdbcConverter extends org.springframework.data.relational.core.conversion.MappingRelationalConverter implements JdbcConverter, ApplicationContextAware
RelationalConverter that uses a MappingContext to apply conversion of relational values to property values.

Conversion is configurable by providing a customized CustomConversions.

Since:
3.2
Author:
Mark Paluch, Jens Schauder, Christoph Strobl, Myeonghyeon Lee, Chirag Tailor
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.springframework.data.relational.core.conversion.MappingRelationalConverter

    org.springframework.data.relational.core.conversion.MappingRelationalConverter.AggregatePathValueProvider, org.springframework.data.relational.core.conversion.MappingRelationalConverter.ConversionContext, org.springframework.data.relational.core.conversion.MappingRelationalConverter.DefaultConversionContext, org.springframework.data.relational.core.conversion.MappingRelationalConverter.DocumentValueProvider, org.springframework.data.relational.core.conversion.MappingRelationalConverter.ProjectingConversionContext, org.springframework.data.relational.core.conversion.MappingRelationalConverter.RelationalPropertyValueProvider
  • Constructor Summary

    Constructors
    Constructor
    Description
    MappingJdbcConverter(org.springframework.data.relational.core.mapping.RelationalMappingContext context, RelationResolver relationResolver)
    Creates a new MappingJdbcConverter given MappingContext and a no-op type factory throwing UnsupportedOperationException on type creation.
    MappingJdbcConverter(org.springframework.data.relational.core.mapping.RelationalMappingContext context, RelationResolver relationResolver, CustomConversions conversions, JdbcTypeFactory typeFactory)
  • Method Summary

    Modifier and Type
    Method
    Description
    getColumnType(org.springframework.data.relational.core.mapping.RelationalPersistentProperty property)
    The type to be used to store this property in the database.
    protected @Nullable Object
     
    getTargetSqlType(org.springframework.data.relational.core.mapping.RelationalPersistentProperty property)
    The SQL type constant used when using this property as a parameter for a SQL statement.
    protected org.springframework.data.relational.core.conversion.MappingRelationalConverter.RelationalPropertyValueProvider
    newValueProvider(org.springframework.data.relational.core.conversion.RowDocumentAccessor documentAccessor, ValueExpressionEvaluator evaluator, org.springframework.data.relational.core.conversion.MappingRelationalConverter.ConversionContext context)
     
    <R> R
    readAndResolve(TypeInformation<R> type, org.springframework.data.relational.domain.RowDocument source, Identifier identifier)
    Read a RowDocument into the requested aggregate type and resolve references by looking these up from RelationResolver.
    @Nullable Object
    readValue(@Nullable Object value, TypeInformation<?> targetType)
    Read and convert a single value that is coming from a database to the targetType expected by the domain model.
    void
    Set the exception translator for this instance.
    protected @Nullable Object
    unwrap(@Nullable Object convertedValue)
    Unwraps values of type JdbcValue.
    writeJdbcValue(@Nullable Object value, TypeInformation<?> columnType, SQLType sqlType)
    Convert a property value into a JdbcValue that contains the converted value and information how to bind it to JDBC parameters.

    Methods inherited from class org.springframework.data.relational.core.conversion.MappingRelationalConverter

    doReadProjection, getConversionContext, getEnvironment, getPotentiallyConvertedSimpleRead, getPropertyAccessor, introspectProjection, newProjectingConversionContext, project, read, read, readAggregate, readAggregate, readCollectionOrArray, readMap, setApplicationContext, writeValue

    Methods inherited from class org.springframework.data.relational.core.conversion.AbstractRelationalConverter

    getConversions, getConversionService, getEntityInstantiators, getMappingContext

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface ApplicationContextAware

    setApplicationContext

    Methods inherited from interface org.springframework.data.relational.core.conversion.RelationalConverter

    getConversionService, getEntityInstantiators, getPropertyAccessor, introspectProjection, project, read, writeValue
  • Constructor Details

  • Method Details

    • setExceptionTranslator

      public void setExceptionTranslator(SQLExceptionTranslator exceptionTranslator)
      Set the exception translator for this instance. Defaults to a SQLErrorCodeSQLExceptionTranslator.
      See Also:
    • getTargetSqlType

      public SQLType getTargetSqlType(org.springframework.data.relational.core.mapping.RelationalPersistentProperty property)
      Description copied from interface: JdbcConverter
      The SQL type constant used when using this property as a parameter for a SQL statement.
      Specified by:
      getTargetSqlType in interface JdbcConverter
      Returns:
      Must not be null.
      See Also:
    • getColumnType

      public Class<?> getColumnType(org.springframework.data.relational.core.mapping.RelationalPersistentProperty property)
      Description copied from interface: JdbcConverter
      The type to be used to store this property in the database. Multidimensional arrays are unwrapped to reflect a top-level array type (e.g. String[][] returns String[]).
      Specified by:
      getColumnType in interface JdbcConverter
      Returns:
      a Class that is suitable for usage with JDBC drivers.
      See Also:
    • readValue

      public @Nullable Object readValue(@Nullable Object value, TypeInformation<?> targetType)
      Read and convert a single value that is coming from a database to the targetType expected by the domain model.
      Specified by:
      readValue in interface org.springframework.data.relational.core.conversion.RelationalConverter
      Overrides:
      readValue in class org.springframework.data.relational.core.conversion.MappingRelationalConverter
      Parameters:
      value - a value as it is returned by the driver accessing the persistence store. May be null.
      targetType - TypeInformation into which the value is to be converted. Must not be null.
      Returns:
    • getPotentiallyConvertedSimpleWrite

      protected @Nullable Object getPotentiallyConvertedSimpleWrite(Object value, TypeInformation<?> type)
      Overrides:
      getPotentiallyConvertedSimpleWrite in class org.springframework.data.relational.core.conversion.MappingRelationalConverter
    • writeJdbcValue

      public JdbcValue writeJdbcValue(@Nullable Object value, TypeInformation<?> columnType, SQLType sqlType)
      Description copied from interface: JdbcConverter
      Convert a property value into a JdbcValue that contains the converted value and information how to bind it to JDBC parameters.
      Specified by:
      writeJdbcValue in interface JdbcConverter
      Parameters:
      value - a value as it is used in the object model. May be null.
      columnType - TypeInformation into which the value is to be converted. Must not be null.
      sqlType - the SQLType to be used if non is specified by a converter.
      Returns:
      The converted value wrapped in a JdbcValue. Guaranteed to be not null.
    • unwrap

      protected @Nullable Object unwrap(@Nullable Object convertedValue)
      Unwraps values of type JdbcValue.
      Overrides:
      unwrap in class org.springframework.data.relational.core.conversion.MappingRelationalConverter
      Parameters:
      convertedValue - a value that might need unwrapping.
    • readAndResolve

      public <R> R readAndResolve(TypeInformation<R> type, org.springframework.data.relational.domain.RowDocument source, Identifier identifier)
      Description copied from interface: JdbcConverter
      Read a RowDocument into the requested aggregate type and resolve references by looking these up from RelationResolver.
      Specified by:
      readAndResolve in interface JdbcConverter
      Type Parameters:
      R - aggregate type.
      Parameters:
      type - target aggregate type.
      source - source RowDocument.
      identifier - identifier chain.
      Returns:
      the converted object.
      See Also:
      • RelationalConverter.read(Class, RowDocument)
    • newValueProvider

      protected org.springframework.data.relational.core.conversion.MappingRelationalConverter.RelationalPropertyValueProvider newValueProvider(org.springframework.data.relational.core.conversion.RowDocumentAccessor documentAccessor, ValueExpressionEvaluator evaluator, org.springframework.data.relational.core.conversion.MappingRelationalConverter.ConversionContext context)
      Overrides:
      newValueProvider in class org.springframework.data.relational.core.conversion.MappingRelationalConverter