共用方式為


ShardMap Class

  • java.lang.Object
    • Cloneable
      • com.microsoft.azure.elasticdb.shard.map.ShardMap

public class ShardMap

Represents a collection of shards and mappings between keys and shards in the collection.

Field Summary

Modifier and Type Field and Description
ShardMapManager shardMapManager

Reference to ShardMapManager.

StoreShardMap storeShardMap

Storage representation.

Constructor Summary

Constructor Description
ShardMap(ShardMapManager shardMapManager, StoreShardMap ssm)

Constructs an instance of ShardMap.

Method Summary

Modifier and Type Method and Description
ShardMap clone()

Clones the given shard map.

abstract ShardMap cloneCore()

Clones the current shard map instance.

final Shard createShard(ShardCreationInfo shardCreationArgs)

Creates a new shard and registers it with the shard map.

final Shard createShard(ShardLocation location)

Atomically adds a shard to ShardMap using the specified location.

final void deleteShard(Shard shard)

Removes a shard from ShardMap.

final String getApplicationNameSuffix()
final UUID getId()

Identity.

final ShardKeyType getKeyType()

Shard map key type.

abstract<V> IShardMapper getMapper()

Gets the mapper. This method is used by OpenConnection and Lookup of V.

final ShardMapType getMapType()

Shard map type.

String getName()

Shard map name.

final Shard getShard(ShardLocation location)

Obtains the shard for the specified location.

final ShardMapManager getShardMapManager()
final List<Shard> getShards()

Gets all shards from the shard map.

final StoreShardMap getStoreShardMap()
final Connection openConnection(IShardProvider shardProvider, String connectionString)

Opens a connection to the given shard provider.

final Connection openConnection(IShardProvider shardProvider, String connectionString, ConnectionOptions options)

Opens a connection to the given shard provider.

final Callable<Connection> openConnectionAsync(IShardProvider shardProvider, String connectionString)

Asynchronously opens a connection to the given shard provider.

final Callable<Connection> openConnectionAsync(IShardProvider shardProvider, String connectionString, ConnectionOptions options)

Asynchronously opens a connection to the given shard provider. All exceptions are reported via the returned task.

<KeyT> Connection openConnectionForKey(KeyT key, String connectionString)

Opens a regular SqlConnection to the shard to which the specified key value is mapped, with Validate.

<KeyT> Connection openConnectionForKey(KeyT key, String connectionString, ConnectionOptions options)

Opens a regular SqlConnection to the shard to which the specified key value is mapped.

<KeyT> Callable<Connection> openConnectionForKeyAsync(KeyT key, String connectionString)

Asynchronously opens a regular SqlConnection to the shard to which the specified key value is mapped, with Validate.

<KeyT> Callable<Connection> openConnectionForKeyAsync(KeyT key, String connectionString, ConnectionOptions options)

Asynchronously opens a regular SqlConnection to the shard to which the specified key value is mapped.

String toString()

Converts the object to its string representation.

final boolean tryGetShard(ShardLocation location, ReferenceObjectHelper<Shard> shard)

Tries to obtains the shard for the specified location.

final Shard updateShard(Shard currentShard, ShardUpdate update)

Updates a shard with the changes specified in the update parameter.

Field Details

shardMapManager

protected ShardMapManager shardMapManager

Reference to ShardMapManager.

storeShardMap

protected StoreShardMap storeShardMap

Storage representation.

Constructor Details

ShardMap

public ShardMap(ShardMapManager shardMapManager, StoreShardMap ssm)

Constructs an instance of ShardMap.

Parameters:

shardMapManager - Reference to ShardMapManager.
ssm - Storage representation.

Method Details

clone

public ShardMap clone()

Clones the given shard map.

Returns:

A cloned instance of the shard map.

cloneCore

protected abstract ShardMap cloneCore()

Clones the current shard map instance.

Returns:

Cloned shard map instance.

createShard

public final Shard createShard(ShardCreationInfo shardCreationArgs)

Creates a new shard and registers it with the shard map.

Parameters:

shardCreationArgs - Information about shard to be added.

Returns:

A new shard registered with this shard map.

createShard

public final Shard createShard(ShardLocation location)

Atomically adds a shard to ShardMap using the specified location.

Parameters:

location - Location of shard to be added.

Returns:

A shard attached to this shard map.

deleteShard

public final void deleteShard(Shard shard)

Removes a shard from ShardMap.

Parameters:

shard - Shard to remove.

getApplicationNameSuffix

public final String getApplicationNameSuffix()

getId

public final UUID getId()

Identity.

getKeyType

public final ShardKeyType getKeyType()

Shard map key type.

getMapper

public abstract IShardMapper getMapper()

Gets the mapper. This method is used by OpenConnection and Lookup of V.

Returns:

Appropriate mapper for the given shard map.

getMapType

public final ShardMapType getMapType()

Shard map type.

getName

public String getName()

Shard map name.

getShard

public final Shard getShard(ShardLocation location)

Obtains the shard for the specified location.

Parameters:

location - Location of the shard.

Returns:

Shard which has the specified location.

getShardMapManager

public final ShardMapManager getShardMapManager()

getShards

public final List getShards()

Gets all shards from the shard map.

Returns:

All shards belonging to the shard map.

getStoreShardMap

public final StoreShardMap getStoreShardMap()

openConnection

public final Connection openConnection(IShardProvider shardProvider, String connectionString)

Opens a connection to the given shard provider.

Parameters:

shardProvider - Shard provider containing shard to be connected to.
connectionString - Connection string for connection. Must have credentials.

openConnection

public final Connection openConnection(IShardProvider shardProvider, String connectionString, ConnectionOptions options)

Opens a connection to the given shard provider.

Parameters:

shardProvider - Shard provider containing shard to be connected to.
connectionString - Connection string for connection. Must have credentials.
options

openConnectionAsync

public final Callable openConnectionAsync(IShardProvider shardProvider, String connectionString)

Asynchronously opens a connection to the given shard provider.

Parameters:

shardProvider - Shard provider containing shard to be connected to.
connectionString - Connection string for connection. Must have credentials.

Returns:

A task encapsulating the SqlConnection All exceptions are reported via the returned task.

openConnectionAsync

public final Callable openConnectionAsync(IShardProvider shardProvider, String connectionString, ConnectionOptions options)

Asynchronously opens a connection to the given shard provider. All exceptions are reported via the returned task.

Parameters:

shardProvider - Shard provider containing shard to be connected to.
connectionString - Connection string for connection. Must have credentials.
options

Returns:

A task encapsulating the SqlConnection.

openConnectionForKey

public Connection openConnectionForKey(KeyT key, String connectionString)

Opens a regular SqlConnection to the shard to which the specified key value is mapped, with Validate.

Parameters:

key - Input key value.
connectionString - Connection string with credential information such as SQL Server credentials or Integrated Security settings. The hostname of the server and the database name for the shard are obtained from the lookup operation for key.

Returns:

An opened SqlConnection. Note that the SqlConnection object returned by this call is not protected against transient faults. Callers should follow best practices to protect the connection against transient faults in their application code, e.g., by using the transient fault handling functionality in the Enterprise Library from Microsoft Patterns and Practices team. This call only works if there is a single default mapping.

openConnectionForKey

public Connection openConnectionForKey(KeyT key, String connectionString, ConnectionOptions options)

Opens a regular SqlConnection to the shard to which the specified key value is mapped.

Parameters:

key - Input key value.
connectionString - Connection string with credential information such as SQL Server credentials or Integrated Security settings. The hostname of the server and the database name for the shard are obtained from the lookup operation for key.
options - Options for validation operations to perform on opened connection.

Returns:

An opened SqlConnection. Note that the SqlConnection object returned by this call is not protected against transient faults. Callers should follow best practices to protect the connection against transient faults in their application code, e.g., by using the transient fault handling functionality in the Enterprise Library from Microsoft Patterns and Practices team. This call only works if there is a single default mapping.

openConnectionForKeyAsync

public Callable openConnectionForKeyAsync(KeyT key, String connectionString)

Asynchronously opens a regular SqlConnection to the shard to which the specified key value is mapped, with Validate.

Parameters:

key - Input key value.
connectionString - Connection string with credential information such as SQL Server credentials or Integrated Security settings. The hostname of the server and the database name for the shard are obtained from the lookup operation for key.

Returns:

A Task encapsulating an opened SqlConnection. Note that the SqlConnection object returned by this call is not protected against transient faults. Callers should follow best practices to protect the connection against transient faults in their application code, e.g., by using the transient fault handling functionality in the Enterprise Library from Microsoft Patterns and Practices team. This call only works if there is a single default mapping.

openConnectionForKeyAsync

public Callable openConnectionForKeyAsync(KeyT key, String connectionString, ConnectionOptions options)

Asynchronously opens a regular SqlConnection to the shard to which the specified key value is mapped.

Parameters:

key - Input key value.
connectionString - Connection string with credential information such as SQL Server credentials or Integrated Security settings. The hostname of the server and the database name for the shard are obtained from the lookup operation for key.
options - Options for validation operations to perform on opened connection.

Returns:

A Task encapsulating an opened SqlConnection. Note that the SqlConnection object returned by this call is not protected against transient faults. Callers should follow best practices to protect the connection against transient faults in their application code, e.g., by using the transient fault handling functionality in the Enterprise Library from Microsoft Patterns and Practices team. This call only works if there is a single default mapping.

toString

public String toString()

Converts the object to its string representation.

Returns:

String representation of the object.

tryGetShard

public final boolean tryGetShard(ShardLocation location, ReferenceObjectHelper shard)

Tries to obtains the shard for the specified location.

Parameters:

location - Location of the shard.
shard - Shard which has the specified location.

Returns:

true if shard with specified location is found, false otherwise.

updateShard

public final Shard updateShard(Shard currentShard, ShardUpdate update)

Updates a shard with the changes specified in the update parameter.

Parameters:

currentShard - Shard being updated.
update - Updated properties of the shard.

Returns:

New Shard with updated information.

Applies to