DataSourceLinkFactory.DataSourceHandler (Apache Tomcat 9.0.120 API Documentation)
Description: declaration: package: org.apache.naming.factory, class: DataSourceLinkFactory, class: DataSourceHandler

# Class DataSourceLinkFactory.DataSourceHandler

java.lang.Object
org.apache.naming.factory.DataSourceLinkFactory.DataSourceHandler

All Implemented Interfaces:
  `InvocationHandler`

Enclosing class:
  `DataSourceLinkFactory`

public static class DataSourceLinkFactory.DataSourceHandler extends Object implements InvocationHandler
Simple wrapper class that will allow a user to configure a ResourceLink for a data source so that when `DataSource.getConnection()` is called, it will invoke `DataSource.getConnection(String, String)` with the preconfigured username and password.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DataSourceHandler(DataSource ds, String username, String password)`
  Construct a DataSourceHandler for the given DataSource and credentials.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Object`
  `invoke(Object proxy, Method method, Object[] args)`
  `Object`
  `unwrap(Class<?> iface)`
  Unwrap the proxy and return the underlying DataSource if the requested interface matches.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### DataSourceHandler

    public DataSourceHandler(DataSource ds, String username, String password) throws Exception
    Construct a DataSourceHandler for the given DataSource and credentials.
    Parameters:
      `ds` - The DataSource to wrap
      `username` - The username to use on getConnection
      `password` - The password to use on getConnection
    Throws:
      `Exception` - if the getConnection method cannot be found

- ## Method Details

  - ### invoke

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
    Specified by:
      `invoke` in interface `InvocationHandler`
    Throws:
      `Throwable`

  - ### unwrap

    public Object unwrap(Class<?> iface) throws SQLException
    Unwrap the proxy and return the underlying DataSource if the requested interface matches.
    Parameters:
      `iface` - The interface to unwrap to
    Returns:
      the underlying DataSource
    Throws:
      `SQLException` - if the interface does not match DataSource