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

jdbc: DriverAction support #174

Closed
nicktorwald opened this issue May 6, 2019 · 3 comments
Closed

jdbc: DriverAction support #174

nicktorwald opened this issue May 6, 2019 · 3 comments

Comments

@nicktorwald
Copy link

This interface may be implemented by a driver that wants to be notified by DriverManager when the driver is deregistered.

A DriverAction implementation is not intended to be used directly by applications. A JDBC Driver may choose to create its DriverAction implementation in a private class to avoid it being called directly.

The JDBC driver's static initialization block must call DriverManager.registerDriver(java.sql.Driver, java.sql.DriverAction) in order to inform DriverManager which DriverAction implementation to call when the JDBC driver is de-registered.

Example:

public class SQLDriver implements java.sql.Driver {
    static SQLDriverAction driverAction = new SQLDriverAction();
    static {
        try {
            java.sql.DriverManager.registerDriver(new SQLDriver(), driverAction);
        } catch (SQLException e) {
            throw new RuntimeException("Can't register driver!");
        }
    }
   
    private class SQLDriverAction implements java.sql.DriverAction {
        ...
    }
}

See more here.

@Totktonada
Copy link
Member

If there are active connections to the database at the time that the deregister method is called, it is implementation specific as to whether the connections are closed or allowed to continue. Once this method is called, it is implementation specific as to whether the driver may limit the ability to create new connections to the database, invoke other Driver methods or throw a SQLException.

What other vendors do for this cases?

@nicktorwald
Copy link
Author

It seems others do not implement this interface. They don't restrict any behaviour of already obtained JDBC connections. This affects only Java SPI ability.
DriverAction is a recommendation if we want to be notified after the driver has been deregistered, so I don't see how we can use it now. It's worth closing the issue or moving it to another milestone

@Totktonada
Copy link
Member

So it does not needed (at least for now) internally and is not a part of public API of a driver. I agree, it worth to close the issue and reopen if we'll need to know about deregistering.

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

No branches or pull requests

2 participants