Class Table

    • Constructor Detail

      • Table

        public Table​(String name,
                     SQLElement tableType)
        Instantiates a new Table.
        Parameters:
        name - the name of the Table
        tableType - RDMS specific string defining type of table
      • Table

        public Table​(String name)
        Instantiates a new Table.
        Parameters:
        name - the name of the Table
      • Table

        public Table​(String name,
                     SQLElement tableType,
                     @NonNull
                     @NonNull List<Column> columns,
                     @NonNull
                     @NonNull List<Constraint> constraints)
        Instantiates a new Table.
        Parameters:
        name - the name of the Table
        tableType - RDMS specific string defining type of table
        columns - the columns on the table
        constraints - the constraints on the table
    • Method Detail

      • addColumn

        public AlterTable addColumn​(@NonNull
                                    @NonNull Column column)
        Adds the given column to the table definition generating an AlterTable statement to perform on the database.
        Parameters:
        column - the column to add
        Returns:
        the AlterTable statement needed to sync the code definition with the database definition
      • addConstraint

        public AlterTable addConstraint​(@NonNull
                                        @NonNull Constraint constraint)
        Adds the given Constraint to the table definition generating an AlterTable statement to perform on the database.
        Parameters:
        constraint - the table constraint to add
        Returns:
        the AlterTable statement needed to sync the code definition with the database definition
      • alterColumn

        public AlterTable alterColumn​(@NonNull
                                      @NonNull String name,
                                      @NonNull
                                      @NonNull Consumer<Column> consumer)
        Alters the definition of the given column generating an AlterTable statement to perform on the database.
        Parameters:
        name - the column to alter
        consumer - the consumer to use to update the column definition
        Returns:
        the AlterTable statement needed to sync the code definition with the database definition
      • batchInsert

        public int batchInsert​(@NonNull
                               @NonNull SQLContext context,
                               @NonNull
                               @NonNull Stream<Map<String,​?>> values)
                        throws SQLException
        Batch insert int.
        Parameters:
        context - the context
        values - the values
        Returns:
        the int
        Throws:
        SQLException - the sql exception
      • batchUpsert

        public int batchUpsert​(@NonNull
                               @NonNull SQLContext context,
                               @NonNull
                               @NonNull List<String> indexedColumns,
                               @NonNull
                               @NonNull Stream<Map<String,​?>> values)
                        throws SQLException
        Batch upsert int.
        Parameters:
        context - the context
        indexedColumns - the indexed columns
        values - the values
        Returns:
        the int
        Throws:
        SQLException - the sql exception
      • column

        public Column column​(String name)
        Column column.
        Parameters:
        name - the name
        Returns:
        the column
      • count

        public long count​(@NonNull
                          @NonNull SQLContext context)
                   throws SQLException
        Performs a select count(0) from this table.
        Parameters:
        context - the context to perform the query on
        Returns:
        the result of the select count query
        Throws:
        SQLException - something happened trying to query
      • delete

        public int delete​(@NonNull
                          @NonNull SQLContext context,
                          @NonNull
                          @NonNull SQLElement where)
                   throws SQLException
        Deletes all rows matching the given where criteria
        Parameters:
        context - the SQLContext to perform the delete on
        where - the criteria for row deletion
        Returns:
        the number of items deleted
        Throws:
        SQLException - something happened trying to update
      • deleteAll

        public int deleteAll​(@NonNull
                             @NonNull SQLContext context)
                      throws SQLException
        Deletes all rows from the table
        Parameters:
        context - the SQLContext to perform the delete on
        Returns:
        the number of items deleted
        Throws:
        SQLException - something happened trying to update
      • dropColumn

        public AlterTable dropColumn​(@NonNull
                                     @NonNull String name)
        Removes the column with the given name from the table definition generating an AlterTable statement to perform on the database.
        Parameters:
        name - the name of the column to drop
        Returns:
        the AlterTable statement needed to sync the code definition with the database definition
      • dropIndex

        public boolean dropIndex​(@NonNull
                                 @NonNull SQLContext context,
                                 String name)
                          throws SQLException
        Drop index boolean.
        Parameters:
        context - the context
        name - the name
        Returns:
        the boolean
        Throws:
        SQLException - the sql exception
      • dropIndexIfExists

        public boolean dropIndexIfExists​(@NonNull
                                         @NonNull SQLContext context,
                                         String name)
                                  throws SQLException
        Drop index if exists boolean.
        Parameters:
        context - the context
        name - the name
        Returns:
        the boolean
        Throws:
        SQLException - the sql exception
      • exists

        public boolean exists​(@NonNull
                              @NonNull SQLContext context)
                       throws SQLException
        Checks if this table exists in the database using the given SQLContext
        Parameters:
        context - the context to use to check for the table's existence.
        Returns:
        True if table exists, False otherwise
        Throws:
        SQLException - something happened trying to query for table existence
      • getKeyword

        public String getKeyword()
        Description copied from class: SQLObject
        Gets the SQL Keyword associated with the object
        Specified by:
        getKeyword in class SQLObject
        Returns:
        the SQL keyword
      • index

        public IndexBuilder index​(String name)
        Index index builder.
        Parameters:
        name - the name
        Returns:
        the index builder
      • insert

        public Insert insert()
        Creates an Insert statement for this table automatically filling in the columns with those that are required and setting the values to either be default (if no columns are required) or named parameters based on the column name.
        Returns:
        the insert statement
      • insert

        public Insert insert​(@NonNull
                             @NonNull InsertType insertType)
        Creates an Insert statement for this table automatically filling in the columns with those that are required and setting the values to either be default (if no columns are required) or named parameters based on the column name.
        Parameters:
        insertType - the type of insert to perform
        Returns:
        the insert statement
      • insert

        public int insert​(@NonNull
                          @NonNull SQLContext context,
                          @NonNull
                          @NonNull Map<String,​Object> values)
                   throws SQLException
        Insert int.
        Parameters:
        context - the context
        values - the values
        Returns:
        the int
        Throws:
        SQLException - the sql exception
      • qualifiedColumnName

        public SQLOperable qualifiedColumnName​(@NonNull
                                               @NonNull Column column)
        Gets the qualified column name, i.e. table.column
        Parameters:
        column - the column name
        Returns:
        the SQLOperable representing the qualified column name
      • qualifiedColumnName

        public SQLOperable qualifiedColumnName​(@NonNull
                                               @NonNull String column)
        Gets the qualified column name, i.e. table.column
        Parameters:
        column - the column name
        Returns:
        the SQLOperable representing the qualified column name
      • renameColumn

        public AlterTable renameColumn​(@NonNull
                                       @NonNull String name,
                                       @NonNull
                                       @NonNull String newName)
        Renames the column with the given name to the given new name generating an AlterTable statement to execute on the database.
        Parameters:
        name - the current column name
        newName - the new column name
        Returns:
        the AlterTable statement needed to sync the code definition with the database definition
      • renameTable

        public AlterTable renameTable​(@NonNull
                                      @NonNull String newName)
        Renames the table to the given new name generating an AlterTable statement to execute on the database.
        Parameters:
        newName - the new table name
        Returns:
        the AlterTable statement needed to sync the code definition with the database definition
      • select

        public Select select​(@NonNull
                             @NonNull String... columns)
        Creates a select statement selecting from this table returning the specified columns
        Parameters:
        columns - the columns to select
        Returns:
        the select statement
      • select

        public Select select​(@NonNull
                             @NonNull SQLElement... columns)
        Creates a select statement selecting from this table returning the specified columns
        Parameters:
        columns - the columns to select
        Returns:
        the select statement
      • select

        public Select select()
        Creates a select statement selecting from this table with nothing else specified
        Returns:
        the select statement
      • selectAll

        public Select selectAll()
        Creates a select statement selecting all columns from this table.
        Returns:
        the select statement
      • update

        public Update update()
        Creates an update statement for this table
        Returns:
        the update statement
      • update

        public Update update​(@NonNull
                             @NonNull UpdateType updateType)
        Creates an update statement for this table
        Parameters:
        updateType - the type of update to perform
        Returns:
        the update statement
      • upsert

        public boolean upsert​(@NonNull
                              @NonNull SQLContext context,
                              String indexedColumn,
                              @NonNull
                              @NonNull Map<String,​Object> values)
                       throws SQLException
        Perform an upsert on the table using the given context, list of columns to base the upsert on, and values to upserted.
        Parameters:
        context - the context to perform the upsert over
        indexedColumn - the column used to determine insert or upsert
        values - the values of the row to be upserted
        Returns:
        True if one or more rows were modified.
        Throws:
        SQLException - the sql exception
      • upsert

        public boolean upsert​(@NonNull
                              @NonNull SQLContext context,
                              List<String> indexedColumns,
                              @NonNull
                              @NonNull Map<String,​Object> values)
                       throws SQLException
        Perform an upsert on the table using the given context, list of columns to base the upsert on, and values to upserted.
        Parameters:
        context - the context to perform the upsert over
        indexedColumns - the columns used to determine insert or upsert
        values - the values of the row to be upserted
        Returns:
        True if one or more rows were modified.
        Throws:
        SQLException - the sql exception