use of org.springframework.data.jdbc.core.convert.JdbcCustomConversions in project spring-data-jdbc by spring-projects.
the class JdbcDb2DialectUnitTests method testCustomConversions.
// GH-974
@Test
void testCustomConversions() {
JdbcCustomConversions customConversions = new JdbcCustomConversions((List<?>) JdbcDb2Dialect.INSTANCE.getConverters());
assertSoftly(softly -> {
softly.assertThat(customConversions.getCustomWriteTarget(LocalDateTime.class)).contains(Timestamp.class);
softly.assertThat(customConversions.getCustomWriteTarget(OffsetDateTime.class)).contains(Timestamp.class);
});
}
use of org.springframework.data.jdbc.core.convert.JdbcCustomConversions 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();
}
}
use of org.springframework.data.jdbc.core.convert.JdbcCustomConversions 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.jdbc.core.convert.JdbcCustomConversions in project spring-data-jdbc by spring-projects.
the class JdbcMySqlDialectUnitTests method testCustomConversions.
// GH-974
@Test
void testCustomConversions() {
JdbcCustomConversions customConversions = new JdbcCustomConversions((List<?>) new JdbcMySqlDialect().getConverters());
assertSoftly(softly -> {
softly.assertThat(customConversions.getCustomWriteTarget(LocalDateTime.class)).isEmpty();
softly.assertThat(customConversions.getCustomWriteTarget(OffsetDateTime.class)).contains(JdbcValue.class);
});
}
Aggregations