Class CreateTable


public class CreateTable extends H2SqlPart

Generates a CREATE TABLE statement for H2.


Sample Generated SQL:

CREATE TABLE IF NOT EXISTS table_name (
  user_id int,
  email text,
  PRIMARY KEY (user_id)
);
  • Constructor Details

    • CreateTable

      public CreateTable()
    • CreateTable

      public CreateTable(String tableName)
      Constructs a CreateTable with the specified table name.
      Parameters:
      tableName - the table name
  • Method Details

    • setPretty

      public CreateTable setPretty(boolean pretty)
      Indicates if line breaks and indentations should be added to output DDL (default false).

      Example output (pretty = true):
      CREATE TABLE IF NOT EXISTS table_name (
        user_id int,
        email text
        PRIMARY KEY (user_id)
      )

      Example output (pretty = false):
      CREATE TABLE IF NOT EXISTS table_name (user_id int, email text, PRIMARY KEY (user_id))
      Overrides:
      setPretty in class SqlPart
    • collectSqlFragment

      public void collectSqlFragment(CodeWriter writer)
      Description copied from class: SqlPart
      Writes this part's SQL to the writer; used by SqlPart.getSqlFragment() and by enclosing parts.
      Specified by:
      collectSqlFragment in class SqlPart
    • getTableName

      public String getTableName()
      Returns the table name.
      Returns:
      the table name
    • setTableName

      public CreateTable setTableName(String tableName)
      Sets the table name.
      Parameters:
      tableName - the table name
      Returns:
      this instance
    • isCheckIfNotExists

      public boolean isCheckIfNotExists()
      Indicates if IF NOT EXISTS clause should be included in the CREATE TABLE statement (default true).
    • setCheckIfNotExists

      public CreateTable setCheckIfNotExists(boolean checkIfNotExists)
      Indicates if IF NOT EXISTS clause should be included in the CREATE TABLE statement (default true).
    • getColumns

      public List<CreateTableColumn> getColumns()
      Returns the list of columns.
      Returns:
      the list of columns
    • setColumns

      public CreateTable setColumns(List<CreateTableColumn> columns)
      Sets the columns.
      Parameters:
      columns - the list of columns
      Returns:
      this instance
    • addColumn

      public CreateTable addColumn(CreateTableColumn column)
      Adds a column to this table.
      Parameters:
      column - the column to add
      Returns:
      this instance
    • getPrimaryKeyColumns

      public List<CreateTableColumn> getPrimaryKeyColumns()
      Returns the list of primary key columns.
      Returns:
      the list of primary key columns