Package edu.caltech.nanodb.commands
Class InsertCommand
- java.lang.Object
-
- edu.caltech.nanodb.commands.Command
-
- edu.caltech.nanodb.commands.QueryCommand
-
- edu.caltech.nanodb.commands.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 theInsertCommand
to insert tuples into a table, when the command is of the form INSERT ...-
Nested classes/interfaces inherited from class edu.caltech.nanodb.commands.QueryCommand
QueryCommand.Type
-
-
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 formINSERT ...
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 formINSERT ...
-
Fields inherited from class edu.caltech.nanodb.commands.QueryCommand
explain, plan
-
-
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 ...
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
execute(NanoDBServer server)
Actually performs the command.java.util.List<java.lang.String>
getColNames()
SelectClause
getSelectClause()
java.lang.String
getTableName()
protected TupleProcessor
getTupleProcessor(EventDispatcher eventDispatcher)
Creates a tuple-processor responsible for dealing with the tuples that are generated by the query command.java.util.List<Expression>
getValues()
private void
insertSingleRow(NanoDBServer server)
This method is used when inserting only a single row of data.protected void
prepareQueryPlan(NanoDBServer server)
Prepares an execution plan for generating the tuples that this query command will operate on.java.lang.String
toString()
-
Methods inherited from class edu.caltech.nanodb.commands.QueryCommand
setExplain
-
Methods inherited from class edu.caltech.nanodb.commands.Command
getCommandType
-
-
-
-
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 benull
.
-
values
private java.util.List<Expression> values
When the insert command is of the formINSERT ... VALUES
, the literal values are stored in this variable. Otherwise this will be set tonull
.
-
selClause
private SelectClause selClause
When the insert command is of the formINSERT ... SELECT
, the details of the select-clause are stored in this variable. Otherwise this will be set tonull
.
-
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()
-
getSelectClause
public SelectClause getSelectClause()
-
execute
public void execute(NanoDBServer server) throws ExecutionException
Description copied from class:Command
Actually performs the command.- Overrides:
execute
in classQueryCommand
- Throws:
ExecutionException
- if an issue occurs during command execution
-
insertSingleRow
private void insertSingleRow(NanoDBServer server) throws ExecutionException
This method is used when inserting only a single row of data.- Throws:
ExecutionException
-
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 classQueryCommand
- 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 classQueryCommand
- 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 classjava.lang.Object
-
-