Reputation: 73
I have been tasked with designing a database engine. I don't have to implement code at all, only design (psuedocode, sequence diagrams, etc). I have been given the methods and am looking for any help to further understand what it is I am doing. Below is what I have got so far, any help is greatly appreciated. This is a homework assignment, not looking for any answers just more insight on how I can better understand designing this software.
DB Methods:
Static void createDB(String dbName):
Create a new folder on disk (i.e.: stored as c:/dbName) This folder will be the root of the database; inside it will consist of tables and indexes >(files)static void deleteDB(String dbName):
for(FolderName in disk folder (c:/) ) if(folderName == dbName) remove from diskstatic Database openDB(String dbName)
void closeDB()
Table createTable(String tableName, long recordSize):
Create new file within database folder tableName Create a header within the file storing the record size This file is an array of bytes, the record size will tell me how big the objects stored in >this table are. (i.e: if the file is 105 bytes total. I know my header is 5 bytes, so every >10 bytes after the header (15, 25, 35 …) is an object within my tableTable getTable(String tableName)
In database folder, iterate through each file If(file name == tableName) Return Table (file)void deleteTable(String tableName)
in database folder, iterate through each file if(file name == tableName) remove table(file)Index createIndex(String indexName)
Index getIndex(String indexName)
void deleteIndex(String indexName)
Table methods:
long getRecordSize()
table is a file (byte[]) first line of file (byte[0]) is the header containing the recordSize return recordSizelong addRecord(byte[] record)
in header of table file get record size and number of objects in file write the record to the spot in the file (spot = (# of objects already in file * record size) >+ header size. (i.e: if header size = 5 bytes, record size = 10 bytes and I have 7 objects in >file already. . . the next object will be added at spot (7 * 10) + 5 = 75 )void removeRecord(long primaryKey)
byte[] getRecord(long primaryKey)
void updateRecord(long primaryKey, byte[] record)
void close()
Index methods:
Void addKey(String key, long value)
IteratorgetValues(String startKey, String endKey)
long deleteKey(String key)
void updateKey(String key, long value)
void close()
Upvotes: 0
Views: 253
Reputation: 91963
First you must understand that these methods are the external interface. You may very well do something more under the hood (spawning long- or shortlived objects in their own threads, have utility libraries and so on).
Start by modeling what you have, in a class diagram or some other way. Then try to understand how the interface is going to be used (maybe by writing some detailed use cases?). I have found CRC cards to be very useful at this step since they make it easy to move things around, look at single classes at a time and so on.
When you understand the system try to figure out what you need in terms of back-end functionality and functions, extend your class diagram with new classes until you have covered everything.
Be prepared to do changes when you start with the sequence diagrams. You may very well catch problems with your initial model during the rest of the work, and it is often useful to solve such problems rather than trying to work around them/ignoring them.
Upvotes: 1