Search in sources :

Example 1 with RelationalMappingContext

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);
}
Also used : BasicJdbcConverter(org.springframework.data.jdbc.core.convert.BasicJdbcConverter) BasicJdbcConverter(org.springframework.data.jdbc.core.convert.BasicJdbcConverter) JdbcConverter(org.springframework.data.jdbc.core.convert.JdbcConverter) RelationalMappingContext(org.springframework.data.relational.core.mapping.RelationalMappingContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with RelationalMappingContext

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);
}
Also used : JdbcMappingContext(org.springframework.data.jdbc.core.mapping.JdbcMappingContext) RelationalMappingContext(org.springframework.data.relational.core.mapping.RelationalMappingContext)

Example 3 with RelationalMappingContext

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);
}
Also used : BasicJdbcConverter(org.springframework.data.jdbc.core.convert.BasicJdbcConverter) RelationalMappingContext(org.springframework.data.relational.core.mapping.RelationalMappingContext) DefaultDataAccessStrategy(org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy) JdbcRepositoryFactory(org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations) JdbcCustomConversions(org.springframework.data.jdbc.core.convert.JdbcCustomConversions) JdbcMappingContext(org.springframework.data.jdbc.core.mapping.JdbcMappingContext) BasicJdbcConverter(org.springframework.data.jdbc.core.convert.BasicJdbcConverter) JdbcConverter(org.springframework.data.jdbc.core.convert.JdbcConverter) Dialect(org.springframework.data.relational.core.dialect.Dialect) H2Dialect(org.springframework.data.relational.core.dialect.H2Dialect) HsqlDbDialect(org.springframework.data.relational.core.dialect.HsqlDbDialect) DefaultJdbcTypeFactory(org.springframework.data.jdbc.core.convert.DefaultJdbcTypeFactory) SqlGeneratorSource(org.springframework.data.jdbc.core.convert.SqlGeneratorSource) DelegatingDataAccessStrategy(org.springframework.data.jdbc.core.convert.DelegatingDataAccessStrategy) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with RelationalMappingContext

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);
}
Also used : RelationalMappingContext(org.springframework.data.relational.core.mapping.RelationalMappingContext) PersistentPropertyPath(org.springframework.data.mapping.PersistentPropertyPath) JdbcMappingContext(org.springframework.data.jdbc.core.mapping.JdbcMappingContext)

Example 5 with RelationalMappingContext

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);
}
Also used : JdbcMappingContext(org.springframework.data.jdbc.core.mapping.JdbcMappingContext) RelationalMappingContext(org.springframework.data.relational.core.mapping.RelationalMappingContext)

Aggregations

RelationalMappingContext (org.springframework.data.relational.core.mapping.RelationalMappingContext)5 JdbcMappingContext (org.springframework.data.jdbc.core.mapping.JdbcMappingContext)4 BeforeEach (org.junit.jupiter.api.BeforeEach)2 BasicJdbcConverter (org.springframework.data.jdbc.core.convert.BasicJdbcConverter)2 JdbcConverter (org.springframework.data.jdbc.core.convert.JdbcConverter)2 DefaultDataAccessStrategy (org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy)1 DefaultJdbcTypeFactory (org.springframework.data.jdbc.core.convert.DefaultJdbcTypeFactory)1 DelegatingDataAccessStrategy (org.springframework.data.jdbc.core.convert.DelegatingDataAccessStrategy)1 JdbcCustomConversions (org.springframework.data.jdbc.core.convert.JdbcCustomConversions)1 SqlGeneratorSource (org.springframework.data.jdbc.core.convert.SqlGeneratorSource)1 JdbcRepositoryFactory (org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory)1 PersistentPropertyPath (org.springframework.data.mapping.PersistentPropertyPath)1 Dialect (org.springframework.data.relational.core.dialect.Dialect)1 H2Dialect (org.springframework.data.relational.core.dialect.H2Dialect)1 HsqlDbDialect (org.springframework.data.relational.core.dialect.HsqlDbDialect)1 NamedParameterJdbcOperations (org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations)1