Class SchemaId

java.lang.Object
io.permazen.schema.SchemaId
All Implemented Interfaces:
Serializable

public class SchemaId extends Object implements Serializable
A unique identifier that corresponds to the structure and encoding of an individual 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 SchemaItems, 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 SchemaModels 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.

SchemaIds for SchemaItems

For SchemaItems, 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 SchemaCompositeIndexs, the structure(s) of the indexed field(s).

SchemaIds for SchemaModels

SchemaId's are also used to determine whether two SchemaModels are structurally compatible. Two SchemaModels 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 SchemaIds.

See Also:
  • Field Details

    • PATTERN

      public static final String PATTERN
      The regular expression that all SchemaId's must match.
    • NUM_HASH_BYTES

      public static final int NUM_HASH_BYTES
      The number of hash bytes in a SchemaId.
      See Also:
  • Constructor Details

  • Method Details

    • getId

      public String getId()
      Get the schema ID in string form.
      Returns:
      schema structure ID
    • getItemType

      public ItemType getItemType()
      Get the ItemType of the schema item that originally generated this schema ID.
      Returns:
      original schema item type
      See Also:
      • SchemaSupport.getItemType()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object