Skip to content

jdbc: DriverAction support #174

Closed
Closed

Description

@nicktorwald

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.

Activity

  1. added this to the JDBC MVP milestone on May 6, 2019
  2. Totktonada commented on May 12, 2019

    @Totktonada

    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?

  3. nicktorwald commented on May 13, 2019

    @nicktorwald
    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

  4. Totktonada commented on Oct 16, 2019

    @Totktonada

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions