public class DriverConnectionProvider extends java.lang.Object implements ConnectionProvider
ConnectionProvider interface. It creates and
returns a connection provided by a target driver or a data source.| Constructor and Description |
|---|
DriverConnectionProvider(java.sql.Driver driver) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptsStrategy(@Nullable 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.
|
@NonNull ConnectionInfo |
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.
|
@Nullable HostSpec |
getHostSpecByStrategy(@NonNull java.util.List<HostSpec> hosts,
@Nullable HostRole role,
@NonNull java.lang.String strategy,
@Nullable java.util.Properties props)
Return a reader or a writer node using the specified strategy.
|
java.util.List<Pair<java.lang.String,java.lang.Object>> |
getSnapshotState() |
java.lang.String |
getTargetName() |
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(@Nullable HostRole role, @NonNull java.lang.String strategy)
ConnectionProvideracceptsStrategy in interface ConnectionProviderrole - determines if the connection provider should return a reader host or a writer
host. Null value means no preferences on host role.strategy - the selection strategy to usepublic @Nullable HostSpec getHostSpecByStrategy(@NonNull java.util.List<HostSpec> hosts, @Nullable 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 strategy, or null if no host matchesjava.sql.SQLException - if an error occurred while returning the hostspublic @NonNull ConnectionInfo 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://")dialect - The database dialecttargetDriverDialect - The target driver dialecthostSpec - The HostSpec containing the host-port information for the host to connect toprops - The Properties to use for the connectionConnectionInfo resulting from the given connection informationjava.sql.SQLException - if an error occurspublic java.lang.String getTargetName()
getTargetName in interface ConnectionProviderpublic java.util.List<Pair<java.lang.String,java.lang.Object>> getSnapshotState()
getSnapshotState in interface StateSnapshotProvider