Delen via


MultiShardConnection Class

  • java.lang.Object
    • AutoCloseable
      • com.microsoft.azure.elasticdb.query.multishard.MultiShardConnection

public class MultiShardConnection

Represents a connection to a set of shards and provides the ability to process queries across the shard set. Purpose: Creates connections to the given set of shards and governs their lifetime Notes: This class is NOT thread-safe.

Field Summary

Modifier and Type Field and Description
String ApplicationNameSuffix

The suffix to append to each shard's ApplicationName. Will help with server-side telemetry.

Constructor Summary

Constructor Description
MultiShardConnection(ArrayList<Pair<ShardLocation, Connection>> shardConnections)

Creates an instance of this class. TEST ONLY

MultiShardConnection(String connectionString, Shard... shards)

Initializes a new instance of the MultiShardConnection class.

Multiple Active Result Sets (MARS) are not supported and are disabled for any processing at the shards.

MultiShardConnection(String connectionString, ShardLocation... shardLocations)

Initializes a new instance of the MultiShardConnection class.

Multiple Active Result Sets (MARS) are not supported and are disabled for any processing at the shards.

Method Summary

Modifier and Type Method and Description
void close()

Releases all resources used by this object.

void closeOpenConnections()

Closes any open connections to shards. Does a best-effort close and doesn't throw.

MultiShardStatement createCommand()

Creates and returns a MultiShardStatement object. The MultiShardStatement object can then be used to execute a command against all shards specified in the connection.

String getConnectionString()

Gets the connection string associated with this connection.

List<Pair<ShardLocation, Connection>> getShardConnections()

Gets the collection of ShardLocations and Connections associated with this connection.

List<ShardLocation> getShardLocations()

Gets the collection of ShardLocations associated with this connection.

List<Shard> getShards()

Gets the collection of Shards associated with this connection.

boolean isClosed()

Check if connection is closed or not.

Field Details

ApplicationNameSuffix

public static String ApplicationNameSuffix= "ESC_MSQv" + GlobalConstants.MultiShardQueryVersionInfo

The suffix to append to each shard's ApplicationName. Will help with server-side telemetry.

Constructor Details

MultiShardConnection

public MultiShardConnection(ArrayList> shardConnections)

Creates an instance of this class. TEST ONLY

Parameters:

shardConnections - Connections to the shards

MultiShardConnection

public MultiShardConnection(String connectionString, Shard... shards)

Initializes a new instance of the MultiShardConnection class.

Multiple Active Result Sets (MARS) are not supported and are disabled for any processing at the shards.

Parameters:

connectionString - These credentials will be used to connect to the Shards. The same credentials are used on all shards. Therefore, all shards need to provide the appropriate permissions for these credentials to execute the command.
shards - The collection of Shards used for this connection instances.

MultiShardConnection

public MultiShardConnection(String connectionString, ShardLocation... shardLocations)

Initializes a new instance of the MultiShardConnection class.

Multiple Active Result Sets (MARS) are not supported and are disabled for any processing at the shards.

Parameters:

connectionString - These credentials will be used to connect to the Shards. The same credentials are used on all shards. Therefore, all shards need to provide the appropriate permissions for these credentials to execute the command.
shardLocations - The collection of ShardLocations used for this connection instances.

Method Details

close

public void close()

Releases all resources used by this object.

closeOpenConnections

public void closeOpenConnections()

Closes any open connections to shards. Does a best-effort close and doesn't throw.

createCommand

public MultiShardStatement createCommand()

Creates and returns a MultiShardStatement object. The MultiShardStatement object can then be used to execute a command against all shards specified in the connection.

Returns:

the MultiShardStatement with CommandText set to null.

getConnectionString

public String getConnectionString()

Gets the connection string associated with this connection.

getShardConnections

public List> getShardConnections()

Gets the collection of ShardLocations and Connections associated with this connection.

getShardLocations

public List getShardLocations()

Gets the collection of ShardLocations associated with this connection.

getShards

public List getShards()

Gets the collection of Shards associated with this connection.

isClosed

public boolean isClosed()

Check if connection is closed or not.

Returns:

true if open, false if closed.

Applies to