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 and schema index tables.

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
    • getObjectTypeName

      public String getObjectTypeName(int storageId)
      Get the object type name corresponding to the given storage ID.
      Parameters:
      storageId - object type storage ID
      Returns:
      associated object type name
      Throws:
      IllegalArgumentException - if storageId is invalid or unknown
    • withSchemaAdded

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

      The schema may already be registered in this bundle. If so, null is returned, reflecting that no change is needed. Otherwise, an encoding of this instance with schemaModel is returned.

      In either case, any explicit storage ID assignments in schemaModel are checked for conflicts with the schemas already registered in this bundle, and any unassigned storage ID's in schemaModel are automatically assigned.

      Parameters:
      schemaIndex - schema table index at which to add the schema or zero for next available
      schemaModel - the new schema to add
      Returns:
      an encoding of this instance with schemaModel added, or null if schemaModel is already registered
      Throws:
      SchemaMismatchException - if schemaModel has one or more explicit storage ID assignments and one of them conflicts with a storage ID assignment already registered 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