public class HikariPooledConnectionProvider extends java.lang.Object implements PooledConnectionProvider, CanReleaseResources
| Modifier and Type | Class and Description |
|---|---|
static class |
HikariPooledConnectionProvider.PoolKey |
| Constructor and Description |
|---|
HikariPooledConnectionProvider(HikariPoolConfigurator hikariPoolConfigurator)
HikariPooledConnectionProvider constructor. |
HikariPooledConnectionProvider(HikariPoolConfigurator hikariPoolConfigurator,
HikariPoolMapping mapping)
HikariPooledConnectionProvider constructor. |
HikariPooledConnectionProvider(HikariPoolConfigurator hikariPoolConfigurator,
HikariPoolMapping mapping,
long poolExpirationNanos,
long poolCleanupNanos)
HikariPooledConnectionProvider constructor. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptsStrategy(@NonNull HostRole role,
@NonNull java.lang.String strategy)
Indicates whether the selection strategy is supported by the connection provider.
|
boolean |
acceptsUrl(@NonNull java.lang.String protocol,
@NonNull HostSpec hostSpec,
@NonNull java.util.Properties props)
Indicates whether this ConnectionProvider can provide connections for the given host and
properties.
|
protected void |
configurePool(com.zaxxer.hikari.HikariConfig config,
java.lang.String protocol,
HostSpec hostSpec,
java.util.Properties connectionProps)
Configures the default required settings for the internal connection pool.
|
java.sql.Connection |
connect(@NonNull java.lang.String protocol,
@NonNull Dialect dialect,
@NonNull HostSpec hostSpec,
@NonNull java.util.Properties props)
Called once per connection that needs to be created.
|
java.sql.Connection |
connect(@NonNull java.lang.String url,
@NonNull java.util.Properties props)
Deprecated.
|
int |
getHostCount()
Returns the number of active connection pools.
|
java.util.Set<java.lang.String> |
getHosts()
Returns a set containing every host URL for which there are one or more connection pool(s).
|
HostSpec |
getHostSpecByStrategy(@NonNull java.util.List<HostSpec> hosts,
@NonNull HostRole role,
@NonNull java.lang.String strategy)
Return a reader or a writer node using the specified strategy.
|
java.util.Set<HikariPooledConnectionProvider.PoolKey> |
getKeys()
Returns a set containing every key associated with an active connection pool.
|
void |
logConnections()
Logs information for every active connection pool.
|
void |
releaseResources()
An object that implements this interface should release all acquired resources assuming it may
be disposed at any time.
|
public HikariPooledConnectionProvider(HikariPoolConfigurator hikariPoolConfigurator)
HikariPooledConnectionProvider constructor. This class can be passed to
ConnectionProviderManager.setConnectionProvider(software.amazon.jdbc.ConnectionProvider) to enable internal connection pools for
each database instance in a cluster. By maintaining internal connection pools, the driver can
improve performance by reusing old Connection objects.hikariPoolConfigurator - a function that returns a HikariConfig with specific
Hikari configurations. By default, the
HikariPooledConnectionProvider will configure the
jdbcUrl, exceptionOverrideClassName, username, and password. Any
additional configuration should be defined by passing in this
parameter. If no additional configuration is desired, pass in a
HikariPoolConfigurator that returns an empty
HikariConfig.public HikariPooledConnectionProvider(HikariPoolConfigurator hikariPoolConfigurator, HikariPoolMapping mapping)
HikariPooledConnectionProvider constructor. This class can be passed to
ConnectionProviderManager.setConnectionProvider(software.amazon.jdbc.ConnectionProvider) to enable internal connection pools for
each database instance in a cluster. By maintaining internal connection pools, the driver can
improve performance by reusing old Connection objects.hikariPoolConfigurator - a function that returns a HikariConfig with specific
Hikari configurations. By default, the
HikariPooledConnectionProvider will configure the
jdbcUrl, exceptionOverrideClassName, username, and password. Any
additional configuration should be defined by passing in this
parameter. If no additional configuration is desired, pass in a
HikariPoolConfigurator that returns an empty
HikariConfig.mapping - a function that returns a String key used for the internal
connection pool keys. An internal connection pool will be
generated for each unique key returned by this function.public HikariPooledConnectionProvider(HikariPoolConfigurator hikariPoolConfigurator, HikariPoolMapping mapping, long poolExpirationNanos, long poolCleanupNanos)
HikariPooledConnectionProvider constructor. This class can be passed to
ConnectionProviderManager.setConnectionProvider(software.amazon.jdbc.ConnectionProvider) to enable internal connection pools for
each database instance in a cluster. By maintaining internal connection pools, the driver can
improve performance by reusing old Connection objects.hikariPoolConfigurator - a function that returns a HikariConfig with specific
Hikari configurations. By default, the
HikariPooledConnectionProvider will configure the
jdbcUrl, exceptionOverrideClassName, username, and password. Any
additional configuration should be defined by passing in this
parameter. If no additional configuration is desired, pass in a
HikariPoolConfigurator that returns an empty
HikariConfig.mapping - a function that returns a String key used for the internal
connection pool keys. An internal connection pool will be
generated for each unique key returned by this function.poolExpirationNanos - the amount of time that a pool should sit in the cache before
being marked as expired for cleanup, in nanoseconds. Expired
pools can still be used and will not be closed unless there
are no active connections.poolCleanupNanos - the interval defining how often expired connection pools
should be cleaned up, in nanoseconds. Note that expired pools
will not be closed unless there are no active connections.public boolean acceptsUrl(@NonNull java.lang.String protocol,
@NonNull HostSpec hostSpec,
@NonNull java.util.Properties props)
ConnectionProvideracceptsUrl in interface ConnectionProviderprotocol - the connection protocol (example "jdbc:mysql://")hostSpec - the HostSpec containing the host-port information for the host to connect toprops - the Properties to use for the connectionpublic boolean acceptsStrategy(@NonNull HostRole role, @NonNull java.lang.String strategy)
ConnectionProvideracceptsStrategy in interface ConnectionProviderrole - determines if the connection provider should return a reader host or a writer
hoststrategy - the selection strategy to usepublic HostSpec getHostSpecByStrategy(@NonNull java.util.List<HostSpec> hosts, @NonNull HostRole role, @NonNull java.lang.String strategy) throws java.sql.SQLException
ConnectionProviderUnsupportedOperationException if the specified strategy is unsupported.getHostSpecByStrategy in interface ConnectionProviderhosts - the list of HostSpec to select fromrole - determines if the connection provider should return a writer or a readerstrategy - the strategy determining how the HostSpec should be selected, e.g.,
random or round-robinHostSpec selected using the specified strategyjava.sql.SQLException - if an error occurred while returning the hostspublic java.sql.Connection connect(@NonNull java.lang.String protocol,
@NonNull Dialect dialect,
@NonNull HostSpec hostSpec,
@NonNull java.util.Properties props)
throws java.sql.SQLException
ConnectionProviderconnect in interface ConnectionProviderprotocol - the connection protocol (example "jdbc:mysql://")dialect - the database dialecthostSpec - the HostSpec containing the host-port information for the host to connect toprops - the Properties to use for the connectionConnection resulting from the given connection informationjava.sql.SQLException - if an error occurs@Deprecated
public java.sql.Connection connect(@NonNull java.lang.String url,
@NonNull java.util.Properties props)
throws java.sql.SQLException
ConnectionProviderConnectionProvider.connect(String, Dialect, HostSpec, Properties) instead.connect in interface ConnectionProviderurl - the connection URLprops - the Properties to use for the connectionConnection resulting from the given connection informationjava.sql.SQLException - if an error occurspublic void releaseResources()
CanReleaseResourcesCalling this method does NOT mean that an object is disposing and there won't be any further calls. An object should keep its functional state after calling this method.
releaseResources in interface CanReleaseResourcesprotected void configurePool(com.zaxxer.hikari.HikariConfig config,
java.lang.String protocol,
HostSpec hostSpec,
java.util.Properties connectionProps)
config - the HikariConfig to configure. By default, this method sets the
jdbcUrl, exceptionOverrideClassName, username, and password. The
HikariConfig passed to this method should be created via a
HikariPoolConfigurator, which allows the user to specify any
additional configuration properties.protocol - the driver protocol that should be used to form connectionshostSpec - the host details used to form the connectionconnectionProps - the connection propertiespublic int getHostCount()
public java.util.Set<java.lang.String> getHosts()
public java.util.Set<HikariPooledConnectionProvider.PoolKey> getKeys()
public void logConnections()