commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz (JIRA)" <>
Subject [jira] Updated: (DBCP-231) Automatic Restart of BasicDataSource After Changing Connection Properties Such as Url
Date Mon, 15 Feb 2010 04:39:27 GMT


Phil Steitz updated DBCP-231:

    Fix Version/s:     (was: 1.4)

> Automatic Restart of BasicDataSource After Changing Connection Properties Such as Url
> -------------------------------------------------------------------------------------
>                 Key: DBCP-231
>                 URL:
>             Project: Commons Dbcp
>          Issue Type: New Feature
>    Affects Versions: 1.3
>            Reporter: Joe Kelly
>            Priority: Minor
>             Fix For: 2.0
> It would be nice if BasicDataSource could automatically "restart" after changing a connection
property. For example, in our application, we sometimes have to change the connection url
at runtime (i.e. we are connected to one database and then, under certain conditions, we switch
to another database). Currently, we workaround this limitation by manually calling BasicDataSource.close()
after calling BasicDataSource.setUrl().
> Looking at the July 11, 2007 snapshot of the source code for BasicDataSource, it appears
that the author was _starting_ to implement this feature. If you look at many of the setters
such as setUrl(), setUsername() and setPassword(), you will see this line of code after the
corresponding instance variable is set:
>   this.restartNeeded = true;
> Furthermore, there is this private restart() method (notice the comment "not used currently"):
>   /**
>     * Not used currently
>     */
>   private void restart() {
>       try {
>           close();
>       } catch (SQLException e) {
>           log("Could not restart DataSource, cause: " + e.getMessage());
>       }
>   }
> To finish implementing this, I think you would only need to add the following snippet
at the very top of createDataSource():
>   if (restartNeeded) {
>     restart();
>   }
> Some users might not like this feature because it might possibly cause active connections
to be killed abruptly (I'm not sure though because I haven't really looked at the implementation
of close() very closely). To calm their fears, perhaps you could make this auto-restart feature
optional by adding a boolean property called  "restartable". Then you could modify my snippet
to this:
>   if (restartable && restartNeeded) {
>     restart();
>   }
> Anyway, just my two cents. I think the class is already pretty useful.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message