Search in sources :

Example 1 with JdbcMappingContext

use of org.springframework.data.jdbc.core.mapping.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) {
    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 2 with JdbcMappingContext

use of org.springframework.data.jdbc.core.mapping.JdbcMappingContext in project spring-data-jdbc by spring-projects.

the class AbstractJdbcConfigurationIntegrationTests method registersSimpleTypesFromCustomConversions.

// GH-975
@Test
void registersSimpleTypesFromCustomConversions() {
    assertApplicationContext(context -> {
        JdbcMappingContext mappingContext = context.getBean(JdbcMappingContext.class);
        assertThat(// 
        mappingContext.getPersistentEntity(AbstractJdbcConfigurationUnderTest.Blah.class)).describedAs(// 
        "Blah should not be an entity, since there is a WritingConversion configured for it").isNull();
    }, AbstractJdbcConfigurationUnderTest.class, Infrastructure.class);
}
Also used : JdbcMappingContext(org.springframework.data.jdbc.core.mapping.JdbcMappingContext) Test(org.junit.jupiter.api.Test)

Example 3 with JdbcMappingContext

use of org.springframework.data.jdbc.core.mapping.JdbcMappingContext in project spring-data-jdbc by spring-projects.

the class JdbcRepositoryFactoryBeanUnitTests method setUp.

@BeforeEach
public void setUp() {
    this.mappingContext = new JdbcMappingContext();
    // Setup standard configuration
    factoryBean = new JdbcRepositoryFactoryBean<>(DummyEntityRepository.class);
    when(beanFactory.getBean(NamedParameterJdbcOperations.class)).thenReturn(mock(NamedParameterJdbcOperations.class));
    ObjectProvider<DataAccessStrategy> provider = mock(ObjectProvider.class);
    when(beanFactory.getBeanProvider(DataAccessStrategy.class)).thenReturn(provider);
    when(provider.getIfAvailable(any())).then((Answer<?>) invocation -> ((Supplier<?>) invocation.getArgument(0)).get());
}
Also used : Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) BasicJdbcConverter(org.springframework.data.jdbc.core.convert.BasicJdbcConverter) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) Dialect(org.springframework.data.relational.core.dialect.Dialect) Mock(org.mockito.Mock) RelationalMappingContext(org.springframework.data.relational.core.mapping.RelationalMappingContext) CrudRepository(org.springframework.data.repository.CrudRepository) Supplier(java.util.function.Supplier) Answer(org.mockito.stubbing.Answer) ObjectProvider(org.springframework.beans.factory.ObjectProvider) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) QueryMappingConfiguration(org.springframework.data.jdbc.repository.QueryMappingConfiguration) Assertions(org.assertj.core.api.Assertions) JdbcMappingContext(org.springframework.data.jdbc.core.mapping.JdbcMappingContext) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Answers(org.mockito.Answers) DataAccessStrategy(org.springframework.data.jdbc.core.convert.DataAccessStrategy) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) DefaultDataAccessStrategy(org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) BeanFactory(org.springframework.beans.factory.BeanFactory) Id(org.springframework.data.annotation.Id) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) JdbcMappingContext(org.springframework.data.jdbc.core.mapping.JdbcMappingContext) DataAccessStrategy(org.springframework.data.jdbc.core.convert.DataAccessStrategy) DefaultDataAccessStrategy(org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy) Supplier(java.util.function.Supplier) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with JdbcMappingContext

use of org.springframework.data.jdbc.core.mapping.JdbcMappingContext 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 5 with JdbcMappingContext

use of org.springframework.data.jdbc.core.mapping.JdbcMappingContext in project spring-data-jdbc by spring-projects.

the class TestConfiguration method jdbcMappingContext.

@Bean
JdbcMappingContext jdbcMappingContext(Optional<NamingStrategy> namingStrategy, CustomConversions conversions) {
    JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy.orElse(NamingStrategy.INSTANCE));
    mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
    return mappingContext;
}
Also used : JdbcMappingContext(org.springframework.data.jdbc.core.mapping.JdbcMappingContext) Bean(org.springframework.context.annotation.Bean)

Aggregations

JdbcMappingContext (org.springframework.data.jdbc.core.mapping.JdbcMappingContext)8 RelationalMappingContext (org.springframework.data.relational.core.mapping.RelationalMappingContext)5 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Test (org.junit.jupiter.api.Test)2 Bean (org.springframework.context.annotation.Bean)2 BasicJdbcConverter (org.springframework.data.jdbc.core.convert.BasicJdbcConverter)2 DefaultDataAccessStrategy (org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy)2 Dialect (org.springframework.data.relational.core.dialect.Dialect)2 NamedParameterJdbcOperations (org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations)2 Supplier (java.util.function.Supplier)1 Assertions (org.assertj.core.api.Assertions)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 Answers (org.mockito.Answers)1 Mock (org.mockito.Mock)1 Mockito (org.mockito.Mockito)1 MockitoExtension (org.mockito.junit.jupiter.MockitoExtension)1 MockitoSettings (org.mockito.junit.jupiter.MockitoSettings)1 Strictness (org.mockito.quality.Strictness)1 Answer (org.mockito.stubbing.Answer)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1