spring-data-relational icon indicating copy to clipboard operation
spring-data-relational copied to clipboard

Enable multiple SQL dialects for multiple datasources

Open kota65535 opened this issue 4 years ago • 4 comments

Related to: https://github.com/spring-projects/spring-data-jdbc/issues/544

As commented in https://github.com/spring-projects/spring-data-jdbc/issues/544#issuecomment-868181965, currently we cannot use different SQL dialects for multiple repositories because there is no way to configure JdbcConverter bean definition for repositories of each datasource.

One possible solution is to add jdbcConverterRef parameter to @EnableJdbcRepositories, like existing jdbcOperationRef, transactionManagerRef, etc.

kota65535 avatar Jun 25 '21 04:06 kota65535

We should allow specifying the JdbcAggregateTemplate that encapsulates data source, dialect, and other related resources.

mp911de avatar Jun 28 '21 14:06 mp911de

@mp911de Thank you for your reply. You mean adding a jdbcAggregateTemplateRef annotation or something to @EnableJdbcRepositories? Maybe the implementation goes with changing JdbcRepositoryFactory constructor to accept a JdbcAggregateTemplate bean directly, and then remove encapsulated beans (converter, dialect, operations). But we also have to create JdbcQueryLookupStrategy instance here which also depends on encapsulated beans (converter, dialect, operations). How should we create it? Should we make encapsulated beans of JdbcAggregateTemplate accessible and reuse them?

kota65535 avatar Jul 05 '21 05:07 kota65535

Yes, @EnableJdbcRepositories should get an attribute jdbcAggregateOperationsRef. Other ..Refs should be obtained from the JdbcAggregateOperations. Adding getters for that purpos is fine. ...ref attributes of @EnableJdbcRepositories should get deprecated.

schauder avatar Oct 20 '21 13:10 schauder

I think it wold be good decision to simplify overall configuration of Data Jdbc from end user side. For now it has very complex structure of beans that should be defined with circular dependencies between them. Maybe we could simplify this configuration to single builder like this:

DataAccessStrategy strategy = DataAccessStrategy.builder()
    .dataSource(datasource) //We can create NamedParameterJdbcTemplate from DataSource internally
    .dialect(dialect) //Also we can infer dialect from DataSource
    .customConversions(conversions) 
    .entitiesPackage("com.example.entity")
    .build()
JdbcAggregateTemplate = new JdbcAggregateTemplate(strategy); //Works as JdbcTemplate and DataSource 

Thats pretty much it for configuration, that user really need to know about library.

Also i think that DataAccessStrategy is better candidate to "God-object" role than JdbcAggregateTemplate. In Spring Template object only provide simplified API for different actions like:

  • JdbcTemplate
  • RestTemplate
  • KafkaTemplate
  • RetryTemplate
  • etc. No one of this objects is god-object or orchestrator object.

AnatoliyYakimov avatar Jul 06 '23 13:07 AnatoliyYakimov