public class SqlRoutingSignal extends java.lang.Object implements RoutingSignal
RoutingSignal. Because a JDBC statement is bound to the connection that created
it, this signal resolves a role only on the statement-creation methods
(Connection.prepareStatement / Connection.prepareCall), where a switch can still
rebind the statement. It also subscribes to plain Statement.execute*(sql) methods for
observation (reuse warning / deferred rotation / optional rebinding), but returns
TargetRole.NO_DECISION for their role because a bound plain statement cannot be rerouted by
switching the current connection.
Requires the sqlParser plugin to be ordered before the unified plugin so parse results
are present in the PluginCallContext during the prepare call.
Optionally (see assumeWriteTransaction) a transaction that was not declared read-only
is treated as a read-write transaction, so a SELECT that opens it is routed to the writer
instead of a reader. See isWriteTransactionAssumed(RwSplitContext).
| Constructor and Description |
|---|
SqlRoutingSignal()
Routes purely on the parsed SQL, without inferring write intent from transaction state.
|
SqlRoutingSignal(boolean assumeWriteTransaction)
Routes on the parsed SQL, optionally inferring write intent from the transaction state.
|
| Modifier and Type | Method and Description |
|---|---|
java.util.Set<java.lang.String> |
extraSubscribedMethods()
Extra JDBC method names this signal needs subscribed beyond the plugin's defaults (e.g.
|
TargetRole |
resolve(RwSplitContext ctx,
java.lang.String methodName,
@Nullable java.lang.Object[] args)
Resolves the desired role for this call.
|
TargetRole |
resolveForBoundStatement(RwSplitContext ctx)
Resolves the desired role for an already-bound plain
Statement from the parsed SQL,
used only for the optional statement-rebinding path. |
TargetRole |
roleFromSqlContext(RwSplitContext ctx)
Computes the routing role from the parsed SQL analysis in the
PluginCallContext:
an explicit RoutingHint wins; otherwise QueryType (only a non-locking
SELECT routes to the reader, and only when write intent is not assumed for the current
transaction); when no parse result is available the writer is used as a safe fallback. |
public SqlRoutingSignal()
public SqlRoutingSignal(boolean assumeWriteTransaction)
assumeWriteTransaction - when true, a transaction that carries no explicit
read-only declaration is treated as a read-write transaction and
routed to the writer (see assumeWriteTransaction).public java.util.Set<java.lang.String> extraSubscribedMethods()
RoutingSignalextraSubscribedMethods in interface RoutingSignalpublic TargetRole resolve(RwSplitContext ctx, java.lang.String methodName, @Nullable java.lang.Object[] args)
RoutingSignalTargetRole.NO_DECISION means the method is not
a routing trigger for this signal (the signal abstains).resolve in interface RoutingSignalctx - the read/write splitting contextmethodName - the JDBC method being invokedargs - the method arguments (may be null)public TargetRole resolveForBoundStatement(RwSplitContext ctx)
RoutingSignalStatement from the parsed SQL,
used only for the optional statement-rebinding path. Returns TargetRole.NO_DECISION
by default (signals that do not route on SQL do not reroute bound statements).resolveForBoundStatement in interface RoutingSignalctx - the read/write splitting contextTargetRole.NO_DECISION if this signal does not applypublic TargetRole roleFromSqlContext(RwSplitContext ctx)
PluginCallContext:
an explicit RoutingHint wins; otherwise QueryType (only a non-locking
SELECT routes to the reader, and only when write intent is not assumed for the current
transaction); when no parse result is available the writer is used as a safe fallback.ctx - the read/write splitting contextTargetRole.NO_DECISION)