File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes URLyBird Data Access Package Design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "URLyBird Data Access Package Design" Watch "URLyBird Data Access Package Design" New topic

URLyBird Data Access Package Design

Bharat Ruparel
Ranch Hand

Joined: Jul 30, 2003
Posts: 493
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 class which belongs to version 1): (interface), (implements DBClient interface and contains a private reference to: ),, and finally 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 directly compares to the interface in his book. Next, the assignment states that this interface must be implemented by a class called ""; will it then correspond to the class? If yes, then I need to create another class that does the work of class in Max's book (I am thinking of calling it simply As in Max's book, the class will contain a private reference to and delegate the actual work to be done to it (so far so good?). What will then correspond to class? Is it an instance of (short for Hotel Room)? If yes, then there the interface 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 class with 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();
if (ch == 0)
more = false;
p_in.skipBytes(p_size - i);
return b.toString();
Bharat Ruparel

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Welcome to JavaRanch, Bharat. Congrats on taking on the assignment and wish you good luck and we are all here to help.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Bharat Ruparel
Ranch Hand

Joined: Jul 30, 2003
Posts: 493
Thanks Mark. Phil is already helping me getting off the block. You guys are great.
Since my first post here, I have been browsing through the forum and am beginning to see some answers to my own questions: It looks like Max has answered the questions that I raise here on the Post "No need for a locking manager?" Here is the quote where I think he answers these questions:
"Regardless of where it should be from an aesthetic level, my feeling is that Sun intended for the locking control to reside inside Data, because they put the locking method signature inside the Data class. Thus, I think you're coloring outside the lines a bit if you don't do that. This is just my opinion, of course. But I think Data is really supposed to be your low level DB API.
Further, I don't think that Data class should be dependent on the connection class at all: As a matter of fact, I don't think that Data should know anything at all about the Connection class. nadda, zip, zilch. IMO, Data should simply be a private member variable of what you're referring as the Connector class(I might refer to it as a Mediator or Adapter). Thus, Connector has a method called, say, lockRec. internally, the lockRec method uses the private member variable Data(one per Connector) to lock the record.
In this scenario, you don't need a lock manager at all, because the Data object handles it's own internal problems and conflicts, like a good object is supposed to. The way is does this is through a static Hashmap. The role of Data here is to make the Connector(Adaptor/Mediator, whatever), feel like the world is simply, sun shiny place to be, and that complexity is just a bad dream. This way, Connector can just be a happy, go lucky, simple remote object."
Reading through this I realize that here is the correspodance between URLyBird and Max's DVD Project
---------------------------------------------- corresponds to
Need to create an adapater class ( in URLyBird which does the job of in Max's book.
Sounds good?
I don't know why people didn't respond to this thread? May be I need to be more precise?
Philippe Maquet

Joined: Jun 02, 2003
Posts: 1872
Hi Bharat,
I don't know why people didn't respond to this thread? May be I need to be more precise?

Maybe yes ;-) (in this thread anyway, because you saw in other ones of you that people reply to you !)
About the locking, I would say yes, Data must be responsible for it. It means that it must at least be the entry point of any lock/unlock method. It doesn't go against a LockManager class (one solution among other ones), because if you use one, Data just delegates its job to it (for the external world, Data is the only visible class if you prefer). You may apply it for other "data stuff" : if you implement a cache, you may decide to code all the caching stuff in Data itself or decide to create some DataCache separate class (package level) because you feel it easier to design and maintain. It's just personal taste.
Thus, Connector has a method called, say, lockRec. internally, the lockRec method uses the private member variable Data(one per Connector) to lock the record.

I suppose that what you call "Connector" is what I call my business tier (which has no name yet for me ). If it's the case, I think that some "lockRec" method is to "low-level" for it. In URLyBird, I just see two methods : book() and find().
Bharat Ruparel
Ranch Hand

Joined: Jul 30, 2003
Posts: 493
Thanks again Phil.
Bharat Ruparel
Ranch Hand

Joined: Jul 30, 2003
Posts: 493
Hello Phil,
I am back with follow-up questions. In early bird assignment (I have URLyBird 1.3.1). It says that must implement Interface. Further, the interface shows create method as throwing DuplicateKey exception.
My question is: what is the key here? is the Record Number? The reason I say that is that the return value of create is shown as int. Moreover, the remaining CRUD methods, i.e., read, update, delete all take Record Number as a parameter. Will the system (meaning my program) generate the record number? Is it simply the number of existing records in the file plus 1 ? Since record number is not explicitly stored in the file, how can there be a duplicate key violation?
I agree. Here's the link:
subject: URLyBird Data Access Package Design
jQuery in Action, 3rd edition