Hello,
I am a new member of JavaRanch. This is a fantastic forum which facilitates learning and certification process very effectively. I am currently working on the Developer's Exam project. I have gotten the URLyBird version 1.3.1 assignment. I have also purchased Max's book and have read through it in detail. I like the layered design approach presented in his book and want to pursue it unless otherwise advised for a good reason. I just want to run my understanding of design presented in his book by the group and see how it can be adapted for the URLyBird project. Any comments from anyone are appreciated.
I am currently focusing on the design of the Database Layer identified in Max's book by the package SampleProject.db in his version 2.0 implementation. It has the following four classes (excluding the DOSclient.java class which belongs to version 1): DBClient.java (interface), DVDDBAdapter.java (implements DBClient interface and contains a private reference to: ), DVDDatabase.java, and finally DVD.java representing a serializable widget that is stored in the database.
If we compare this to the URLyBird assignment then I see the following mapping between the two: First the package suncertify.db compares directly to the package SampleProject.db in Max's book. Next, the required interface given under the section Server in the assignment called DBMain.java directly compares to the DBClient.java interface in his book. Next, the assignment states that this interface must be implemented by a class called "Data.java"; will it then correspond to the DVDDBAdapter.java class? If yes, then I need to create another class that does the work of DVDDatabase.java class in Max's book (I am thinking of calling it simply Database.java). As in Max's book, the Data.java class will contain a private reference to Database.java and delegate the actual work to be done to it (so far so good?). What will then correspond to DVD.java class? Is it an instance of Room.java (short for Hotel Room)? If yes, then there the interface DBMain.java is NOT really defined in an object-oriented manner. Rather, it definitely has a File/Record orientation. There are several questions that come to my mind. For starters: all the CRUD (create, read, update, delete) methods communicate with the database using Record Numbers (recNo) and return/send the instance data as an array of
String rather than as an instance of Room object. Any problems with that? Next, if you consider the definition of the create method given in the interface (public int create(String [] data) throws DuplicateKeyException. My question is: what is the unique key here? is it the ID of the customer holding a room? Does it mean that there cannot be two records (not deleted) in the database with the same customer ID? Who generates this key? My program? Next, the interface also has all the locking methods, e.g., lock, unlock, and isLocked. As in Max's book, I am thinking of implementing the methods in Database.java class with Data.java adapter class simply delegating actual work to it, sounds good?
Let me know what you think.
By the way, on a different topic, the database schema presented in the Data File Format is a bit flawed (unless somebody corrects me here). I found that third field defined from the top, i.e., Maximum occupancy of this room (database field name is size) has a field length of 4 giving the impresssion that it is probably stored as an int. Not so, when i read it using RAF.readInt() method (RAF stands for RandomAccessFile), I got the ASCII value of the numbers. When I read it as a fixed-string that is 4 characters wide, I got the right result. Another thing to be aware of is that the deleted flag before the start of the actual record must still be read as a single byte using RAF.readByte() method. I found the following method very useful when reading the records off the file and am posting here since I see many posts that seem to be floundering around the same issue. I am not trying to give the code away, simpy pointing the gotchas and giving the basic building blocks.
static String readFixedString( RandomAccessFile p_in, short p_size) throws IOException {
StringBuffer b = new StringBuffer(p_size);
int i = 0;
boolean more = true;
while (more && i < p_size) {
char ch = (char) p_in.readByte();
i++;
if (ch == 0)
more = false;
else
b.append(ch);
}
p_in.skipBytes(p_size - i);
return b.toString();
}
Regards.
Bharat Ruparel