Package edu.caltech.nanodb.storage
Class IndexedTableManager
- java.lang.Object
-
- edu.caltech.nanodb.storage.IndexedTableManager
-
- All Implemented Interfaces:
TableManager
public class IndexedTableManager extends java.lang.Object implements TableManager
This class provides an implementation of theTableManager
interface for tables that can have indexes and constraints on them.
-
-
Field Summary
Fields Modifier and Type Field Description private static org.apache.logging.log4j.Logger
logger
A logging object for reporting anything interesting that happens.private java.util.HashMap<java.lang.String,TableInfo>
openTables
private StorageManager
storageManager
-
Constructor Summary
Constructors Constructor Description IndexedTableManager(StorageManager storageManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
analyzeTable(TableInfo tableInfo)
This function analyzes the specified table, and updates the table's statistics to be the most up-to-date values.void
closeTable(TableInfo tableInfo)
This method closes a table file that is currently open, flushing any dirty pages to the table's storage in the process.TableInfo
createTable(java.lang.String tableName, Schema schema, CommandProperties properties)
Creates a new table file with the table-name and schema specified in the passed-inTableInfo
object.void
dropTable(java.lang.String tableName)
Drops the specified table from the database.private java.lang.String
getTableFileName(java.lang.String tableName)
This method takes a table name and returns a filename string that specifies where the table's data is stored.java.util.Set<java.lang.String>
getTables()
Returns a set of the names of the tables available.TableInfo
openTable(java.lang.String tableName)
This method opens the data file corresponding to the specified table name and reads in the table's schema.void
saveTableInfo(TableInfo tableInfo)
This method saves the schema and other details of a table into the backing table file, using the schema and other details specified in the passed-inTableInfo
object.boolean
tableExists(java.lang.String tableName)
Returns true if the specified table exists, or false otherwise.
-
-
-
Field Detail
-
logger
private static org.apache.logging.log4j.Logger logger
A logging object for reporting anything interesting that happens.
-
storageManager
private StorageManager storageManager
-
openTables
private java.util.HashMap<java.lang.String,TableInfo> openTables
-
-
Constructor Detail
-
IndexedTableManager
IndexedTableManager(StorageManager storageManager)
-
-
Method Detail
-
getTableFileName
private java.lang.String getTableFileName(java.lang.String tableName)
This method takes a table name and returns a filename string that specifies where the table's data is stored.- Parameters:
tableName
- the name of the table to get the filename of- Returns:
- the name of the file that holds the table's data
-
getTables
public java.util.Set<java.lang.String> getTables()
Description copied from interface:TableManager
Returns a set of the names of the tables available.- Specified by:
getTables
in interfaceTableManager
- Returns:
- a list of table names
-
tableExists
public boolean tableExists(java.lang.String tableName)
Description copied from interface:TableManager
Returns true if the specified table exists, or false otherwise.- Specified by:
tableExists
in interfaceTableManager
- Parameters:
tableName
- the name of the table to check for existence- Returns:
true
if the specified table exists, orfalse
if it doesn't exist
-
createTable
public TableInfo createTable(java.lang.String tableName, Schema schema, CommandProperties properties)
Description copied from interface:TableManager
Creates a new table file with the table-name and schema specified in the passed-inTableInfo
object. Additional details such as the data file and the table manager are stored into the passed-inTableInfo
object upon successful creation of the new table.- Specified by:
createTable
in interfaceTableManager
-
saveTableInfo
public void saveTableInfo(TableInfo tableInfo)
Description copied from interface:TableManager
This method saves the schema and other details of a table into the backing table file, using the schema and other details specified in the passed-inTableInfo
object. It is used to initialize new tables, and also to update tables when their schema changes.- Specified by:
saveTableInfo
in interfaceTableManager
- Parameters:
tableInfo
- This object is an in/out parameter. It is used to specify the name and schema of the new table being created. When the table is successfully created, the object is updated with the actual file that the table's schema and data are stored in.
-
openTable
public TableInfo openTable(java.lang.String tableName)
Description copied from interface:TableManager
This method opens the data file corresponding to the specified table name and reads in the table's schema. If the table is already open then the cached data is simply returned. If no such table exists,null
is returned.- Specified by:
openTable
in interfaceTableManager
- Parameters:
tableName
- the name of the table to open. This is generally whatever was specified in a SQL statement that references the table.- Returns:
- an object that holds the details of the open table, or
null
if the table does not exist.
-
analyzeTable
public void analyzeTable(TableInfo tableInfo)
Description copied from interface:TableManager
This function analyzes the specified table, and updates the table's statistics to be the most up-to-date values.- Specified by:
analyzeTable
in interfaceTableManager
- Parameters:
tableInfo
- the opened table to analyze.
-
closeTable
public void closeTable(TableInfo tableInfo)
Description copied from interface:TableManager
This method closes a table file that is currently open, flushing any dirty pages to the table's storage in the process.- Specified by:
closeTable
in interfaceTableManager
- Parameters:
tableInfo
- the table to close
-
dropTable
public void dropTable(java.lang.String tableName)
Description copied from interface:TableManager
Drops the specified table from the database.- Specified by:
dropTable
in interfaceTableManager
- Parameters:
tableName
- the name of the table to drop
-
-