Uploaded image for project: 'Commons DBCP'
  1. Commons DBCP
  2. DBCP-276

DriverAdapterCPDS should allow to specify vendor specific properties

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.3
    • None

    Description

      Currently, the class DriverAdapterCPDS creates instances of the package-visible class PooledConnectionImpl by passing a java.sql.Connection created via method
      DriverManager.getConnection(String url, String user, String password).

      However, there is a more general methods that could reasonably replace this, namely:
      DriverManager.getConnection(String url, java.util.Properties info).
      One reason to prefer this one is to specify vendor specific properties, in our case CHARSET_CONVERTER_CLASS for the sybase jdbc driver.

      There are three ways out, ordered by increasing convenience:

      (1) Make class PooledConnectionImpl and its constructor public, then we can subclass DriverAdapterCPDS and override method getPooledConnection(String username, String password) to instantiate PooledConnectionImpl with a differently created java.sql.Connection.

      (2) In DriverAdapterCPDS, factor out the statement
      DriverManager.getConnection(getUrl(), username, password),
      into a protected, non-final method, say createConnection(String username, String password).
      Then we can subclass DriverAdapterCPDS and override this method appropriately.

      (3) Add a member variable DriverAdapterCPDS.mConnectionProps and a method such as DriverAdapterCPDS.setProperties(Properties props) that adds all properties to mConnectionProps. In DriverAdapterCPDS, instead of invoking DriverManager.getConnection(getUrl(), username, password), do:
      mConnectionProps.put("user", username);
      mConnectionProps.put("password", password);
      DriverManager.getConnection(getUrl(), mConnectionProps);

      By the definition of DriverManager.getConnection(String url, String user, String password), this should be equivalent at least in case both username and password are set.

      Attachments

        Activity

          People

            psteitz Phil Steitz
            olivermatz Oliver Matz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: