Class BasicJdbcConverter
java.lang.Object
org.springframework.data.relational.core.conversion.BasicRelationalConverter
org.springframework.data.jdbc.core.convert.BasicJdbcConverter
- All Implemented Interfaces:
Aware
,ApplicationContextAware
,JdbcConverter
,RelationalConverter
public class BasicJdbcConverter
extends BasicRelationalConverter
implements JdbcConverter, ApplicationContextAware
RelationalConverter
that uses a MappingContext
to apply basic conversion of relational values to
property values.
Conversion is configurable by providing a customized CustomConversions
.
- Since:
- 1.1
- Author:
- Mark Paluch, Jens Schauder, Christoph Strobl, Myeonghyeon Lee
- See Also:
-
Constructor Summary
ConstructorDescriptionBasicJdbcConverter
(MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> context, RelationResolver relationResolver) Creates a newBasicRelationalConverter
givenMappingContext
and ano-op type factory
throwingUnsupportedOperationException
on type creation.BasicJdbcConverter
(MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> context, RelationResolver relationResolver, CustomConversions conversions, JdbcTypeFactory typeFactory, IdentifierProcessing identifierProcessing) Creates a newBasicRelationalConverter
givenMappingContext
. -
Method Summary
Modifier and TypeMethodDescriptionClass<?>
getColumnType
(RelationalPersistentProperty property) The type to be used to store this property in the database.int
getSqlType
(RelationalPersistentProperty property) The SQL type constant used when using this property as a parameter for a SQL statement.<T> T
mapRow
(PersistentPropertyPathExtension path, ResultSet resultSet, Identifier identifier, Object key) <T> T
mapRow
(RelationalPersistentEntity<T> entity, ResultSet resultSet, Object key) readValue
(Object value, TypeInformation<?> type) Read a relational value into the desireddestination type
.void
setApplicationContext
(ApplicationContext applicationContext) writeJdbcValue
(Object value, Class<?> columnType, int sqlType) Convert a property value into aJdbcValue
that contains the converted value and information how to bind it to JDBC parameters.writeValue
(Object value, TypeInformation<?> type) Write a property value into a relational type that can be stored natively.Methods inherited from class org.springframework.data.relational.core.conversion.BasicRelationalConverter
createInstance, createTypeDescriptor, getConversions, getConversionService, getEntityInstantiators, getMappingContext, getPropertyAccessor
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.relational.core.conversion.RelationalConverter
createInstance, getConversionService, getEntityInstantiators, getMappingContext, getPropertyAccessor
-
Constructor Details
-
BasicJdbcConverter
public BasicJdbcConverter(MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> context, RelationResolver relationResolver) Creates a newBasicRelationalConverter
givenMappingContext
and ano-op type factory
throwingUnsupportedOperationException
on type creation. UseBasicJdbcConverter(MappingContext, RelationResolver, CustomConversions, JdbcTypeFactory, IdentifierProcessing)
(MappingContext, RelationResolver, JdbcTypeFactory)} to convert arrays and large objects into JDBC-specific types.- Parameters:
context
- must not be null.relationResolver
- used to fetch additional relations from the database. Must not be null.
-
BasicJdbcConverter
public BasicJdbcConverter(MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> context, RelationResolver relationResolver, CustomConversions conversions, JdbcTypeFactory typeFactory, IdentifierProcessing identifierProcessing) Creates a newBasicRelationalConverter
givenMappingContext
.- Parameters:
context
- must not be null.relationResolver
- used to fetch additional relations from the database. Must not be null.typeFactory
- must not be nullidentifierProcessing
- must not be null- Since:
- 2.0
-
-
Method Details
-
setApplicationContext
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
-
getSqlType
Description copied from interface:JdbcConverter
The SQL type constant used when using this property as a parameter for a SQL statement.- Specified by:
getSqlType
in interfaceJdbcConverter
- Returns:
- Must not be
null
. - See Also:
-
getColumnType
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[][]
returnsString[]
).- Specified by:
getColumnType
in interfaceJdbcConverter
- Returns:
- a
Class
that is suitable for usage with JDBC drivers. - See Also:
-
readValue
Description copied from interface:RelationalConverter
Read a relational value into the desireddestination type
.- Specified by:
readValue
in interfaceRelationalConverter
- Overrides:
readValue
in classBasicRelationalConverter
- Parameters:
value
- a value as it is returned by the driver accessing the persistence store. May benull
.type
-TypeInformation
into which the value is to be converted. Must not benull
.- Returns:
- The converted value. May be
null
.
-
writeValue
Description copied from interface:RelationalConverter
Write a property value into a relational type that can be stored natively.- Specified by:
writeValue
in interfaceRelationalConverter
- Overrides:
writeValue
in classBasicRelationalConverter
- Parameters:
value
- a value as it is used in the object model. May benull
.type
-TypeInformation
into which the value is to be converted. Must not benull
.- Returns:
- The converted value. May be
null
.
-
writeJdbcValue
Description copied from interface:JdbcConverter
Convert a property value into aJdbcValue
that contains the converted value and information how to bind it to JDBC parameters.- Specified by:
writeJdbcValue
in interfaceJdbcConverter
- Parameters:
value
- a value as it is used in the object model. May benull
.columnType
-TypeInformation
into which the value is to be converted. Must not benull
.sqlType
- the type constant fromTypes
to be used if non is specified by a converter.- Returns:
- The converted value wrapped in a
JdbcValue
. Guaranteed to be not null.
-
mapRow
Description copied from interface:JdbcConverter
- Specified by:
mapRow
in interfaceJdbcConverter
- Parameters:
entity
- the persistent entity type.resultSet
- theResultSet
to read from.key
- primary key.- Returns:
-
mapRow
public <T> T mapRow(PersistentPropertyPathExtension path, ResultSet resultSet, Identifier identifier, Object key) Description copied from interface:JdbcConverter
- Specified by:
mapRow
in interfaceJdbcConverter
- Parameters:
path
- path to the owning property.resultSet
- theResultSet
to read from.identifier
- entity identifier.key
- primary key.- Returns:
-