Class CreateTableCommand


  • public class CreateTableCommand
    extends Command
    This command handles the CREATE TABLE DDL operation.
    • Nested Class Summary

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<ColumnInfo> columnInfos
      List of column-declarations for the new table.
      private java.util.List<ConstraintDecl> constraints
      List of constraints for the new table.
      private boolean ifNotExists
      If this flag is true then the create-table operation should only be performed if the specified table doesn't already exist.
      private static org.apache.logging.log4j.Logger logger
      A logging object for reporting anything interesting that happens.
      private CommandProperties properties
      Any additional properties specified in the command.
      private java.lang.String tableName
      Name of the table to be created.
      private boolean temporary
      If this flag is true then the table is a temporary table.
      • Fields inherited from class edu.caltech.nanodb.commands.Command

        out
    • Constructor Summary

      Constructors 
      Constructor Description
      CreateTableCommand​(java.lang.String tableName)
      Create a new object representing a CREATE TABLE statement.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addColumn​(TableColumnDecl colDecl)
      Adds a column description to this create-table command.
      void addConstraint​(ConstraintDecl con)
      Adds a constraint to this create-table command.
      void execute​(NanoDBServer server)
      Actually performs the command.
      java.util.List<ColumnInfo> getColumns()
      Returns an immutable list of the column descriptions that are part of this CREATE TABLE command.
      java.util.List<ConstraintDecl> getConstraints()
      Returns an immutable list of the constraint declarations that are part of this CREATE TABLE command.
      boolean getIfNotExists()
      Returns true if table creation should only be attempted if it doesn't already exist, false if table creation should always be attempted.
      CommandProperties getProperties()
      Returns any additional properties specified for the command, or null if no additional properties were specified.
      private void initIndexes​(StorageManager storageManager, TableInfo tableInfo)  
      private void initTableConstraints​(StorageManager storageManager, Schema schema, java.util.HashMap<java.lang.String,​TableInfo> referencedTables)  
      boolean isTemporary()
      Returns true if the table is a temporary table, false otherwise.
      void setIfNotExists​(boolean b)
      Sets the flag indicating whether table creation should only be attempted if it doesn't already exist.
      void setProperties​(CommandProperties properties)
      Sets any additional properties associated with the command.
      void setTemporary​(boolean b)
      Specifies whether the table is a temporary table or not.
      java.lang.String toString()  
      java.lang.String toVerboseString()
      Returns a verbose, multi-line string containing all of the details of this table.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • logger

        private static org.apache.logging.log4j.Logger logger
        A logging object for reporting anything interesting that happens.
      • tableName

        private java.lang.String tableName
        Name of the table to be created.
      • temporary

        private boolean temporary
        If this flag is true then the table is a temporary table.
      • ifNotExists

        private boolean ifNotExists
        If this flag is true then the create-table operation should only be performed if the specified table doesn't already exist.
      • columnInfos

        private java.util.List<ColumnInfo> columnInfos
        List of column-declarations for the new table.
      • constraints

        private java.util.List<ConstraintDecl> constraints
        List of constraints for the new table.
      • properties

        private CommandProperties properties
        Any additional properties specified in the command.
    • Constructor Detail

      • CreateTableCommand

        public CreateTableCommand​(java.lang.String tableName)
        Create a new object representing a CREATE TABLE statement.
        Parameters:
        tableName - the name of the table to be created
    • Method Detail

      • isTemporary

        public boolean isTemporary()
        Returns true if the table is a temporary table, false otherwise.
        Returns:
        true if the table is a temporary table, false otherwise.
      • setTemporary

        public void setTemporary​(boolean b)
        Specifies whether the table is a temporary table or not.
        Parameters:
        b - true if the table is a temporary table, false otherwise.
      • getIfNotExists

        public boolean getIfNotExists()
        Returns true if table creation should only be attempted if it doesn't already exist, false if table creation should always be attempted.
        Returns:
        true if table creation should only be attempted if it doesn't already exist, false if table creation should always be attempted.
      • setIfNotExists

        public void setIfNotExists​(boolean b)
        Sets the flag indicating whether table creation should only be attempted if it doesn't already exist.
        Parameters:
        b - the flag indicating whether table creation should only be attempted if it doesn't already exist.
      • setProperties

        public void setProperties​(CommandProperties properties)
        Sets any additional properties associated with the command. The value may be null to indicate no properties.
        Parameters:
        properties - any additional properties to associate with the command.
      • getProperties

        public CommandProperties getProperties()
        Returns any additional properties specified for the command, or null if no additional properties were specified.
        Returns:
        any additional properties specified for the command, or null if no additional properties were specified.
      • addColumn

        public void addColumn​(TableColumnDecl colDecl)
        Adds a column description to this create-table command. This method is primarily used by the SQL parser.
        Parameters:
        colDecl - the details of the column to add
        Throws:
        java.lang.NullPointerException - if colDecl is null
      • getColumns

        public java.util.List<ColumnInfo> getColumns()
        Returns an immutable list of the column descriptions that are part of this CREATE TABLE command.
        Returns:
        an immutable list of the column descriptions that are part of this CREATE TABLE command.
      • addConstraint

        public void addConstraint​(ConstraintDecl con)
        Adds a constraint to this create-table command. This method is primarily used by the SQL parser.
        Parameters:
        con - the details of the table constraint to add
        Throws:
        java.lang.NullPointerException - if con is null
      • getConstraints

        public java.util.List<ConstraintDecl> getConstraints()
        Returns an immutable list of the constraint declarations that are part of this CREATE TABLE command.
        Returns:
        an immutable list of the constraint declarations that are part of this CREATE TABLE command.
      • initTableConstraints

        private void initTableConstraints​(StorageManager storageManager,
                                          Schema schema,
                                          java.util.HashMap<java.lang.String,​TableInfo> referencedTables)
      • toString

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

        public java.lang.String toVerboseString()
        Returns a verbose, multi-line string containing all of the details of this table.
        Returns:
        a detailed description of the table described by this command