BaseShardMapper Class

  • java.lang.Object
    • com.microsoft.azure.elasticdb.shard.mapper.BaseShardMapper

public class BaseShardMapper

Base class for keyed mappers.

Field Summary

Modifier and Type Field and Description
final UUID DEFAULT_OWNER
ShardMap shardMap

Containing shard map.

ShardMapManager shardMapManager

Reference to ShardMapManager.

Constructor Summary

Constructor Description
BaseShardMapper(ShardMapManager shardMapManager, ShardMap sm)

Base shard mapper, which is just a holder of some fields.

Method Summary

Modifier and Type Method and Description
final<MappingT extends IShardProvider &IMappingInfoProvider> MappingT add(MappingT mapping, ActionGeneric3Param<ShardMapManager, ShardMap, StoreMapping, MappingT> constructMapping)

Adds a mapping to shard map.

final<MappingT extends IMappingInfoProvider> void ensureMappingBelongsToShardMap(MappingT mapping, String operationName, String parameterName)

Validates the input parameters and ensures that the mapping parameter belong to this shard map.

final<MappingT extends IShardProvider &IMappingInfoProvider> UUID getLockOwnerForMapping(MappingT mapping, ShardManagementErrorCategory errorCategory)

Gets the lock owner of a mapping.

final<MappingT> List<MappingT> getMappingsForRange(Range range, Shard shard, LookupOptions lookupOptions, ActionGeneric3Param<ShardMapManager, ShardMap, StoreMapping, MappingT> constructMapping, ShardManagementErrorCategory errorCategory, String mappingType)

Gets all the mappings that exist within given range.

final ShardMap getShardMap()
final ShardMapManager getShardMapManager()
final<MappingT extends IShardProvider &IMappingInfoProvider> void lockOrUnlockMappings(MappingT mapping, UUID lockOwnerId, LockOwnerIdOpType lockOwnerIdOpType, ShardManagementErrorCategory errorCategory)

Locks or unlocks a given mapping or all mappings.

final<MappingT extends IShardProvider, KeyT> MappingT lookup(KeyT key, LookupOptions lookupOptions, ActionGeneric3Param<ShardMapManager, ShardMap, StoreMapping, MappingT> constructMapping, ShardManagementErrorCategory errorCategory)

Looks up the key value and returns the corresponding mapping.

final<MappingT extends IShardProvider, KeyT> Connection openConnectionForKey(KeyT key, ActionGeneric3Param<ShardMapManager, ShardMap, StoreMapping, MappingT> constructMapping, ShardManagementErrorCategory errorCategory, String connectionString)

Given a key value, obtains a SqlConnection to the shard in the mapping that contains the key value.

final<MappingT extends IShardProvider, KeyT> Connection openConnectionForKey(KeyT key, ActionGeneric3Param<ShardMapManager, ShardMap, StoreMapping, MappingT> constructMapping, ShardManagementErrorCategory errorCategory, String connectionString, ConnectionOptions options)

Given a key value, obtains a SqlConnection to the shard in the mapping that contains the key value.

final<MappingT extends IShardProvider, KeyT> Callable<Connection> openConnectionForKeyAsync(KeyT key, ActionGeneric3Param<ShardMapManager, ShardMap, StoreMapping, MappingT> constructMapping, ShardManagementErrorCategory errorCategory, String connectionString)
final<MappingT extends IShardProvider, KeyT> Callable<Connection> openConnectionForKeyAsync(KeyT key, ActionGeneric3Param<ShardMapManager, ShardMap, StoreMapping, MappingT> constructMapping, ShardManagementErrorCategory errorCategory, String connectionString, ConnectionOptions options)

Given a key value, asynchronously obtains a SqlConnection to the shard in the mapping that contains the key value.

final<MappingT extends IShardProvider &IMappingInfoProvider> void remove(MappingT mapping, ActionGeneric3Param<ShardMapManager, ShardMap, StoreMapping, MappingT> constructMapping, UUID lockOwnerId)

Removes a mapping from shard map.

static<MappingT, UpdateT, StatusT> MappingT setStatus(MappingT mapping, StatusT status, Function<StatusT, StatusT> getStatus, Function<StatusT, UpdateT> createUpdate, ActionGeneric3Param<MappingT, UpdateT, UUID, MappingT> runUpdate)

Sets the status of a shard mapping

static<MappingT, UpdateT, StatusT> MappingT setStatus(MappingT mapping, StatusT status, Function<StatusT, StatusT> getStatus, Function<StatusT, UpdateT> createUpdate, ActionGeneric3Param<MappingT, UpdateT, UUID, MappingT> runUpdate, UUID lockOwnerId)

Sets the status of a shard mapping

final<MappingT extends IShardProvider &IMappingInfoProvider, UpdateT extends IMappingUpdate<StatusT>, StatusT> MappingT update(MappingT currentMapping, UpdateT update, ActionGeneric3Param<ShardMapManager, ShardMap, StoreMapping, MappingT> constructMapping, Function<StatusT, Integer> statusAsInt, Function<Integer, StatusT> intAsStatus)

Allows for update to a mapping with the updates provided in the update parameter.

final<MappingT extends IShardProvider &IMappingInfoProvider, UpdateT extends IMappingUpdate<StatusT>, StatusT> MappingT update(MappingT currentMapping, UpdateT update, ActionGeneric3Param<ShardMapManager, ShardMap, StoreMapping, MappingT> constructMapping, Function<StatusT, Integer> statusAsInt, Function<Integer, StatusT> intAsStatus, UUID lockOwnerId)

Allows for update to a mapping with the updates provided in the update parameter.

Field Details

DEFAULT_OWNER

protected static final UUID DEFAULT_OWNER= UUID.randomUUID()

shardMap

protected ShardMap shardMap

Containing shard map.

shardMapManager

protected ShardMapManager shardMapManager

Reference to ShardMapManager.

Constructor Details

BaseShardMapper

protected BaseShardMapper(ShardMapManager shardMapManager, ShardMap sm)

Base shard mapper, which is just a holder of some fields.

Parameters:

shardMapManager - Reference to ShardMapManager.
sm - Containing shard map.

Method Details

add

protected final MappingT add(MappingT mapping, ActionGeneric3Param constructMapping)

Adds a mapping to shard map.

Parameters:

mapping - Mapping being added.
constructMapping - Delegate to construct a mapping object.

Returns:

The added mapping object.

ensureMappingBelongsToShardMap

protected final void ensureMappingBelongsToShardMap(MappingT mapping, String operationName, String parameterName)

Validates the input parameters and ensures that the mapping parameter belong to this shard map.

Parameters:

mapping - Mapping to be validated.
operationName - Operation being performed.
parameterName - Parameter name for mapping parameter.

getLockOwnerForMapping

public final UUID getLockOwnerForMapping(MappingT mapping, ShardManagementErrorCategory errorCategory)

Gets the lock owner of a mapping.

Parameters:

mapping - The mapping
errorCategory - Error category to use for the store operation

Returns:

Lock owner for the mapping.

getMappingsForRange

protected final List getMappingsForRange(Range range, Shard shard, LookupOptions lookupOptions, ActionGeneric3Param constructMapping, ShardManagementErrorCategory errorCategory, String mappingType)

Gets all the mappings that exist within given range.

Parameters:

range - Optional range value, if null, we cover everything.
shard - Optional shard parameter, if null, we cover all shards.
lookupOptions - Whether to use cache and/or storage for lookups.
constructMapping - Delegate to construct a mapping object.
errorCategory - Category under which errors will be posted.
mappingType - Name of mapping type.

Returns:

Read-only collection of mappings that overlap with given range.

getShardMap

protected final ShardMap getShardMap()

getShardMapManager

protected final ShardMapManager getShardMapManager()

lockOrUnlockMappings

public final void lockOrUnlockMappings(MappingT mapping, UUID lockOwnerId, LockOwnerIdOpType lockOwnerIdOpType, ShardManagementErrorCategory errorCategory)

Locks or unlocks a given mapping or all mappings.

Parameters:

mapping - Optional mapping
lockOwnerId - The lock owner id
lockOwnerIdOpType - Operation to perform on this mapping with the given lockOwnerId
errorCategory - Error category to use for the store operation

lookup

protected final MappingT lookup(KeyT key, LookupOptions lookupOptions, ActionGeneric3Param constructMapping, ShardManagementErrorCategory errorCategory)

Looks up the key value and returns the corresponding mapping.

Parameters:

key - Input key value.
lookupOptions - Whether to use cache and/or storage for lookups.
constructMapping - Delegate to construct a mapping object.
errorCategory - Category under which errors must be thrown.

Returns:

Mapping that contains the key value.

openConnectionForKey

protected final Connection openConnectionForKey(KeyT key, ActionGeneric3Param constructMapping, ShardManagementErrorCategory errorCategory, String connectionString)

Given a key value, obtains a SqlConnection to the shard in the mapping that contains the key value.

Parameters:

key - Input key value.
constructMapping - Delegate to construct a mapping object.
errorCategory - Error category.
connectionString - Connection string with credential information, the DataSource and Database are obtained from the results of the lookup operation for key.

Returns:

An opened SqlConnection.

openConnectionForKey

protected final Connection openConnectionForKey(KeyT key, ActionGeneric3Param constructMapping, ShardManagementErrorCategory errorCategory, String connectionString, ConnectionOptions options)

Given a key value, obtains a SqlConnection to the shard in the mapping that contains the key value.

Parameters:

key - Input key value.
constructMapping - Delegate to construct a mapping object.
errorCategory - Error category.
connectionString - Connection string with credential information, the DataSource and Database are obtained from the results of the lookup operation for key.
options - Options for validation operations to perform on opened connection.

Returns:

An opened SqlConnection.

openConnectionForKeyAsync

protected final Callable openConnectionForKeyAsync(KeyT key, ActionGeneric3Param constructMapping, ShardManagementErrorCategory errorCategory, String connectionString)

Parameters:

key
constructMapping
errorCategory
connectionString

openConnectionForKeyAsync

protected final Callable openConnectionForKeyAsync(KeyT key, ActionGeneric3Param constructMapping, ShardManagementErrorCategory errorCategory, String connectionString, ConnectionOptions options)

Given a key value, asynchronously obtains a SqlConnection to the shard in the mapping that contains the key value.

Parameters:

key - Input key value.
constructMapping - Delegate to construct a mapping object.
errorCategory - Error category.
connectionString - Connection string with credential information, the DataSource and Database are obtained from the results of the lookup operation for key.
options - Options for validation operations to perform on opened connection.

Returns:

A task encapsulating an opened SqlConnection as the result.

remove

protected final void remove(MappingT mapping, ActionGeneric3Param constructMapping, UUID lockOwnerId)

Removes a mapping from shard map.

Parameters:

mapping - Mapping being removed.
constructMapping - Delegate to construct a mapping object.
lockOwnerId - Lock owner id of this mapping

setStatus

protected static static MappingT setStatus(MappingT mapping, StatusT status, Function getStatus, Function createUpdate, ActionGeneric3Param runUpdate)

Sets the status of a shard mapping

Parameters:

mapping - Mapping being added.
status - Status of mapping mapping being added.
getStatus - Delegate to construct new status from status input status.
createUpdate - Delegate to construct new update from new status returned by getStatus getStatus.
runUpdate - Delegate to perform update from the mapping input mapping and the update object returned by getStatus createUpdate .

setStatus

protected static static MappingT setStatus(MappingT mapping, StatusT status, Function getStatus, Function createUpdate, ActionGeneric3Param runUpdate, UUID lockOwnerId)

Sets the status of a shard mapping

Parameters:

mapping - Mapping being added.
status - Status of mapping mapping being added.
getStatus - Delegate to construct new status from status input status.
createUpdate - Delegate to construct new update from new status returned by getStatus getStatus.
runUpdate - Delegate to perform update from the mapping input mapping and the update object returned by getStatus createUpdate .
lockOwnerId - Lock owner id of this mapping

update

protected final, StatusT> MappingT update(MappingT currentMapping, UpdateT update, ActionGeneric3Param constructMapping, Function statusAsInt, Function intAsStatus)

Allows for update to a mapping with the updates provided in the update parameter.

Parameters:

currentMapping - Mapping being updated.
update - Updated properties of the Shard.
constructMapping - Delegate to construct a mapping object.
statusAsInt - Delegate to get the mapping status as an integer value.
intAsStatus - Delegate to get the mapping status from an integer value.

Returns:

New instance of mapping with updated information.

update

protected final, StatusT> MappingT update(MappingT currentMapping, UpdateT update, ActionGeneric3Param constructMapping, Function statusAsInt, Function intAsStatus, UUID lockOwnerId)

Allows for update to a mapping with the updates provided in the update parameter.

Parameters:

currentMapping - Mapping being updated.
update - Updated properties of the Shard.
constructMapping - Delegate to construct a mapping object.
statusAsInt - Delegate to get the mapping status as an integer value.
intAsStatus - Delegate to get the mapping status from an integer value.
lockOwnerId - Lock owner id of this mapping

Returns:

New instance of mapping with updated information.

Applies to