use of org.springframework.data.jdbc.core.mapping.JdbcMappingContext in project spring-data-jdbc by spring-projects.
the class AbstractJdbcConfiguration method jdbcMappingContext.
/**
* Register a {@link JdbcMappingContext} and apply an optional {@link NamingStrategy}.
*
* @param namingStrategy optional {@link NamingStrategy}. Use {@link NamingStrategy#INSTANCE} as fallback.
* @param customConversions see {@link #jdbcCustomConversions()}.
* @return must not be {@literal null}.
*/
@Bean
public JdbcMappingContext jdbcMappingContext(Optional<NamingStrategy> namingStrategy, JdbcCustomConversions customConversions) {
JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy.orElse(NamingStrategy.INSTANCE));
mappingContext.setSimpleTypeHolder(customConversions.getSimpleTypeHolder());
return mappingContext;
}
use of org.springframework.data.jdbc.core.mapping.JdbcMappingContext in project spring-data-jdbc by spring-projects.
the class EntityRowMapperUnitTests method createRowMapper.
@SuppressWarnings("unchecked")
private <T> EntityRowMapper<T> createRowMapper(Class<T> type, NamingStrategy namingStrategy) {
RelationalMappingContext context = new JdbcMappingContext(namingStrategy);
DataAccessStrategy accessStrategy = mock(DataAccessStrategy.class);
// the ID of the entity is used to determine what kind of ResultSet is needed for subsequent selects.
Set<Trivial> trivials = //
Stream.of(//
new Trivial(1L, "one"), //
new Trivial(2L, "two")).collect(Collectors.toSet());
Set<Map.Entry<Integer, Trivial>> simpleEntriesWithInts = trivials.stream().collect(Collectors.toMap(it -> it.getId().intValue(), Function.identity())).entrySet();
Set<Map.Entry<String, Trivial>> simpleEntriesWithStringKeys = trivials.stream().collect(Collectors.toMap(Trivial::getName, Function.identity())).entrySet();
doReturn(trivials).when(accessStrategy).findAllByPath(identifierOfValue(ID_FOR_ENTITY_NOT_REFERENCING_MAP), any(PersistentPropertyPath.class));
doReturn(simpleEntriesWithStringKeys).when(accessStrategy).findAllByPath(identifierOfValue(ID_FOR_ENTITY_REFERENCING_MAP), any(PersistentPropertyPath.class));
doReturn(simpleEntriesWithInts).when(accessStrategy).findAllByPath(identifierOfValue(ID_FOR_ENTITY_REFERENCING_LIST), any(PersistentPropertyPath.class));
doReturn(trivials).when(accessStrategy).findAllByPath(identifierOfValue(ID_FOR_ENTITY_NOT_REFERENCING_MAP), any(PersistentPropertyPath.class));
doReturn(simpleEntriesWithStringKeys).when(accessStrategy).findAllByPath(identifierOfValue(ID_FOR_ENTITY_REFERENCING_MAP), any(PersistentPropertyPath.class));
doReturn(simpleEntriesWithInts).when(accessStrategy).findAllByPath(identifierOfValue(ID_FOR_ENTITY_REFERENCING_LIST), any(PersistentPropertyPath.class));
BasicJdbcConverter converter = new BasicJdbcConverter(context, accessStrategy, new JdbcCustomConversions(), JdbcTypeFactory.unsupported(), IdentifierProcessing.ANSI);
return new //
EntityRowMapper<>(//
(RelationalPersistentEntity<T>) context.getRequiredPersistentEntity(type), //
converter);
}
use of org.springframework.data.jdbc.core.mapping.JdbcMappingContext in project spring-data-jdbc by spring-projects.
the class SqlGeneratorFixedNamingStrategyUnitTests method configureSqlGenerator.
/**
* Plug in a custom {@link NamingStrategy} for this test case.
*/
private SqlGenerator configureSqlGenerator(NamingStrategy namingStrategy) {
RelationalMappingContext context = new JdbcMappingContext(namingStrategy);
JdbcConverter converter = new BasicJdbcConverter(context, (identifier, path) -> {
throw new UnsupportedOperationException();
});
RelationalPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
return new SqlGenerator(context, converter, persistentEntity, AnsiDialect.INSTANCE);
}
Aggregations