Package org.h2.schema

Class Schema

All Implemented Interfaces:
HasSQL
Direct Known Subclasses:
MetaSchema

public class Schema extends DbObject
A schema as created by the SQL statement CREATE SCHEMA
  • Field Details

  • Constructor Details

    • Schema

      public Schema(Database database, int id, String schemaName, RightOwner owner, boolean system)
      Create a new schema object.
      Parameters:
      database - the database
      id - the object id
      schemaName - the schema name
      owner - the owner of the schema
      system - if this is a system schema (such a schema can not be dropped)
  • Method Details

    • canDrop

      public boolean canDrop()
      Check if this schema can be dropped. System schemas can not be dropped.
      Returns:
      true if it can be dropped
    • getCreateSQLForCopy

      public String getCreateSQLForCopy(Table table, String quotedName)
      Description copied from class: DbObject
      Build a SQL statement to re-create the object, or to create a copy of the object with a different name or referencing a different table
      Specified by:
      getCreateSQLForCopy in class DbObject
      Parameters:
      table - the new table
      quotedName - the quoted name
      Returns:
      the SQL statement
    • getCreateSQL

      public String getCreateSQL()
      Description copied from class: DbObject
      Construct the CREATE ... SQL statement for this object.
      Specified by:
      getCreateSQL in class DbObject
      Returns:
      the SQL statement
    • getType

      public int getType()
      Description copied from class: DbObject
      Get the object type.
      Specified by:
      getType in class DbObject
      Returns:
      the object type
    • isEmpty

      public boolean isEmpty()
      Return whether is this schema is empty (does not contain any objects).
      Returns:
      true if this schema is empty, false otherwise
    • getChildren

      public ArrayList<DbObject> getChildren()
      Description copied from class: DbObject
      Get the list of dependent children (for tables, this includes indexes and so on).
      Overrides:
      getChildren in class DbObject
      Returns:
      the list of children, or null
    • removeChildrenAndResources

      public void removeChildrenAndResources(SessionLocal session)
      Description copied from class: DbObject
      Delete all dependent children objects and resources of this object.
      Specified by:
      removeChildrenAndResources in class DbObject
      Parameters:
      session - the session
    • removeChildrenFromMap

      private void removeChildrenFromMap(SessionLocal session, ConcurrentHashMap<String,? extends SchemaObject> map)
    • getOwner

      public RightOwner getOwner()
      Get the owner of this schema.
      Returns:
      the owner
    • getTableEngineParams

      public ArrayList<String> getTableEngineParams()
      Get table engine params of this schema.
      Returns:
      default table engine params
    • setTableEngineParams

      public void setTableEngineParams(ArrayList<String> tableEngineParams)
      Set table engine params of this schema.
      Parameters:
      tableEngineParams - default table engine params
    • getMap

      private Map<String,SchemaObject> getMap(int type)
    • add

      public void add(SchemaObject obj)
      Add an object to this schema. This method must not be called within CreateSchemaObject; use Database.addSchemaObject() instead
      Parameters:
      obj - the object to add
    • rename

      public void rename(SchemaObject obj, String newName)
      Rename an object.
      Parameters:
      obj - the object to rename
      newName - the new name
    • findTableOrView

      public Table findTableOrView(SessionLocal session, String name)
      Try to find a table or view with this name. This method returns null if no object with this name exists. Local temporary tables are also returned. Synonyms are not returned or resolved.
      Parameters:
      session - the session
      name - the object name
      Returns:
      the object or null
    • resolveTableOrView

      public Table resolveTableOrView(SessionLocal session, String name)
      Try to find a table or view with this name. This method returns null if no object with this name exists. Local temporary tables are also returned. If a synonym with this name exists, the backing table of the synonym is returned
      Parameters:
      session - the session
      name - the object name
      Returns:
      the object or null
    • getSynonym

      public TableSynonym getSynonym(String name)
      Try to find a synonym with this name. This method returns null if no object with this name exists.
      Parameters:
      name - the object name
      Returns:
      the object or null
    • findDomain

      public Domain findDomain(String name)
      Get the domain if it exists, or null if not.
      Parameters:
      name - the name of the domain
      Returns:
      the domain or null
    • findIndex

      public Index findIndex(SessionLocal session, String name)
      Try to find an index with this name. This method returns null if no object with this name exists.
      Parameters:
      session - the session
      name - the object name
      Returns:
      the object or null
    • findTrigger

      public TriggerObject findTrigger(String name)
      Try to find a trigger with this name. This method returns null if no object with this name exists.
      Parameters:
      name - the object name
      Returns:
      the object or null
    • findSequence

      public Sequence findSequence(String sequenceName)
      Try to find a sequence with this name. This method returns null if no object with this name exists.
      Parameters:
      sequenceName - the object name
      Returns:
      the object or null
    • findConstraint

      public Constraint findConstraint(SessionLocal session, String name)
      Try to find a constraint with this name. This method returns null if no object with this name exists.
      Parameters:
      session - the session
      name - the object name
      Returns:
      the object or null
    • findConstant

      public Constant findConstant(String constantName)
      Try to find a user defined constant with this name. This method returns null if no object with this name exists.
      Parameters:
      constantName - the object name
      Returns:
      the object or null
    • findFunction

      public FunctionAlias findFunction(String functionAlias)
      Try to find a user defined function with this name. This method returns null if no object with this name exists.
      Parameters:
      functionAlias - the object name
      Returns:
      the object or null
    • findAggregate

      public UserAggregate findAggregate(String name)
      Get the user defined aggregate function if it exists. This method returns null if no object with this name exists.
      Parameters:
      name - the name of the user defined aggregate function
      Returns:
      the aggregate function or null
    • findFunctionOrAggregate

      public UserDefinedFunction findFunctionOrAggregate(String name)
      Try to find a user defined function or aggregate function with the specified name. This method returns null if no object with this name exists.
      Parameters:
      name - the object name
      Returns:
      the object or null
    • reserveUniqueName

      public void reserveUniqueName(String name)
      Reserve a unique object name.
      Parameters:
      name - the object name
    • freeUniqueName

      public void freeUniqueName(String name)
      Release a unique object name.
      Parameters:
      name - the object name
    • getUniqueName

      private String getUniqueName(DbObject obj, Map<String,? extends SchemaObject> map, String prefix)
    • getUniqueConstraintName

      public String getUniqueConstraintName(SessionLocal session, Table table)
      Create a unique constraint name.
      Parameters:
      session - the session
      table - the constraint table
      Returns:
      the unique name
    • getUniqueDomainConstraintName

      public String getUniqueDomainConstraintName(SessionLocal session, Domain domain)
      Create a unique constraint name.
      Parameters:
      session - the session
      domain - the constraint domain
      Returns:
      the unique name
    • getUniqueIndexName

      public String getUniqueIndexName(SessionLocal session, Table table, String prefix)
      Create a unique index name.
      Parameters:
      session - the session
      table - the indexed table
      prefix - the index name prefix
      Returns:
      the unique name
    • getTableOrView

      public Table getTableOrView(SessionLocal session, String name)
      Get the table or view with the given name. Local temporary tables are also returned.
      Parameters:
      session - the session
      name - the table or view name
      Returns:
      the table or view
      Throws:
      DbException - if no such object exists
    • getDomain

      public Domain getDomain(String name)
      Get the domain with the given name.
      Parameters:
      name - the domain name
      Returns:
      the domain
      Throws:
      DbException - if no such object exists
    • getIndex

      public Index getIndex(String name)
      Get the index with the given name.
      Parameters:
      name - the index name
      Returns:
      the index
      Throws:
      DbException - if no such object exists
    • getConstraint

      public Constraint getConstraint(String name)
      Get the constraint with the given name.
      Parameters:
      name - the constraint name
      Returns:
      the constraint
      Throws:
      DbException - if no such object exists
    • getConstant

      public Constant getConstant(String constantName)
      Get the user defined constant with the given name.
      Parameters:
      constantName - the constant name
      Returns:
      the constant
      Throws:
      DbException - if no such object exists
    • getSequence

      public Sequence getSequence(String sequenceName)
      Get the sequence with the given name.
      Parameters:
      sequenceName - the sequence name
      Returns:
      the sequence
      Throws:
      DbException - if no such object exists
    • getAll

      public ArrayList<SchemaObject> getAll(ArrayList<SchemaObject> addTo)
      Get all objects.
      Parameters:
      addTo - list to add objects to, or null to allocate a new list
      Returns:
      the specified list with added objects, or a new (possibly empty) list with all objects
    • getAll

      public void getAll(int type, ArrayList<SchemaObject> addTo)
      Get all objects of the given type.
      Parameters:
      type - the object type
      addTo - list to add objects to
    • getAllDomains

      public Collection<Domain> getAllDomains()
    • getAllConstraints

      public Collection<Constraint> getAllConstraints()
    • getAllConstants

      public Collection<Constant> getAllConstants()
    • getAllSequences

      public Collection<Sequence> getAllSequences()
    • getAllTriggers

      public Collection<TriggerObject> getAllTriggers()
    • getAllTablesAndViews

      public Collection<Table> getAllTablesAndViews(SessionLocal session)
      Get all tables and views.
      Parameters:
      session - the session, null to exclude meta tables
      Returns:
      a (possible empty) list of all objects
    • getAllIndexes

      public Collection<Index> getAllIndexes()
    • getAllSynonyms

      public Collection<TableSynonym> getAllSynonyms()
    • getAllFunctionsAndAggregates

      public Collection<UserDefinedFunction> getAllFunctionsAndAggregates()
    • getTableOrViewByName

      public Table getTableOrViewByName(SessionLocal session, String name)
      Get the table with the given name, if any.
      Parameters:
      session - the session
      name - the table name
      Returns:
      the table or null if not found
    • remove

      public void remove(SchemaObject obj)
      Remove an object from this schema.
      Parameters:
      obj - the object to remove
    • createTable

      public Table createTable(CreateTableData data)
      Add a table to the schema.
      Parameters:
      data - the create table information
      Returns:
      the created Table object
    • createSynonym

      public TableSynonym createSynonym(CreateSynonymData data)
      Add a table synonym to the schema.
      Parameters:
      data - the create synonym information
      Returns:
      the created TableSynonym object
    • createTableLink

      public TableLink createTableLink(int id, String tableName, String driver, String url, String user, String password, String originalSchema, String originalTable, boolean emitUpdates, boolean force)
      Add a linked table to the schema.
      Parameters:
      id - the object id
      tableName - the table name of the alias
      driver - the driver class name
      url - the database URL
      user - the user name
      password - the password
      originalSchema - the schema name of the target table
      originalTable - the table name of the target table
      emitUpdates - if updates should be emitted instead of delete/insert
      force - create the object even if the database can not be accessed
      Returns:
      the TableLink object