1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package edu.caltech.nanodb.commands;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import edu.caltech.nanodb.server.NanoDBServer;
/**
* This Command class represents the <tt>OPTIMIZE</tt> SQL command, which
* optimizes a table's representation (along with any indexes) to improve access
* performance and space utilization. This is not a standard SQL command.
*/
public class OptimizeCommand extends Command {
/**
* Table names are kept in a set so that we don't need to worry about a
* particular table being specified multiple times.
*/
private LinkedHashSet<String> tableNames;
/**
* Construct a new <tt>OPTIMIZE</tt> command with an empty table list.
* Tables can be added to the internal list using the {@link #addTable}
* method.
*/
public OptimizeCommand() {
super(Command.Type.UTILITY);
tableNames = new LinkedHashSet<>();
}
/**
* Construct a new <tt>OPTIMIZE</tt> command to optimize the specified
* table.
*
* @param tableName the name of the table to optimize.
*/
public OptimizeCommand(String tableName) {
this();
addTable(tableName);
}
/**
* Add a table to the list of tables to optimize.
*
* @param tableName the name of the table to optimize.
*/
public void addTable(String tableName) {
if (tableName == null)
throw new NullPointerException("tableName cannot be null");
tableNames.add(tableName);
}
/**
* Returns the set of tables to optimize in an unmodifiable set.
*
* @return the set of tables to optimize in an unmodifiable set.
*/
public Set<String> getTableNames() {
return Collections.unmodifiableSet(tableNames);
}
@Override
public void execute(NanoDBServer server) throws ExecutionException {
throw new ExecutionException("Not yet implemented!");
}
/**
* Prints a simple representation of the optimize command, including the
* names of the tables to be optimized.
*
* @return a string representing this optimize command
*/
@Override
public String toString() {
return "Optimize[" + tableNames + "]";
}
}