Dela via


ShardKey Class

  • java.lang.Object
    • Comparable<ShardKey>
      • com.microsoft.azure.elasticdb.shard.base.ShardKey

public class ShardKey

Shard key value. Wraps the type and value and allows normalization/denormalization for serialization.

Field Summary

Modifier and Type Field and Description
final int MAXIMUM_VAR_BYTES_KEY_SIZE

Maximum size allowed for VarBytes keys.

final int SIZE_OF_DATE_TIME_OFFSET

Size of Guid.

final int SIZE_OF_GUID

Size of Guid.

Constructor Summary

Constructor Description
ShardKey()

endregion

region Constructors

ShardKey(byte[] value)

Constructs a shard key using a byte array.

ShardKey(Duration value)

Constructs a shard key using TimeSpan value.

ShardKey(int value)

Constructs a shard key using 32-bit integer value.

ShardKey(LocalDateTime value)

Constructs a shard key using DateTime value.

ShardKey(long value)

Constructs a shard key using 64-bit integer value.

ShardKey(Object value)

Constructs a shard key using given object.

ShardKey(OffsetDateTime value)

Constructs a shard key using TimeSpan value.

ShardKey(ShardKeyType keyType, Object value)

Constructs a shard key using given object and keyType.

ShardKey(UUID value)

Constructs a shard key using a Guid.

Method Summary

Modifier and Type Method and Description
int compareTo(ShardKey other)

Compares between two ShardKey values.

ShardKeyType detectShardKeyType(Object value)

Given an object detect its ShardKeyType.

boolean equals(Object obj)

Determines whether the specified object is equal to the current object.

boolean equals(ShardKey other)

Performs equality comparison with another given ShardKey.

ShardKey fromRawValue(ShardKeyType keyType, byte[] rawValue)

endregion

Instantiates a new shard key using the specified type and binary representation.

Class getDataType()

Gets the type of the value present in the object.

boolean getHasValue()

endregion

True if the key has a value; otherwise, false. Positive infinity returns false.

boolean getIsMax()

True if the key value is positive infinity; otherwise, false.

boolean getIsMin()

Returns true if the key value is negative infinity; otherwise, false.

ShardKeyType getKeyType()

Gets the type of the shard key.

ShardKey getMaxBinary()

Represents negative infinity.

ShardKey getMaxDateTime()

Represents negative infinity.

ShardKey getMaxDateTimeOffset()

Represents negative infinity.

ShardKey getMaxGuid()

Represents negative infinity.

ShardKey getMaxInt()

Represents negative infinity.

ShardKey getMaxLong()

Represents negative infinity.

ShardKey getMaxTimeSpan()

Represents negative infinity.

ShardKey getMinBinary()

Represents negative infinity.

ShardKey getMinDateTime()

Represents negative infinity.

ShardKey getMinDateTimeOffset()

Represents negative infinity.

ShardKey getMinGuid()

Represents negative infinity.

ShardKey getMinInt()

endregion

region Static Getters Represents negative infinity.

ShardKey getMinLong()

Represents negative infinity.

ShardKey getMinTimeSpan()

Represents negative infinity.

ShardKey getNextKey()

Gets the next higher key

byte [] getRawValue()

Gets a byte array representing the key value.

String getStoreValue()

Converts the object to its string representation.

Object getValue()

Gets the denormalized value of the key.

int hashCode()

Calculates the hash code for this instance.

boolean isSupportedType(Class type)

Checks whether the specified type is supported as ShardKey type.

ShardKey max(ShardKey left, ShardKey right)

Gets the maximum of two shard keys.

ShardKey min(ShardKey left, ShardKey right)

Gets the minimum of two shard keys.

boolean opEquality(ShardKey left, ShardKey right)

Equality operator.

boolean opGreaterThan(ShardKey left, ShardKey right)

Compares two ShardKey using lexicographic order (greater than).

boolean opGreaterThanOrEqual(ShardKey left, ShardKey right)

Compares two ShardKey using lexicographic order (greater or equal).

boolean opInequality(ShardKey left, ShardKey right)

Inequality operator.

boolean opLessThan(ShardKey left, ShardKey right)

endregion

region Operators Compares two ShardKey using lexicographic order (less than).

boolean opLessThanOrEqual(ShardKey left, ShardKey right)

Compares two ShardKey using lexicographic order (less or equal).

int qpHash(int hashKey, int value)

Mix up the hash key and add the specified value into it.

ShardKeyType shardKeyTypeFromType(Class type)

Gets the ShardKeyType corresponding to CLR type.

String toString()

Converts the object to its string representation.

Class typeFromShardKeyType(ShardKeyType keyType)

Gets the CLR type corresponding to the specified ShardKeyType.

Field Details

MAXIMUM_VAR_BYTES_KEY_SIZE

public static final int MAXIMUM_VAR_BYTES_KEY_SIZE= 128

Maximum size allowed for VarBytes keys.

SIZE_OF_DATE_TIME_OFFSET

public static final int SIZE_OF_DATE_TIME_OFFSET= 16

Size of Guid.

SIZE_OF_GUID

public static final int SIZE_OF_GUID= 16

Size of Guid.

Constructor Details

ShardKey

public ShardKey()

endregion

region Constructors

ShardKey

public ShardKey(byte[] value)

Constructs a shard key using a byte array.

Parameters:

value - Input byte array.

ShardKey

public ShardKey(Duration value)

Constructs a shard key using TimeSpan value.

Parameters:

value - Input TimeSpan.

ShardKey

public ShardKey(int value)

Constructs a shard key using 32-bit integer value.

Parameters:

value - Input 32-bit integer.

ShardKey

public ShardKey(LocalDateTime value)

Constructs a shard key using DateTime value.

Parameters:

value - Input DateTime.

ShardKey

public ShardKey(long value)

Constructs a shard key using 64-bit integer value.

Parameters:

value - Input 64-bit integer.

ShardKey

public ShardKey(Object value)

Constructs a shard key using given object.

Parameters:

value - Input object.

ShardKey

public ShardKey(OffsetDateTime value)

Constructs a shard key using TimeSpan value.

Parameters:

value - Input DateTimeOffset.

ShardKey

public ShardKey(ShardKeyType keyType, Object value)

Constructs a shard key using given object and keyType.

Parameters:

keyType - The key type of value in object.
value - Input object.

ShardKey

public ShardKey(UUID value)

Constructs a shard key using a Guid.

Parameters:

value - Input Guid.

Method Details

compareTo

public int compareTo(ShardKey other)

Compares between two ShardKey values.

Parameters:

other - The ShardKey compared with this object.

Returns:

0 for equality, <-1 if this key is less than other ,> 1 otherwise.

detectShardKeyType

public static ShardKeyType detectShardKeyType(Object value)

Given an object detect its ShardKeyType.

Parameters:

value - Given value. Must be non-null.

Returns:

Corresponding ShardKeyType.

equals

public boolean equals(Object obj)

Determines whether the specified object is equal to the current object.

Parameters:

obj - The object to compare with the current object.

Returns:

True if the specified object is equal to the current object; otherwise, false.

equals

public boolean equals(ShardKey other)

Performs equality comparison with another given ShardKey.

Parameters:

other - ShardKey to compare with.

Returns:

True if same shard key, false otherwise.

fromRawValue

public static ShardKey fromRawValue(ShardKeyType keyType, byte[] rawValue)

endregion

Instantiates a new shard key using the specified type and binary representation.

Parameters:

keyType - Type of the shard key (Int32, Int64, Guid, byte[] etc.).
rawValue - Binary representation of the key.

Returns:

A new shard key instance.

getDataType

public Class getDataType()

Gets the type of the value present in the object.

getHasValue

public boolean getHasValue()

endregion

True if the key has a value; otherwise, false. Positive infinity returns false.

getIsMax

public boolean getIsMax()

True if the key value is positive infinity; otherwise, false.

getIsMin

public boolean getIsMin()

Returns true if the key value is negative infinity; otherwise, false.

getKeyType

public ShardKeyType getKeyType()

Gets the type of the shard key.

getMaxBinary

public static ShardKey getMaxBinary()

Represents negative infinity.

getMaxDateTime

public static ShardKey getMaxDateTime()

Represents negative infinity.

getMaxDateTimeOffset

public static ShardKey getMaxDateTimeOffset()

Represents negative infinity.

getMaxGuid

public static ShardKey getMaxGuid()

Represents negative infinity.

getMaxInt

public static ShardKey getMaxInt()

Represents negative infinity.

getMaxLong

public static ShardKey getMaxLong()

Represents negative infinity.

getMaxTimeSpan

public static ShardKey getMaxTimeSpan()

Represents negative infinity.

getMinBinary

public static ShardKey getMinBinary()

Represents negative infinity.

getMinDateTime

public static ShardKey getMinDateTime()

Represents negative infinity.

getMinDateTimeOffset

public static ShardKey getMinDateTimeOffset()

Represents negative infinity.

getMinGuid

public static ShardKey getMinGuid()

Represents negative infinity.

getMinInt

public static ShardKey getMinInt()

endregion

region Static Getters Represents negative infinity.

getMinLong

public static ShardKey getMinLong()

Represents negative infinity.

getMinTimeSpan

public static ShardKey getMinTimeSpan()

Represents negative infinity.

getNextKey

public ShardKey getNextKey()

Gets the next higher key

Returns:

Incremented newly constructed ShardKey Returns a new ShardKey that is the numerical successor of this ShardKey (add a binary bit). For example, if this ShardKey has the integer value 0, getNextKey() returns a ShardKey with the value 1. Alternatively, if this ShardKey is a byte array with the value 0x1234, getNextKey() returns a ShardKey with the value 0x1234...251 zeros....1

getRawValue

public byte [] getRawValue()

Gets a byte array representing the key value.

getStoreValue

public String getStoreValue()

Converts the object to its string representation.

Returns:

String representation of the object.

getValue

public Object getValue()

Gets the denormalized value of the key.

hashCode

public int hashCode()

Calculates the hash code for this instance.

Returns:

Hash code for the object.

isSupportedType

public static boolean isSupportedType(Class type)

Checks whether the specified type is supported as ShardKey type.

Parameters:

type - Input type.

Returns:

True if supported, false otherwise.

max

public static ShardKey max(ShardKey left, ShardKey right)

Gets the maximum of two shard keys.

Parameters:

left - Left hand side.
right - Right hand side.

Returns:

Maximum of two shard keys.

min

public static ShardKey min(ShardKey left, ShardKey right)

Gets the minimum of two shard keys.

Parameters:

left - Left hand side.
right - Right hand side.

Returns:

Minimum of two shard keys.

opEquality

public static boolean opEquality(ShardKey left, ShardKey right)

Equality operator.

Parameters:

left - Left hand side
right - Right hand side

Returns:

True if the two objects are equal, false in all other cases

opGreaterThan

public static boolean opGreaterThan(ShardKey left, ShardKey right)

Compares two ShardKey using lexicographic order (greater than).

Parameters:

left - Left hand side ShardKey of the operator.
right - Right hand side ShardKey of the operator.

Returns:

True if lhs> rhs

opGreaterThanOrEqual

public static boolean opGreaterThanOrEqual(ShardKey left, ShardKey right)

Compares two ShardKey using lexicographic order (greater or equal).

Parameters:

left - Left hand side ShardKey of the operator.
right - Right hand side ShardKey of the operator.

Returns:

True if lhs>= rhs

opInequality

public static boolean opInequality(ShardKey left, ShardKey right)

Inequality operator.

Parameters:

left - Left hand side
right - Right hand side

Returns:

True if the two objects are not equal, false in all other cases

opLessThan

public static boolean opLessThan(ShardKey left, ShardKey right)

endregion

region Operators Compares two ShardKey using lexicographic order (less than).

Parameters:

left - Left hand side ShardKey of the operator.
right - Right hand side ShardKey of the operator.

Returns:

True if lhs <rhs

opLessThanOrEqual

public static boolean opLessThanOrEqual(ShardKey left, ShardKey right)

Compares two ShardKey using lexicographic order (less or equal).

Parameters:

left - Left hand side ShardKey of the operator.
right - Right hand side ShardKey of the operator.

Returns:

True if lhs <= rhs

qpHash

public static int qpHash(int hashKey, int value)

Mix up the hash key and add the specified value into it.

Parameters:

hashKey - The previous value of the hash
value - The additional value to mix into the hash

Returns:

The updated hash value

shardKeyTypeFromType

public static ShardKeyType shardKeyTypeFromType(Class type)

Gets the ShardKeyType corresponding to CLR type.

Parameters:

type - CLR type.

Returns:

ShardKey type.

toString

public String toString()

Converts the object to its string representation.

Returns:

String representation of the object.

typeFromShardKeyType

public static Class typeFromShardKeyType(ShardKeyType keyType)

Gets the CLR type corresponding to the specified ShardKeyType.

Parameters:

keyType - Input ShardKeyType.

Returns:

CLR type.

Applies to