Class InsertCommand


  • public class InsertCommand
    extends QueryCommand
    This command object represents a top-level INSERT command issued against the database. INSERT commands have two forms. The first form is INSERT ... VALUES, in which case a literal tuple-value is specified and stored. The second form is INSERT ... SELECT, in which case a select-clause object is evaluated, and its results are stored into the specified table.
    See Also:
    TupleLiteral, SelectClause
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  InsertCommand.TupleInserter
      An implementation of the tuple processor interface used by the InsertCommand to insert tuples into a table, when the command is of the form INSERT ...
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<java.lang.String> colNames
      An optional list of column-names that can be specified in the INSERT command.
      private SelectClause selClause
      When the insert command is of the form INSERT ...
      private TableInfo tableInfo
      The table that the data will be inserted into, once it has been opened.
      private java.lang.String tableName
      The name of the table that the data will be inserted into.
      private java.util.List<Expression> values
      When the insert command is of the form INSERT ...
      • Fields inherited from class edu.caltech.nanodb.commands.Command

        out
    • Constructor Summary

      Constructors 
      Constructor Description
      InsertCommand​(java.lang.String tableName, java.util.List<java.lang.String> colNames, SelectClause selClause)
      Constructs a new insert command for INSERT ...
      InsertCommand​(java.lang.String tableName, java.util.List<java.lang.String> colNames, java.util.List<Expression> values)
      Constructs a new insert command for INSERT ...
    • Field Detail

      • tableName

        private java.lang.String tableName
        The name of the table that the data will be inserted into.
      • colNames

        private java.util.List<java.lang.String> colNames
        An optional list of column-names that can be specified in the INSERT command. If the INSERT command didn't specify a list of column-names then this will be null.
      • values

        private java.util.List<Expression> values
        When the insert command is of the form INSERT ... VALUES, the literal values are stored in this variable. Otherwise this will be set to null.
      • selClause

        private SelectClause selClause
        When the insert command is of the form INSERT ... SELECT, the details of the select-clause are stored in this variable. Otherwise this will be set to null.
      • tableInfo

        private TableInfo tableInfo
        The table that the data will be inserted into, once it has been opened.
    • Constructor Detail

      • InsertCommand

        public InsertCommand​(java.lang.String tableName,
                             java.util.List<java.lang.String> colNames,
                             java.util.List<Expression> values)
        Constructs a new insert command for INSERT ... VALUES statements.
      • InsertCommand

        public InsertCommand​(java.lang.String tableName,
                             java.util.List<java.lang.String> colNames,
                             SelectClause selClause)
        Constructs a new insert command for INSERT ... SELECT statements.
    • Method Detail

      • getTableName

        public java.lang.String getTableName()
      • getColNames

        public java.util.List<java.lang.String> getColNames()
      • getValues

        public java.util.List<Expression> getValues()
      • prepareQueryPlan

        protected void prepareQueryPlan​(NanoDBServer server)
        Description copied from class: QueryCommand
        Prepares an execution plan for generating the tuples that this query command will operate on. Since the specific plan to generate depends on the operation being performed, this is an abstract method to be implemented by subclasses. For example, SELECTs support very sophisticated operations and thus require complex plans, but a DELETE operation simply requires a scan over a tuple file, perhaps with a predicate applied.
        Specified by:
        prepareQueryPlan in class QueryCommand
        Parameters:
        server - the server to use for planning, fetching table schemas, statistics, and other details relevant for planning
      • getTupleProcessor

        protected TupleProcessor getTupleProcessor​(EventDispatcher eventDispatcher)
        Description copied from class: QueryCommand
        Creates a tuple-processor responsible for dealing with the tuples that are generated by the query command. Depending on the operation being performed, different tuple-processors are appropriate. For example, the SELECT processor sends the tuples to the console or to a remote client; the DELETE processor deletes the tuples from the referenced table.
        Specified by:
        getTupleProcessor in class QueryCommand
        Parameters:
        eventDispatcher - used for notifying other components in the database when rows are inserted/updated/deleted
        Returns:
        the tuple processor to use in processing tuples generated by the query
      • toString

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