use of org.springframework.data.jdbc.mapping.model.JdbcMappingContext in project spring-data-jdbc by spring-projects.
the class EntityRowMapperUnitTests method createRowMapper.
private <T> EntityRowMapper<T> createRowMapper(Class<T> type, NamingStrategy namingStrategy) {
JdbcMappingContext context = new //
JdbcMappingContext(//
namingStrategy, //
mock(NamedParameterJdbcOperations.class), //
__ -> {
});
DataAccessStrategy accessStrategy = mock(DataAccessStrategy.class);
// the ID of the entity is used to determine what kind of ResultSet is needed for subsequent selects.
doReturn(new HashSet<>(asList(new Trivial(), new Trivial()))).when(accessStrategy).findAllByProperty(eq(ID_FOR_ENTITY_NOT_REFERENCING_MAP), any(JdbcPersistentProperty.class));
doReturn(new HashSet<>(asList(//
new SimpleEntry("one", new Trivial()), //
new SimpleEntry("two", new Trivial())))).when(accessStrategy).findAllByProperty(eq(ID_FOR_ENTITY_REFERENCING_MAP), any(JdbcPersistentProperty.class));
doReturn(new HashSet<>(asList(//
new SimpleEntry(1, new Trivial()), //
new SimpleEntry(2, new Trivial())))).when(accessStrategy).findAllByProperty(eq(ID_FOR_ENTITY_REFERENCING_LIST), any(JdbcPersistentProperty.class));
GenericConversionService conversionService = new GenericConversionService();
conversionService.addConverter(new IterableOfEntryToMapConverter());
DefaultConversionService.addDefaultConverters(conversionService);
Jsr310Converters.getConvertersToRegister().forEach(conversionService::addConverter);
return new EntityRowMapper<>((JdbcPersistentEntity<T>) context.getRequiredPersistentEntity(type), context, accessStrategy);
}
use of org.springframework.data.jdbc.mapping.model.JdbcMappingContext in project spring-data-jdbc by spring-projects.
the class SqlGeneratorContextBasedNamingStrategyUnitTests method configureSqlGenerator.
/**
* Plug in a custom {@link NamingStrategy} for this test case.
*/
private SqlGenerator configureSqlGenerator(NamingStrategy namingStrategy) {
JdbcMappingContext context = new JdbcMappingContext(namingStrategy, mock(NamedParameterJdbcOperations.class), __ -> {
});
JdbcPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
return new SqlGenerator(context, persistentEntity, new SqlGeneratorSource(context));
}
use of org.springframework.data.jdbc.mapping.model.JdbcMappingContext in project spring-data-jdbc by spring-projects.
the class SqlGeneratorFixedNamingStrategyUnitTests method configureSqlGenerator.
/**
* Plug in a custom {@link NamingStrategy} for this test case.
*
* @param namingStrategy
*/
private SqlGenerator configureSqlGenerator(NamingStrategy namingStrategy) {
JdbcMappingContext context = new JdbcMappingContext(namingStrategy, mock(NamedParameterJdbcOperations.class), __ -> {
});
JdbcPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
return new SqlGenerator(context, persistentEntity, new SqlGeneratorSource(context));
}
use of org.springframework.data.jdbc.mapping.model.JdbcMappingContext in project spring-data-jdbc by spring-projects.
the class SqlGeneratorUnitTests method setUp.
@Before
public void setUp() {
NamingStrategy namingStrategy = new PrefixingNamingStrategy();
JdbcMappingContext context = new JdbcMappingContext(namingStrategy, mock(NamedParameterJdbcOperations.class), __ -> {
});
JdbcPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
this.sqlGenerator = new SqlGenerator(context, persistentEntity, new SqlGeneratorSource(context));
}
use of org.springframework.data.jdbc.mapping.model.JdbcMappingContext in project spring-data-jdbc by spring-projects.
the class TestConfiguration method jdbcRepositoryFactory.
@Bean
JdbcRepositoryFactory jdbcRepositoryFactory(DataAccessStrategy dataAccessStrategy) {
NamedParameterJdbcOperations jdbcTemplate = namedParameterJdbcTemplate();
final JdbcMappingContext context = new JdbcMappingContext(NamingStrategy.INSTANCE, jdbcTemplate, __ -> {
});
return new //
JdbcRepositoryFactory(//
publisher, //
context, //
dataAccessStrategy);
}
Aggregations