All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.infoplace.simpledb.DB

java.lang.Object
   |
   +----com.infoplace.simpledb.DB

public class DB
extends Object
This class implements a database based on relational model. It is a collection of tables with schema. The first column of a table is always assumed to be the primary key, no other column can be a key. All the columns are type aware, see the documentation for DBTable for the details. The database uses hashing mechanism for indexing the records. The records of a table are distributed into multiple files. The database works excellent for small tables, upto 25,000 records per table. All database operations are thread safe within the same process. Currently, inter-process data-locking is not yet implemented. Therefore, if you have two process inserting records into the database, there is no gaurantee that both insertion will be reflected in the database. But this will work fine within a same process using multiple threads. This inter-process limitation is due to lack of 'file-lock' functionality in java.

The table, represented by object DBTable, allows standard operations, like, insert, retreive, update, remove, and find records.

The database supports the standard operations like:

See Also:
DBTable, DBIterator, DBException

Variable Index

 o kReadOnlyMode
This defines the database read-only access mode.
 o kReadWriteMode
This defines the database read-write access mode.

Constructor Index

 o DB(String, String)
Create a new database.
 o DB(String, String, byte)
Open an existing database.

Method Index

 o close()
Close an existing database.
 o createTable(String, String[], String[], int)
Create a new database table.
 o createTable(String, String[], String[], int, String, String)
Create a new database table.
 o delete(String, String)
Delete the whole database.
 o deleteTable(String)
Delete a databse table.
 o exists(String, String)
Check for existence of the database.
 o existsTable(String)
Check for existence of a database table.
 o getName()
Get the database name.
 o getPathName()
Get the database pathname.
 o getTables()
Get all the tables in the database.
 o openTable(String)
Open an existing database table.

Variables

 o kReadOnlyMode
 public static final byte kReadOnlyMode
This defines the database read-only access mode.

 o kReadWriteMode
 public static final byte kReadWriteMode
This defines the database read-write access mode.

Constructors

 o DB
 public DB(String name,
           String pathname,
           byte mode) throws DBException
Open an existing database. This constructor will open a database of the given name.

Parameters:
name - Name of the database to be opened
pathname - File path to the directory where database exists
mode - Defines the database access mode, defined by kReadOnlyMode and kReadWriteMode
Throws: DBException
When database does not exists or an io error, look at the getMessage() value for exact error
 o DB
 public DB(String name,
           String pathname) throws DBException
Create a new database. This constructor will create a new database of the given name.

Parameters:
name - Name of the database to be created.
pathname - File path to the directory where database needs to be created.
Throws: DBException
When a database of same name already exists or an io error, look at the getMessage() value for exact error.

Methods

 o getName
 public String getName()
Get the database name.

 o getPathName
 public String getPathName()
Get the database pathname.

 o exists
 public static synchronized boolean exists(String name,
                                           String pathname)
Check for existence of the database.

Parameters:
name - Name of the database
pathname - File path to the directory where database may exists
Returns:
true If the database exists. Otherwise, false.
 o delete
 public static synchronized void delete(String name,
                                        String pathname) throws DBException
Delete the whole database. This deletes all the tables in the database too. Exercise caution when using this method.

Parameters:
name - Name of the database
pathname - File path to the directory where database exists
Throws: DBException
When a database does not exists or an io error, look at the getMessage() value for exact error
 o close
 public synchronized void close() throws DBException
Close an existing database. Once the database is closed, the database object and all the table objects becomes stale. No operation is allowed on stale object, a DBException is thrown on any operation.

Throws: DBException
When the object is stale, look at the getMessage() value for exact error
 o createTable
 public synchronized DBTable createTable(String name,
                                         String columns[],
                                         String types[],
                                         int maxRecords) throws DBException
Create a new database table.

Parameters:
name - Name of the table to create.
columns - An array of column names.
types - An array of column types, the types corresponds to the columns being defined, see DBTable for the column types.
maxRecords - Guess the maximum number of records in the table. This data is used to compute the optimal number of hash buckets.
Returns:
The table object representing the new table.
Throws: DBException
When a database table of same name already exists or an io error, look at the getMessage() value for exact error.
 o createTable
 public synchronized DBTable createTable(String name,
                                         String columns[],
                                         String types[],
                                         int maxRecords,
                                         String columnSeparator,
                                         String valueSeparator) throws DBException
Create a new database table. This one is same as the other createTable, except that it takes additional two arguments to customize column and value separator strings. The column separator defaults to DBTable.kColumnSeparator and the value separator defaults to DBTable.kvalueSeparator. These attributes are maintained at each table level.

Throws: DBException
When a database table of same name already exists or an io error, look at the getMessage() value for exact error.
 o openTable
 public synchronized DBTable openTable(String name) throws DBException
Open an existing database table.

Parameters:
name - Name of the table to open.
Returns:
The table object representing the opened table.
Throws: DBException
When the database table does not exists or an io error, look at the getMessage() value for exact error.
 o deleteTable
 public synchronized void deleteTable(String name) throws DBException
Delete a databse table.

Parameters:
name - Name of the table to delete.
Throws: DBException
When the database table does not exists or an io error, look at the getMessage() value for exact error.
 o existsTable
 public synchronized boolean existsTable(String name) throws DBException
Check for existence of a database table.

Parameters:
name - Name of the table to open.
Returns:
If the table exists then true. Otherwise false.
Throws: DBException
When the database object is stale, look at the getMessage() value for exact error.
 o getTables
 public synchronized Vector getTables() throws DBException
Get all the tables in the database.

Returns:
The vector object contains DBTable objects, corresponding to the tables in the database.
Throws: DBException
When the database object is stale, look at the getMessage() value for exact error.

All Packages  Class Hierarchy  This Package  Previous  Next  Index