Interface SchemaService

All Superinterfaces:
AutoCloseable, NamedImplementation
All Known Subinterfaces:
SchemaServiceAuthenticatedMutator, SchemaServiceUtilLayer
All Known Implementing Classes:
SchemaService.Delegating, SchemaServiceEtcdImpl, SchemaServiceKvImpl, SchemaServiceLegacyTransientImpl, StaticSchemaServiceImpl

public interface SchemaService
extends NamedImplementation, AutoCloseable
Provides methods for interacting with the system Schema store.
  • Method Details

    • about

      String about()
      Information about a SchemaService instance. Useful for debugging.
      Returns:
      a string containing information about the instance
    • authenticate

      default boolean authenticate​(@NotNull String user, @NotNull String password)
      Authenticate using the given user and password. Implementations are not required to allow re-authentication.
      Parameters:
      user - the user to authenticate
      password - the password for the user
      Returns:
      true only if the authentication succeeded
    • authenticate

      boolean authenticate​(@NotNull String user, @NotNull String password, @NotNull String operateAs)
      Authenticate using the given user and password, operating as the operateAs user. Implementations are not required to allow re-authentication.
      Parameters:
      user - the user to authenticate
      password - the password for the user
      operateAs - attempt to operate as this effective user
      Returns:
      true only if the authentication succeeded
    • authenticate

      boolean authenticate()
      Authenticate using default authentication. This will be using the default private key or however WAuthenticationClientManager.DEFAULT has been authenticated.
      Returns:
      true only if the authentication succeeded
    • fromDefinition

      @NotNull default MutableSchema fromDefinition​(@NotNull TableDefinition definition, @NotNull String namespace, @NotNull String tableName, int storageType, @NotNull NamespaceSet set) throws SchemaValidationException
      Create a MutableSchema that supports SchemaXml from a TableDefinition, using the specified namespace, table name, storage type and NamespaceSet. Values of namespace, table name, storage type and Namespace set from the input definition are not used.
      Parameters:
      definition - create a schema based on this table definition
      namespace - the namespace of the new schema
      tableName - the table name of the new schema
      storageType - the storage type of the table
      set - the namespace set for the schema
      Returns:
      a new MutableSchema.
      Throws:
      SchemaValidationException - if there was a problem creating the new schema.
    • fromDefinition

      @NotNull MutableSchema fromDefinition​(@NotNull TableDefinition definition, @NotNull String namespace, @NotNull String tableName, int storageType, @NotNull NamespaceSet set, boolean useNanosecondTimePrecision) throws SchemaValidationException
      Create a MutableSchema that supports SchemaXml from a TableDefinition, using the specified namespace, table name, storage type and NamespaceSet. Values of namespace, table name, storage type and Namespace set from the input definition are not used.
      Parameters:
      definition - create a schema based on this table definition
      namespace - the namespace of the new schema
      tableName - the table name of the new schema
      storageType - the storage type of the table
      set - the namespace set for the schema
      useNanosecondTimePrecision - whether to set nanosecond time precision for DateTime columns
      Returns:
      a new MutableSchema.
      Throws:
      SchemaValidationException - if there was a problem creating the new schema.
    • fromDefinition

      @NotNull default MutableSchema fromDefinition​(@NotNull TableDefinition definition, @NotNull String namespace, @NotNull String tableName, int storageType, @NotNull String set) throws SchemaValidationException
      Convenience method translates the namespace set from string to NamespaceSet and delegate to fromDefinition(TableDefinition, String, String, int, NamespaceSet)
      Throws:
      SchemaValidationException
    • fromDefinition

      @NotNull default MutableSchema fromDefinition​(@NotNull TableDefinition definition, @NotNull NamespaceSet namespaceSet) throws SchemaValidationException
      Create a MutableSchema that supports SchemaXml from a TableDefinition, using the given namespace set and taking namespace, table name, and storage type from the given TableDefinition.
      Parameters:
      definition - create a schema based on this table definition
      namespaceSet - the namespace set for the schema
      Returns:
      a new MutableSchema.
      Throws:
      SchemaValidationException - if there was a problem creating the new schema
    • fromDefinition

      @NotNull default MutableSchema fromDefinition​(@NotNull TableDefinition definition, @NotNull String namespaceSet) throws SchemaValidationException
      Convenience method translates the namespace set from string to NamespaceSet and delegate to fromDefinition(TableDefinition, NamespaceSet)
      Throws:
      SchemaValidationException
    • fromElement

      @NotNull SchemaXml fromElement​(org.jdom2.Element elem) throws SchemaValidationException
      Create a Schema that supports SchemaXml from an input Element. The input element will be validated.
      Parameters:
      elem - the element to create the schema from
      Returns:
      a new Schema
      Throws:
      SchemaValidationException - if the input element is not a properly structured Schema element
    • asElement

      org.jdom2.Element asElement​(Schema schema)
    • asSchemaXml

      SchemaXml asSchemaXml​(Schema schema)
    • getLatestSchema

      @Nullable Schema getLatestSchema​(@NotNull String namespace, @NotNull String tableName)
      Get the latest version of the Schema defined by namespace and table name
      Parameters:
      namespace - the namespace of the table
      tableName - the table name
      Returns:
      the latest version of namespace.tablename or null if none was found
    • getSchema

      @Nullable default Schema getSchema​(@NotNull String namespace, @NotNull String tableName)
      Convenience method for getLatestSchema(String, String).
    • getLatestSchemaXml

      @Nullable SchemaXml getLatestSchemaXml​(@NotNull String namespace, @NotNull String tableName)
      Get the latest version of the Schema defined by namespace and table name, as an implementation supporting SchemaXml.
      Parameters:
      namespace - the namespace of the table
      tableName - the table name
      Returns:
      the latest version of namespace.tablename or null if none was found
    • getSchema

      @Nullable Schema getSchema​(@NotNull String namespace, @NotNull String tableName, @NotNull SchemaVersion version)
      Get the specified version of the Schema defined by namespace and table name
      Parameters:
      namespace - the namespace of the table
      tableName - the table name
      version - the version of this schema to retrieve
      Returns:
      the requested version of the schema for namespace.tableName or null if none was found
    • getAllSchemas

      @NotNull Collection<Schema> getAllSchemas()
      Get a collection of all known schemas in the system. The latest version of each will be returned. // TODO: subject to ACL visibility?
      Returns:
      a collection of all known schemas
    • getSchemas

      @NotNull Collection<Schema> getSchemas​(@NotNull NamespaceSet namespaceSet)
      Get a collection of all known schemas in the system, with the given namespace set. The latest version of each will be returned.
      Returns:
      a collection of all known schemas in the given namespace set
    • getSchemasForNamespaceSet

      @NotNull default Collection<Schema> getSchemasForNamespaceSet​(@NotNull String namespaceSet)
      Convenience method translates the namespace set from string to NamespaceSet and delegate to getSchemas(NamespaceSet)
    • getSchemas

      @NotNull Collection<Schema> getSchemas​(@NotNull String namespace)
      Get a collection of all known schemas in the given namespace. The latest version of each will be returned.
      Returns:
      a collection of all known schemas in the given namespace
    • getLatestTableDefinitionSchema

      @Nullable TableDefinitionSchema getLatestTableDefinitionSchema​(@NotNull String namespace, @NotNull String tableName)
      Get the latest version of the TableDefinitionSchema defined by namespace and table name
      Parameters:
      namespace - the namespace of the table
      tableName - the table name
      Returns:
      the latest version of namespace.tableName or null if none was found
    • getLatestTableDefinition

      @Nullable default TableDefinition getLatestTableDefinition​(@NotNull String namespace, @NotNull String tableName)
      Get the latest version of the Schema for the namespace and table name, and return its TableDefinition.
      Parameters:
      namespace - The namespace of the table
      tableName - The table name
      Returns:
      The TableDefinition for the latest version of namespace.tableName or null if none was found
    • getLatestTableDefinitionRequired

      default TableDefinition getLatestTableDefinitionRequired​(@NotNull String namespace, @NotNull String tableName)
      Get the latest version of the Schema for the namespace and table name, and return its TableDefinition.
      Parameters:
      namespace - The namespace of the table
      tableName - The table name
      Returns:
      The TableDefinition for the latest version of namespace.tableName
      Throws:
      SchemaException - if the Schema was not found
    • getNamespaceSet

      @NotNull NamespaceSet getNamespaceSet​(@NotNull String namespace) throws IllegalArgumentException
      Get the NamespaceSet for a particular namespace.
      Parameters:
      namespace - The namespace name
      Returns:
      the namespace set of the namespace
      Throws:
      IllegalArgumentException - if the namespace does not exist
    • containsNamespace

      boolean containsNamespace​(@NotNull String namespace, boolean includeDeleted)
      Find out whether the given namespace is known to the schema service.
      Parameters:
      namespace - the namespace in question
      includeDeleted - true if deleted namespaces should be considered
      Returns:
      true if the namespace is found
    • containsNamespace

      default boolean containsNamespace​(@NotNull String namespace)
      Find out whether the given namespace is known to the schema service.
      Parameters:
      namespace - the namespace in question
      Returns:
      true if the namespace is found
    • containsSchema

      boolean containsSchema​(@NotNull String namespace, @NotNull String tableName)
      Find out if the given schema exists. Does not check for deleted schemas.
      Parameters:
      namespace - the namespace of the table
      tableName - the table name
      Returns:
      true if a schema is found for namespace.tableName
    • listNamespaces

      @NotNull default Collection<String> listNamespaces()
      Get a collection of the namespaces available.
      Returns:
      a collection of namespace names
    • listNamespaces

      @NotNull Collection<String> listNamespaces​(boolean includeDeleted)
      Get a collection of the namespaces available.
      Parameters:
      includeDeleted - true if deleted namespaces should be included
      Returns:
      a collection of namespace names
    • listNamespaces

      @NotNull default Collection<String> listNamespaces​(@NotNull NamespaceSet namespaceSet)
      Get a collection of the namespaces available in the given namespace set.
      Parameters:
      namespaceSet - list namespaces in this namespace set (User, System)
      Returns:
      a collection of namespace names
    • listNamespaces

      @NotNull default Collection<String> listNamespaces​(@NotNull String namespaceSet)
      Convenience method translates the namespace set from string to NamespaceSet and delegate to listNamespaces(NamespaceSet)
    • listNamespaces

      @NotNull Collection<String> listNamespaces​(@NotNull NamespaceSet namespaceSet, boolean includeDeleted)
      Get a collection of the namespaces available in the given namespace set.
      Parameters:
      namespaceSet - list namespaces in this set (User, System)
      includeDeleted - true if deleted namespaces should be included
      Returns:
      a collection of namespace names
    • listTableNames

      @NotNull default Collection<String> listTableNames​(@NotNull String namespace)
      Get a collection of all table names in the specified namespace.
      Parameters:
      namespace - the name of the namespace
      Returns:
      a collection of all available schemas in namespace
    • listTableNames

      @NotNull Collection<String> listTableNames​(@NotNull String namespace, boolean includeDeleted)
      Get a collection of all table names in the specified namespace.
      Parameters:
      namespace - the name of the namespace
      includeDeleted - tf deleted schemas should be included
      Returns:
      a collection of all available schemas in namespace, empty list if namespace does not exit
    • listAllTables

      @NotNull Map<NamespaceSet,​Map<String,​Collection<String>>> listAllTables()
      Get a map of all known tables in all known namespaces for all namespace sets.
      Returns:
      all the table names, mapped by namespace set and namespace
    • createNamespace

      boolean createNamespace​(@NotNull NamespaceSet namespaceSet, @NotNull String namespaceName) throws SchemaException
      Add a namespace with the given name to the schema service, in the requested namespace set. Returns true if the namespace was added, false if it already exists. Throws a SchemaException if the namespace could not be added.
      Parameters:
      namespaceSet - add namespaceName to this namespace set
      namespaceName - name of the new namespace
      Returns:
      true if the namespace was added, false if it already exists.
      Throws:
      SchemaException - if the namespace could not be added to the given namespace set
    • createNamespace

      default boolean createNamespace​(@NotNull String namespaceSet, @NotNull String namespaceName) throws SchemaException
      Convenience method translates the namespace set from string to NamespaceSet and delegate to createNamespace(NamespaceSet, String)
      Throws:
      SchemaException
    • createNamespace

      boolean createNamespace​(@NotNull NamespaceSet namespaceSet, @NotNull String namespaceName, @NotNull String code, @NotNull String comment) throws SchemaException
      Add a namespace with the given name to the schema service, in the requested namespace set. Returns true if the namespace was added, false if it already exists. Throws a SchemaException if the namespace could not be added.
      Parameters:
      namespaceSet - add namespaceName to this namespace set
      namespaceName - name of the new namespace
      code - pass-thru to kv persistence, indicates the code source of this update
      comment - pass-thru to kv persistence - a comment for this update
      Returns:
      true if the namespace was added, false if it already exists.
      Throws:
      SchemaException - if the namespace could not be added to the given namespace set
    • removeNamespace

      void removeNamespace​(@NotNull String namespaceName, @NotNull String code, @NotNull String comment) throws SchemaException
      Remove the given namespace. The namespace must be empty (contain no schemas).
      Parameters:
      namespaceName - the namespace to remove
      code - pass-thru to kv persistence, indicates the code source of this update
      comment - pass-thru to kv persistence - a comment for this update
      Throws:
      SchemaException - if the namespace cannot be removed
    • removeNamespace

      void removeNamespace​(@NotNull String namespaceName)
      Remove the given namespace. The namespace must be empty (contain no schemas).
      Parameters:
      namespaceName - the namespace to remove
      Throws:
      SchemaException - if the namespace cannot be removed
    • addSchema

      @NotNull Schema addSchema​(@NotNull Schema newSchema) throws SchemaException
      Add the specified schema to the service.
      Parameters:
      newSchema - the schema to add
      Returns:
      the schema actually stored in the SchemaService
      Throws:
      SchemaException - if the schema could not be added
    • addSchema

      @NotNull Schema addSchema​(@NotNull Schema newSchema, @NotNull String code, @NotNull String comment) throws SchemaException
      Add the specified schema to the service.
      Parameters:
      newSchema - the schema to add
      code - pass-thru to kv persistence, indicates the code source of this update
      comment - pass-thru to kv persistence - a comment for this update * @return the schema actually stored in the SchemaService
      Throws:
      SchemaException - if the schema could not be added
    • addSchema

      @NotNull Schema addSchema​(@NotNull TableDefinitionSchema newSchema) throws SchemaException
      Add the specified schema to the service.
      Parameters:
      newSchema - the schema to add
      Returns:
      the schema actually stored in the SchemaService
      Throws:
      SchemaException - if the schema could not be added or already exists
    • addSchema

      @NotNull Schema addSchema​(@NotNull TableDefinitionSchema newSchema, @NotNull String code, @NotNull String comment) throws SchemaException
      Add the specified schema to the service.
      Parameters:
      newSchema - the schema to add
      code - pass-thru to kv persistence, indicates the code source of this update
      comment - pass-thru to kv persistence - a comment for this update
      Returns:
      the schema actually stored in the SchemaService
      Throws:
      SchemaException - if the schema could not be added or already exists
    • updateSchema

      @NotNull Schema updateSchema​(@NotNull Schema newSchema) throws IllegalArgumentException, SchemaException
      Update the schema with the same namespace and table name with the specified new schema.
      Parameters:
      newSchema - the schema to update with
      Throws:
      IllegalArgumentException - if the namespace or table does not exist
      SchemaException - if the schema could not be updated
    • updateSchema

      @NotNull Schema updateSchema​(@NotNull Schema newSchema, @NotNull String code, @NotNull String comment) throws IllegalArgumentException, SchemaException
      Update the schema with the same namespace and table name with the specified new schema.
      Parameters:
      newSchema - the schema to update with
      code - pass-thru to kv persistence, indicates the code source of this update
      comment - pass-thru to kv persistence - a comment for this update
      Returns:
      the schema actually stored in the SchemaService
      Throws:
      IllegalArgumentException - if the namespace or table does not exist
      SchemaException - if the schema could not be updated
    • updateSchema

      @NotNull Schema updateSchema​(@NotNull TableDefinitionSchema newSchema) throws IllegalArgumentException, SchemaException
      Update the schema with the same namespace and table name with the specified new schema.
      Parameters:
      newSchema - the schema to update with.
      Returns:
      the schema actually stored in the SchemaService
      Throws:
      IllegalArgumentException - if the namespace or table does not exist
      SchemaException - if the schema could not be updated
    • updateSchema

      @NotNull Schema updateSchema​(@NotNull TableDefinitionSchema newSchema, @NotNull String code, @NotNull String comment) throws IllegalArgumentException, SchemaException
      Update the schema with the same namespace and table name with the specified new schema.
      Parameters:
      newSchema - the schema to update with.
      code - pass-thru to kv persistence, indicates the code source of this update
      comment - pass-thru to kv persistence - a comment for this update
      Returns:
      the schema actually stored in the SchemaService
      Throws:
      IllegalArgumentException - if the namespace or table does not exist
      SchemaException - if the schema could not be updated
    • deleteSchema

      void deleteSchema​(@NotNull String namespace, @NotNull String tableName) throws IllegalArgumentException, SchemaException
      Delete the specified schema.
      Parameters:
      namespace - the namespace of the schema to delete
      tableName - the name of the schema to delete
      Throws:
      IllegalArgumentException - if the namespace or table could not be found
      SchemaException - if the schema could not be deleted
    • deleteSchema

      void deleteSchema​(@NotNull String namespace, @NotNull String tableName, @NotNull String code, @NotNull String comment) throws IllegalArgumentException, SchemaException
      Delete the specified schema.
      Parameters:
      namespace - the namespace of the schema to delete
      tableName - the name of the schema to delete
      code - pass-thru to kv persistence, indicates the code source of this delete
      comment - pass-thru to kv persistence - a comment for this delete
      Throws:
      IllegalArgumentException - if the namespace or table could not be found
      SchemaException - if the schema could not be deleted
    • deleteSchema

      default void deleteSchema​(@NotNull TableDefinitionSchema schema) throws IllegalArgumentException, SchemaException
      Delete the specified schema.
      Parameters:
      schema - the schema to delete
      Throws:
      IllegalArgumentException - if the namespace or table could not be found
      SchemaException - if the schema could not be deleted
    • deleteSchema

      default void deleteSchema​(@NotNull TableDefinitionSchema schema, @NotNull String code, @NotNull String comment) throws IllegalArgumentException, SchemaException
      Delete the specified schema.
      Parameters:
      schema - the schema to delete
      code - pass-thru to kv persistence, indicates the code source of this delete
      comment - pass-thru to kv persistence - a comment for this delete
      Throws:
      IllegalArgumentException - if the namespace or table could not be found
      SchemaException - if the schema could not be deleted
    • shutdown

      default void shutdown()
      Shut down the schema service. This may involve cleaning up threads and releasing resources.
    • close

      default void close()
      Specified by:
      close in interface AutoCloseable
    • initializationStage

      default Future<Void> initializationStage()
      Get a future representing a possibly asynchronous initialization stage. The initialization stage is finished when the future is done, and does not throw an exception.
      Returns:
      a Future representing successful completion of initialization.