Spring JdbcTemplate, SimpleJdbcCall and DataSource

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Spring JdbcTemplate, SimpleJdbcCall and DataSource

Toivo Adams
Spring JdbcTemplate, SimpleJdbcCall and DataSource

Does anybody use Spring JdbcTemplate, SimpleJdbcCall?
Both take DataSource constructor parameeter and not Connection.
And later when SimpleJdbcCall (or JdbcTemplate) need Connection, it will ask it from DataSource and release afterwards.

Currently DBCPService returns only Connection.
I want to add method which returns also DataSource.

Opinions?

Thanks
Toivo
Reply | Threaded
Open this post in threaded view
|

Re: Spring JdbcTemplate, SimpleJdbcCall and DataSource

Matt Burgess-2
Toivo,

I'm guessing the original DBCPService API only has getConnection()
because that was all that was really needed by the processors at the
time, and/or to keep more control over the DataSource object (for
example, the controller service's shutdown() method closes the
DataSource). Having said that, NiFi has extended other APIs to allow
more access to the underlying objects, with the caveat that the user
must take care of more of the "plumbing"/lifecycle. An example is the
ProcessSession.read(flowFile) method [1] which returns an InputStream
(rather than requiring an InputStreamCallback to which the InputStream
is provided and otherwise managed by the framework).

For that reason, and because DataSource is part of javax.sql vs.
needing an additional DBCP dependency in the API, I think
getDataSource() is a legitimate addition to the DBCPService API if you
have other NiFi work that requires it.  One thing to note: the
nifi-hive-nar supplies subclasses of DBCPService, so any changes to
the API would have to be implemented in those subclasses as well
(HiveConnectionPool [2], unit tests, etc.)

Regards,
Matt

[1] https://github.com/apache/nifi/blob/master/nifi-api/src/main/java/org/apache/nifi/processor/ProcessSession.java#L570
[2] https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/dbcp/hive/HiveConnectionPool.java

On Mon, Jan 9, 2017 at 4:20 AM, Toivo Adams <[hidden email]> wrote:

> Spring JdbcTemplate, SimpleJdbcCall and DataSource
>
> Does anybody use Spring JdbcTemplate, SimpleJdbcCall?
> Both take DataSource constructor parameeter and not Connection.
> And later when SimpleJdbcCall (or JdbcTemplate) need Connection, it will ask
> it from DataSource and release afterwards.
>
> Currently DBCPService returns only Connection.
> I want to add method which returns also DataSource.
>
> Opinions?
>
> Thanks
> Toivo
>
>
>
>
> --
> View this message in context: http://apache-nifi-developer-list.39713.n7.nabble.com/Spring-JdbcTemplate-SimpleJdbcCall-and-DataSource-tp14405.html
> Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Spring JdbcTemplate, SimpleJdbcCall and DataSource

Toivo Adams
Hi Matt,

Right, getConnection() was sufficient, and still is in the most of the cases.
DataSource is needed rarely and is exception.

https://issues.apache.org/jira/browse/NIFI-3339
I added getDataSource() and updated code in numerous places where API is used.

Thanks
Toivo
Reply | Threaded
Open this post in threaded view
|

Re: Spring JdbcTemplate, SimpleJdbcCall and DataSource

Toivo Adams
Please, can anyone review PR?
https://github.com/apache/nifi/pull/1417

Thanks
Toivo
Reply | Threaded
Open this post in threaded view
|

Re: Spring JdbcTemplate, SimpleJdbcCall and DataSource

Koji Kawamura-2
Hi Toivo,

Sorry for the delayed response, I reviewed the PR and posted few
comments. Please check the PR.
https://github.com/apache/nifi/pull/1417

Thanks,
Koji

On Fri, Jan 20, 2017 at 4:51 PM, Toivo Adams <[hidden email]> wrote:

> Please, can anyone review PR?
> https://github.com/apache/nifi/pull/1417
>
> Thanks
> Toivo
>
>
>
> --
> View this message in context: http://apache-nifi-developer-list.39713.n7.nabble.com/Spring-JdbcTemplate-SimpleJdbcCall-and-DataSource-tp14405p14482.html
> Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Spring JdbcTemplate, SimpleJdbcCall and DataSource

Toivo Adams
Hi Koji,

Thank you for reviewing.

Great ideas.
I created new PR.
https://github.com/apache/nifi/pull/1450

Spring JDBCTemplate usage example is in DBCPServiceTest.java
testGetDataSource() and createInsertSelectDrop(DataSource dataSource)

Thanks
Toivo