Class ColumnBuilder
- java.lang.Object
-
- com.jgcomptech.tools.databasetools.jdbc.builders.ColumnBuilder
-
public class ColumnBuilder extends java.lang.Object
A builder class for creating a database table column.- Since:
- 1.4.0
-
-
Constructor Summary
Constructors Constructor Description ColumnBuilder(java.lang.String columnName, DataTypes type)
Generates sql code for creation of a table column.ColumnBuilder(java.lang.String columnName, DataTypes type, int length)
Generates sql code for creation of a table column.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ColumnBuilder
autoIncrement()
Sets the AUTO INCREMENT constraint on the column.java.lang.String
build(Database db)
Builds the sql statement to create the column.ColumnBuilder
defaultValue(java.lang.String defaultValue)
Sets the DEFAULT constraint on the column.java.lang.String
getColumnName()
Returns the name of the column.DataTypes
getType()
Returns the data type of the column.ColumnBuilder
notNull()
Sets the NOT NULL constraint on the column.ColumnBuilder
primaryKey()
Sets the PRIMARY KEY constraint on the column.java.lang.String
toString()
Returns the sql statement to create the column and will return an empty string ifbuild(com.jgcomptech.tools.databasetools.jdbc.Database)
hasn't been run.ColumnBuilder
unique()
Sets the UNIQUE constraint on the column.
-
-
-
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 columntype
- 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 columntype
- the data type of the columnlength
- 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 ifbuild(com.jgcomptech.tools.databasetools.jdbc.Database)
hasn't been run.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the sql statement to create the column
-
-