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

Support configuration of connection URL via EmbeddedDatabaseBuilder [SPR-16619] #21160

Closed
spring-projects-issues opened this issue Mar 20, 2018 · 4 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 20, 2018

Dan Lipofsky opened SPR-16619 and commented

H2EmbeddedDatabaseConfigurer is not public. So I can't extend it, and even if I could EmbeddedDatabaseBuilder does not have a pass-through method to set the configurer on the underlying EmbeddedDatabaseFactory.

All I really want to do is change the URL flags in H2EmbeddedDatabaseConfigurer but there is no way to do it.

Please please add a pass-through method to the builder to set the configurer on the factory and also make the existing configurers public.


Affects: 4.3.13, 5.0.4

@spring-projects-issues spring-projects-issues added in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.x Backlog milestone Jan 11, 2019
@sbrannen sbrannen changed the title EmbeddedDatabaseBuilder needs more flexibility [SPR-16619] Support configuration of connection URL via EmbeddedDatabaseBuilder [SPR-16619] Nov 29, 2022
@snicoll
Copy link
Member

snicoll commented Jan 4, 2024

I can see how setDatabaseType and setDatabaseConfigurer are trumping each other. Even the factory that gets the configurer is private so there's not much we can do here with the current arrangement. When a connection pool is available, Spring Boot is doing its own thing, see org.springframework.boot.jdbc.EmbeddedDatabaseConnection, which offers the usual customizations. If no connection pool is around, it defers to this infrastructure but then there is no way to tune the properties of the connection.

I don't really see why this has to be so private to be honest. We'd have to spike before opening things a little.

@wilkinsona is there anything particular that Spring Boot could use when a connection pool is not available? Or perhaps something that would make it common with the connection pool use case?

@wilkinsona
Copy link
Member

It's hard to say with any certainty because, as far as I can remember, no one's asked for Boot's purely embedded (no connection pool) case to be more configurable. That may well be due to a connection pool being on the classpath the vast majority of the time.

The URLs in Boot's EmbeddedDatabaseConnection match those in the various sub-classes of AbstractEmbeddedDatabaseConfigurer. That perhaps opens the door to allowing Boot to pass the URL down into the builder somehow. Things would then continue to work as they do today by default and spring.datasource.url – which is currently ignored in the purely embedded case – could be set for customization purposes.

@snicoll
Copy link
Member

snicoll commented Jan 4, 2024

Thanks Andy. I did try something which gives some flexibility to call the configurer with whatever arguments we want and tune things after if necessary, see snicoll@f52ac3a

This can be used as follows:

        this.factory.setDatabaseConfigurer(EmbeddedDatabaseConfigurers.customizeConfigurer(
                EmbeddedDatabaseType.H2, defaultConfigurer ->
                        new EmbeddedDatabaseConfigurerDelegate(defaultConfigurer) {
                            @Override
                            public void configureConnectionProperties(ConnectionProperties properties, String databaseName) {
                                super.configureConnectionProperties(properties, "custom-db-name");
                            }
                        }));

@snicoll snicoll self-assigned this Jan 4, 2024
@snicoll snicoll modified the milestones: 6.x Backlog, 6.2.x Jan 4, 2024
@snicoll snicoll modified the milestones: 6.2.x, 6.2.0-M1 Jan 8, 2024
snicoll added a commit to snicoll/spring-framework that referenced this issue Jan 31, 2024
This commit allows EmbeddedDatabaseConfigurer instances to be further
customized if necessary. EmbeddedDatabaseBuilder has a way now to set
a DatabaseConfigurer rather than just a type to provide full control,
or customize an existing supported database type using the new
EmbeddedDatabaseConfigurers#customizeConfigurer callback.

Closes spring-projectsgh-21160
@bclozel bclozel changed the title Support configuration of connection URL via EmbeddedDatabaseBuilder [SPR-16619] Support configuration of connection URL via EmbeddedDatabaseBuilder [SPR-16619] Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants