MultiShardStatement Class
- java.
lang. Object - AutoCloseable
- com.
microsoft. azure. elasticdb. query. multishard. MultiShardStatement
- com.
public class MultiShardStatement
Complements the MultiShardConnection with a command object similar to the triad of Connection, Statement, and ResultSet. The MultiShardStatement takes a T-SQL command statement as its input and executes the command across its collection of shards specified by its corresponding MultiShardConnection. The results from processing the MultiShardStatement are made available through the execute methods and the MultiShardResultSet. Purpose: Complements the MultiShardConnection and abstracts away the work of running a given command against multiple shards Notes: This class is NOT thread-safe. Since the Sync API internally invokes the async API, connections to shards with connection string property "context connection = true" are not supported. Transaction semantics are not supported.
Field Summary
Modifier and Type | Field and Description |
---|---|
Event<EventHandler<Shard |
shardExecutionBegan
The event handler invoked when execution has begun on a given shard. |
Event<EventHandler<Shard |
shardExecutionCanceled
The event handler invoked when execution on a given shard is canceled, either explicitly via the provided CancellationToken or implicitly as a result of the chosen MultiShardExecutionPolicy. |
Event<EventHandler<Shard |
shardExecutionFaulted
The event handler invoked when execution on a given shard has faulted. This handler is only invoked on exceptions for which execution could not be retried further as a result of the exception's non-transience or as a result of the chosen RetryBehavior. |
Event<EventHandler<Shard |
shardExecutionReaderReturned
The event handler invoked when executeQuery on a certain shard has successfully returned a reader. This is an internal-only method, and differs from shardExecutionSucceeded in that it is invoked BEFORE the reader is added to the MultiShardResultSet; this adding is rife with side effects that are difficult to isolate. |
Event<EventHandler<Shard |
shardExecutionSucceeded
The event handler invoked when execution has successfully completed on a given shard or its shard-specific ResultSet has been returned. |
Method Summary
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Attempts to cancel an in progress MultiShardStatement and any ongoing work that is performed at the shards on behalf of the command. We don't want cancel throwing any exceptions. Just cancel. |
void | close() |
Multi |
create(MultiShardConnection connection, String commandText)
Instance constructor of this class. Default command timeout of 300 seconds is used. |
Multi |
create(MultiShardConnection connection, String commandText, int commandTimeout)
Instance constructor of this class. Default command type is text. |
void |
dispose(boolean disposing)
Dispose off any unmanaged/managed resources held. We purposely want to ignore exceptions. |
Multi |
executeQuery()
The ExecuteReader methods of the MultiShardStatement execute the given command statement on each shard and return the concatenation (i.e. UNION ALL) of the individual results from the shards in a MultiShardResultSet. The execution policy regarding result completeness can be controlled by setting the MultiShardExecutionPolicy. The default execution policy is to return complete results. |
Multi |
executeQuery(CommandBehavior behavior)
The ExecuteReader methods of the MultiShardStatement execute the given command statement on each shard and return the concatenation (i.e. UNION ALL) of the individual results from the shards in a MultiShardResultSet. The execution policy regarding result completeness can be controlled by setting the MultiShardExecutionPolicy. The default execution policy is to return complete results. |
Multi |
executeQuery(CommandBehavior behavior, RetryPolicy commandRetryPolicy, MultiShardExecutionPolicy executionPolicy)
Runs the given query against all shards and returns a reader that encompasses results from them. Design Principles - Commands are executed in a parallel, non-blocking manner. - Only the calling thread is blocked until the command is complete against all shards. |
Callable<Multi |
executeQueryAsync()
The ExecuteReader methods of the MultiShardStatement execute the given command statement on each shard and return the concatenation (i.e. UNION ALL) of the individual results from the shards in a MultiShardResultSet. The execution policy regarding result completeness can be controlled by setting the MultiShardExecutionPolicy. The default execution policy is to return complete results. |
Callable<Multi |
executeQueryAsync(CommandBehavior behavior)
The ExecuteReader methods of the MultiShardStatement execute the given command statement on each shard and return the concatenation (i.e. UNION ALL) of the individual results from the shards in a MultiShardResultSet. The execution policy regarding result completeness can be controlled by setting the MultiShardExecutionPolicy. The default execution policy is to return complete results. |
Callable<Multi |
executeQueryAsync(CommandBehavior behavior, RetryPolicy commandRetryPolicy, MultiShardExecutionPolicy executionPolicy)
Executes the given query against all shards asynchronously. |
String |
getCommandText()
Gets the command text to execute against the set of shards. |
int |
getCommandTimeout()
Time in seconds to wait for the command to be executed on ALL shards. A value of 0 indicates no wait time limit. The default is 300 seconds. |
int |
getCommandTimeoutPerShard()
This property controls the timeout for running a command against individual shards. |
Multi |
getConnection() |
Multi |
getExecutionOptions() |
Multi |
getExecutionPolicy() |
Retry |
getRetryBehavior() |
Retry |
getRetryPolicy() |
void |
resetCommandTimeout()
Resets the commandTimeout property to its default value. |
void |
resetCommandTimeoutPerShard()
Resets the CommandTimeoutPerShard property to its default value. |
void |
setCommandText(String value)
Sets the command text to execute against the set of shards. |
void | setCommandTimeout(int commandTimeout) |
void |
setCommandTimeoutPerShard(int value)
This property controls the timeout for running a command against individual shards. |
void | setExecutionOptions(MultiShardExecutionOptions value) |
void | setExecutionPolicy(MultiShardExecutionPolicy value) |
void |
setParameters(int index, int type, Object... objects)
Set query parameters. Currently only Table type parameter is supported. |
void | setRetryBehavior(RetryBehavior value) |
void | setRetryPolicy(RetryPolicy value) |
Field Details
shardExecutionBegan
public Event
The event handler invoked when execution has begun on a given shard.
shardExecutionCanceled
public Event
The event handler invoked when execution on a given shard is canceled, either explicitly via the provided CancellationToken or implicitly as a result of the chosen MultiShardExecutionPolicy.
shardExecutionFaulted
public Event
The event handler invoked when execution on a given shard has faulted. This handler is only invoked on exceptions for which execution could not be retried further as a result of the exception's non-transience or as a result of the chosen RetryBehavior.
shardExecutionReaderReturned
public Event
The event handler invoked when executeQuery on a certain shard has successfully returned a reader. This is an internal-only method, and differs from shardExecutionSucceeded in that it is invoked BEFORE the reader is added to the MultiShardResultSet; this adding is rife with side effects that are difficult to isolate.
shardExecutionSucceeded
public Event
The event handler invoked when execution has successfully completed on a given shard or its shard-specific ResultSet has been returned.
Method Details
cancel
public void cancel()
Attempts to cancel an in progress MultiShardStatement and any ongoing work that is performed at the shards on behalf of the command. We don't want cancel throwing any exceptions. Just cancel.
close
public void close()
create
public static MultiShardStatement create(MultiShardConnection connection, String commandText)
Instance constructor of this class. Default command timeout of 300 seconds is used.
Parameters:
Returns:
create
public static MultiShardStatement create(MultiShardConnection connection, String commandText, int commandTimeout)
Instance constructor of this class. Default command type is text.
Parameters:
Returns:
dispose
protected void dispose(boolean disposing)
Dispose off any unmanaged/managed resources held. We purposely want to ignore exceptions.
Parameters:
executeQuery
public MultiShardResultSet executeQuery()
The ExecuteReader methods of the MultiShardStatement execute the given command statement on each shard and return the concatenation (i.e. UNION ALL) of the individual results from the shards in a MultiShardResultSet. The execution policy regarding result completeness can be controlled by setting the MultiShardExecutionPolicy. The default execution policy is to return complete results.
Returns:
Throws:
executeQuery
public MultiShardResultSet executeQuery(CommandBehavior behavior)
The ExecuteReader methods of the MultiShardStatement execute the given command statement on each shard and return the concatenation (i.e. UNION ALL) of the individual results from the shards in a MultiShardResultSet. The execution policy regarding result completeness can be controlled by setting the MultiShardExecutionPolicy. The default execution policy is to return complete results.
Parameters:
Returns:
Throws:
executeQuery
public MultiShardResultSet executeQuery(CommandBehavior behavior, RetryPolicy commandRetryPolicy, MultiShardExecutionPolicy executionPolicy)
Runs the given query against all shards and returns a reader that encompasses results from them. Design Principles - Commands are executed in a parallel, non-blocking manner. - Only the calling thread is blocked until the command is complete against all shards.
Parameters:
Returns:
Throws:
executeQueryAsync
public Callable
The ExecuteReader methods of the MultiShardStatement execute the given command statement on each shard and return the concatenation (i.e. UNION ALL) of the individual results from the shards in a MultiShardResultSet. The execution policy regarding result completeness can be controlled by setting the MultiShardExecutionPolicy. The default execution policy is to return complete results.
Returns:
Throws:
executeQueryAsync
public Callable
The ExecuteReader methods of the MultiShardStatement execute the given command statement on each shard and return the concatenation (i.e. UNION ALL) of the individual results from the shards in a MultiShardResultSet. The execution policy regarding result completeness can be controlled by setting the MultiShardExecutionPolicy. The default execution policy is to return complete results.
Parameters:
Returns:
Throws:
executeQueryAsync
public Callable
Executes the given query against all shards asynchronously.
Parameters:
Returns:
Throws:
getCommandText
public String getCommandText()
Gets the command text to execute against the set of shards.
getCommandTimeout
public int getCommandTimeout()
Time in seconds to wait for the command to be executed on ALL shards. A value of 0 indicates no wait time limit. The default is 300 seconds.
getCommandTimeoutPerShard
public int getCommandTimeoutPerShard()
This property controls the timeout for running a command against individual shards.
getConnection
public MultiShardConnection getConnection()
getExecutionOptions
public MultiShardExecutionOptions getExecutionOptions()
getExecutionPolicy
public MultiShardExecutionPolicy getExecutionPolicy()
getRetryBehavior
public RetryBehavior getRetryBehavior()
getRetryPolicy
public RetryPolicy getRetryPolicy()
resetCommandTimeout
public void resetCommandTimeout()
Resets the commandTimeout property to its default value.
resetCommandTimeoutPerShard
public void resetCommandTimeoutPerShard()
Resets the CommandTimeoutPerShard property to its default value.
setCommandText
public void setCommandText(String value)
Sets the command text to execute against the set of shards.
Parameters:
setCommandTimeout
public void setCommandTimeout(int commandTimeout)
Parameters:
setCommandTimeoutPerShard
public void setCommandTimeoutPerShard(int value)
This property controls the timeout for running a command against individual shards.
Parameters:
setExecutionOptions
public void setExecutionOptions(MultiShardExecutionOptions value)
Parameters:
setExecutionPolicy
public void setExecutionPolicy(MultiShardExecutionPolicy value)
Parameters:
setParameters
public void setParameters(int index, int type, Object... objects)
Set query parameters. Currently only Table type parameter is supported.
Parameters:
setRetryBehavior
public void setRetryBehavior(RetryBehavior value)
Parameters:
setRetryPolicy
public void setRetryPolicy(RetryPolicy value)
Parameters: