public class XADataSourceConnectionProvider extends java.lang.Object implements ConnectionProvider
ConnectionProvider for the XA datasource path. It wraps a configured target
XADataSource, opens a single XAConnection lazily on first use, and returns a fresh
logical Connection handle over that same physical XA connection on each
connect(java.lang.String, software.amazon.jdbc.dialect.Dialect, software.amazon.jdbc.targetdriverdialect.TargetDriverDialect, software.amazon.jdbc.HostSpec, java.util.Properties) call.
Because an XA branch is pinned to one physical session and the XAResource is bound to
this XAConnection, the same XAConnection is reused for the lifetime of this
provider (i.e. of the owning XAConnectionWrapper); it is never repointed to a different
host. The target XADataSource is expected to be fully configured before it is handed to
this provider.
| Constructor and Description |
|---|
XADataSourceConnectionProvider(@NonNull javax.sql.XADataSource xaDataSource) |
XADataSourceConnectionProvider(@NonNull javax.sql.XADataSource xaDataSource,
@Nullable java.lang.String resolvedUrl) |
| 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.
|
@NonNull javax.sql.XAConnection |
getOrOpenXaConnection()
Returns the single owning
XAConnection, opening it on first use. |
java.util.List<Pair<java.lang.String,java.lang.Object>> |
getSnapshotState() |
java.lang.String |
getTargetName() |
@Nullable javax.sql.XAConnection |
getXaConnectionOrNull()
Returns the owning
XAConnection if it has been opened, otherwise null. |
public XADataSourceConnectionProvider(@NonNull javax.sql.XADataSource xaDataSource)
public XADataSourceConnectionProvider(@NonNull javax.sql.XADataSource xaDataSource,
@Nullable java.lang.String resolvedUrl)
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(@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
ConnectionProviderconnect 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 @NonNull javax.sql.XAConnection getOrOpenXaConnection()
throws java.sql.SQLException
XAConnection, opening it on first use. Reused for the lifetime
of this provider so the XAResource and every logical handle share one physical session.java.sql.SQLException - if the XA connection cannot be opened.public @Nullable javax.sql.XAConnection getXaConnectionOrNull()
XAConnection if it has been opened, otherwise null.public java.lang.String getTargetName()
getTargetName in interface ConnectionProviderpublic java.util.List<Pair<java.lang.String,java.lang.Object>> getSnapshotState()
getSnapshotState in interface StateSnapshotProvider