Class SchemaBundle

java.lang.Object
io.permazen.core.SchemaBundle

public class SchemaBundle extends Object
Reflects the Schema table currently recorded in a Database as seen by a particular Transaction. This includes any Schemas that may have been added or deleted during the transaction.

This class also captures the current Storage ID table.

Instances are immutable and thread safe.

  • Constructor Details

  • Method Details

    • getEncoded

      public SchemaBundle.Encoded getEncoded()
      Get the encoded form of this instance.
      Returns:
      encoded schema bundle
    • getEncodingRegistry

      public EncodingRegistry getEncodingRegistry()
      Get the EncodingRegistry associated with this instance.
      Returns:
      encoding registry
    • getSchemasBySchemaIndex

      public NavigableMap<Integer,Schema> getSchemasBySchemaIndex()
      Get all of the schemas in this bundle keyed by schema index.
      Returns:
      unmodifiable map of Schemas indexed by schema index
    • getSchemasBySchemaId

      public Map<SchemaId,Schema> getSchemasBySchemaId()
      Get all of the schemas in this bundle keyed by SchemaId.
      Returns:
      unmodifiable map of Schemas indexed by schema ID
    • getSchema

      public Schema getSchema(int schemaIndex)
      Get the Schema in this bundle with the given schema index.
      Parameters:
      schemaIndex - schema index
      Returns:
      corresponding schema
      Throws:
      IllegalArgumentException - if schemaIndex is invalid or unknown
    • getSchema

      public Schema getSchema(SchemaId schemaId)
      Get the Schema in this bundle having the given schema ID.
      Parameters:
      schemaId - schema structure ID
      Returns:
      schema with ID schemaId
      Throws:
      IllegalArgumentException - if schemaId is not known
    • getSchemaIdsByStorageId

      public Map<Integer,SchemaId> getSchemaIdsByStorageId()
      Get all of the storage ID's in this bundle with their corresponding SchemaId's.
      Returns:
      unmodifiable map from storage ID to SchemaId
    • getStorageId

      public int getStorageId(SchemaId schemaId)
      Get the storage ID corresponding to the given schema ID.
      Parameters:
      schemaId - schema structure ID
      Returns:
      associated storage ID
      Throws:
      IllegalArgumentException - if schemaId is not known
    • withSchemaAdded

      public SchemaBundle.Encoded withSchemaAdded(int schemaIndex, SchemaModel schemaModel)
      Build an SchemaBundle.Encoded instance with the specified schema added.

      Any required storage ID assignments will be added automatically.

      Parameters:
      schemaIndex - schema table index at which to add the schema or zero for next available
      schemaModel - the new schema to add
      Throws:
      IllegalArgumentException - if the schema already exists
      SchemaMismatchException - if schemaModel has any explicit storage ID assignments that conflict with other schemas in this bundle
      SchemaMismatchException - if schemaIndex is non-zero and some schema already exists at that index
      IllegalArgumentException - if schemaModel is not locked down
      IllegalArgumentException - if schemaModel does not validate
      IllegalArgumentException - if schemaModel is null
      IllegalArgumentException - if schemaIndex is negative
    • withSchemaRemoved

      public SchemaBundle.Encoded withSchemaRemoved(SchemaId schemaId)
      Build an SchemaBundle.Encoded instance with the specified schema removed.

      Any obsolete storage ID assignments will be removed automatically.

      Parameters:
      schemaId - ID of the schema to remove
      Throws:
      IllegalArgumentException - if schemaId is null
      IllegalArgumentException - if the schema does not exist