public class DataSourceConnectionProvider extends java.lang.Object implements ConnectionProvider
ConnectionProvider interface. It creates and
returns an instance of PgConnection.| Constructor and Description |
|---|
DataSourceConnectionProvider(@NonNull javax.sql.DataSource dataSource) |
| 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.
|
java.sql.Connection |
connect(@NonNull java.lang.String protocol,
@NonNull Dialect dialect,
@NonNull TargetDriverDialect targetDriverDialect,
@NonNull HostSpec hostSpec,
@NonNull java.util.Properties props)
Called once per connection that needs to be created.
|
HostSpec |
getHostSpecByStrategy(@NonNull java.util.List<HostSpec> hosts,
@NonNull HostRole role,
@NonNull java.lang.String strategy,
@Nullable java.util.Properties props)
Return a reader or a writer node using the specified strategy.
|
java.lang.String |
getTargetName() |
protected java.sql.Connection |
openConnection(@NonNull javax.sql.DataSource ds,
@NonNull java.lang.String protocol,
@NonNull TargetDriverDialect targetDriverDialect,
@NonNull HostSpec hostSpec,
@NonNull java.util.Properties props) |
public DataSourceConnectionProvider(@NonNull javax.sql.DataSource dataSource)
public boolean acceptsUrl(@NonNull java.lang.String protocol,
@NonNull HostSpec hostSpec,
@NonNull java.util.Properties props)
acceptsUrl 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, @Nullable java.util.Properties props) 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-robinprops - any properties that are required by the provided strategy to select a hostHostSpec 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 TargetDriverDialect targetDriverDialect,
@NonNull HostSpec hostSpec,
@NonNull java.util.Properties props)
throws java.sql.SQLException
connect 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 connectiondialect - the database dialecttargetDriverDialect - the target driver dialectConnection resulting from the given connection informationjava.sql.SQLException - if an error occursprotected java.sql.Connection openConnection(@NonNull javax.sql.DataSource ds,
@NonNull java.lang.String protocol,
@NonNull TargetDriverDialect targetDriverDialect,
@NonNull HostSpec hostSpec,
@NonNull java.util.Properties props)
throws java.sql.SQLException
java.sql.SQLExceptionpublic java.lang.String getTargetName()
getTargetName in interface ConnectionProvider