Search in sources :

Example 1 with Dialect

use of org.springframework.data.relational.core.dialect.Dialect in project spring-data-jdbc by spring-projects.

the class AbstractJdbcConfiguration method jdbcCustomConversions.

/**
 * Register custom {@link Converter}s in a {@link JdbcCustomConversions} object if required. These
 * {@link JdbcCustomConversions} will be registered with the
 * {@link #jdbcConverter(JdbcMappingContext, NamedParameterJdbcOperations, RelationResolver, JdbcCustomConversions, Dialect)}.
 * Returns an empty {@link JdbcCustomConversions} instance by default.
 *
 * @return will never be {@literal null}.
 */
@Bean
public JdbcCustomConversions jdbcCustomConversions() {
    try {
        Dialect dialect = applicationContext.getBean(Dialect.class);
        SimpleTypeHolder simpleTypeHolder = dialect.simpleTypes().isEmpty() ? JdbcSimpleTypes.HOLDER : new SimpleTypeHolder(dialect.simpleTypes(), JdbcSimpleTypes.HOLDER);
        return new JdbcCustomConversions(CustomConversions.StoreConversions.of(simpleTypeHolder, storeConverters(dialect)), userConverters());
    } catch (NoSuchBeanDefinitionException exception) {
        LOG.warn("No dialect found. CustomConversions will be configured without dialect specific conversions.");
        return new JdbcCustomConversions();
    }
}
Also used : SimpleTypeHolder(org.springframework.data.mapping.model.SimpleTypeHolder) Dialect(org.springframework.data.relational.core.dialect.Dialect) JdbcDialect(org.springframework.data.jdbc.core.dialect.JdbcDialect) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) JdbcCustomConversions(org.springframework.data.jdbc.core.convert.JdbcCustomConversions) Bean(org.springframework.context.annotation.Bean)

Example 2 with Dialect

use of org.springframework.data.relational.core.dialect.Dialect in project spring-data-jdbc by spring-projects.

the class DefaultDataAccessStrategyUnitTests method before.

@BeforeEach
public void before() {
    DelegatingDataAccessStrategy relationResolver = new DelegatingDataAccessStrategy();
    Dialect dialect = HsqlDbDialect.INSTANCE;
    converter = new BasicJdbcConverter(context, relationResolver, new JdbcCustomConversions(), new DefaultJdbcTypeFactory(jdbcOperations), dialect.getIdentifierProcessing());
    accessStrategy = new // 
    DefaultDataAccessStrategy(// 
    new SqlGeneratorSource(context, converter, dialect), // 
    context, // 
    converter, namedJdbcOperations);
    relationResolver.setDelegate(accessStrategy);
}
Also used : Dialect(org.springframework.data.relational.core.dialect.Dialect) HsqlDbDialect(org.springframework.data.relational.core.dialect.HsqlDbDialect) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with Dialect

use of org.springframework.data.relational.core.dialect.Dialect 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 Dialect

use of org.springframework.data.relational.core.dialect.Dialect in project spring-data-jdbc by spring-projects.

the class DefaultDataAccessStrategyUnitTests method createAccessStrategyWithConverter.

private DefaultDataAccessStrategy createAccessStrategyWithConverter(List<?> converters) {
    DelegatingDataAccessStrategy relationResolver = new DelegatingDataAccessStrategy();
    Dialect dialect = HsqlDbDialect.INSTANCE;
    JdbcConverter converter = new BasicJdbcConverter(context, relationResolver, new JdbcCustomConversions(converters), new DefaultJdbcTypeFactory(jdbcOperations), dialect.getIdentifierProcessing());
    DefaultDataAccessStrategy accessStrategy = new // 
    DefaultDataAccessStrategy(// 
    new SqlGeneratorSource(context, converter, dialect), // 
    context, // 
    converter, namedJdbcOperations);
    relationResolver.setDelegate(accessStrategy);
    return accessStrategy;
}
Also used : Dialect(org.springframework.data.relational.core.dialect.Dialect) HsqlDbDialect(org.springframework.data.relational.core.dialect.HsqlDbDialect)

Aggregations

Dialect (org.springframework.data.relational.core.dialect.Dialect)4 HsqlDbDialect (org.springframework.data.relational.core.dialect.HsqlDbDialect)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 JdbcCustomConversions (org.springframework.data.jdbc.core.convert.JdbcCustomConversions)2 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 Bean (org.springframework.context.annotation.Bean)1 BasicJdbcConverter (org.springframework.data.jdbc.core.convert.BasicJdbcConverter)1 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 JdbcConverter (org.springframework.data.jdbc.core.convert.JdbcConverter)1 SqlGeneratorSource (org.springframework.data.jdbc.core.convert.SqlGeneratorSource)1 JdbcDialect (org.springframework.data.jdbc.core.dialect.JdbcDialect)1 JdbcMappingContext (org.springframework.data.jdbc.core.mapping.JdbcMappingContext)1 JdbcRepositoryFactory (org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory)1 SimpleTypeHolder (org.springframework.data.mapping.model.SimpleTypeHolder)1 H2Dialect (org.springframework.data.relational.core.dialect.H2Dialect)1 RelationalMappingContext (org.springframework.data.relational.core.mapping.RelationalMappingContext)1 NamedParameterJdbcOperations (org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations)1