Skip to content

Improve configurability of EmbeddedDatabaseBuilder [SPR-11410] #16037

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

Closed
spring-projects-issues opened this issue Feb 10, 2014 · 8 comments
Closed
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 10, 2014

Martin Ahrer opened SPR-11410 and commented

Internally EmbeddedDatabaseBuilder delegates creation of the database instance to a factory. It would be helpful if that could be an injection target (setter or constructor).


Affects: 4.0.1

Issue Links:

Referenced from: commits dc6d675

1 votes, 5 watchers

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

The EmbeddedDatabaseBuilder gets created with an EmbeddedDatabaseFactory and a ResourceDatabasePopulator that's being set on that EmbeddedDatabaseFactory... Accepting an external EmbeddedDatabaseFactory reference doesn't seem to be ideal here since we'd have to apply our ResourceDatabasePopulator to it, effectively modifying the state of the EmbeddedDatabaseFactory and not just delegating to it.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Jon Osborn commented

Ok with that but how do we put properties on the factory? For example, I can't find a way to set 'ignore drops' using java with @Configuration style setup.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good point. We could either mirror all relevant EmbeddedDatabaseFactory options there, or provide a "getFactory()" accessor that allows for further fine-tuning. I'll revisit this for 4.0.2 still.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Jon Osborn commented

both getDatabaseFactory() and getDatabasePopulator(), please.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Looking at this stylistically and practically, it might make sense to simply use EmbeddedDatabaseFactory with a ResourceDatabasePopulator and skip the builder. There isn't that much benefit in EmbeddedDatabaseBuilder anymore once you start calling setters on the factory and the populator directly: only really the addScript variant with a String location and the part with the default scripts. Would it make more sense to add those script conveniences to ResourceDatabasePopulator instead, for direct use without a builder?

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Jon Osborn commented

yes...I think the builder is a little overkill if we are going to just delegate everything. Developers would probably still like the convenience of the builder type of syntax for unit tests. It is very easy to understand and setup quite easily using the @Configuration style.

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Resolved as described in the comments for GitHub commit dc6d675:

Improve configurability of EmbeddedDatabaseBuilder

This commit improves the configurability of EmbeddedDatabaseBuilder by
exposing the following new configuration methods.

  • setDataSourceFactory(DataSourceFactory)
  • addScripts(String...)
  • setScriptEncoding(String)
  • setSeparator(String)
  • setCommentPrefix(String)
  • setBlockCommentStartDelimiter(String)
  • setBlockCommentEndDelimiter(String)
  • continueOnError(boolean)
  • ignoreFailedDrops(boolean)

If more fine grained control over the configuration of the embedded
database is required, users are recommended to use
EmbeddedDatabaseFactory with a ResourceDatabasePopulator and forego use
of the builder.

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

As can be seen in the updated Javadoc for EmbeddedDatabaseBuilder, these new options greatly improve the usefulness of the builder:

EmbeddedDatabase db = new EmbeddedDatabaseBuilder()
    .setType(H2)
    .setScriptEncoding("UTF-8")
    .ignoreFailedDrops(true)
    .addScript("schema.sql")
    .addScripts("user_data.sql", "country_data.sql")
    .build();

// ...

db.shutdown();

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

2 participants