use of org.springframework.data.jdbc.mapping.model.JdbcPersistentEntity in project spring-data-jdbc by spring-projects.
the class EntityRowMapper method readEntityFrom.
private <S> S readEntityFrom(ResultSet rs, PersistentProperty<?> property) {
String prefix = property.getName() + "_";
@SuppressWarnings("unchecked") JdbcPersistentEntity<S> entity = (JdbcPersistentEntity<S>) context.getRequiredPersistentEntity(property.getActualType());
if (readFrom(rs, entity.getRequiredIdProperty(), prefix) == null) {
return null;
}
S instance = instantiator.createInstance(entity, new ResultSetParameterValueProvider(rs, entity, conversions, prefix));
PersistentPropertyAccessor accessor = entity.getPropertyAccessor(instance);
ConvertingPropertyAccessor propertyAccessor = new ConvertingPropertyAccessor(accessor, conversions);
for (JdbcPersistentProperty p : entity) {
propertyAccessor.setProperty(p, readFrom(rs, p, prefix));
}
return instance;
}
use of org.springframework.data.jdbc.mapping.model.JdbcPersistentEntity in project spring-data-jdbc by spring-projects.
the class DefaultDataAccessStrategy method getPropertyMap.
private <S> MapSqlParameterSource getPropertyMap(final S instance, JdbcPersistentEntity<S> persistentEntity) {
MapSqlParameterSource parameters = new MapSqlParameterSource();
persistentEntity.doWithProperties((PropertyHandler<JdbcPersistentProperty>) property -> {
if (!property.isEntity()) {
Object value = persistentEntity.getPropertyAccessor(instance).getProperty(property);
Object convertedValue = convert(value, property.getColumnType());
parameters.addValue(property.getColumnName(), convertedValue, JdbcUtil.sqlTypeFor(property.getColumnType()));
}
});
return parameters;
}
Aggregations