Package com.tableau.hyperapi

# Class Catalog

java.lang.Object
com.tableau.hyperapi.Catalog

public final class Catalog extends Object
The catalog of a connection.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `attachDatabase(String databasePath)`
  Attaches a database to this connection.
  `void`
  `attachDatabase(String databasePath, Name databaseAlias)`
  Attaches a database to this connection under the alias databaseAlias.
  `void`
  `createDatabase(String databasePath)`
  Creates a new database given the database file path.
  `void`
  `createDatabaseIfNotExists(String databasePath)`
  Creates a database if it doesn't exist yet; otherwise does nothing.
  `void`
  `createSchema(SchemaName schema)`
  Creates a schema.
  `void`
  `createSchemaIfNotExists(SchemaName schema)`
  Creates a schema if no schema with that name exists; otherwise does nothing.
  `void`
  `createTable(TableDefinition tableDefinition)`
  Creates a table.
  `void`
  `createTableIfNotExists(TableDefinition tableDefinition)`
  Creates a table if no table with that name exists; otherwise does nothing.
  `void`
  `detachAllDatabases()`
  Detaches all databases from this connection.
  `void`
  `detachDatabase(Name databaseAlias)`
  Detaches a database from this connection.
  `void`
  `dropDatabase(String databasePath)`
  Drops a database file.
  `void`
  `dropDatabaseIfExists(String databasePath)`
  Drops a database file if it exists; otherwise does nothing.
  `Connection`
  `getConnection()`
  Returns the underlying connection.
  `List<SchemaName>`
  `getSchemaNames()`
  Gets the names of all schemas in the first database in the database search path.
  `List<SchemaName>`
  `getSchemaNames(Name database)`
  Gets the names of all schemas in the specified database.
  `TableDefinition`
  `getTableDefinition(TableName tableName)`
  Returns the table definition if a table with the given name exists.
  `List<TableName>`
  `getTableNames(SchemaName schema)`
  Gets the names of all tables in the specified schema.
  `boolean`
  `hasTable(TableName tableName)`
  Returns whether a table with this name exists.

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### hasTable

    public boolean hasTable(TableName tableName)
    Returns whether a table with this name exists.
    Parameters:
      `tableName` - A qualified table name.
    Returns:
      Whether a table with this name exists.
    Throws:
      `HyperException` - Thrown when querying the table fails.

  - ### getTableDefinition

    public TableDefinition getTableDefinition(TableName tableName)
    Returns the table definition if a table with the given name exists.

    This will perform queries against Hyper so if you need to access different fields in the schema, for performance reasons, make sure to keep the object and access its fields.

    Note that the table definitions name will always be fully qualified, even if the input name was not. E.g., if the user queries table "foo", which resolves to the table "db1"."bar"."foo", then the resulting TableDefinition will have the latter set as name.

    Parameters:
      `tableName` - The qualified name of the table to retrieve its schema.
    Returns:
      The table definition.
    Throws:
      `HyperException` - Thrown when the table does not exist or querying the table fails.

  - ### createTable

    public void createTable(TableDefinition tableDefinition)
    Creates a table.

    The table definition schema is validated during this call and an exception will be thrown if a column definition is found to be invalid.

    The method will throw if a table with this name already exists.

    Parameters:
      `tableDefinition` - A table definition describing the new table.
    Throws:
      `HyperException` - Thrown when the table definition is invalid, or when Hyper can't create the table.

  - ### createTableIfNotExists

    public void createTableIfNotExists(TableDefinition tableDefinition)
    Creates a table if no table with that name exists; otherwise does nothing.

    The table definition schema is validated during this call and an exception will be thrown if a column definition is found to be invalid.

    Parameters:
      `tableDefinition` - The table definition with the schema of the table.
    Throws:
      `HyperException` - Thrown when the table definition is invalid, or when Hyper can't create the table.

  - ### createSchema

    public void createSchema(SchemaName schema)
    Creates a schema.

    The method will throw if a schema with this name already exists.

    Parameters:
      `schema` - The name of the schema.
    Throws:
      `HyperException` - Thrown when the schema already exists or when Hyper can't create the schema.

  - ### createSchemaIfNotExists

    public void createSchemaIfNotExists(SchemaName schema)
    Creates a schema if no schema with that name exists; otherwise does nothing.
    Parameters:
      `schema` - The name of the schema.
    Throws:
      `HyperException` - Thrown when Hyper can't create the schema.

  - ### getSchemaNames

    public List<SchemaName> getSchemaNames()
    Gets the names of all schemas in the first database in the database search path.

    Note that by default, this is the single database that is attached if only one database is attached. In the cross db use case, the database search path is empty by default, so this method will fail by default. The user can set the database search path in this case to specify from which database to retrieve schema names.

    Returns:
      The schema names.
    Throws:
      `HyperException` - Thrown if querying the schema was unsuccessful or no database is attached or in the search path.

  - ### getSchemaNames

    public List<SchemaName> getSchemaNames(Name database)
    Gets the names of all schemas in the specified database.
    Parameters:
      `database` - The database name.
    Returns:
      The schema names.
    Throws:
      `HyperException` - Thrown if querying the schema was unsuccessful or no database with the given name is attached.

  - ### getTableNames

    public List<TableName> getTableNames(SchemaName schema)
    Gets the names of all tables in the specified schema.
    Parameters:
      `schema` - The schema name.
    Returns:
      The table names.
    Throws:
      `HyperException` - Thrown if querying the schema was unsuccessful or no schema with the given name exists.

  - ### createDatabase

    public void createDatabase(String databasePath)
    Creates a new database given the database file path.

    Does not automatically attach to the newly-created database.

    Parameters:
      `databasePath` - The file path to the database to create.
    Throws:
      `HyperException` - Thrown when the database creation fails or if a file with that name already exists.

  - ### createDatabaseIfNotExists

    public void createDatabaseIfNotExists(String databasePath)
    Creates a database if it doesn't exist yet; otherwise does nothing.

    Does not automatically attach to the newly-created database. If a database with that name already exists, will do nothing.

    Parameters:
      `databasePath` - The file path to the database to create.
    Throws:
      `HyperException` - Thrown when the database creation fails or if a non-database file with that name already exists.

  - ### attachDatabase

    public void attachDatabase(String databasePath)
    Attaches a database to this connection.

    Uses the stem of the databasePath as alias. E.g., "foo/bar.hyper" will use the alias "bar".

    Parameters:
      `databasePath` - The path to the database file.
    Throws:
      `HyperException` - Thrown when database doesn't exist or attaching fails.

  - ### attachDatabase

    public void attachDatabase(String databasePath, Name databaseAlias)
    Attaches a database to this connection under the alias databaseAlias.
    Parameters:
      `databasePath` - The path to the database file.
      `databaseAlias` - The alias for the database.
    Throws:
      `HyperException` - Thrown when database doesn't exist, aslias is already in use or attaching fails.

  - ### detachDatabase

    public void detachDatabase(Name databaseAlias)
    Detaches a database from this connection.
    Parameters:
      `databaseAlias` - The alias of the database.
    Throws:
      `HyperException` - Thrown when no such database was attached to the connection or detaching fails.

  - ### detachAllDatabases

    public void detachAllDatabases()
    Detaches all databases from this connection.
    Throws:
      `HyperException` - Thrown when detaching fails.

  - ### dropDatabase

    public void dropDatabase(String databasePath)
    Drops a database file.
    Parameters:
      `databasePath` - The path to the database.
    Throws:
      `HyperException` - Thrown when database file with that path doesn't exist or dropping fails for some other reason.

  - ### dropDatabaseIfExists

    public void dropDatabaseIfExists(String databasePath)
    Drops a database file if it exists; otherwise does nothing.
    Parameters:
      `databasePath` - The path to the database.
    Throws:
      `HyperException` - Thrown when dropping fails.

  - ### getConnection

    public Connection getConnection()
    Returns the underlying connection.
    Returns:
      The underlying connection.