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

Incompatibility with Postgres Data Source #125

Closed
rrowlands opened this issue Dec 30, 2022 · 4 comments
Closed

Incompatibility with Postgres Data Source #125

rrowlands opened this issue Dec 30, 2022 · 4 comments

Comments

@rrowlands
Copy link

rrowlands commented Dec 30, 2022

Hi,

I am having an issue with your library when I attempt to use it in conjunction with a Postgres data source.

The following very basic code:

final String url = DriverWrapper.POSTGIS_PROTOCOL + "//127.0.0.1:5432/postgres";
    
BaseDataSource ds = new PGSimpleDataSource();
ds.setUrl(url);
ds.setUser("postgres");
ds.setPassword("postgres");
Connection conn = ds.getConnection();
    
System.out.println(conn.toString());

Produces the error:

Exception in thread "main" java.lang.IllegalArgumentException: URL invalid jdbc:postgresql_postGIS://127.0.0.1:5443/postgres
	at org.postgresql.ds.common.BaseDataSource.setUrl(BaseDataSource.java:1367)
	at com.runwaysdk.Sandbox.main(Sandbox.java:76)

Due primarily to the fact that the Postgres BaseDataSource includes hardcoded assumptions that the jdbc protocol will always be 'postgresql'. See here and here.

Am I doing something wrong here? All of your test code appears to use the DriverManager.getConnection interface, which works because it bypasses that DataSource abstraction.

Additionally, I am unable to bypass your DriverWrapper, due to the fact that it is auto-loaded by the Java service loader paradigm. This causes issues because if I do not use the 'postgresql_postGIS' protocol, when DriverManager.getConnection is invoked via BaseDataSource.getConnection, the DriverWrapper throws a SQL exception Unknown protocol or subprotocol in url. This is already documented as an issue in ticket #113. As a result, I fear that my only path forward might be to repackage your jar without the META-INF service loader file, or to repackage the jar with a fix for #113 included.

Thanks

@phillipross
Copy link
Contributor

Might this be related to the currently open PR (#115 ) ? I seem to recall there being a chain of related problems around this. But ultimately I think it was determined that the "driver wrapping" approach might be deficient for several reasons. It might very well be the case that using the datasource interface to produce wrapped/proxied connections might be better. This probably entails extracting the driver wrapping logic from the wrapper class(es) and using it in the datasource implementation class?

@rrowlands
Copy link
Author

rrowlands commented Jan 4, 2023

The changes contained within PR #115 would resolve ticket #113, which in turn would also resolve my blocker. In the PR, you mentioned that the tests were failing, however I can't quite tell why since it seems like there's some problem with logs. Can we please get that PR merged?

@phillipross
Copy link
Contributor

right, i was hoping the original author of the PR could resolve the issues with the build but I'll have to take a look. it might just need a rebase or something simple 😉

@phillipross
Copy link
Contributor

PR #115 has been debugged and merged, so I'll close this ticket out

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

No branches or pull requests

2 participants