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

Allowing Driver to be specified as an input parameter instead of using DriverManager.getDriver (for Sybase use case) #323

Closed
shantstepanian opened this issue May 28, 2020 · 2 comments · Fixed by #327
Assignees

Comments

@shantstepanian
Copy link

In DatabaseInfoRetriever, the two calls to DriverManager.getDriver(url) to get the driver cause some annoyance with Sybase, notably since different DBMS types use the same jdbc:sybase:Tds format, and since even different jdbc driver classes (notably the jdbc3 vs 4 driver) use the same url. For running multiple deployments in the same JVM across databases, this causes issues

It would be nice to be able to pass in the driver class directly, as to avoid the DriverManager lookup logic. I call the SchemaCrawler crawl() method to get data from SchemaCrawler, so I think it is just a matter of propagating that parameter through

The snippet below is what I'd replace the calls to DriverManager with. The method below would fall back to DriverManager.getDriver if the parameter isn't specified

  private Driver getDriver(String url) throws SQLException {
    return Optional.ofNullable(driverClassParam)  // TODO determine how to pass the driverClass in
      .map(driverClass -> {
        try {
          return driverClass.getDeclaredConstructor().newInstance();
        } catch (InstantiationException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
          throw new RuntimeException(e);
        }
      })
      .orElse(DriverManager.getDriver(url));
  }
@sualeh
Copy link
Collaborator

sualeh commented May 28, 2020

@shantstepanian - I will take a look at your suggestions, and make the requested changes.

@sualeh sualeh self-assigned this May 28, 2020
sualeh added a commit that referenced this issue May 31, 2020
@sualeh
Copy link
Collaborator

sualeh commented May 31, 2020

@shantstepanian - it is such a bummer that the JDBC specification does not provide a clean way to obtain the JDBC driver from it's API. I have modified the DatabaseServerType to take a third constructor parameter for the driver class name. The code changes are committed, and there are unit tests to validate the new behavior. Please take a look at the commit that fixes the issue - the code changes are not too many.

I am ready to release SchemaCrawler 16.9.1 as soon as you submit a pull request to https://github.com/schemacrawler/SchemaCrawler-Database-Plugins to add a third parameter to and optionally fix the URL matching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants