Class QueryCommand

  • Direct Known Subclasses:
    DeleteCommand, InsertCommand, SelectCommand, UpdateCommand

    public abstract class QueryCommand
    extends Command
    This class represents all SQL query commands, including SELECT, INSERT, UPDATE, and DELETE. The main difference between these commands is simply what happens with the tuples that are retrieved from the database.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  QueryCommand.Type
      Typesafe enumeration of query-command types.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean explain
      If this flag is true then the command is to be explained only.
      private static org.apache.logging.log4j.Logger logger
      A logging object for reporting anything interesting that happens.
      protected PlanNode plan  
      private QueryCommand.Type queryType
      The type of this query command, from the QueryCommand.Type enum.
      • Fields inherited from class edu.caltech.nanodb.commands.Command

        out
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected QueryCommand​(QueryCommand.Type queryType)
      Initializes a new query-command object.
    • Field Detail

      • logger

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

        protected boolean explain
        If this flag is true then the command is to be explained only. Otherwise the command is to be executed normally.
    • Constructor Detail

      • QueryCommand

        protected QueryCommand​(QueryCommand.Type queryType)
        Initializes a new query-command object.
        Parameters:
        queryType - the kind of query command that is being executed
    • Method Detail

      • setExplain

        public void setExplain​(boolean f)
      • execute

        public void execute​(NanoDBServer server)
        Description copied from class: Command
        Actually performs the command.
        Specified by:
        execute in class Command
      • prepareQueryPlan

        protected abstract void prepareQueryPlan​(NanoDBServer server)
        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.
        Parameters:
        server - the server to use for planning, fetching table schemas, statistics, and other details relevant for planning
      • getTupleProcessor

        protected abstract TupleProcessor getTupleProcessor​(EventDispatcher eventDispatcher)
        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.
        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