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 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. They provide a simple way to determine whether two schema items are structurally compatible. Two schema items are structurally compatibile if they are identified and encoded in the same way and therefore can and should share the same storage ID assignment in the database. The String form of a SchemaId looks like SimpleField_12e983a72e72ed56741ddc45e47d3377, where the prefix indicates the schema item type.

SchemaId's are also used to quickly determine whether two SchemaModels are identical except for explicit storage ID assignments. If so, and assuming they don't have any conflicting explicit storage ID's, then they can map to the same Schema in the database. In other words, they can share the same schema index, analogous to how two SchemaItems with the same SchemaId can share the same storage ID.

Note that SchemaModel equality is a stronger condition that includes storage ID's.

For SchemaItems, a SchemaId covers its "structure", where that is defined as:

  • For each SchemaObjectType, its object type name.
  • For each ComplexSchemaField, it's field name, complex field type (list, set, or map), and the structures of its sub-field(s).
  • For counter fields, it's name and field type (i.e., counter).
  • For simple fields, it's 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).

SchemaId calculations do not include storage ID's; instead, storage ID's are assigned when a SchemaModel is recorded in a database.

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