Package edu.caltech.nanodb.commands
Class ConstraintDecl
- java.lang.Object
-
- edu.caltech.nanodb.commands.ConstraintDecl
-
public class ConstraintDecl extends java.lang.Object
Constraints may be specified at the table level, or they may be specified on individual columns. Obviously, the kinds of constraint allowed depends on what the constraint is associated with.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
columnConstraint
Flag indicating whether the constraint is specified at the table-level or at the column-level.private java.util.List<java.lang.String>
columnNames
ForTableConstraintType.UNIQUE
andTableConstraintType.PRIMARY_KEY
constraints, this is a list of one or more column names that are constrained.private java.lang.String
name
The optional name of the constraint, ornull
if no name was specified.private ForeignKeyValueChangeOption
onDeleteOption
ForTableConstraintType.FOREIGN_KEY
constraints, this is theForeignKeyValueChangeOption
for ON DELETE behavior.private ForeignKeyValueChangeOption
onUpdateOption
ForTableConstraintType.FOREIGN_KEY
constraints, this is theForeignKeyValueChangeOption
for ON UPDATE behavior.private java.util.List<java.lang.String>
refColumnNames
ForTableConstraintType.FOREIGN_KEY
constraints, this is a list of one or more column names in the reference-table that are referenced by the foreign-key constraint.private java.lang.String
refTableName
ForTableConstraintType.FOREIGN_KEY
constraints, this is the table that is referenced by the column.private TableConstraintType
type
The type of the constraint.
-
Constructor Summary
Constructors Constructor Description ConstraintDecl(TableConstraintType type, boolean columnConstraint)
Create a new unnamed constraint for a table or a table-column.ConstraintDecl(TableConstraintType type, java.lang.String name, boolean columnConstraint)
Create a new named constraint for a table or a table-column.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addColumn(java.lang.String columnName)
Add a column to the constraint.void
addRefColumn(java.lang.String columnName)
Add a reference-column to aTableConstraintType.FOREIGN_KEY
constraint.java.util.List<java.lang.String>
getColumnNames()
java.lang.String
getName()
Returns the name of the constraint.ForeignKeyValueChangeOption
getOnDeleteOption()
Returns the ON DELETEForeignKeyValueChangeOption
for aTableConstraintType.FOREIGN_KEY
constraint.ForeignKeyValueChangeOption
getOnUpdateOption()
Returns the ON UPDATEForeignKeyValueChangeOption
for aTableConstraintType.FOREIGN_KEY
constraint.java.util.List<java.lang.String>
getRefColumnNames()
java.lang.String
getRefTable()
Returns the name of the referenced table for aTableConstraintType.FOREIGN_KEY
constraint.TableConstraintType
getType()
Returns the type of this constraint.boolean
isColumnConstraint()
Returns true if this constraint is associated with a table-column, or false if it is a table-level constraint.void
setOnDeleteOption(ForeignKeyValueChangeOption f)
Add an ON DELETE option to aTableConstraintType.FOREIGN_KEY
constraint.void
setOnUpdateOption(ForeignKeyValueChangeOption f)
Add an ON UPDATE option to aTableConstraintType.FOREIGN_KEY
constraint.void
setRefTable(java.lang.String tableName)
Add a reference-table to aTableConstraintType.FOREIGN_KEY
constraint.java.lang.String
toString()
-
-
-
Field Detail
-
name
private java.lang.String name
The optional name of the constraint, ornull
if no name was specified.
-
type
private TableConstraintType type
The type of the constraint.
-
columnConstraint
private boolean columnConstraint
Flag indicating whether the constraint is specified at the table-level or at the column-level. A value oftrue
indicates that it is a column-level constraint; a value offalse
indicates that it is a table-level constraint.
-
columnNames
private java.util.List<java.lang.String> columnNames
ForTableConstraintType.UNIQUE
andTableConstraintType.PRIMARY_KEY
constraints, this is a list of one or more column names that are constrained. Note that for a column constraint, this list will contain exactly one column name. For a table-level constraint, this list will contain one or more column names.For any other constraint type, this will be set to null.
-
refTableName
private java.lang.String refTableName
ForTableConstraintType.FOREIGN_KEY
constraints, this is the table that is referenced by the column.For any other constraint type, this will be set to null.
-
refColumnNames
private java.util.List<java.lang.String> refColumnNames
ForTableConstraintType.FOREIGN_KEY
constraints, this is a list of one or more column names in the reference-table that are referenced by the foreign-key constraint. Note that for a column-constraint, this list will contain exactly one column-name. For a table-constraint, this list will contain one or more column-names.For any other constraint type, this will be set to
null
.
-
onDeleteOption
private ForeignKeyValueChangeOption onDeleteOption
ForTableConstraintType.FOREIGN_KEY
constraints, this is theForeignKeyValueChangeOption
for ON DELETE behavior.For any other constraint type, this will be set to null.
-
onUpdateOption
private ForeignKeyValueChangeOption onUpdateOption
ForTableConstraintType.FOREIGN_KEY
constraints, this is theForeignKeyValueChangeOption
for ON UPDATE behavior.For any other constraint type, this will be set to null.
-
-
Constructor Detail
-
ConstraintDecl
public ConstraintDecl(TableConstraintType type, boolean columnConstraint)
Create a new unnamed constraint for a table or a table-column.
-
ConstraintDecl
public ConstraintDecl(TableConstraintType type, java.lang.String name, boolean columnConstraint)
Create a new named constraint for a table or a table-column.
-
-
Method Detail
-
getName
public java.lang.String getName()
Returns the name of the constraint.- Returns:
- the name of the constraint.
-
getType
public TableConstraintType getType()
Returns the type of this constraint.
-
isColumnConstraint
public boolean isColumnConstraint()
Returns true if this constraint is associated with a table-column, or false if it is a table-level constraint.
-
addColumn
public void addColumn(java.lang.String columnName)
Add a column to the constraint. This specifies that the constraint governs values in the column. For column-level constraints, only a single column may be specified. For table-level constraints, one or more columns may be specified.- Parameters:
columnName
- the column governed by the constraint- Throws:
java.lang.NullPointerException
- if columnName is nulljava.lang.IllegalStateException
- if this is a column-constraint and there is already one column specified- Design Note:
- (donnie) Column names are checked for existence and uniqueness
when initializing the corresponding objects for storage on the
table schema. See
Schema.addCandidateKey(edu.caltech.nanodb.relations.KeyColumnRefs)
andSchema.addForeignKey(edu.caltech.nanodb.relations.ForeignKeyColumnRefs)
for details.
-
getColumnNames
public java.util.List<java.lang.String> getColumnNames()
-
setRefTable
public void setRefTable(java.lang.String tableName)
Add a reference-table to aTableConstraintType.FOREIGN_KEY
constraint. This specifies the table that constrains the values in the column.- Parameters:
tableName
- the table referenced in the constraint- Throws:
java.lang.NullPointerException
- if tableName is nulljava.lang.IllegalStateException
- if this constraint is not a foreign-key constraint- Design Note:
- (donnie) Existence of the referenced table is checked in the
CreateTableCommand.execute(edu.caltech.nanodb.server.NanoDBServer)
method's operation.
-
getRefTable
public java.lang.String getRefTable()
Returns the name of the referenced table for aTableConstraintType.FOREIGN_KEY
constraint.- Returns:
- the name of the referenced table for a FOREIGN_KEY constraint.
-
addRefColumn
public void addRefColumn(java.lang.String columnName)
Add a reference-column to aTableConstraintType.FOREIGN_KEY
constraint. This specifies the column that constrains the values in the column. For column-level constraints, only a single column may be specified. For table-level constraints, one or more columns may be specified.- Parameters:
columnName
- the column referenced in the constraint- Throws:
java.lang.NullPointerException
- if columnName is nulljava.lang.IllegalStateException
- if this constraint is not a foreign-key constraint, or if this is a column-constraint and there is already one reference-column specified- Design Note:
- (donnie) Column names are checked for existence and uniqueness
when initializing the corresponding objects for storage on the
table schema. See
Schema.addCandidateKey(edu.caltech.nanodb.relations.KeyColumnRefs)
andSchema.addForeignKey(edu.caltech.nanodb.relations.ForeignKeyColumnRefs)
for details.
-
getRefColumnNames
public java.util.List<java.lang.String> getRefColumnNames()
-
setOnDeleteOption
public void setOnDeleteOption(ForeignKeyValueChangeOption f)
Add an ON DELETE option to aTableConstraintType.FOREIGN_KEY
constraint.- Parameters:
f
- theForeignKeyValueChangeOption
to set for ON DELETE behavior- Throws:
java.lang.IllegalStateException
- if this constraint is not a foreign-key constraint
-
getOnDeleteOption
public ForeignKeyValueChangeOption getOnDeleteOption()
Returns the ON DELETEForeignKeyValueChangeOption
for aTableConstraintType.FOREIGN_KEY
constraint.- Returns:
- the ON DELETE
ForeignKeyValueChangeOption
-
setOnUpdateOption
public void setOnUpdateOption(ForeignKeyValueChangeOption f)
Add an ON UPDATE option to aTableConstraintType.FOREIGN_KEY
constraint.- Parameters:
f
- theForeignKeyValueChangeOption
to set for ON UPDATE behavior- Throws:
java.lang.IllegalStateException
- if this constraint is not a foreign-key constraint
-
getOnUpdateOption
public ForeignKeyValueChangeOption getOnUpdateOption()
Returns the ON UPDATEForeignKeyValueChangeOption
for aTableConstraintType.FOREIGN_KEY
constraint.- Returns:
- the ON UPDATE
ForeignKeyValueChangeOption
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-