Class SchemaId
- All Implemented Interfaces:
Serializable
SchemaItem
component
of a SchemaModel
, or an entire SchemaModel
.
SchemaId
's are calculated by taking a secure hash over the structural components of some schema item such as
an object type, a field, or an index, or over an entire SchemaModel
.
For SchemaItem
s, they provide a simple way to determine whether two schema items have the same structure,
meaning they are identified and encoded in the same way. Two SchemaItem
that have the same
SchemaId
will always have the same storage ID assigned when they are recorded in a database.
For an entire SchemaModel
, the SchemaId
serves the same purpose by encompassing all of the
SchemaItem
components of the SchemaModel
. Two SchemaModel
s that have the same SchemaId
will always have the same schema index assigned when they are recorded in a database (that is, they are considered
the same schema).
The String
form of a SchemaId
looks like SimpleField_12e983a72e72ed56741ddc45e47d3377
,
where the prefix before the underscore indicates the thing being identified.
SchemaId
s for SchemaItem
s
For SchemaItem
s, the SchemaId
hash function covers its "structure", which is defined as:
- For each
SchemaObjectType
, its object type name. - For each
ComplexSchemaField
, its field name, complex field type (list, set, or map), and the structures of its sub-field(s). - For counter fields, its name and field type (i.e., counter).
- For simple fields, its name field type (i.e., simple), and encoding.
- For enum and enum array fields, also the enum's identifier list.
- For
SchemaCompositeIndex
s, the structure(s) of the indexed field(s).
SchemaId
s for SchemaModel
s
SchemaId
's are also used to determine whether two SchemaModel
s are structurally compatible.
Two SchemaModel
s with the same SchemaId
will always share the same schema index in a database.
The SchemaId
hash of a SchemaModel
includes all of its SchemaItem
components. This hash does
not include any explicit storage ID assignments. As a result, attempting to register a SchemaModel
having explicit storage ID assignments that disagree with assignments already recorded in a database will result
in a SchemaMismatchException
. For this reason, explicit storage ID assignments are discouraged.
Note that equals()
includes explicit storage ID assignments, so in the case that any exist
this is a stronger test than just comparing SchemaId
s.
- See Also:
-
Field Details
-
Constructor Details
-
SchemaId
Constructor.- Parameters:
id
- the schema structure ID in string form- Throws:
IllegalArgumentException
- ifid
is null or invalid
-
SchemaId
Constructor.- Parameters:
itemType
- schema item typehash
-NUM_HASH_BYTES
hash bytes- Throws:
IllegalArgumentException
- if either parameter is nullIllegalArgumentException
- ifbytes
has the wrong length
-
-
Method Details
-
getId
Get the schema ID in string form.- Returns:
- schema structure ID
-
getItemType
Get theItemType
of the schema item that originally generated this schema ID.- Returns:
- original schema item type
- See Also:
-
SchemaSupport.getItemType()
-
toString
-
hashCode
public int hashCode() -
equals
-