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

Let ebean module support multiple named dataSources #771

Closed
thomasguo opened this issue May 15, 2017 · 4 comments
Closed

Let ebean module support multiple named dataSources #771

thomasguo opened this issue May 15, 2017 · 4 comments
Milestone

Comments

@thomasguo
Copy link

thomasguo commented May 15, 2017

Sometimes we need to connect to multiple databases within the same application. Currently with Jdbc
module we can do like this:

{
  use(new Jdbc("db.main"));
  use(new Jdbc("db.audit"));

  get("/db", req -> {
    DataSource maindb = require(DataSource.class);
    DataSource auditdb = require("db.audit", DataSource.class);
    // ...
  });
}

But with ebean module, we cannot name the EbeanServer bean on the same way. Currently Jooby just parses the url to 'guess' a database name, that makes it difficult to inject the ebeanserver via name. Why not we just use the Ebeanby's name as the datasource name?

@jknack jknack added this to the 1.1.2 milestone May 17, 2017
@jknack
Copy link
Member

jknack commented May 21, 2017

Can you explain why database name isn't enough? The reason why jdbc module allow to use the key as name is bc of backward compatibility.

New jdbc-like modules use the database name.

@thomasguo
Copy link
Author

Because in case there are many datasources, we need to specify its name when retrieve the instance via require() or injection in code. On the other hand, when the applications is deployed to prod environment, the datasource.url is determined by users, not by developers. We want more flexibility.
When I review the ebeanby code, I find it could append a 'database' or 'databaseName' parameter to the URL to specify database name. So now I think this is not a big problem any more. Please just ignore this request if it doesn't fit the whole desgin.

BTW, in multi-datasource case with ebean module, the hot-reload feture doesn't work in dev mode. I mean, using mvn jooby:run command. Seems the ebean enhancement cause it.

@jknack
Copy link
Member

jknack commented May 22, 2017

On the other hand, when the applications is deployed to prod environment, the datasource.url is determined by users, not by developers. We want more flexibility.

That's a good argument.

BTW, in multi-datasource case with ebean module, the hot-reload feture doesn't work in dev mode. I mean, using mvn jooby:run command. Seems the ebean enhancement cause it.

Raise a new issue, add an example and error output. I will look later

@thomasguo
Copy link
Author

OK. I am going to raise a new issue now.

@jknack jknack closed this as completed in 965c72e May 25, 2017
jknack added a commit that referenced this issue May 25, 2017
Let ebean module support multiple named dataSources fix #771
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants