Question: Complete the following DBTable class BTree class. The DBTable class implements the basic parts of a database table. The BTree class implements a B+ Tree.

Complete the following DBTable class BTree class. The DBTable class implements the basic parts of a database table. The BTree class implements a B+ Tree. The DBTable must use the B+Tree to find rows in the table. Every DBTable method will use Btree.

//Implement DBTable class

public class DBTable {

RandomAccessFile rows; //the file that stores the rows in the table

long free; //head of the free list space for rows

int numOtherFields;

int otherFieldLengths[];

//add other instance variables as needed

private class Row {

private int keyField;

private char otherFields[][];

/*

Each row consists of unique key and one or more character array fields.

Each character array field is a fixed length field (for example 10

characters).

Each field can have a different length.

Fields are padded with null characters so a field with a length of

of x characters always uses space for x characters.

*/

//Constructors and other Row methods

}

public DBTable(String filename, int fL[], int bsize ) {

/*

Use this constructor to create a new DBTable.

filename is the name of the file used to store the table

fL is the lengths of the otherFields

fL.length indicates how many other fields are part of the row

bsize is the block size. It is used to calculate the order of the B+Tree

A B+Tree must be created for the key field in the table

If a file with name filename exists, the file should be deleted before the

new file is created.

*/

}

public DBTable(String filename) {

//Use this constructor to open an existing DBTable

}

public boolean insert(int key, char fields[][]) {

//PRE: the length of each row is fields matches the expected length

/*

If a row with the key is not in the table, the row is added and the method

returns true otherwise the row is not added and the method returns false.

The method must use the B+tree to determine if a row with the key exists.

If the row is added the key is also added into the B+tree.

*/

return false;

}

public boolean remove(int key) {

/*

If a row with the key is in the table it is removed and true is returned

otherwise false is returned.

The method must use the B+Tree to determine if a row with the key exists.

If the row is deleted the key must be deleted from the B+Tree

*/

return false;

}

public LinkedList search(int key) {

/*

If a row with the key is found in the table return a list of the other fields in

the row.

The string values in the list should not include the null characters.

If a row with the key is not found return an empty list

The method must use the equality search in B+Tree

*/

}

public LinkedList> rangeSearch(int low, int high) {

//PRE: low <= high

/*

For each row with a key that is in the range low to high inclusive a list

of the fields (including the key) in the row is added to the list

returned by the call.

If there are no rows with a key in the range return an empty list

The method must use the range search in B+Tree

*/

}

public void print() {

//Print the rows to standard output is ascending order (based on the keys)

//One row per line

}

public void close() {

//close the DBTable. The table should not be used after it is closed

}

} -------------------------------------------------------------------------------------------- //Implement BTree class

import java.io.RandomAccessFile;

import java.util.LinkedList;

public class BTree {

RandomAccessFile f;

int order;

int blockSize;

long root;

long free;

//add instance variables as needed.

private class BTreeNode {

private int count;

private int keys[];

private long children[];

private long address; //the address of the node in the file

//constructors and other method

}

public BTree(String filename, int bsize) {

//bsize is the block size. This value is used to calculate the order

//of the B+Tree

//all B+Tree nodes will use bsize bytes

//makes a new B+tree

}

public BTree(String filename) {

//open an existing B+Tree

}

public boolean insert(int key, long addr) {

/*

If key is not a duplicate add, key to the B+tree

addr (in DBTable) is the address of the row that contains the key

return true if the key is added

return false if the key is a duplicate

*/

return false;

}

public long remove(int key) {

/*

If the key is in the Btree, remove the key and return the address of the

row return 0 if the key is not found in the B+tree

*/

return 0;

}

public long search(int k) {

/*

This is an equality search

If the key is found return the address of the row with the key

otherwise return 0

*/

return 0;

}

public LinkedList rangeSearch(int low, int high){

//PRE: low <= high

/*

return a list of row addresses for all keys in the range low to high inclusive

return an empty list when no keys are in the range

*/

LinkedList list = new LinkedList<>();

return list;

}

public void print() {

//print the B+Tree to standard output

//print one node per line

//This method can be helpful for debugging

}

public void close() {

//close the B+tree. The tree should not be accessed after close is called

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!