simpledb
Class Catalog

java.lang.Object
  extended by simpledb.Catalog

public class Catalog
extends java.lang.Object

The Catalog keeps track of all available tables in the database and their associated schemas. For now, this is a stub catalog that must be populated with tables by a user program before it can be used -- eventually, this should be converted to a catalog that reads a catalog table from disk.


Constructor Summary
Catalog()
          Constructor.
 
Method Summary
 void addTable(DbFile file)
          Add a new table to the catalog.
 void addTable(DbFile file, java.lang.String name)
           
 void addTable(DbFile file, java.lang.String name, java.lang.String pkeyField)
          Add a new table to the catalog.
 void clear()
          Delete all tables from the catalog
 DbFile getDbFile(int tableid)
          Returns the DbFile that can be used to read the contents of the specified table.
 java.lang.String getPrimaryKey(int tableid)
           
 int getTableId(java.lang.String name)
          Return the id of the table with a specified name,
 java.lang.String getTableName(int id)
           
 TupleDesc getTupleDesc(int tableid)
          Returns the tuple descriptor (schema) of the specified table
 void loadSchema(java.lang.String catalogFile)
          Reads the schema from a file and creates the appropriate tables in the database.
 java.util.Iterator<java.lang.Integer> tableIdIterator()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Catalog

public Catalog()
Constructor. Creates a new, empty catalog.

Method Detail

addTable

public void addTable(DbFile file,
                     java.lang.String name,
                     java.lang.String pkeyField)
Add a new table to the catalog. This table's contents are stored in the specified DbFile.

Parameters:
file - the contents of the table to add; file.getId() is the identfier of this file/tupledesc param for the calls getTupleDesc and getFile
name - the name of the table -- may be an empty string. May not be null. If a name
pkeyField - the name of the primary key field conflict exists, use the last table to be added as the table for a given name.

addTable

public void addTable(DbFile file,
                     java.lang.String name)

addTable

public void addTable(DbFile file)
Add a new table to the catalog. This table has tuples formatted using the specified TupleDesc and its contents are stored in the specified DbFile.

Parameters:
file - the contents of the table to add; file.getId() is the identfier of this file/tupledesc param for the calls getTupleDesc and getFile

getTableId

public int getTableId(java.lang.String name)
               throws java.util.NoSuchElementException
Return the id of the table with a specified name,

Throws:
java.util.NoSuchElementException - if the table doesn't exist

getTupleDesc

public TupleDesc getTupleDesc(int tableid)
                       throws java.util.NoSuchElementException
Returns the tuple descriptor (schema) of the specified table

Parameters:
tableid - The id of the table, as specified by the DbFile.getId() function passed to addTable
Throws:
java.util.NoSuchElementException - if the table doesn't exist

getDbFile

public DbFile getDbFile(int tableid)
                 throws java.util.NoSuchElementException
Returns the DbFile that can be used to read the contents of the specified table.

Parameters:
tableid - The id of the table, as specified by the DbFile.getId() function passed to addTable
Throws:
java.util.NoSuchElementException

getPrimaryKey

public java.lang.String getPrimaryKey(int tableid)

tableIdIterator

public java.util.Iterator<java.lang.Integer> tableIdIterator()

getTableName

public java.lang.String getTableName(int id)

clear

public void clear()
Delete all tables from the catalog


loadSchema

public void loadSchema(java.lang.String catalogFile)
Reads the schema from a file and creates the appropriate tables in the database.

Parameters:
catalogFile -