ShardKey Class
- java.
lang. Object - Comparable<ShardKey>
- com.
microsoft. azure. elasticdb. shard. base. ShardKey
- com.
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. |
Shard |
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. |
Shard |
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. |
Shard |
getKeyType()
Gets the type of the shard key. |
Shard |
getMaxBinary()
Represents negative infinity. |
Shard |
getMaxDateTime()
Represents negative infinity. |
Shard |
getMaxDateTimeOffset()
Represents negative infinity. |
Shard |
getMaxGuid()
Represents negative infinity. |
Shard |
getMaxInt()
Represents negative infinity. |
Shard |
getMaxLong()
Represents negative infinity. |
Shard |
getMaxTimeSpan()
Represents negative infinity. |
Shard |
getMinBinary()
Represents negative infinity. |
Shard |
getMinDateTime()
Represents negative infinity. |
Shard |
getMinDateTimeOffset()
Represents negative infinity. |
Shard |
getMinGuid()
Represents negative infinity. |
Shard |
getMinInt()
endregion region Static Getters Represents negative infinity. |
Shard |
getMinLong()
Represents negative infinity. |
Shard |
getMinTimeSpan()
Represents negative infinity. |
Shard |
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. |
Shard |
max(ShardKey left, ShardKey right)
Gets the maximum of two shard keys. |
Shard |
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. |
Shard |
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:
ShardKey
public ShardKey(Duration value)
Constructs a shard key using TimeSpan value.
Parameters:
ShardKey
public ShardKey(int value)
Constructs a shard key using 32-bit integer value.
Parameters:
ShardKey
public ShardKey(LocalDateTime value)
Constructs a shard key using DateTime value.
Parameters:
ShardKey
public ShardKey(long value)
Constructs a shard key using 64-bit integer value.
Parameters:
ShardKey
public ShardKey(Object value)
Constructs a shard key using given object.
Parameters:
ShardKey
public ShardKey(OffsetDateTime value)
Constructs a shard key using TimeSpan value.
Parameters:
ShardKey
public ShardKey(ShardKeyType keyType, Object value)
Constructs a shard key using given object and keyType.
Parameters:
ShardKey
public ShardKey(UUID value)
Constructs a shard key using a Guid.
Parameters:
Method Details
compareTo
detectShardKeyType
public static ShardKeyType detectShardKeyType(Object value)
Given an object detect its ShardKeyType.
Parameters:
Returns:
equals
public boolean equals(Object obj)
Determines whether the specified object is equal to the current object.
Parameters:
Returns:
equals
public boolean equals(ShardKey other)
Performs equality comparison with another given ShardKey.
Parameters:
Returns:
fromRawValue
public static ShardKey fromRawValue(ShardKeyType keyType, byte[] rawValue)
endregion
Instantiates a new shard key using the specified type and binary representation.
Parameters:
Returns:
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:
getRawValue
public byte [] getRawValue()
Gets a byte array representing the key value.
getStoreValue
public String getStoreValue()
Converts the object to its string representation.
Returns:
getValue
public Object getValue()
Gets the denormalized value of the key.
hashCode
public int hashCode()
Calculates the hash code for this instance.
Returns:
isSupportedType
public static boolean isSupportedType(Class type)
Checks whether the specified type is supported as ShardKey type.
Parameters:
Returns:
max
public static ShardKey max(ShardKey left, ShardKey right)
Gets the maximum of two shard keys.
Parameters:
Returns:
min
public static ShardKey min(ShardKey left, ShardKey right)
Gets the minimum of two shard keys.
Parameters:
Returns:
opEquality
public static boolean opEquality(ShardKey left, ShardKey right)
Equality operator.
Parameters:
Returns:
opGreaterThan
opGreaterThanOrEqual
opInequality
public static boolean opInequality(ShardKey left, ShardKey right)
Inequality operator.
Parameters:
Returns:
opLessThan
opLessThanOrEqual
qpHash
public static int qpHash(int hashKey, int value)
Mix up the hash key and add the specified value into it.
Parameters:
Returns:
shardKeyTypeFromType
public static ShardKeyType shardKeyTypeFromType(Class type)
Gets the ShardKeyType corresponding to CLR type.
Parameters:
Returns:
toString
public String toString()
Converts the object to its string representation.
Returns:
typeFromShardKeyType
public static Class typeFromShardKeyType(ShardKeyType keyType)
Gets the CLR type corresponding to the specified ShardKeyType.
Parameters:
Returns: