com.holonplatform.jdbc.internal

## Class DefaultMultiTenantDataSource

- java.lang.Object
- - com.holonplatform.jdbc.internal.DefaultMultiTenantDataSource

- All Implemented Interfaces:
    MultiTenantDataSource, Closeable, AutoCloseable, Wrapper, CommonDataSource, DataSource

      public class DefaultMultiTenantDataSource
      extends Object
      implements MultiTenantDataSource

  Default `MultiTenantDataSource` implementation.

  An internal cache is used to store and reuse tenant DataSource instances.

  Since:
    4.3.0

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `DefaultMultiTenantDataSource.DefaultBuilder` Default `MultiTenantDataSource` builder.

    - ### Nested classes/interfaces inherited from interface com.holonplatform.jdbc.MultiTenantDataSource

      `MultiTenantDataSource.Builder`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultMultiTenantDataSource()` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `Connection` | `getConnection()`
    `Connection` | `getConnection(String username, String password)`
    `int` | `getLoginTimeout()`
    `PrintWriter` | `getLogWriter()`
    `Logger` | `getParentLogger()`
    `boolean` | `isWrapperFor(Class<?> iface)`
    `void` | `reset()` Reset tenant `DataSource`s internal cache.
    `void` | `reset(String tenantId)` Reset internal cached `DataSource` for given `tenantId`, if present.
    `void` | `setLoginTimeout(int seconds)`
    `void` | `setLogWriter(PrintWriter out)`
    `void` | `setTenantDataSourceProvider(TenantDataSourceProvider tenantDataSourceProvider)` Set the `TenantDataSourceProvider` to use to obtain configured DataSource instances according to current tenant id.
    `void` | `setTenantResolver(com.holonplatform.core.tenancy.TenantResolver tenantResolver)` Set the `TenantResolver` to use to obtain the current tenant id.
    `<I> I` | `unwrap(Class<I> iface)`

    - ### Methods inherited from class java.lang.Object

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

    - ### Methods inherited from interface com.holonplatform.jdbc.MultiTenantDataSource

      `builder`

- - ### Constructor Detail

    - #### DefaultMultiTenantDataSource

          public DefaultMultiTenantDataSource()

      Constructor

  - ### Method Detail

    - #### reset

          public void reset()

      Description copied from interface: `MultiTenantDataSource`
      Reset tenant `DataSource`s internal cache.
      Specified by:
        `reset` in interface `MultiTenantDataSource`

    - #### reset

          public void reset(String tenantId)

      Description copied from interface: `MultiTenantDataSource`
      Reset internal cached `DataSource` for given `tenantId`, if present.
      Specified by:
        `reset` in interface `MultiTenantDataSource`
      Parameters:
        `tenantId` - Tenant id to reset

    - #### setTenantResolver

          public void setTenantResolver(com.holonplatform.core.tenancy.TenantResolver tenantResolver)

      Set the `TenantResolver` to use to obtain the current tenant id.

      If not setted, the default context resource `TenantResolver.getCurrent()` is used if available.

      Parameters:
        `tenantResolver` - the TenantResolver to set

    - #### setTenantDataSourceProvider

          public void setTenantDataSourceProvider(TenantDataSourceProvider tenantDataSourceProvider)

      Set the `TenantDataSourceProvider` to use to obtain configured DataSource instances according to current tenant id.

      If not setted, the default context resource `TenantDataSourceProvider.getCurrent()` is used if available.

      Parameters:
        `tenantDataSourceProvider` - the TenantDataSourceProvider to set

    - #### getConnection

          public Connection getConnection()
                                   throws SQLException

      Specified by:
        `getConnection` in interface `DataSource`
      Throws:
        `SQLException`

    - #### getConnection

          public Connection getConnection(String username,
                                          String password)
                                   throws SQLException

      Specified by:
        `getConnection` in interface `DataSource`
      Throws:
        `SQLException`

    - #### getLogWriter

          public PrintWriter getLogWriter()
                                   throws SQLException

      Specified by:
        `getLogWriter` in interface `CommonDataSource`
      Throws:
        `SQLException`

    - #### setLogWriter

          public void setLogWriter(PrintWriter out)
                            throws SQLException

      Specified by:
        `setLogWriter` in interface `CommonDataSource`
      Throws:
        `SQLException`

    - #### setLoginTimeout

          public void setLoginTimeout(int seconds)
                               throws SQLException

      Specified by:
        `setLoginTimeout` in interface `CommonDataSource`
      Throws:
        `SQLException`

    - #### getLoginTimeout

          public int getLoginTimeout()
                              throws SQLException

      Specified by:
        `getLoginTimeout` in interface `CommonDataSource`
      Throws:
        `SQLException`

    - #### getParentLogger

          public Logger getParentLogger()
                                 throws SQLFeatureNotSupportedException

      Specified by:
        `getParentLogger` in interface `CommonDataSource`
      Throws:
        `SQLFeatureNotSupportedException`

    - #### unwrap

          public <I> I unwrap(Class<I> iface)
                       throws SQLException

      Specified by:
        `unwrap` in interface `Wrapper`
      Throws:
        `SQLException`

    - #### isWrapperFor

          public boolean isWrapperFor(Class<?> iface)
                               throws SQLException

      Specified by:
        `isWrapperFor` in interface `Wrapper`
      Throws:
        `SQLException`

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Throws:
        `IOException`

Copyright © 2019 The Holon Platform. All rights reserved.