Package com.gengoai.sql.object
Class Column
- java.lang.Object
-
- com.gengoai.sql.object.Column
-
- All Implemented Interfaces:
NamedSQLElement
,SQLOperable
,SQLElement
,Serializable
public class Column extends Object implements Serializable, NamedSQLElement, SQLOperable
Represents a column in a database table.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Column(String name, String type)
Instantiates a new Column.Column(String name, String type, @NonNull Collection<Constraint> constraints)
Instantiates a new Column.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Column
asStored(SQLElement element)
Sets a value that is auto generated for the column on insertion time and is stored in the database.Column
asVirtual(SQLElement element)
Sets a value that is auto generated for the column on query time and not stored in the database.Column
autoIncrement()
Sets this column as having its value auto incremented on assertion.Column
autoIncrement(boolean isAutoIncrement)
Sets whether or not the column has an auto incremented valueColumn
check(@NonNull SQLElement element)
Adds a Check constraint on this column.Column
check(String name, @NonNull SQLElement element)
Adds a Check constraint with the given name on this column.void
clearConstraints()
Clears all constraints on the column.Column
collate(String collate)
Sets the collation used for this columnColumn
defaultValue(SQLElement defaultValue)
Sets the default value to be assigned to the column when no value is given on an insert.List<Constraint>
getConstraints()
Gets an unmodifiable view of the constraints on the column.boolean
hasConstraintOfType(@NonNull Class<? extends Constraint> constraintClass)
Checks if a constraint of the give type is on the columnboolean
isRequired()
Determines if the column is requires a value to be specified during insertion.Column
notNull()
Sets the column to not allow null values.Column
notNull(ConflictClause conflictClause)
Sets the column to not allow null values optionally specifying what happens when insertion of a null value is attempted.Column
primaryKey()
Sets this column as the primary key of the table.Column
unique()
Sets the column to have a uniqueness constraintColumn
unique(@NonNull String name, ConflictClause conflictClause)
Sets the column to have a uniqueness constraint optionally specifying what happens when insertion of a duplicate value is attempted.Column
unique(ConflictClause conflictClause)
Sets the column to have a uniqueness constraint optionally specifying what happens when insertion of a duplicate value is attempted.Column
unique(String name)
Sets the column to have a uniqueness constraint-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.gengoai.sql.NamedSQLElement
getName
-
Methods inherited from interface com.gengoai.sql.SQLElement
getClassName
-
-
-
-
Constructor Detail
-
Column
public Column(String name, String type)
Instantiates a new Column.- Parameters:
name
- the name of the columntype
- the data type of the column
-
Column
public Column(String name, String type, @NonNull @NonNull Collection<Constraint> constraints)
Instantiates a new Column.- Parameters:
name
- the name of the columntype
- the data type of the columnconstraints
- the column constraints
-
-
Method Detail
-
asStored
public Column asStored(SQLElement element)
Sets a value that is auto generated for the column on insertion time and is stored in the database.- Parameters:
element
- the element / expression to generate the column's value- Returns:
- this column
-
asVirtual
public Column asVirtual(SQLElement element)
Sets a value that is auto generated for the column on query time and not stored in the database.- Parameters:
element
- the element / expression to generate the column's value- Returns:
- this column
-
autoIncrement
public Column autoIncrement()
Sets this column as having its value auto incremented on assertion.- Returns:
- this column
-
autoIncrement
public Column autoIncrement(boolean isAutoIncrement)
Sets whether or not the column has an auto incremented value- Parameters:
isAutoIncrement
- True - auto increment, False - do not auto increment- Returns:
- this column
-
check
public Column check(@NonNull @NonNull SQLElement element)
Adds a Check constraint on this column.- Parameters:
element
- the check- Returns:
- this column
-
check
public Column check(String name, @NonNull @NonNull SQLElement element)
Adds a Check constraint with the given name on this column.- Parameters:
name
- the name of the constraintelement
- the check- Returns:
- this column
-
clearConstraints
public void clearConstraints()
Clears all constraints on the column.
-
collate
public Column collate(String collate)
Sets the collation used for this column- Parameters:
collate
- the collation- Returns:
- this column
-
defaultValue
public Column defaultValue(SQLElement defaultValue)
Sets the default value to be assigned to the column when no value is given on an insert.- Parameters:
defaultValue
- the default value- Returns:
- this column
-
getConstraints
public List<Constraint> getConstraints()
Gets an unmodifiable view of the constraints on the column.- Returns:
- the constraints
-
hasConstraintOfType
public boolean hasConstraintOfType(@NonNull @NonNull Class<? extends Constraint> constraintClass)
Checks if a constraint of the give type is on the column- Parameters:
constraintClass
- the constraint class- Returns:
- True if the column has at least one constraint of the given type
-
isRequired
public boolean isRequired()
Determines if the column is requires a value to be specified during insertion.- Returns:
- true if the column requires a value to be specified during insertion, false not required.
-
notNull
public Column notNull()
Sets the column to not allow null values.- Returns:
- this column
-
notNull
public Column notNull(ConflictClause conflictClause)
Sets the column to not allow null values optionally specifying what happens when insertion of a null value is attempted.- Parameters:
conflictClause
- theConflictClause
defining what happens when insertion of a null value is attempted.- Returns:
- this column
-
primaryKey
public Column primaryKey()
Sets this column as the primary key of the table.- Returns:
- this column
-
unique
public Column unique()
Sets the column to have a uniqueness constraint- Returns:
- this column
-
unique
public Column unique(String name)
Sets the column to have a uniqueness constraint- Parameters:
name
- the name of the constraint- Returns:
- this column
-
unique
public Column unique(ConflictClause conflictClause)
Sets the column to have a uniqueness constraint optionally specifying what happens when insertion of a duplicate value is attempted.- Parameters:
conflictClause
- theConflictClause
defining what happens when insertion of a duplicate value is attempted.- Returns:
- this column
-
unique
public Column unique(@NonNull @NonNull String name, ConflictClause conflictClause)
Sets the column to have a uniqueness constraint optionally specifying what happens when insertion of a duplicate value is attempted.- Parameters:
name
- the name of the constraintconflictClause
- theConflictClause
defining what happens when insertion of a duplicate value is attempted.- Returns:
- this column
-
-