Class 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 Detail

      • name

        private java.lang.String name
        The optional name of the constraint, or null if no name was specified.
      • columnConstraint

        private boolean columnConstraint
        Flag indicating whether the constraint is specified at the table-level or at the column-level. A value of true indicates that it is a column-level constraint; a value of false indicates that it is a table-level constraint.
      • columnNames

        private java.util.List<java.lang.String> columnNames
        For TableConstraintType.UNIQUE and TableConstraintType.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
        For TableConstraintType.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
        For TableConstraintType.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.

    • 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.
      • 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 null
        java.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) and Schema.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 a TableConstraintType.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 null
        java.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 a TableConstraintType.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 a TableConstraintType.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 null
        java.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) and Schema.addForeignKey(edu.caltech.nanodb.relations.ForeignKeyColumnRefs) for details.
      • getRefColumnNames

        public java.util.List<java.lang.String> getRefColumnNames()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object