Class SqlResultEntityTypeMapper<RS,R>
java.lang.Object
io.micronaut.data.runtime.mapper.sql.SqlResultEntityTypeMapper<RS,R>
- Type Parameters:
RS- The result set typeR- The result type
- All Implemented Interfaces:
SqlTypeMapper<RS,R>, TypeMapper<RS, R>
@Internal
public final class SqlResultEntityTypeMapper<RS,R>
extends Object
implements SqlTypeMapper<RS,R>
A
TypeMapper that can take a RuntimePersistentEntity and a ResultReader
and materialize an instance using column naming conventions mapped by the entity.
Instances are stateful and are not thread safe: an instance caches the column name of every property it has
read and the ordinals those columns have in the result set being mapped, and hasNext(RS) keeps track of the
cursor. Create one mapper per query execution, the way the repository operations do, and do not share an instance
between threads or retain it after the result set has been consumed.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThe pushing mapper helper interface. -
Constructor Summary
ConstructorsConstructorDescriptionSqlResultEntityTypeMapper(RuntimePersistentEntity<R> entity, ResultReader<RS, String> resultReader, @Nullable Set<JoinPath> joinPaths, @Nullable SqlJsonColumnReader<RS> jsonColumnReader, DataConversionService conversionService) Constructor used to customize the join paths.SqlResultEntityTypeMapper(RuntimePersistentEntity<R> entity, ResultReader<RS, String> resultReader, @Nullable Set<JoinPath> joinPaths, @Nullable SqlJsonColumnReader<RS> jsonColumnReader, @Nullable BiFunction<RuntimePersistentEntity<Object>, Object, Object> loadListener, DataConversionService conversionService, @Nullable DatabaseConversionContextFactory conversionContextFactory) Constructor used to customize the join paths.SqlResultEntityTypeMapper(RuntimePersistentEntity<R> entity, ResultReader<RS, String> resultReader, @Nullable Set<JoinPath> joinPaths, @Nullable SqlJsonColumnReader<RS> jsonColumnReader, @Nullable BiFunction<RuntimePersistentEntity<Object>, Object, Object> loadListener, DataConversionService conversionService, @Nullable DatabaseConversionContextFactory conversionContextFactory, boolean optionalEmbeddedResult) Constructor used to customize the join paths.SqlResultEntityTypeMapper(@Nullable String prefix, RuntimePersistentEntity<R> entity, ResultReader<RS, String> resultReader, @Nullable SqlJsonColumnReader<RS> jsonColumnReader, DataConversionService conversionService) Default constructor.SqlResultEntityTypeMapper(@Nullable String prefix, RuntimePersistentEntity<R> entity, ResultReader<RS, String> resultReader, @Nullable SqlJsonColumnReader<RS> jsonColumnReader, DataConversionService conversionService, @Nullable DatabaseConversionContextFactory conversionContextFactory) Constructor with a prefix that applies the properties' attribute converters. -
Method Summary
Modifier and TypeMethodDescriptionbooleanIs another result available.Map the given result set to the given object.@Nullable ObjectRead a value for the given name from the given object.@Nullable ObjectRead a value for the given name from the given object.readEntity(RS rs) Read the entity from the result set.@Nullable RreadEntityOrNull(RS rs) Read the entity from the result set, ornullwhen the row has no value for it, which is the case for an optional embedded projection none of whose columns is set.Read multiple entities with a pushing mapper.Read one entity with a pushing mapper.
-
Constructor Details
-
SqlResultEntityTypeMapper
public SqlResultEntityTypeMapper(@Nullable String prefix, RuntimePersistentEntity<R> entity, ResultReader<RS, String> resultReader, @Nullable SqlJsonColumnReader<RS> jsonColumnReader, DataConversionService conversionService) Default constructor.- Parameters:
prefix- The prefix to startup from.entity- The entityresultReader- The result readerjsonColumnReader- The json column readerconversionService- The conversion service
-
SqlResultEntityTypeMapper
public SqlResultEntityTypeMapper(@Nullable String prefix, RuntimePersistentEntity<R> entity, ResultReader<RS, String> resultReader, @Nullable SqlJsonColumnReader<RS> jsonColumnReader, DataConversionService conversionService, @Nullable DatabaseConversionContextFactory conversionContextFactory) Constructor with a prefix that applies the properties' attribute converters.- Parameters:
prefix- The prefix to start from.entity- The entityresultReader- The result readerjsonColumnReader- The json column readerconversionService- The conversion serviceconversionContextFactory- The conversion context factory- Since:
- 5.3.0
-
SqlResultEntityTypeMapper
public SqlResultEntityTypeMapper(RuntimePersistentEntity<R> entity, ResultReader<RS, String> resultReader, @Nullable Set<JoinPath> joinPaths, @Nullable SqlJsonColumnReader<RS> jsonColumnReader, DataConversionService conversionService) Constructor used to customize the join paths.- Parameters:
entity- The entityresultReader- The result readerjoinPaths- The join pathsjsonColumnReader- The json column readerconversionService- The conversion service
-
SqlResultEntityTypeMapper
public SqlResultEntityTypeMapper(RuntimePersistentEntity<R> entity, ResultReader<RS, String> resultReader, @Nullable Set<JoinPath> joinPaths, @Nullable SqlJsonColumnReader<RS> jsonColumnReader, @Nullable BiFunction<RuntimePersistentEntity<Object>, Object, Object> loadListener, DataConversionService conversionService, @Nullable DatabaseConversionContextFactory conversionContextFactory) Constructor used to customize the join paths.- Parameters:
entity- The entityresultReader- The result readerjoinPaths- The join pathsjsonColumnReader- The json column readerloadListener- The event listenerconversionService- The conversion serviceconversionContextFactory- The conversion context factory
-
SqlResultEntityTypeMapper
public SqlResultEntityTypeMapper(RuntimePersistentEntity<R> entity, ResultReader<RS, String> resultReader, @Nullable Set<JoinPath> joinPaths, @Nullable SqlJsonColumnReader<RS> jsonColumnReader, @Nullable BiFunction<RuntimePersistentEntity<Object>, Object, Object> loadListener, DataConversionService conversionService, @Nullable DatabaseConversionContextFactory conversionContextFactory, boolean optionalEmbeddedResult) Constructor used to customize the join paths.- Parameters:
entity- The entityresultReader- The result readerjoinPaths- The join pathsjsonColumnReader- The json column readerloadListener- The event listenerconversionService- The conversion serviceconversionContextFactory- The conversion context factoryoptionalEmbeddedResult- Whether the entity is an optional embedded property projected as the query result, which is then read asnullwhen none of its values is set- Since:
- 5.2.0
-
-
Method Details
-
getConversionService
- Specified by:
getConversionServicein interfaceTypeMapper<RS,R> - Returns:
- The conversion service to use.
-
getEntity
- Returns:
- The entity to be materialized
-
getResultReader
- Returns:
- The result reader instance.
-
map
Description copied from interface:TypeMapperMap the given result set to the given object.- Specified by:
mapin interfaceTypeMapper<RS,R> - Parameters:
rs- The object to maptype- The type- Returns:
- The mapped object
- Throws:
DataAccessException- If the object cannot be mapped.
-
readEntity
Read the entity from the result set.- Parameters:
rs- The result set- Returns:
- The entity
- Throws:
DataAccessException- Since:
- 4.2.0
-
readEntityOrNull
Read the entity from the result set, ornullwhen the row has no value for it, which is the case for an optional embedded projection none of whose columns is set.- Parameters:
rs- The result set- Returns:
- The entity or null
- Throws:
DataAccessException- Since:
- 5.2.0
-
read
Description copied from interface:TypeMapperRead a value for the given name from the given object.- Specified by:
readin interfaceTypeMapper<RS,R> - Parameters:
resultSet- The object to read fromname- The name- Returns:
- The value
-
read
Description copied from interface:TypeMapperRead a value for the given name from the given object.- Specified by:
readin interfaceTypeMapper<RS,R> - Parameters:
resultSet- The object to read fromargument- The argument- Returns:
- The value
-
hasNext
Description copied from interface:SqlTypeMapperIs another result available.- Specified by:
hasNextin interfaceSqlTypeMapper<RS,R> - Parameters:
resultSet- The result set- Returns:
- True if it is
-
readOneMapper
Read one entity with a pushing mapper.- Returns:
- The pushing mapper
-
readManyMapper
Read multiple entities with a pushing mapper.- Returns:
- The pushing mapper
-
getPersistentEntity
-