use of org.springframework.data.relational.core.mapping.RelationalMappingContext in project spring-data-jdbc by spring-projects.
the class JdbcAggregateTemplateUnitTests method setUp.
@BeforeEach
public void setUp() {
RelationalMappingContext mappingContext = new RelationalMappingContext(NamingStrategy.INSTANCE);
JdbcConverter converter = new BasicJdbcConverter(mappingContext, relationResolver);
template = new JdbcAggregateTemplate(eventPublisher, mappingContext, converter, dataAccessStrategy);
((JdbcAggregateTemplate) template).setEntityCallbacks(callbacks);
}
use of org.springframework.data.relational.core.mapping.RelationalMappingContext 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) {
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, NonQuotingDialect.INSTANCE);
}
use of org.springframework.data.relational.core.mapping.RelationalMappingContext in project spring-data-jdbc by spring-projects.
the class SimpleJdbcRepositoryEventsUnitTests method before.
@BeforeEach
public void before() {
RelationalMappingContext context = new JdbcMappingContext();
NamedParameterJdbcOperations operations = createIdGeneratingOperations();
DelegatingDataAccessStrategy delegatingDataAccessStrategy = new DelegatingDataAccessStrategy();
Dialect dialect = HsqlDbDialect.INSTANCE;
JdbcConverter converter = new BasicJdbcConverter(context, delegatingDataAccessStrategy, new JdbcCustomConversions(), new DefaultJdbcTypeFactory(operations.getJdbcOperations()), dialect.getIdentifierProcessing());
SqlGeneratorSource generatorSource = new SqlGeneratorSource(context, converter, dialect);
this.dataAccessStrategy = spy(new DefaultDataAccessStrategy(generatorSource, context, converter, operations));
delegatingDataAccessStrategy.setDelegate(dataAccessStrategy);
doReturn(true).when(dataAccessStrategy).update(any(), any());
JdbcRepositoryFactory factory = new JdbcRepositoryFactory(dataAccessStrategy, context, converter, H2Dialect.INSTANCE, publisher, operations);
this.repository = factory.getRepository(DummyEntityRepository.class);
}
use of org.springframework.data.relational.core.mapping.RelationalMappingContext 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.relational.core.mapping.RelationalMappingContext 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