Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable multiple SQL dialects for multiple datasources #994

Open
kota65535 opened this issue Jun 25, 2021 · 4 comments
Open

Enable multiple SQL dialects for multiple datasources #994

kota65535 opened this issue Jun 25, 2021 · 4 comments
Labels
type: enhancement A general enhancement

Comments

@kota65535
Copy link

Related to: #544

As commented in #544 (comment), 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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 25, 2021
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 28, 2021
@mp911de
Copy link
Member

mp911de commented Jun 28, 2021

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

@kota65535
Copy link
Author

kota65535 commented Jul 5, 2021

@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?

@schauder
Copy link
Contributor

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.

@AnatoliyYakimov
Copy link

AnatoliyYakimov commented Jul 6, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants