Class ColumnBuilder


  • public class ColumnBuilder
    extends java.lang.Object
    A builder class for creating a database table column.
    Since:
    1.4.0
    • Constructor Detail

      • ColumnBuilder

        public ColumnBuilder​(java.lang.String columnName,
                             DataTypes type)
        Generates sql code for creation of a table column.
        Parameters:
        columnName - the name of the column
        type - the data type of the column
      • ColumnBuilder

        public ColumnBuilder​(java.lang.String columnName,
                             DataTypes type,
                             int length)
        Generates sql code for creation of a table column.
        Parameters:
        columnName - the name of the column
        type - the data type of the column
        length - the max length of the column
    • Method Detail

      • getColumnName

        public java.lang.String getColumnName()
        Returns the name of the column.
        Returns:
        the name of the column
      • getType

        public DataTypes getType()
        Returns the data type of the column.
        Returns:
        the data type of the column
      • notNull

        public ColumnBuilder notNull()
        Sets the NOT NULL constraint on the column.
        Returns:
        the instance of the column to continue building
      • unique

        public ColumnBuilder unique()
        Sets the UNIQUE constraint on the column.
        Returns:
        the instance of the column to continue building
      • primaryKey

        public ColumnBuilder primaryKey()
        Sets the PRIMARY KEY constraint on the column.
        Returns:
        the instance of the column to continue building
      • autoIncrement

        public ColumnBuilder autoIncrement()
        Sets the AUTO INCREMENT constraint on the column. Depending on the database this may use the IDENTITY constraint instead.
        Returns:
        the instance of the column to continue building
      • defaultValue

        public ColumnBuilder defaultValue​(java.lang.String defaultValue)
        Sets the DEFAULT constraint on the column.
        Parameters:
        defaultValue - the value to set
        Returns:
        the instance of the column to continue building
      • build

        public java.lang.String build​(Database db)
        Builds the sql statement to create the column.
        Parameters:
        db - the database object for database type checking
        Returns:
        the sql statement as a string
      • toString

        public java.lang.String toString()
        Returns the sql statement to create the column and will return an empty string if build(com.jgcomptech.tools.databasetools.jdbc.Database) hasn't been run.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the sql statement to create the column