Setting connection properties

1,337 views
Skip to first unread message

atta ur rehman

unread,
Jun 12, 2014, 10:36:39 AM6/12/14
to hika...@googlegroups.com
Hi all,

I'm trying to introduce HikariCP for a legacy financial application. It has a homegrown 'pool' that creates connections like this: 

Properties props = ....
conn = DriverManager.getConnection(getDatabaseProperty("url"), props);

props has some Sybase JDBC driver specific properties for charsets and what not. 

I was wondering how'd I'll achieve the same effect in Hikari. IConnectionCustomizer interface is the closest I have gotten so far. But I do need some pass some 'state' to my implementation of this interface. Which doesn't seem possible as it's been initialized in a private method. 

I could have set an arbitrary property using HikariConfig.addDatasourceProperty() but I don't have access to DS or config in the IConnectionCustomizer impl. 

Any ideas? 

Thanks. 

ATTA

Brett Wooldridge

unread,
Jun 12, 2014, 11:09:27 AM6/12/14
to hika...@googlegroups.com
You should be able to use "driver-based" configuration, something like so:

Properties props = ...
HikariDatasource ds = new HikariDataSource();
ds.setDataSourceProperties(props);
ds.setJdbcUrl("url");
ds.setDriveClassName("com.sybase.jdbc2.jdbc.SybDriver");

conn = ds.getConnection();

You of course do not have to use Properties, use can configure everything by URL, but if you have them it makes sense to use them.

atta ur rehman

unread,
Jun 12, 2014, 11:16:30 AM6/12/14
to hika...@googlegroups.com
Thanks, Brett. 

Just to be sure, the properties set using setDataSourceProperties() would be set on underlying connection? 

For our Oracle connection, we have something like this: 

if (isOracle()) {
    prop.setProperty("defaultRowPrefetch", getDatabaseProperty("fetchSize"));
}

Which we use to set the prefetch row setting on Oracle driver. Adding this property to HDS would set it on connection as well? If so, problem solved! 

Thanks again. 

ATTA


Brett Wooldridge

unread,
Jun 12, 2014, 11:29:10 AM6/12/14
to hika...@googlegroups.com
Yes.  But they will be set upon first call to getConnection(), and will not be set after that.  As long as you do that before the
DriverManager is initialized internally, you should be fine.

atta ur rehman

unread,
Jun 12, 2014, 12:47:16 PM6/12/14
to hika...@googlegroups.com
Thanks, Brett. I'll go ahead and test it now. 

Here is feature that I think would be useful: in addition to IConnectionCustomizer class name, if would be nice if we could set an instance of this implementation. Much like dataSourceClassName and dataSource properties. This would allow the clients to construct instance of IConnectionCustomizer that either has non-default constructor or custom properties. 

ATTA

Reply all
Reply to author
Forward
0 new messages