Class TableBuilder


  • public class TableBuilder
    extends SQLBuilder
    A builder class for creating an CREATE sql statement to create a new table.
    Since:
    1.4.0
    • Constructor Detail

      • TableBuilder

        public TableBuilder()
    • Method Detail

      • CREATE

        public TableBuilder CREATE​(java.lang.String tableName,
                                   Database db)
                            throws java.sql.SQLException
        Generates sql code for creation of a table.
        Parameters:
        tableName - the name of the table to create
        db - the database object for database type checking
        Returns:
        the instance of the builder to continue building
        Throws:
        java.lang.IllegalStateException - if this is not the first method called
        java.sql.SQLException - if a database access error occurs
      • addColumn

        public TableBuilder addColumn​(ColumnBuilder builder)
        Adds a column to the table using the ColumnBuilder class.
        Parameters:
        builder - the ColumnBuilder instance
        Returns:
        the instance of the builder to continue building
        Throws:
        java.lang.IllegalStateException - if the CREATE statement is not called first
      • addColumn

        public TableBuilder addColumn​(java.lang.String columnSql)
        Adds a column to the table using a sql string.
        Parameters:
        columnSql - the sql statement to create the column
        Returns:
        the instance of the builder to continue building
        Throws:
        java.lang.IllegalStateException - if the CREATE statement is not called first
      • build

        public TypedStatement build​(Database db)
                             throws java.sql.SQLException
        Runs buildPreparedStatement and passes this object to a new instance of TypedStatement.
        Specified by:
        build in class SQLBuilder
        Parameters:
        db - the database to request the PreparedStatement object from
        Returns:
        a new instance of TypedStatement
        Throws:
        java.sql.SQLException - if a database access error occurs
      • build

        public TypedStatement build()
                             throws java.sql.SQLException
        Runs buildPreparedStatement and passes this object to a new instance of TypedStatement. Uses the db object passed into the constructor.
        Returns:
        a new instance of TypedStatement
        Throws:
        java.sql.SQLException - if a database access error occurs
      • buildAndCreate

        public boolean buildAndCreate()
                               throws java.sql.SQLException
        Runs buildPreparedStatement, executes the statement and returns true if no errors occurred.
        Returns:
        the result of the statement as a boolean, true if no errors occurred
        Throws:
        java.sql.SQLException - if a database access error occurs