All Implemented Interfaces:
ISchema, IStatement, IStatementContainer, IHashable

public class ChSchema extends ChAbstractStatement implements ISchema, IStatementContainer
Represents a ClickHouse database schema (database in ClickHouse terms). Contains tables, views, dictionaries and has an associated engine type.
  • Constructor Details

    • ChSchema

      public ChSchema(String name)
      Creates a new ClickHouse schema with the specified name.
      Parameters:
      name - the name of the schema
  • Method Details

    • getCreationSQL

      public void getCreationSQL(SQLScript script)
      Description copied from interface: IStatement
      Generates the SQL statements needed to create this database object. This is an abstract method that must be implemented by subclasses to provide the specific CREATE SQL for each object type.
      Specified by:
      getCreationSQL in interface IStatement
      Parameters:
      script - the SQL script to append creation statements to
    • appendAlterSQL

      public ObjectState appendAlterSQL(IStatement newCondition, SQLScript script)
      Description copied from interface: IStatement
      Fill script with object changes and return change type
      Specified by:
      appendAlterSQL in interface IStatement
      Parameters:
      newCondition - new object state
      script - script to collect changes
      Returns:
      object change type
    • getDropSQL

      public void getDropSQL(SQLScript script, boolean generateExists)
      Description copied from interface: IStatement
      Generates DROP SQL for this statement.
      Specified by:
      getDropSQL in interface IStatement
      Overrides:
      getDropSQL in class AbstractStatement
      Parameters:
      script - the SQL script to append the DROP statement to
      generateExists - whether to include "IF EXISTS" in the DROP statement
    • setEngine

      public void setEngine(String engine)
    • getRelations

      public Stream<IRelation> getRelations()
      Description copied from interface: ISchema
      Gets all relations (tables, views, sequences) in this schema.
      Specified by:
      getRelations in interface ISchema
      Returns:
      a stream of relations
    • fillDescendantsList

      public void fillDescendantsList(List<Collection<? extends AbstractStatement>> l)
      Overrides:
      fillDescendantsList in class AbstractStatement
    • fillChildrenList

      public void fillChildrenList(List<Collection<? extends AbstractStatement>> l)
      Overrides:
      fillChildrenList in class AbstractStatement
    • getRelation

      public IRelation getRelation(String name)
      Description copied from interface: ISchema
      Gets a relation by name.
      Specified by:
      getRelation in interface ISchema
      Parameters:
      name - the relation name
      Returns:
      the relation with the given name, or null if not found
    • getChild

      public AbstractStatement getChild(String name, DbObjType type)
      Description copied from interface: IStatementContainer
      Gets a child statement by name and type.
      Specified by:
      getChild in interface IStatementContainer
      Parameters:
      name - the name of the child to find
      type - the type of the child to find
      Returns:
      the child statement, or null if not found
    • getChildrenByType

      public Collection<IStatement> getChildrenByType(DbObjType type)
      Description copied from interface: IStatementContainer
      get all children by type
      Specified by:
      getChildrenByType in interface IStatementContainer
      Parameters:
      type - the type of the children
      Returns:
      unmodifiable collection of child statement, or empty list
    • addChild

      public void addChild(IStatement st)
      Description copied from interface: IStatementContainer
      Adds a child statement to this container.
      Specified by:
      addChild in interface IStatementContainer
      Parameters:
      st - the child statement to add
    • getStatementContainer

      public IStatementContainer getStatementContainer(String name)
      Gets a statement container by name.
      Specified by:
      getStatementContainer in interface ISchema
      Parameters:
      name - the name of the container to find
      Returns:
      the statement container with the given name, or null if not found
    • getStatementContainers

      public Stream<IStatementContainer> getStatementContainers()
      Gets a stream of all statement containers in this schema.
      Returns:
      a stream of statement containers
    • getIndexByName

      public ChIndex getIndexByName(String indexName)
      Finds an index by name across all tables and views in this schema.
      Parameters:
      indexName - the name of the index to find
      Returns:
      the index with the given name, or null if not found
    • getConstraintByName

      public ChConstraint getConstraintByName(String constraintName)
      Finds a constraint by name across all tables and views in this schema.
      Parameters:
      constraintName - the name of the constraint to find
      Returns:
      the constraint with the given name, or null if not found
    • getTable

      public ChTable getTable(String name)
    • computeHash

      public void computeHash(Hasher hasher)
      Description copied from interface: IHashable
      Computes the hash of the implementing object using the provided hasher. The implementation should call appropriate put methods on the hasher for all fields that should contribute to the hash value.
      Specified by:
      computeHash in interface IHashable
      Parameters:
      hasher - the hasher instance to use for hash computation
    • compare

      public boolean compare(IStatement obj)
      Description copied from class: AbstractStatement
      This method does not account for nested child PgStatements. Shallow version of AbstractStatement.equals(Object)
      Specified by:
      compare in interface IStatement
      Overrides:
      compare in class AbstractStatement
    • compareChildren

      public boolean compareChildren(AbstractStatement obj)
      Description copied from class: AbstractStatement
      Deep part of AbstractStatement.equals(Object). Compares all object's child PgStatements for equality.
      Overrides:
      compareChildren in class AbstractStatement